Skip to content

Commit 38551ce

Browse files
committed
Use the ZMPCS Evaluation Engine and the KZG Commitment Engine in tests.
1 parent b662d4c commit 38551ce

File tree

6 files changed

+64
-34
lines changed

6 files changed

+64
-34
lines changed

src/lib.rs

+21-10
Original file line numberDiff line numberDiff line change
@@ -946,13 +946,10 @@ mod tests {
946946
use core::fmt::Write;
947947

948948
use super::*;
949-
#[allow(dead_code)]
950-
type ZM<E> = provider::non_hiding_zeromorph::ZMEvaluation<E>;
949+
type ZM<E> = provider::non_hiding_zeromorph::ZMPCS<E>;
951950
type EE<G> = provider::ipa_pc::EvaluationEngine<G>;
952951
type S<G, EE> = spartan::snark::RelaxedR1CSSNARK<G, EE>;
953952
type SPrime<G, EE> = spartan::ppsnark::RelaxedR1CSSNARK<G, EE>;
954-
#[allow(dead_code)]
955-
type SZM<G, E> = spartan::snark::RelaxedR1CSSNARK<G, ZM<E>>;
956953

957954
use ::bellpepper_core::{num::AllocatedNum, ConstraintSystem, SynthesisError};
958955
use core::marker::PhantomData;
@@ -1066,12 +1063,12 @@ mod tests {
10661063
let trivial_circuit2_grumpkin = TrivialCircuit::<<grumpkin::Point as Group>::Scalar>::default();
10671064
let cubic_circuit1_grumpkin = CubicCircuit::<<bn256::Point as Group>::Scalar>::default();
10681065

1069-
test_pp_digest_with::<bn256::Point, grumpkin::Point, _, _, EE<_>, EE<_>>(
1066+
test_pp_digest_with::<bn256::Point, grumpkin::Point, _, _, ZM<halo2curves::bn256::Bn256>, EE<_>>(
10701067
&trivial_circuit1_grumpkin,
10711068
&trivial_circuit2_grumpkin,
10721069
"184d05f08dca260f010cb48c6cf8c5eb61dedfc270e5a18226eb622cf7da0203",
10731070
);
1074-
test_pp_digest_with::<bn256::Point, grumpkin::Point, _, _, EE<_>, EE<_>>(
1071+
test_pp_digest_with::<bn256::Point, grumpkin::Point, _, _, ZM<halo2curves::bn256::Bn256>, EE<_>>(
10751072
&cubic_circuit1_grumpkin,
10761073
&trivial_circuit2_grumpkin,
10771074
"2fb992932b2a642b4ce8f52646a7ef6a5a486682716cf969df50021107afff03",
@@ -1325,7 +1322,12 @@ mod tests {
13251322
type G2 = pasta_curves::vesta::Point;
13261323

13271324
test_ivc_nontrivial_with_compression_with::<G1, G2, EE<_>, EE<_>>();
1328-
test_ivc_nontrivial_with_compression_with::<bn256::Point, grumpkin::Point, EE<_>, EE<_>>();
1325+
test_ivc_nontrivial_with_compression_with::<
1326+
bn256::Point,
1327+
grumpkin::Point,
1328+
ZM<halo2curves::bn256::Bn256>,
1329+
EE<_>,
1330+
>();
13291331
test_ivc_nontrivial_with_compression_with::<secp256k1::Point, secq256k1::Point, EE<_>, EE<_>>();
13301332
}
13311333

@@ -1433,8 +1435,12 @@ mod tests {
14331435
type G2 = pasta_curves::vesta::Point;
14341436

14351437
test_ivc_nontrivial_with_spark_compression_with::<G1, G2, EE<_>, EE<_>>();
1436-
test_ivc_nontrivial_with_spark_compression_with::<bn256::Point, grumpkin::Point, EE<_>, EE<_>>(
1437-
);
1438+
test_ivc_nontrivial_with_spark_compression_with::<
1439+
bn256::Point,
1440+
grumpkin::Point,
1441+
ZM<halo2curves::bn256::Bn256>,
1442+
EE<_>,
1443+
>();
14381444
test_ivc_nontrivial_with_spark_compression_with::<
14391445
secp256k1::Point,
14401446
secq256k1::Point,
@@ -1587,7 +1593,12 @@ mod tests {
15871593
type G2 = pasta_curves::vesta::Point;
15881594

15891595
test_ivc_nondet_with_compression_with::<G1, G2, EE<_>, EE<_>>();
1590-
test_ivc_nondet_with_compression_with::<bn256::Point, grumpkin::Point, EE<_>, EE<_>>();
1596+
test_ivc_nondet_with_compression_with::<
1597+
bn256::Point,
1598+
grumpkin::Point,
1599+
ZM<halo2curves::bn256::Bn256>,
1600+
EE<_>,
1601+
>();
15911602
test_ivc_nondet_with_compression_with::<secp256k1::Point, secq256k1::Point, EE<_>, EE<_>>();
15921603
}
15931604

src/provider/bn256_grumpkin.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ use halo2curves::grumpkin::{
2727
G1Affine as GrumpkinAffine, G1Compressed as GrumpkinCompressed, G1 as GrumpkinPoint,
2828
};
2929

30+
use super::kzg_commitment::KZGCommitmentEngine;
31+
3032
/// Re-exports that give access to the standard aliases used in the code base, for bn256
3133
pub mod bn256 {
3234
pub use halo2curves::bn256::{
@@ -58,7 +60,8 @@ impl_traits!(
5860
Bn256Compressed,
5961
Bn256Point,
6062
Bn256Affine,
61-
"30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001"
63+
"30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001",
64+
KZGCommitmentEngine<halo2curves::bn256::Bn256>
6265
);
6366

6467
impl_traits!(

src/provider/kzg_commitment.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ where
3636

3737
fn setup(label: &'static [u8], n: usize) -> Self::CommitmentKey {
3838
// TODO: this is just for testing, replace by grabbing from a real setup for production
39-
let label_bytes: [u8; 32] = label[..32].try_into().unwrap();
40-
let rng = &mut StdRng::from_seed(label_bytes);
41-
UVUniversalKZGParam::gen_srs_for_testing(rng, n)
39+
let mut bytes = [0u8; 32];
40+
let len = label.len().min(32);
41+
bytes[..len].copy_from_slice(&label[..len]);
42+
let rng = &mut StdRng::from_seed(bytes);
43+
UVUniversalKZGParam::gen_srs_for_testing(rng, n.next_power_of_two())
4244
}
4345

4446
fn commit(ck: &Self::CommitmentKey, v: &[<E::G1 as Group>::Scalar]) -> Self::Commitment {

src/provider/mod.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,24 @@ macro_rules! impl_traits {
157157
$name_compressed:ident,
158158
$name_curve:ident,
159159
$name_curve_affine:ident,
160-
$order_str:literal
160+
$order_str:expr
161+
) => {
162+
impl_traits!(
163+
$name,
164+
$name_compressed,
165+
$name_curve,
166+
$name_curve_affine,
167+
$order_str,
168+
CommitmentEngine<Self>
169+
);
170+
};
171+
(
172+
$name:ident,
173+
$name_compressed:ident,
174+
$name_curve:ident,
175+
$name_curve_affine:ident,
176+
$order_str:literal,
177+
$commitment_engine:ty
161178
) => {
162179
impl Group for $name::Point {
163180
type Base = $name::Base;
@@ -167,7 +184,7 @@ macro_rules! impl_traits {
167184
type RO = PoseidonRO<Self::Base, Self::Scalar>;
168185
type ROCircuit = PoseidonROCircuit<Self::Base>;
169186
type TE = Keccak256Transcript<Self>;
170-
type CE = CommitmentEngine<Self>;
187+
type CE = $commitment_engine;
171188

172189
fn vartime_multiscalar_mul(
173190
scalars: &[Self::Scalar],

src/provider/non_hiding_zeromorph.rs

+13-16
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,26 @@
44
55
use crate::{
66
errors::{NovaError, PCSError},
7-
spartan::{math::Math, polys::multilinear::MultilinearPolynomial},
7+
spartan::polys::multilinear::MultilinearPolynomial,
88
traits::{commitment::Len, evaluation::EvaluationEngineTrait, Group, TranscriptEngineTrait},
9-
Commitment, CommitmentKey,
9+
Commitment,
1010
};
1111
use abomonation_derive::Abomonation;
1212
use ff::{BatchInvert, Field, PrimeField};
1313
use group::{Curve, Group as _};
1414
use pairing::{Engine, MillerLoopResult, MultiMillerLoop};
15-
use rand::thread_rng;
1615
use rayon::prelude::{
1716
IndexedParallelIterator, IntoParallelIterator, IntoParallelRefMutIterator, ParallelIterator,
1817
};
1918
use serde::{de::DeserializeOwned, Deserialize, Serialize};
2019
use std::{borrow::Borrow, iter, marker::PhantomData};
2120

22-
use super::non_hiding_kzg::{
23-
UVKZGCommitment, UVKZGEvaluation, UVKZGPoly, UVKZGProof, UVKZGProverKey, UVKZGVerifierKey,
24-
UVUniversalKZGParam, UVKZGPCS,
21+
use super::{
22+
kzg_commitment::KZGCommitmentEngine,
23+
non_hiding_kzg::{
24+
UVKZGCommitment, UVKZGEvaluation, UVKZGPoly, UVKZGProof, UVKZGProverKey, UVKZGVerifierKey,
25+
UVUniversalKZGParam, UVKZGPCS,
26+
},
2527
};
2628

2729
/// `ZMProverKey` is used to generate a proof
@@ -408,27 +410,22 @@ fn eval_and_quotient_scalars<F: Field>(y: F, x: F, z: F, u: &[F]) -> (F, Vec<F>)
408410

409411
impl<E: MultiMillerLoop> EvaluationEngineTrait<E::G1> for ZMPCS<E>
410412
where
411-
E::G1: Group<PreprocessedGroupElement = E::G1Affine, Scalar = E::Fr>,
413+
E::G1: Group<PreprocessedGroupElement = E::G1Affine, Scalar = E::Fr, CE = KZGCommitmentEngine<E>>,
412414
E::G1Affine: Serialize + DeserializeOwned,
413415
E::G2Affine: Serialize + DeserializeOwned,
414416
{
415417
type ProverKey = ZMProverKey<E>;
416-
417418
type VerifierKey = ZMVerifierKey<E>;
418419

419420
type EvaluationArgument = ZMProof<E>;
420421

421-
fn setup(ck: &CommitmentKey<E::G1>) -> (Self::ProverKey, Self::VerifierKey) {
422-
let max_vars = ck.length().log_2();
423-
let mut rng = thread_rng();
424-
let max_poly_size = 1 << (max_vars + 1);
425-
let universal_setup = UVUniversalKZGParam::<E>::gen_srs_for_testing(&mut rng, max_poly_size);
426-
427-
trim(&universal_setup, max_poly_size)
422+
fn setup(ck: &UVUniversalKZGParam<E>) -> (Self::ProverKey, Self::VerifierKey) {
423+
// TODO: refine!!
424+
trim(&ck, ck.length() - 1)
428425
}
429426

430427
fn prove(
431-
ck: &CommitmentKey<E::G1>,
428+
ck: &UVUniversalKZGParam<E>,
432429
pk: &Self::ProverKey,
433430
transcript: &mut <E::G1 as Group>::TE,
434431
comm: &Commitment<E::G1>,

src/spartan/direct.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl<G: Group, S: RelaxedR1CSSNARKTrait<G>, C: StepCircuit<G::Scalar>> DirectSNA
153153
#[cfg(test)]
154154
mod tests {
155155
use super::*;
156-
use crate::provider::{bn256_grumpkin::bn256, secp_secq::secp256k1};
156+
use crate::provider::{bn256_grumpkin::bn256, non_hiding_zeromorph::ZMPCS, secp_secq::secp256k1};
157157
use ::bellpepper_core::{num::AllocatedNum, ConstraintSystem, SynthesisError};
158158
use core::marker::PhantomData;
159159
use ff::PrimeField;
@@ -219,7 +219,7 @@ mod tests {
219219
test_direct_snark_with::<G, Spp>();
220220

221221
type G2 = bn256::Point;
222-
type EE2 = crate::provider::ipa_pc::EvaluationEngine<G2>;
222+
type EE2 = ZMPCS<halo2curves::bn256::Bn256>;
223223
type S2 = crate::spartan::snark::RelaxedR1CSSNARK<G2, EE2>;
224224
type S2pp = crate::spartan::ppsnark::RelaxedR1CSSNARK<G2, EE2>;
225225
test_direct_snark_with::<G2, S2>();

0 commit comments

Comments
 (0)