Skip to content

Commit

Permalink
Merge pull request #38 from artem-bakuta/solidity-verifier-pp-spartan…
Browse files Browse the repository at this point in the history
…-keys_verifier

Automatic JSONs generation for e2e Pasta flow
  • Loading branch information
storojs72 authored Feb 7, 2024
2 parents dd3b1a2 + 3838031 commit d5f5fb5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk
.idea/jpa-buddy.xml
.idea/misc.xml
.idea/vcs.xml
.idea/workspace.xml
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ bitvec = "1.0"
byteorder = "1.4.3"
thiserror = "1.0"
halo2curves = { version="0.1.0", features = [ "derive_serde" ] }
serde_json = "1.0.111"

[target.'cfg(any(target_arch = "x86_64", target_arch = "aarch64"))'.dependencies]
pasta-msm = { version = "0.1.4" }
Expand Down
40 changes: 28 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1053,15 +1053,15 @@ mod tests {
test_ivc_nontrivial_with::<bn256::Point, grumpkin::Point>();
}

fn test_ivc_nontrivial_with_compression_with<G1, G2>()
where
G1: Group<Base = <G2 as Group>::Scalar>,
G2: Group<Base = <G1 as Group>::Scalar>,
fn test_ivc_nontrivial_with_compression_with<G1, G2>(generate_keys_to_json: bool)
where
G1: Group<Base = <G2 as Group>::Scalar>,
G2: Group<Base = <G1 as Group>::Scalar>,
// this is due to the reliance on CommitmentKeyExtTrait as a bound in ipa_pc
<G1::CE as CommitmentEngineTrait<G1>>::CommitmentKey:
CommitmentKeyExtTrait<G1, CE = <G1 as Group>::CE>,
<G2::CE as CommitmentEngineTrait<G2>>::CommitmentKey:
CommitmentKeyExtTrait<G2, CE = <G2 as Group>::CE>,
<G1::CE as CommitmentEngineTrait<G1>>::CommitmentKey:
CommitmentKeyExtTrait<G1, CE = <G1 as Group>::CE>,
<G2::CE as CommitmentEngineTrait<G2>>::CommitmentKey:
CommitmentKeyExtTrait<G2, CE = <G2 as Group>::CE>,
{
let circuit_primary = TrivialTestCircuit::default();
let circuit_secondary = CubicCircuit::default();
Expand Down Expand Up @@ -1122,13 +1122,19 @@ mod tests {
assert_eq!(zn_secondary, vec![<G2 as Group>::Scalar::from(2460515u64)]);

// produce the prover and verifier keys for compressed snark
let (pk, vk) = CompressedSNARK::<_, _, _, _, S1<G1>, S2<G2>>::setup(&pp).unwrap();
let (pk, vk) = CompressedSNARK::<_, _, _, _, S1Prime<G1>, S2Prime<G2>>::setup(&pp).unwrap();

if generate_keys_to_json {
let serialized_vk = serde_json::to_string(&vk).unwrap();std::fs::write(std::path::Path::new("vk.json"), serialized_vk).expect("Unable to write file");
}
// produce a compressed SNARK
let res = CompressedSNARK::<_, _, _, _, S1<G1>, S2<G2>>::prove(&pp, &pk, &recursive_snark);
let res = CompressedSNARK::<_, _, _, _, S1Prime<G1>, S2Prime<G2>>::prove(&pp, &pk, &recursive_snark);
assert!(res.is_ok());
let compressed_snark = res.unwrap();

if generate_keys_to_json {
let serialized_compressed_snark = serde_json::to_string(&compressed_snark).unwrap();std::fs::write(std::path::Path::new("compressed-snark.json"), serialized_compressed_snark).expect("Unable to write file");
}
// verify the compressed SNARK
let res = compressed_snark.verify(
&vk,
Expand All @@ -1144,8 +1150,8 @@ mod tests {
type G1 = pasta_curves::pallas::Point;
type G2 = pasta_curves::vesta::Point;

test_ivc_nontrivial_with_compression_with::<G1, G2>();
test_ivc_nontrivial_with_compression_with::<bn256::Point, grumpkin::Point>();
test_ivc_nontrivial_with_compression_with::<G1, G2>(false);
test_ivc_nontrivial_with_compression_with::<bn256::Point, grumpkin::Point>(false);
}

fn test_ivc_nontrivial_with_spark_compression_with<G1, G2>()
Expand Down Expand Up @@ -1469,4 +1475,14 @@ mod tests {
test_ivc_base_with::<G1, G2>();
test_ivc_base_with::<bn256::Point, grumpkin::Point>();
}

// cargo +nightly test test_ivc_nontrivial_with_compression_pasta --release -- --nocapture --ignored
#[test]
#[ignore]
fn solidity_compatibility_e2e_pasta() {
type G1 = pasta_curves::pallas::Point;
type G2 = pasta_curves::vesta::Point;

test_ivc_nontrivial_with_compression_with::<G1, G2>(true);
}
}

0 comments on commit d5f5fb5

Please sign in to comment.