From 02245e457c2d20d50c796ddabc9c2bf3e75d6579 Mon Sep 17 00:00:00 2001 From: poma Date: Fri, 31 Jan 2020 14:11:52 +0800 Subject: [PATCH] export circom-compatible verifying key --- phase2/src/bin/export_keys.rs | 6 ++++++ phase2/test.sh | 7 +++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/phase2/src/bin/export_keys.rs b/phase2/src/bin/export_keys.rs index 90cafa2..2241a6c 100644 --- a/phase2/src/bin/export_keys.rs +++ b/phase2/src/bin/export_keys.rs @@ -43,6 +43,7 @@ struct ProvingKeyJson { pub vk_delta_2: Vec>, #[serde(rename = "hExps")] pub h: Vec>, + // Todo: add json fields: nPublic, nVars, polsA, polsB, polsC, protocol: groth } #[derive(Serialize, Deserialize)] @@ -54,6 +55,9 @@ struct VerifyingKeyJson { pub vk_gamma_2: Vec>, pub vk_delta_2: Vec>, pub vk_alfabeta_12: Vec>>, + pub protocol: String, + #[serde(rename = "nPublic")] + pub inputs_count: usize, } fn main() { @@ -97,6 +101,8 @@ fn main() { vk_gamma_2: p2_to_vec(¶ms.vk.gamma_g2), vk_delta_2: p2_to_vec(¶ms.vk.delta_g2), vk_alfabeta_12: pairing_to_vec(&Bn256::pairing(params.vk.alpha_g1, params.vk.beta_g2)), + inputs_count: params.vk.ic.len() - 1, + protocol: String::from("groth"), }; let pk_json = serde_json::to_string(&proving_key).unwrap(); diff --git a/phase2/test.sh b/phase2/test.sh index e33ec2b..895b9b8 100755 --- a/phase2/test.sh +++ b/phase2/test.sh @@ -26,14 +26,13 @@ cargo run --release --bin verify_contribution circuit.json circom2.params circom cargo run --release --bin contribute circom3.params circom4.params askldfjklasdf cargo run --release --bin verify_contribution circuit.json circom3.params circom4.params -# generate resulting keys -cargo run --release --bin export_keys circom4.params vk.json pk.json # create dummy keys in circom format echo "Generating dummy key files..." npx snarkjs setup --protocol groth +# generate resulting keys +cargo run --release --bin export_keys circom4.params vk.json pk.json # patch dummy keys with actual keys params cargo run --release --bin copy_json proving_key.json pk.json transformed_pk.json -cargo run --release --bin copy_json verification_key.json vk.json transformed_vk.json # generate solidity verifier cargo run --release --bin generate_verifier circom4.params verifier.sol @@ -41,4 +40,4 @@ cargo run --release --bin generate_verifier circom4.params verifier.sol # try to generate and verify proof npx snarkjs calculatewitness cargo run --release --bin prove circuit.json witness.json circom4.params proof.json public.json -npx snarkjs verify --vk transformed_vk.json --proof proof.json \ No newline at end of file +npx snarkjs verify --vk vk.json --proof proof.json \ No newline at end of file