-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Template of test on groth_verify function
- Loading branch information
1 parent
7c73ead
commit 5fcb2a3
Showing
1 changed file
with
61 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,83 @@ | ||
use aiken.{G1Element, G2Element} // ,MillerLoopResult | ||
use aiken/builtin.{bls12_381_final_verify, bls12_381_miller_loop, bls12_381_g1_scalar_mul, bls12_381_g1_add, bls12_381_mul_miller_loop_result} | ||
use aiken.{G1Element, G2Element} | ||
// ,MillerLoopResult | ||
use aiken/builtin.{ | ||
bls12_381_final_verify, bls12_381_g1_add, bls12_381_g1_scalar_mul, | ||
bls12_381_g1_uncompress, bls12_381_miller_loop, | ||
bls12_381_mul_miller_loop_result, | ||
} | ||
use aiken/list.{head, map2, reduce, tail} | ||
|
||
pub type VerificationKey { | ||
pub type SnarkVerificationKey { | ||
nPublic: Int, | ||
vkAlpha: G1Element, | ||
vkBeta: G2Element, | ||
vkGamma: G2Element, | ||
vkDelta: G2Element, | ||
vkAlphaBeta: List<G2Element>, | ||
vkIC: List<G1Element> | ||
vkIC: List<G1Element>, | ||
} | ||
|
||
pub type Proof { | ||
piA: G1Element, | ||
piB: G2Element, | ||
piC: G1Element | ||
piC: G1Element, | ||
} | ||
|
||
pub fn pairing(g1: G1Element, g2: G2Element) { | ||
bls12_381_miller_loop(g1, g2) | ||
bls12_381_miller_loop(g1, g2) | ||
} | ||
|
||
pub fn groth_verify( | ||
vk: SnarkVerificationKey, | ||
proof: Proof, | ||
public: List<Int>, | ||
) -> Bool { | ||
// let n = vk.nPublic | ||
|
||
let eAB = pairing(proof.piA, proof.piB) | ||
let eAlphaBeta = pairing(vk.vkAlpha, vk.vkBeta) | ||
|
||
expect Some(vkICHead) = head(vk.vkIC) | ||
expect Some(vkICTail) = tail(vk.vkIC) | ||
let derived_vkIC = map2(public, vkICTail, bls12_381_g1_scalar_mul) | ||
let vkI = reduce(derived_vkIC, vkICHead, bls12_381_g1_add) | ||
let eIGamma = pairing(vkI, vk.vkGamma) | ||
let eCDelta = pairing(proof.piC, vk.vkDelta) | ||
|
||
let mlr1 = bls12_381_mul_miller_loop_result(eAlphaBeta, eIGamma) | ||
let mlr2 = bls12_381_mul_miller_loop_result(mlr1, eCDelta) | ||
bls12_381_final_verify(eAB, mlr2) | ||
} | ||
|
||
pub fn groth_verify(vk: VerificationKey, proof: Proof, public: List<Int>) -> Bool { | ||
// let n = vk.nPublic | ||
// Test (3 Factorial problem) | ||
|
||
let eAB = pairing(proof.piA, proof.piB) | ||
let eAlphaBeta = pairing(vk.vkAlpha, vk.vkBeta) | ||
test groth_verify_1() { | ||
// Template of VK | ||
let vk: SnarkVerificationKey = | ||
SnarkVerificationKey { | ||
nPublic: 8, | ||
vkAlpha: #<Bls12_381, G1>"97f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb", | ||
vkBeta: #<Bls12_381, G2>"93e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8", | ||
vkGamma: #<Bls12_381, G2>"93e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8", | ||
vkDelta: #<Bls12_381, G2>"93e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8", | ||
vkAlphaBeta: [ | ||
#<Bls12_381, G2>"93e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8", | ||
], | ||
vkIC: [ | ||
#<Bls12_381, G1>"97f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb", | ||
], | ||
} | ||
|
||
expect Some(vkICHead) = head(vk.vkIC) | ||
expect Some(vkICTail) = tail(vk.vkIC) | ||
let derived_vkIC = map2(public, vkICTail, bls12_381_g1_scalar_mul) | ||
let vkI = reduce(derived_vkIC, vkICHead, bls12_381_g1_add) | ||
let eIGamma = pairing(vkI, vk.vkGamma) | ||
let eCDelta = pairing(proof.piC, vk.vkDelta) | ||
// Template of Proof | ||
let pk: Proof = | ||
Proof { | ||
piA: #<Bls12_381, G1>"97f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb", | ||
piB: #<Bls12_381, G2>"93e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8", | ||
piC: #<Bls12_381, G1>"97f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb", | ||
} | ||
// Template of public values | ||
let public_values: List<Int> = | ||
[562, 3] | ||
|
||
let mlr1 = bls12_381_mul_miller_loop_result(eAlphaBeta, eIGamma) | ||
let mlr2 = bls12_381_mul_miller_loop_result(mlr1, eCDelta) | ||
bls12_381_final_verify(eAB, mlr2) | ||
groth_verify(vk, pk, public_values) | ||
} |