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

Prover: add constraints parameter #1850

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
36 changes: 29 additions & 7 deletions msm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ mod tests {
use rand::{rngs::StdRng, thread_rng, Rng, SeedableRng};

use crate::{
mvlookup::Lookup, proof::Witness, prover::prove, verifier::verify, BaseSponge, Fp,
OpeningProof, ScalarSponge, BN254,
columns::Column, mvlookup::Lookup, proof::Witness, prover::prove, verifier::verify,
BaseSponge, Fp, OpeningProof, ScalarSponge, BN254,
};

#[test]
Expand All @@ -66,9 +66,15 @@ mod tests {
srs.full_srs.add_lagrange_basis(domain.d1);

let witness = Witness::random(domain);
let constraints: Vec<_> = vec![];

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

// verify the proof
let verifies = verify::<_, OpeningProof, BaseSponge, ScalarSponge>(domain, &srs, &proof);
Expand All @@ -88,12 +94,22 @@ mod tests {
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>(domain, &srs, witness);
let proof = prove::<_, OpeningProof, BaseSponge, ScalarSponge, Column>(
domain,
&srs,
witness,
constraints.clone(),
);

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

// Swap the opening proof. The verification should fail.
{
Expand Down Expand Up @@ -146,6 +162,7 @@ mod tests {
srs.full_srs.add_lagrange_basis(domain.d1);

let mut witness = Witness::random(domain);
let constraints = vec![];
// Take one random f_i (FIXME: taking first one for now)
let looked_up_values = witness.mvlookups[0].f[0].clone();
// We change a random looked up element (FIXME: first one for now)
Expand All @@ -157,7 +174,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>(domain, &srs, witness);
let proof = prove::<_, OpeningProof, BaseSponge, ScalarSponge, Column>(
domain,
&srs,
witness,
constraints,
);
let verifies = verify::<_, OpeningProof, BaseSponge, ScalarSponge>(domain, &srs, &proof);
// FIXME: At the moment, it does verify. It should not. We are missing constraints.
assert!(!verifies);
Expand Down
9 changes: 8 additions & 1 deletion msm/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use ark_ff::UniformRand;
use kimchi_msm::columns::Column;
use rand::thread_rng;

use kimchi::circuits::domains::EvaluationDomains;
Expand Down Expand Up @@ -38,7 +39,13 @@ pub fn main() {
let witness = env.get_witness();

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

println!("Verifying the proof");
let verifies = verify::<_, OpeningProof, BaseSponge, ScalarSponge>(domain, &srs, &proof);
Expand Down
3 changes: 3 additions & 0 deletions msm/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use ark_ff::Zero;
use ark_poly::Evaluations;
use ark_poly::{univariate::DensePolynomial, Polynomial, Radix2EvaluationDomain as D};
use kimchi::circuits::domains::EvaluationDomains;
use kimchi::circuits::expr::{ConstantExpr, Expr};
use kimchi::plonk_sponge::FrSponge;
use kimchi::{curve::KimchiCurve, groupmap::GroupMap};
use mina_poseidon::sponge::ScalarChallenge;
Expand All @@ -22,10 +23,12 @@ pub fn prove<
OpeningProof: OpenProof<G>,
EFqSponge: Clone + FqSponge<G::BaseField, G, G::ScalarField>,
EFrSponge: FrSponge<G::ScalarField>,
Column,
>(
domain: EvaluationDomains<G::ScalarField>,
srs: &OpeningProof::SRS,
inputs: Witness<G>,
_constraints: Vec<Expr<ConstantExpr<G::ScalarField>, Column>>,
) -> Proof<G, OpeningProof>
where
OpeningProof::SRS: Sync,
Expand Down