Skip to content

Commit 4c5ff06

Browse files
huitseekermpenciak
authored andcommitted
refactor: Parametrization of lib.rs Tests for Various Evaluation Engines (lurk-lang#70)
[microsoft/171](microsoft/Nova#171) introduced enhanced genericity in tests to facilitate unit testing across diverse curve cycles. Since then, the lib.rs tests, being designed to verify certain behaviors of the decider SNARK, tend to embed the use of a RelaxedR1CSSnark<G, EE>. They do this under the alias (where the test carefully chooses a specific import path for RelaxedR1CSSnark): ```rust type S1<G> = RelaxedR1CSSnark<G, ipa_pc::EvaluationEgine<G>> ``` Effectively, this constrains the PCS utilized by that decider to the IPA, even if the only thing the test function needed to be specific about is `RelaxedR1CSSnark`. Hence, these generic tests then had to accommodate constraints facilitating the use of the IPA, specifically: ``` <G::CE as CommitmentEngineTrait<G>>::CommitmentKey: CommitmentKeyExtTrait<G> ``` This is because the IPA operates exclusively with a "splittable" key, a concept delineated by the CommitmentKeyExtTrait. However, two core adjustments are required: - For the inclusion of different PCSs (for instance, Zeromorph), it's imperative to render `EE<G>: EvaluationEngineTrait<G>` configurable. - Parametrizing the tests based on the `EvaluationEngineTrait` implementation eliminates boundaries associated with `CommitmentKeyExtTrait`. Such boundaries matching the `EvaluationEngine` and `CommitmentEngine` only materialize when the scheme is instantiated (i.e., during test invocation), a pointwhere they are seamlessly met. The present PR effects this parametrization, effectively making the lib.rs tests functions variable based on the evaluation engine in use.
1 parent 37f3f00 commit 4c5ff06

File tree

1 file changed

+53
-44
lines changed

1 file changed

+53
-44
lines changed

src/lib.rs

+53-44
Original file line numberDiff line numberDiff line change
@@ -940,14 +940,14 @@ type CE<G> = <G as Group>::CE;
940940
#[cfg(test)]
941941
mod tests {
942942
use crate::provider::bn256_grumpkin::{bn256, grumpkin};
943-
use crate::provider::pedersen::CommitmentKeyExtTrait;
944943
use crate::provider::secp_secq::{secp256k1, secq256k1};
944+
use crate::traits::evaluation::EvaluationEngineTrait;
945945
use core::fmt::Write;
946946

947947
use super::*;
948948
type EE<G> = provider::ipa_pc::EvaluationEngine<G>;
949-
type S<G1> = spartan::snark::RelaxedR1CSSNARK<G1, EE<G1>>;
950-
type SPrime<G1> = spartan::ppsnark::RelaxedR1CSSNARK<G1, EE<G1>>;
949+
type S<G, EE> = spartan::snark::RelaxedR1CSSNARK<G, EE>;
950+
type SPrime<G, EE> = spartan::ppsnark::RelaxedR1CSSNARK<G, EE>;
951951

952952
use ::bellpepper_core::{num::AllocatedNum, ConstraintSystem, SynthesisError};
953953
use core::marker::PhantomData;
@@ -1008,20 +1008,20 @@ mod tests {
10081008
}
10091009
}
10101010

1011-
fn test_pp_digest_with<G1, G2, T1, T2>(circuit1: &T1, circuit2: &T2, _expected: &str)
1011+
fn test_pp_digest_with<G1, G2, T1, T2, E1, E2>(circuit1: &T1, circuit2: &T2, _expected: &str)
10121012
where
10131013
G1: Group<Base = <G2 as Group>::Scalar>,
10141014
G2: Group<Base = <G1 as Group>::Scalar>,
10151015
T1: StepCircuit<G1::Scalar>,
10161016
T2: StepCircuit<G2::Scalar>,
1017-
<G1::CE as CommitmentEngineTrait<G1>>::CommitmentKey: CommitmentKeyExtTrait<G1>,
1018-
<G2::CE as CommitmentEngineTrait<G2>>::CommitmentKey: CommitmentKeyExtTrait<G2>,
1017+
E1: EvaluationEngineTrait<G1>,
1018+
E2: EvaluationEngineTrait<G2>,
10191019
<G1::Scalar as PrimeField>::Repr: Abomonation,
10201020
<G2::Scalar as PrimeField>::Repr: Abomonation,
10211021
{
10221022
// this tests public parameters with a size specifically intended for a spark-compressed SNARK
1023-
let pp_hint1 = Some(SPrime::<G1>::commitment_key_floor());
1024-
let pp_hint2 = Some(SPrime::<G2>::commitment_key_floor());
1023+
let pp_hint1 = Some(SPrime::<G1, E1>::commitment_key_floor());
1024+
let pp_hint2 = Some(SPrime::<G2, E2>::commitment_key_floor());
10251025
let pp = PublicParams::<G1, G2, T1, T2>::new(circuit1, circuit2, pp_hint1, pp_hint2);
10261026

10271027
let digest_str = pp
@@ -1045,13 +1045,13 @@ mod tests {
10451045
let trivial_circuit2 = TrivialCircuit::<<G2 as Group>::Scalar>::default();
10461046
let cubic_circuit1 = CubicCircuit::<<G1 as Group>::Scalar>::default();
10471047

1048-
test_pp_digest_with::<G1, G2, _, _>(
1048+
test_pp_digest_with::<G1, G2, _, _, EE<_>, EE<_>>(
10491049
&trivial_circuit1,
10501050
&trivial_circuit2,
10511051
"fd9cafd3d142c3ab694e35384293211fcf377fa484343d0d6889e6664103c802",
10521052
);
10531053

1054-
test_pp_digest_with::<G1, G2, _, _>(
1054+
test_pp_digest_with::<G1, G2, _, _, EE<_>, EE<_>>(
10551055
&cubic_circuit1,
10561056
&trivial_circuit2,
10571057
"6701f6db5a6e3f0e0002740913d6f465ec432cdf59a0dcc68152904a9a4f9d00",
@@ -1061,12 +1061,12 @@ mod tests {
10611061
let trivial_circuit2_grumpkin = TrivialCircuit::<<grumpkin::Point as Group>::Scalar>::default();
10621062
let cubic_circuit1_grumpkin = CubicCircuit::<<bn256::Point as Group>::Scalar>::default();
10631063

1064-
test_pp_digest_with::<bn256::Point, grumpkin::Point, _, _>(
1064+
test_pp_digest_with::<bn256::Point, grumpkin::Point, _, _, EE<_>, EE<_>>(
10651065
&trivial_circuit1_grumpkin,
10661066
&trivial_circuit2_grumpkin,
10671067
"184d05f08dca260f010cb48c6cf8c5eb61dedfc270e5a18226eb622cf7da0203",
10681068
);
1069-
test_pp_digest_with::<bn256::Point, grumpkin::Point, _, _>(
1069+
test_pp_digest_with::<bn256::Point, grumpkin::Point, _, _, EE<_>, EE<_>>(
10701070
&cubic_circuit1_grumpkin,
10711071
&trivial_circuit2_grumpkin,
10721072
"2fb992932b2a642b4ce8f52646a7ef6a5a486682716cf969df50021107afff03",
@@ -1076,12 +1076,12 @@ mod tests {
10761076
let trivial_circuit2_secp = TrivialCircuit::<<secq256k1::Point as Group>::Scalar>::default();
10771077
let cubic_circuit1_secp = CubicCircuit::<<secp256k1::Point as Group>::Scalar>::default();
10781078

1079-
test_pp_digest_with::<secp256k1::Point, secq256k1::Point, _, _>(
1079+
test_pp_digest_with::<secp256k1::Point, secq256k1::Point, _, _, EE<_>, EE<_>>(
10801080
&trivial_circuit1_secp,
10811081
&trivial_circuit2_secp,
10821082
"da68dde1bb88f9a342fe7facedf14ab5e7f3d9afc2777697606ff3de061d1601",
10831083
);
1084-
test_pp_digest_with::<secp256k1::Point, secq256k1::Point, _, _>(
1084+
test_pp_digest_with::<secp256k1::Point, secq256k1::Point, _, _, EE<_>, EE<_>>(
10851085
&cubic_circuit1_secp,
10861086
&trivial_circuit2_secp,
10871087
"4a7d379403a99a46592b70c8446206542ce09e08dc96c0ba57f36efce8b0fa00",
@@ -1227,13 +1227,12 @@ mod tests {
12271227
test_ivc_nontrivial_with::<secp256k1::Point, secq256k1::Point>();
12281228
}
12291229

1230-
fn test_ivc_nontrivial_with_compression_with<G1, G2>()
1230+
fn test_ivc_nontrivial_with_compression_with<G1, G2, E1, E2>()
12311231
where
12321232
G1: Group<Base = <G2 as Group>::Scalar>,
12331233
G2: Group<Base = <G1 as Group>::Scalar>,
1234-
// this is due to the reliance on CommitmentKeyExtTrait as a bound in ipa_pc
1235-
<G1::CE as CommitmentEngineTrait<G1>>::CommitmentKey: CommitmentKeyExtTrait<G1>,
1236-
<G2::CE as CommitmentEngineTrait<G2>>::CommitmentKey: CommitmentKeyExtTrait<G2>,
1234+
E1: EvaluationEngineTrait<G1>,
1235+
E2: EvaluationEngineTrait<G2>,
12371236
// this is due to the reliance on Abomonation
12381237
<<G1 as Group>::Scalar as PrimeField>::Repr: Abomonation,
12391238
<<G2 as Group>::Scalar as PrimeField>::Repr: Abomonation,
@@ -1297,10 +1296,11 @@ mod tests {
12971296
assert_eq!(zn_secondary, vec![<G2 as Group>::Scalar::from(2460515u64)]);
12981297

12991298
// produce the prover and verifier keys for compressed snark
1300-
let (pk, vk) = CompressedSNARK::<_, _, _, _, S<G1>, S<G2>>::setup(&pp).unwrap();
1299+
let (pk, vk) = CompressedSNARK::<_, _, _, _, S<G1, E1>, S<G2, E2>>::setup(&pp).unwrap();
13011300

13021301
// produce a compressed SNARK
1303-
let res = CompressedSNARK::<_, _, _, _, S<G1>, S<G2>>::prove(&pp, &pk, &recursive_snark);
1302+
let res =
1303+
CompressedSNARK::<_, _, _, _, S<G1, E1>, S<G2, E2>>::prove(&pp, &pk, &recursive_snark);
13041304
assert!(res.is_ok());
13051305
let compressed_snark = res.unwrap();
13061306

@@ -1319,18 +1319,17 @@ mod tests {
13191319
type G1 = pasta_curves::pallas::Point;
13201320
type G2 = pasta_curves::vesta::Point;
13211321

1322-
test_ivc_nontrivial_with_compression_with::<G1, G2>();
1323-
test_ivc_nontrivial_with_compression_with::<bn256::Point, grumpkin::Point>();
1324-
test_ivc_nontrivial_with_compression_with::<secp256k1::Point, secq256k1::Point>();
1322+
test_ivc_nontrivial_with_compression_with::<G1, G2, EE<_>, EE<_>>();
1323+
test_ivc_nontrivial_with_compression_with::<bn256::Point, grumpkin::Point, EE<_>, EE<_>>();
1324+
test_ivc_nontrivial_with_compression_with::<secp256k1::Point, secq256k1::Point, EE<_>, EE<_>>();
13251325
}
13261326

1327-
fn test_ivc_nontrivial_with_spark_compression_with<G1, G2>()
1327+
fn test_ivc_nontrivial_with_spark_compression_with<G1, G2, E1, E2>()
13281328
where
13291329
G1: Group<Base = <G2 as Group>::Scalar>,
13301330
G2: Group<Base = <G1 as Group>::Scalar>,
1331-
// this is due to the reliance on CommitmentKeyExtTrait as a bound in ipa_pc
1332-
<G1::CE as CommitmentEngineTrait<G1>>::CommitmentKey: CommitmentKeyExtTrait<G1>,
1333-
<G2::CE as CommitmentEngineTrait<G2>>::CommitmentKey: CommitmentKeyExtTrait<G2>,
1331+
E1: EvaluationEngineTrait<G1>,
1332+
E2: EvaluationEngineTrait<G2>,
13341333
// this is due to the reliance on Abomonation
13351334
<<G1 as Group>::Scalar as PrimeField>::Repr: Abomonation,
13361335
<<G2 as Group>::Scalar as PrimeField>::Repr: Abomonation,
@@ -1347,8 +1346,8 @@ mod tests {
13471346
>::new(
13481347
&circuit_primary,
13491348
&circuit_secondary,
1350-
Some(SPrime::commitment_key_floor()),
1351-
Some(SPrime::commitment_key_floor()),
1349+
Some(SPrime::<_, E1>::commitment_key_floor()),
1350+
Some(SPrime::<_, E2>::commitment_key_floor()),
13521351
);
13531352

13541353
let num_steps = 3;
@@ -1401,11 +1400,15 @@ mod tests {
14011400
// run the compressed snark with Spark compiler
14021401

14031402
// produce the prover and verifier keys for compressed snark
1404-
let (pk, vk) = CompressedSNARK::<_, _, _, _, SPrime<G1>, SPrime<G2>>::setup(&pp).unwrap();
1403+
let (pk, vk) =
1404+
CompressedSNARK::<_, _, _, _, SPrime<G1, E1>, SPrime<G2, E2>>::setup(&pp).unwrap();
14051405

14061406
// produce a compressed SNARK
1407-
let res =
1408-
CompressedSNARK::<_, _, _, _, SPrime<G1>, SPrime<G2>>::prove(&pp, &pk, &recursive_snark);
1407+
let res = CompressedSNARK::<_, _, _, _, SPrime<G1, E1>, SPrime<G2, E2>>::prove(
1408+
&pp,
1409+
&pk,
1410+
&recursive_snark,
1411+
);
14091412
assert!(res.is_ok());
14101413
let compressed_snark = res.unwrap();
14111414

@@ -1424,18 +1427,23 @@ mod tests {
14241427
type G1 = pasta_curves::pallas::Point;
14251428
type G2 = pasta_curves::vesta::Point;
14261429

1427-
test_ivc_nontrivial_with_spark_compression_with::<G1, G2>();
1428-
test_ivc_nontrivial_with_spark_compression_with::<bn256::Point, grumpkin::Point>();
1429-
test_ivc_nontrivial_with_spark_compression_with::<secp256k1::Point, secq256k1::Point>();
1430+
test_ivc_nontrivial_with_spark_compression_with::<G1, G2, EE<_>, EE<_>>();
1431+
test_ivc_nontrivial_with_spark_compression_with::<bn256::Point, grumpkin::Point, EE<_>, EE<_>>(
1432+
);
1433+
test_ivc_nontrivial_with_spark_compression_with::<
1434+
secp256k1::Point,
1435+
secq256k1::Point,
1436+
EE<_>,
1437+
EE<_>,
1438+
>();
14301439
}
14311440

1432-
fn test_ivc_nondet_with_compression_with<G1, G2>()
1441+
fn test_ivc_nondet_with_compression_with<G1, G2, E1, E2>()
14331442
where
14341443
G1: Group<Base = <G2 as Group>::Scalar>,
14351444
G2: Group<Base = <G1 as Group>::Scalar>,
1436-
// this is due to the reliance on CommitmentKeyExtTrait as a bound in ipa_pc
1437-
<G1::CE as CommitmentEngineTrait<G1>>::CommitmentKey: CommitmentKeyExtTrait<G1>,
1438-
<G2::CE as CommitmentEngineTrait<G2>>::CommitmentKey: CommitmentKeyExtTrait<G2>,
1445+
E1: EvaluationEngineTrait<G1>,
1446+
E2: EvaluationEngineTrait<G2>,
14391447
// this is due to the reliance on Abomonation
14401448
<<G1 as Group>::Scalar as PrimeField>::Repr: Abomonation,
14411449
<<G2 as Group>::Scalar as PrimeField>::Repr: Abomonation,
@@ -1555,10 +1563,11 @@ mod tests {
15551563
assert!(res.is_ok());
15561564

15571565
// produce the prover and verifier keys for compressed snark
1558-
let (pk, vk) = CompressedSNARK::<_, _, _, _, S<G1>, S<G2>>::setup(&pp).unwrap();
1566+
let (pk, vk) = CompressedSNARK::<_, _, _, _, S<G1, E1>, S<G2, E2>>::setup(&pp).unwrap();
15591567

15601568
// produce a compressed SNARK
1561-
let res = CompressedSNARK::<_, _, _, _, S<G1>, S<G2>>::prove(&pp, &pk, &recursive_snark);
1569+
let res =
1570+
CompressedSNARK::<_, _, _, _, S<G1, E1>, S<G2, E2>>::prove(&pp, &pk, &recursive_snark);
15621571
assert!(res.is_ok());
15631572
let compressed_snark = res.unwrap();
15641573

@@ -1572,9 +1581,9 @@ mod tests {
15721581
type G1 = pasta_curves::pallas::Point;
15731582
type G2 = pasta_curves::vesta::Point;
15741583

1575-
test_ivc_nondet_with_compression_with::<G1, G2>();
1576-
test_ivc_nondet_with_compression_with::<bn256::Point, grumpkin::Point>();
1577-
test_ivc_nondet_with_compression_with::<secp256k1::Point, secq256k1::Point>();
1584+
test_ivc_nondet_with_compression_with::<G1, G2, EE<_>, EE<_>>();
1585+
test_ivc_nondet_with_compression_with::<bn256::Point, grumpkin::Point, EE<_>, EE<_>>();
1586+
test_ivc_nondet_with_compression_with::<secp256k1::Point, secq256k1::Point, EE<_>, EE<_>>();
15781587
}
15791588

15801589
fn test_ivc_base_with<G1, G2>()

0 commit comments

Comments
 (0)