|
| 1 | +use aiken/builtin.{bls12_381_final_verify, bls12_381_miller_loop} |
| 2 | +use aiken/crypto/bitwise.{State} |
| 3 | +use aiken/crypto/bls12_381/g1 |
| 4 | +use aiken/crypto/bls12_381/g2 |
| 5 | +use aiken/crypto/bls12_381/scalar.{Scalar} |
| 6 | + |
| 7 | +pub fn miller_loop(q: G1Element, p: G2Element) -> MillerLoopResult { |
| 8 | + bls12_381_miller_loop(q, p) |
| 9 | +} |
| 10 | + |
| 11 | +pub fn final_exponentiation( |
| 12 | + left: MillerLoopResult, |
| 13 | + right: MillerLoopResult, |
| 14 | +) -> Bool { |
| 15 | + bls12_381_final_verify(left, right) |
| 16 | +} |
| 17 | + |
| 18 | +test simple_miller_loop_with_final_exponentiation() { |
| 19 | + // prove: e(q^x, p^m) == e(q, p^m*x) |
| 20 | + let secret: State<Scalar> = scalar.from_int(44203) |
| 21 | + let public_value: G1Element = g1.generator |> g1.scale(secret) |
| 22 | + let message: ByteArray = #"acab" |
| 23 | + let domain_tag: ByteArray = "BLS-TEST" |
| 24 | + let challenge: G2Element = g2.hash_to_group(message, domain_tag) |
| 25 | + let witness: G2Element = |
| 26 | + g2.hash_to_group(message, domain_tag) |> g2.scale(secret) |
| 27 | + let left: MillerLoopResult = miller_loop(public_value, challenge) |
| 28 | + let right: MillerLoopResult = miller_loop(g1.generator, witness) |
| 29 | + final_exponentiation(left, right) |
| 30 | +} |
0 commit comments