Skip to content
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

Pass a rng instance in prover #1851

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions msm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ mod tests {
use ark_ff::UniformRand;
use kimchi::circuits::domains::EvaluationDomains;
use poly_commitment::pairing_proof::PairingSRS;
use rand::{rngs::StdRng, thread_rng, Rng, SeedableRng};

use crate::{
columns::Column, mvlookup::Lookup, proof::Witness, prover::prove, verifier::verify,
Expand All @@ -54,13 +53,15 @@ mod tests {

#[test]
fn test_completeness() {
let mut rng = o1_utils::tests::make_test_rng();

// Include tests for completeness for MVLookup as the random witness
// includes all arguments
let domain_size = 1 << 8;
let domain = EvaluationDomains::<Fp>::create(domain_size).unwrap();

// Trusted setup toxic waste
let x = Fp::rand(&mut rand::rngs::OsRng);
let x = Fp::rand(&mut rng);

let mut srs: PairingSRS<BN254> = PairingSRS::create(x, domain.d1.size as usize);
srs.full_srs.add_lagrange_basis(domain.d1);
Expand All @@ -69,11 +70,12 @@ mod tests {
let constraints: Vec<_> = vec![];

// generate the proof
let proof = prove::<_, OpeningProof, BaseSponge, ScalarSponge, Column>(
let proof = prove::<_, OpeningProof, BaseSponge, ScalarSponge, Column, _>(
domain,
&srs,
witness,
constraints,
&mut rng,
);

// verify the proof
Expand All @@ -83,32 +85,36 @@ mod tests {

#[test]
fn test_soundness() {
let mut rng = o1_utils::tests::make_test_rng();

// We generate two different witness and two different proofs.
let domain_size = 1 << 8;
let domain = EvaluationDomains::<Fp>::create(domain_size).unwrap();

// Trusted setup toxic waste
let x = Fp::rand(&mut rand::rngs::OsRng);
let x = Fp::rand(&mut rng);

let mut srs: PairingSRS<BN254> = PairingSRS::create(x, domain.d1.size as usize);
srs.full_srs.add_lagrange_basis(domain.d1);

let witness = Witness::random(domain);
let constraints = vec![];
// generate the proof
let proof = prove::<_, OpeningProof, BaseSponge, ScalarSponge, Column>(
let proof = prove::<_, OpeningProof, BaseSponge, ScalarSponge, Column, _>(
domain,
&srs,
witness,
constraints.clone(),
&mut rng,
);

let witness_prime = Witness::random(domain);
let proof_prime = prove::<_, OpeningProof, BaseSponge, ScalarSponge, Column>(
let proof_prime = prove::<_, OpeningProof, BaseSponge, ScalarSponge, Column, _>(
domain,
&srs,
witness_prime,
constraints,
&mut rng,
);

// Swap the opening proof. The verification should fail.
Expand Down Expand Up @@ -147,9 +153,7 @@ mod tests {
#[test]
#[ignore]
fn test_soundness_mvlookup() {
let seed: [u8; 32] = thread_rng().gen();
eprintln!("Seed: {:?}", seed);
let mut rng = StdRng::from_seed(seed);
let mut rng = o1_utils::tests::make_test_rng();

// We generate two different witness and two different proofs.
let domain_size = 1 << 8;
Expand All @@ -174,11 +178,12 @@ mod tests {
// Overwriting the first looked up value
witness.mvlookups[0].f[0][0] = wrong_looked_up_value;
// generate the proof
let proof = prove::<_, OpeningProof, BaseSponge, ScalarSponge, Column>(
let proof = prove::<_, OpeningProof, BaseSponge, ScalarSponge, Column, _>(
domain,
&srs,
witness,
constraints,
&mut rng,
);
let verifies = verify::<_, OpeningProof, BaseSponge, ScalarSponge>(domain, &srs, &proof);
// FIXME: At the moment, it does verify. It should not. We are missing constraints.
Expand Down
6 changes: 5 additions & 1 deletion msm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ pub fn generate_random_msm_witness() -> BuilderEnv<BN254G1Affine> {
}

pub fn main() {
// FIXME: use a proper RNG
let mut rng = o1_utils::tests::make_test_rng();

println!("Creating the domain and SRS");
let domain = EvaluationDomains::<Fp>::create(DOMAIN_SIZE).unwrap();

Expand All @@ -40,11 +43,12 @@ pub fn main() {

println!("Generating the proof");
let constraints = vec![];
let proof = prove::<_, OpeningProof, BaseSponge, ScalarSponge, Column>(
let proof = prove::<_, OpeningProof, BaseSponge, ScalarSponge, Column, _>(
domain,
&srs,
witness,
constraints,
&mut rng,
);

println!("Verifying the proof");
Expand Down
6 changes: 5 additions & 1 deletion msm/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use poly_commitment::{
evaluation_proof::DensePolynomialOrEvaluations,
OpenProof, SRS,
};
use rand::{CryptoRng, RngCore};
use rayon::iter::IntoParallelIterator;
use rayon::iter::ParallelIterator;

Expand All @@ -24,14 +25,17 @@ pub fn prove<
EFqSponge: Clone + FqSponge<G::BaseField, G, G::ScalarField>,
EFrSponge: FrSponge<G::ScalarField>,
Column,
RNG,
>(
domain: EvaluationDomains<G::ScalarField>,
srs: &OpeningProof::SRS,
inputs: Witness<G>,
_constraints: Vec<Expr<ConstantExpr<G::ScalarField>, Column>>,
rng: &mut RNG,
) -> Proof<G, OpeningProof>
where
OpeningProof::SRS: Sync,
RNG: RngCore + CryptoRng,
{
// Interpolate all columns on d1, using trait Into.
let evaluations: WitnessColumns<Evaluations<G::ScalarField, D<G::ScalarField>>> = inputs
Expand Down Expand Up @@ -224,7 +228,7 @@ where
v,
u,
fq_sponge_before_evaluations,
&mut rand::rngs::OsRng,
rng,
);
// -- End opening proof - Preparing the structures

Expand Down