-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deterministic tests #345
Deterministic tests #345
Changes from 10 commits
afbf46d
1a7d21b
426231e
8a04849
38d6fa1
c6991f0
24b5deb
bfbbcf1
ed4c33b
0c54819
a309ab1
22f7f7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ use halo2_middleware::ff::{Field, PrimeField}; | |
use halo2_middleware::zal::traits::MsmAccel; | ||
use halo2curves::pairing::Engine; | ||
use halo2curves::{CurveAffine, CurveExt}; | ||
use rand_core::{OsRng, RngCore}; | ||
use rand_core::RngCore; | ||
use std::fmt::Debug; | ||
use std::marker::PhantomData; | ||
|
||
|
@@ -139,8 +139,8 @@ where | |
type ParamsProver = ParamsKZG<E>; | ||
type ParamsVerifier = ParamsVerifierKZG<E>; | ||
|
||
fn new_params(k: u32) -> Self::ParamsProver { | ||
ParamsKZG::new(k) | ||
fn new_params(k: u32, rng: impl RngCore) -> Self::ParamsProver { | ||
ParamsKZG::new(k, rng) | ||
} | ||
|
||
fn read_params<R: io::Read>(reader: &mut R) -> io::Result<Self::ParamsProver> { | ||
|
@@ -429,8 +429,8 @@ where | |
E::G1: CurveExt<AffineExt = E::G1Affine>, | ||
E::G2Affine: SerdeCurveAffine, | ||
{ | ||
fn new(k: u32) -> Self { | ||
Self::setup(k, OsRng) | ||
fn new(k: u32, rng: impl RngCore) -> Self { | ||
Self::setup(k, rng) | ||
} | ||
|
||
fn commit( | ||
|
@@ -453,20 +453,19 @@ mod test { | |
use crate::poly::commitment::ParamsProver; | ||
use crate::poly::commitment::{Blind, Params}; | ||
use crate::poly::kzg::commitment::ParamsKZG; | ||
use halo2_debug::test_rng; | ||
use halo2_middleware::ff::Field; | ||
use halo2_middleware::zal::impls::H2cEngine; | ||
|
||
#[test] | ||
fn test_commit_lagrange() { | ||
const K: u32 = 6; | ||
|
||
use rand_core::OsRng; | ||
|
||
use crate::poly::EvaluationDomain; | ||
use halo2curves::bn256::{Bn256, Fr}; | ||
|
||
let engine = H2cEngine::new(); | ||
let params = ParamsKZG::<Bn256>::new(K); | ||
let params = ParamsKZG::<Bn256>::new(K, test_rng()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This randomness is used to generate mock params for testing, so |
||
let domain = EvaluationDomain::new(1, K); | ||
|
||
let mut a = domain.empty_lagrange(); | ||
|
@@ -477,7 +476,7 @@ mod test { | |
|
||
let b = domain.lagrange_to_coeff(a.clone()); | ||
|
||
let alpha = Blind(Fr::random(OsRng)); | ||
let alpha = Blind(Fr::random(test_rng())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But this randomness is part of the real protocol, here we need some security guarantees so we probably want to use a different randomness source rather than |
||
|
||
assert_eq!( | ||
params.commit(&engine, &b, alpha), | ||
|
@@ -492,7 +491,7 @@ mod test { | |
use super::super::commitment::Params; | ||
use halo2curves::bn256::Bn256; | ||
|
||
let params0 = ParamsKZG::<Bn256>::new(K); | ||
let params0 = ParamsKZG::<Bn256>::new(K, test_rng()); | ||
let mut data = vec![]; | ||
<ParamsKZG<_> as Params<_>>::write(¶ms0, &mut data).unwrap(); | ||
let params1: ParamsKZG<Bn256> = Params::read::<_>(&mut &data[..]).unwrap(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,9 @@ mod test { | |
TranscriptReadBuffer, TranscriptWriterBuffer, | ||
}; | ||
use group::Curve; | ||
use halo2_debug::test_rng; | ||
use halo2_middleware::ff::WithSmallOrderMulGroup; | ||
use halo2_middleware::zal::{impls::H2cEngine, traits::MsmAccel}; | ||
use rand_core::OsRng; | ||
|
||
#[test] | ||
fn test_roundtrip_ipa() { | ||
|
@@ -29,7 +29,7 @@ mod test { | |
const K: u32 = 4; | ||
|
||
let engine = H2cEngine::new(); | ||
let params = ParamsIPA::<EqAffine>::new(K); | ||
let params = ParamsIPA::<EqAffine>::new(K, test_rng()); | ||
|
||
let proof = create_proof::< | ||
IPACommitmentScheme<EqAffine>, | ||
|
@@ -67,7 +67,7 @@ mod test { | |
const K: u32 = 4; | ||
|
||
let engine = H2cEngine::new(); | ||
let params = ParamsIPA::<EqAffine>::new(K); | ||
let params = ParamsIPA::<EqAffine>::new(K, test_rng()); | ||
|
||
let proof = create_proof::< | ||
IPACommitmentScheme<EqAffine>, | ||
|
@@ -105,7 +105,7 @@ mod test { | |
const K: u32 = 4; | ||
|
||
let engine = H2cEngine::new(); | ||
let params = ParamsKZG::<Bn256>::new(K); | ||
let params = ParamsKZG::<Bn256>::new(K, test_rng()); | ||
|
||
let proof = create_proof::<_, ProverGWC<_>, _, Blake2bWrite<_, _, Challenge255<_>>>( | ||
&engine, ¶ms, | ||
|
@@ -138,7 +138,7 @@ mod test { | |
const K: u32 = 4; | ||
|
||
let engine = H2cEngine::new(); | ||
let params = ParamsKZG::<Bn256>::new(K); | ||
let params = ParamsKZG::<Bn256>::new(K, test_rng()); | ||
|
||
let proof = create_proof::< | ||
KZGCommitmentScheme<Bn256>, | ||
|
@@ -256,7 +256,7 @@ mod test { | |
|
||
let mut transcript = T::init(vec![]); | ||
|
||
let blind = Blind::new(&mut OsRng); | ||
let blind = Blind::new(&mut test_rng()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as previous comment, this randomness is not part of the testing. |
||
let a = params.commit(engine, &ax, blind).to_affine(); | ||
let b = params.commit(engine, &bx, blind).to_affine(); | ||
let c = params.commit(engine, &cx, blind).to_affine(); | ||
|
@@ -297,7 +297,7 @@ mod test { | |
|
||
let prover = P::new(params); | ||
prover | ||
.create_proof(&mut OsRng, &mut transcript, queries) | ||
.create_proof(&mut test_rng(), &mut transcript, queries) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not 100% on this one, but I'd say its not part of testing either. |
||
.unwrap(); | ||
|
||
transcript.finalize() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[package] | ||
name = "halo2_debug" | ||
version = "0.3.0" | ||
authors = [ | ||
"Privacy Scaling Explorations team", | ||
] | ||
edition = "2021" | ||
rust-version = "1.66.0" | ||
description = """ | ||
Halo2 Debug. This package contains utilities for debugging and testing within | ||
the halo2 ecosystem. | ||
""" | ||
license = "MIT OR Apache-2.0" | ||
repository = "https://github.com/privacy-scaling-explorations/halo2" | ||
documentation = "https://privacy-scaling-explorations.github.io/halo2/" | ||
categories = ["cryptography"] | ||
keywords = ["halo", "proofs", "zkp", "zkSNARKs"] | ||
|
||
[package.metadata.docs.rs] | ||
all-features = true | ||
rustdoc-args = ["--cfg", "docsrs", "--html-in-header", "katex-header.html"] | ||
|
||
[dependencies] | ||
tiny-keccak = { version = "2.0.2", features=["keccak"] } | ||
hex = "0.4.3" | ||
rand_core = "0.6.4" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put the new rng here directly (in
setup()
) instead of having it innew()
?.We just want randomness in the setup of mock KZG parameters, but we don't need it in IPA so IMO it's better not to modify the common interface of
ParamsProver
.