generate public inputs file for proof, test script update
This commit is contained in:
parent
95379a1a1c
commit
21c3c6115e
@ -34,14 +34,15 @@ struct ProofJson {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: Vec<String> = std::env::args().collect();
|
let args: Vec<String> = std::env::args().collect();
|
||||||
if args.len() != 5 {
|
if args.len() != 6 {
|
||||||
println!("Usage: \n<circuit.json> <witness.json> <params> <proof.json>");
|
println!("Usage: \n<circuit.json> <witness.json> <params> <proof.json> <public.json>");
|
||||||
std::process::exit(exitcode::USAGE);
|
std::process::exit(exitcode::USAGE);
|
||||||
}
|
}
|
||||||
let circuit_filename = &args[1];
|
let circuit_filename = &args[1];
|
||||||
let witness_filename = &args[2];
|
let witness_filename = &args[2];
|
||||||
let params_filename = &args[3];
|
let params_filename = &args[3];
|
||||||
let proof_filename = &args[4];
|
let proof_filename = &args[4];
|
||||||
|
let public_filename = &args[5];
|
||||||
|
|
||||||
let should_filter_points_at_infinity = false;
|
let should_filter_points_at_infinity = false;
|
||||||
let rng = &mut rand::XorShiftRng::new_unseeded(); // TODO: change this unsafe unseeded random (!)
|
let rng = &mut rand::XorShiftRng::new_unseeded(); // TODO: change this unsafe unseeded random (!)
|
||||||
@ -75,41 +76,32 @@ fn main() {
|
|||||||
let repr_to_big = |r| {
|
let repr_to_big = |r| {
|
||||||
BigUint::from_str_radix(&format!("{}", r)[2..], 16).unwrap().to_str_radix(10)
|
BigUint::from_str_radix(&format!("{}", r)[2..], 16).unwrap().to_str_radix(10)
|
||||||
};
|
};
|
||||||
|
let repr_to_big2 = |r| {
|
||||||
|
BigUint::from_str_radix(&format!("{}", r)[2..], 16).unwrap().to_str_radix(10)
|
||||||
|
};
|
||||||
let p1_to_vec = |p : &<Bn256 as Engine>::G1Affine| {
|
let p1_to_vec = |p : &<Bn256 as Engine>::G1Affine| {
|
||||||
let mut v = vec![];
|
vec![
|
||||||
//println!("test: {}", p.get_x().into_repr());
|
repr_to_big(p.get_x().into_repr()),
|
||||||
let x = repr_to_big(p.get_x().into_repr());
|
repr_to_big(p.get_y().into_repr()),
|
||||||
v.push(x);
|
if p.is_zero() { "0".to_string() } else { "1".to_string() }
|
||||||
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
|
|
||||||
};
|
};
|
||||||
let p2_to_vec = |p : &<Bn256 as Engine>::G2Affine| {
|
let p2_to_vec = |p : &<Bn256 as Engine>::G2Affine| {
|
||||||
let mut v = vec![];
|
vec![
|
||||||
let x = p.get_x();
|
vec![
|
||||||
let mut x_v = vec![];
|
repr_to_big(p.get_x().c0.into_repr()),
|
||||||
x_v.push(repr_to_big(x.c0.into_repr()));
|
repr_to_big(p.get_x().c1.into_repr()),
|
||||||
x_v.push(repr_to_big(x.c1.into_repr()));
|
],
|
||||||
v.push(x_v);
|
vec![
|
||||||
|
repr_to_big(p.get_y().c0.into_repr()),
|
||||||
let y = p.get_y();
|
repr_to_big(p.get_y().c1.into_repr()),
|
||||||
let mut y_v = vec![];
|
],
|
||||||
y_v.push(repr_to_big(y.c0.into_repr()));
|
if p.is_zero() {
|
||||||
y_v.push(repr_to_big(y.c1.into_repr()));
|
vec!["0".to_string(), "0".to_string()]
|
||||||
v.push(y_v);
|
} else {
|
||||||
|
vec!["1".to_string(), "0".to_string()]
|
||||||
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
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let proof = ProofJson {
|
let proof = ProofJson {
|
||||||
@ -122,5 +114,12 @@ fn main() {
|
|||||||
let proof_json = serde_json::to_string(&proof).unwrap();
|
let proof_json = serde_json::to_string(&proof).unwrap();
|
||||||
fs::write(proof_filename, proof_json.as_bytes()).unwrap();
|
fs::write(proof_filename, proof_json.as_bytes()).unwrap();
|
||||||
|
|
||||||
|
let mut public_inputs = vec![];
|
||||||
|
for x in input[1..].iter() {
|
||||||
|
public_inputs.push(repr_to_big2(x.into_repr()));
|
||||||
|
}
|
||||||
|
let public_json = serde_json::to_string(&public_inputs).unwrap();
|
||||||
|
fs::write(public_filename, public_json.as_bytes()).unwrap();
|
||||||
|
|
||||||
println!("Done!")
|
println!("Done!")
|
||||||
}
|
}
|
@ -1,9 +1,12 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
rm -f pk.json vk.json transformed_vk.json transformed_pk.* proof.json
|
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
if [ ! -f ../powersoftau/phase1radix2m0 ]; then
|
||||||
|
echo "Please run powers of tau test first to generate radix files"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# move results of powers of tau here
|
# move results of powers of tau here
|
||||||
cp ../powersoftau/phase1radix* .
|
cp ../powersoftau/phase1radix* .
|
||||||
|
|
||||||
@ -26,6 +29,7 @@ cargo run --release --bin verify_contribution circuit.json circom3.params circom
|
|||||||
# generate resulting keys
|
# generate resulting keys
|
||||||
cargo run --release --bin export_keys circom4.params vk.json pk.json
|
cargo run --release --bin export_keys circom4.params vk.json pk.json
|
||||||
# create dummy keys in circom format
|
# create dummy keys in circom format
|
||||||
|
echo "generating dummy key files..."
|
||||||
npx snarkjs setup --protocol groth
|
npx snarkjs setup --protocol groth
|
||||||
# patch dummy keys with actual keys params
|
# 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 proving_key.json pk.json transformed_pk.json
|
||||||
@ -35,6 +39,6 @@ cargo run --release --bin copy_json verification_key.json vk.json transformed_vk
|
|||||||
cargo run --release --bin generate_verifier circom4.params verifier.sol
|
cargo run --release --bin generate_verifier circom4.params verifier.sol
|
||||||
|
|
||||||
# try to generate and verify proof
|
# try to generate and verify proof
|
||||||
snarkjs calculatewitness
|
npx snarkjs calculatewitness
|
||||||
cargo run --release --bin prove circuit.json witness.json circom4.params proof.json
|
cargo run --release --bin prove circuit.json witness.json circom4.params proof.json public.json
|
||||||
snarkjs verify --vk transformed_vk.json --proof proof.json
|
npx snarkjs verify --vk transformed_vk.json --proof proof.json
|
Loading…
Reference in New Issue
Block a user