export alphabeta_12 pairing to verifying key

This commit is contained in:
poma 2020-01-18 21:02:47 +07:00
parent f182648aa4
commit ee37151483
No known key found for this signature in database
GPG Key ID: BA20CB01FE165657
3 changed files with 56 additions and 38 deletions

@ -21,10 +21,6 @@ fn main() {
reference_json[key] = value.clone();
}
if reference_json.contains_key("vk_alfabeta_12") {
reference_json.remove("vk_alfabeta_12").unwrap();
}
fs::write(out_file, serde_json::to_string(&reference_json).unwrap().as_bytes()).unwrap();
println!("Done");
}

@ -49,6 +49,7 @@ struct VerifyingKeyJson {
pub vk_beta_2: Vec<Vec<String>>,
pub vk_gamma_2: Vec<Vec<String>>,
pub vk_delta_2: Vec<Vec<String>>,
pub vk_alfabeta_12: Vec<Vec<Vec<String>>>,
}
fn main() {
@ -89,40 +90,60 @@ fn main() {
};
let p1_to_vec = |p : &<Bn256 as Engine>::G1Affine| {
let mut v = vec![];
//println!("test: {}", p.get_x().into_repr());
let x = repr_to_big(p.get_x().into_repr());
v.push(x);
let y = repr_to_big(p.get_y().into_repr());
v.push(y);
if p.is_zero() {
v.push("0".to_string());
} else {
v.push("1".to_string());
}
v
vec![
repr_to_big(p.get_x().into_repr()),
repr_to_big(p.get_y().into_repr()),
if p.is_zero() { "0".to_string() } else { "1".to_string() }
]
};
let p2_to_vec = |p : &<Bn256 as Engine>::G2Affine| {
let mut v = vec![];
let x = p.get_x();
let mut x_v = vec![];
x_v.push(repr_to_big(x.c0.into_repr()));
x_v.push(repr_to_big(x.c1.into_repr()));
v.push(x_v);
let y = p.get_y();
let mut y_v = vec![];
y_v.push(repr_to_big(y.c0.into_repr()));
y_v.push(repr_to_big(y.c1.into_repr()));
v.push(y_v);
if p.is_zero() {
v.push(["0".to_string(), "0".to_string()].to_vec());
} else {
v.push(["1".to_string(), "0".to_string()].to_vec());
}
v
vec![
vec![
repr_to_big(p.get_x().c0.into_repr()),
repr_to_big(p.get_x().c1.into_repr()),
],
vec![
repr_to_big(p.get_y().c0.into_repr()),
repr_to_big(p.get_y().c1.into_repr()),
],
if p.is_zero() {
vec!["0".to_string(), "0".to_string()]
} else {
vec!["1".to_string(), "0".to_string()]
}
]
};
let pairing_to_vec = |p : bellman_ce::pairing::bn256::Fq12| {
vec![
vec![
vec![
repr_to_big(p.c0.c0.c0.into_repr()),
repr_to_big(p.c0.c0.c1.into_repr()),
],
vec![
repr_to_big(p.c0.c1.c0.into_repr()),
repr_to_big(p.c0.c1.c1.into_repr()),
],
vec![
repr_to_big(p.c0.c2.c0.into_repr()),
repr_to_big(p.c0.c2.c1.into_repr()),
]
],
vec![
vec![
repr_to_big(p.c1.c0.c0.into_repr()),
repr_to_big(p.c1.c0.c1.into_repr()),
],
vec![
repr_to_big(p.c1.c1.c0.into_repr()),
repr_to_big(p.c1.c1.c1.into_repr()),
],
vec![
repr_to_big(p.c1.c2.c0.into_repr()),
repr_to_big(p.c1.c2.c1.into_repr()),
]
],
]
};
let a = params.a.clone();
for e in a.iter() {
@ -170,6 +191,7 @@ fn main() {
vk_beta_2: vec![],
vk_gamma_2: vec![],
vk_delta_2: vec![],
vk_alfabeta_12: vec![],
};
let ic = params.vk.ic.clone();
@ -182,6 +204,7 @@ fn main() {
let vk_gamma_2 = params.vk.gamma_g2.clone();
verification_key.vk_gamma_2 = p2_to_vec(&vk_gamma_2);
verification_key.vk_delta_2 = p2_to_vec(&vk_delta_2);
verification_key.vk_alfabeta_12 = pairing_to_vec(Bn256::pairing(vk_alfa_1, vk_beta_2));
let pk_json = serde_json::to_string(&proving_key).unwrap();
fs::write(pk_filename, pk_json.as_bytes()).unwrap();

@ -30,7 +30,6 @@ npx snarkjs setup --protocol groth
# 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
node ./tools/patch_vk/patch_vk.js
# generate solidity verifier
cargo run --release --bin generate_verifier circom4.params verifier.sol
@ -38,4 +37,4 @@ cargo run --release --bin generate_verifier circom4.params verifier.sol
# try to generate and verify proof
snarkjs calculatewitness
cargo run --release --bin prove circuit.json witness.json circom4.params proof.json
snarkjs verify --vk patched_transformed_vk.json --proof proof.json
snarkjs verify --vk transformed_vk.json --proof proof.json