Created
January 31, 2026 17:13
-
-
Save sug0/4d01b635b1975affa30ca252502641de to your computer and use it in GitHub Desktop.
BBS signatures demo (https://eprint.iacr.org/2023/275.pdf)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use bls12_381::{G1Affine, G2Affine, G2Prepared, Scalar, multi_miller_loop, pairing}; | |
| use group::Group; | |
| fn main() { | |
| // secret key | |
| let x: Scalar = 1234u64.into(); | |
| // public key | |
| let x_g: G2Affine = (G2Affine::generator() * x).into(); | |
| // message | |
| let m: Scalar = 420u64.into(); | |
| // signature | |
| let s: G1Affine = (G1Affine::generator() * (x + m).invert().unwrap()).into(); | |
| let x_g_plus_m_g: G2Affine = (x_g + G2Affine::generator() * m).into(); | |
| assert_eq!( | |
| pairing(&s, &x_g_plus_m_g), | |
| pairing(&G1Affine::generator(), &G2Affine::generator()), | |
| ); | |
| println!("verified pairing equation 1"); | |
| let g2_neg: G2Affine = (-G2Affine::generator()).into(); | |
| let g2_neg: G2Prepared = g2_neg.into(); | |
| assert!( | |
| multi_miller_loop(&[ | |
| (&s, &x_g_plus_m_g.into()), | |
| (&G1Affine::generator(), &g2_neg), | |
| ]) | |
| .final_exponentiation() | |
| .is_identity() | |
| .unwrap_u8() | |
| == 1 | |
| ); | |
| println!("verified pairing equation 2"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment