From 67fa659646c34dd98664a03c9e4de24075997384 Mon Sep 17 00:00:00 2001 From: Danny Willems Date: Fri, 1 Nov 2024 18:48:32 +0100 Subject: [PATCH 1/3] o1vm: simplify types in proof and prover --- o1vm/src/pickles/proof.rs | 4 ++-- o1vm/src/pickles/prover.rs | 44 ++++++++++++++++-------------------- o1vm/src/pickles/verifier.rs | 15 +++++------- 3 files changed, 28 insertions(+), 35 deletions(-) diff --git a/o1vm/src/pickles/proof.rs b/o1vm/src/pickles/proof.rs index 099484cc25..e3548cdbfe 100644 --- a/o1vm/src/pickles/proof.rs +++ b/o1vm/src/pickles/proof.rs @@ -1,10 +1,10 @@ use kimchi::{curve::KimchiCurve, proof::PointEvaluations}; use poly_commitment::{ipa::OpeningProof, PolyComm}; -use crate::interpreters::mips::column::N_MIPS_SEL_COLS; +use crate::interpreters::mips::{column::N_MIPS_SEL_COLS, witness::SCRATCH_SIZE}; pub struct WitnessColumns { - pub scratch: [G; crate::interpreters::mips::witness::SCRATCH_SIZE], + pub scratch: [G; SCRATCH_SIZE], pub instruction_counter: G, pub error: G, pub selector: S, diff --git a/o1vm/src/pickles/prover.rs b/o1vm/src/pickles/prover.rs index 35870df3cf..ebafbb695a 100644 --- a/o1vm/src/pickles/prover.rs +++ b/o1vm/src/pickles/prover.rs @@ -1,6 +1,5 @@ use std::array; -use ark_ec::{AffineRepr, Group}; use ark_ff::{One, PrimeField, Zero}; use ark_poly::{univariate::DensePolynomial, Evaluations, Polynomial, Radix2EvaluationDomain as D}; use kimchi::{ @@ -65,7 +64,7 @@ pub fn prove< rng: &mut RNG, ) -> Result, ProverError> where - ::BaseField: PrimeField, + G::BaseField: PrimeField, RNG: RngCore + CryptoRng, { let num_chunks = 1; @@ -76,11 +75,13 @@ where //////////////////////////////////////////////////////////////////////////// // Round 1: Creating and absorbing column commitments //////////////////////////////////////////////////////////////////////////// - type F = DensePolynomial<<::Group as Group>::ScalarField>; debug!("Prover: interpolating all columns, including the selectors"); let ProofInputs { evaluations } = inputs; - let polys: WitnessColumns, [F; N_MIPS_SEL_COLS]> = { + let polys: WitnessColumns< + DensePolynomial, + [DensePolynomial; N_MIPS_SEL_COLS], + > = { let WitnessColumns { scratch, instruction_counter, @@ -91,18 +92,17 @@ where let domain_size = domain.d1.size as usize; // Build the selectors - let selector: [Vec<<::Group as Group>::ScalarField>; N_MIPS_SEL_COLS] = - array::from_fn(|i| { - let mut s_i = Vec::with_capacity(domain_size); - for s in &selector { - s_i.push(if G::ScalarField::from(i as u64) == *s { - G::ScalarField::one() - } else { - G::ScalarField::zero() - }) - } - s_i - }); + let selector: [Vec; N_MIPS_SEL_COLS] = array::from_fn(|i| { + let mut s_i = Vec::with_capacity(domain_size); + for s in &selector { + s_i.push(if G::ScalarField::from(i as u64) == *s { + G::ScalarField::one() + } else { + G::ScalarField::zero() + }) + } + s_i + }); let eval_col = |evals: Vec| { Evaluations::>::from_vec_and_domain(evals, domain.d1) @@ -307,16 +307,12 @@ where } }; // All evaluations at ζ - let zeta_evaluations: WitnessColumns< - <::Group as Group>::ScalarField, - [<::Group as Group>::ScalarField; N_MIPS_SEL_COLS], - > = evals(&zeta); + let zeta_evaluations: WitnessColumns = + evals(&zeta); // All evaluations at ζω - let zeta_omega_evaluations: WitnessColumns< - <::Group as Group>::ScalarField, - [<::Group as Group>::ScalarField; N_MIPS_SEL_COLS], - > = evals(&zeta_omega); + let zeta_omega_evaluations: WitnessColumns = + evals(&zeta_omega); let chunked_quotient = quotient_poly .to_chunked_polynomial(DEGREE_QUOTIENT_POLYNOMIAL as usize, domain.d1.size as usize); diff --git a/o1vm/src/pickles/verifier.rs b/o1vm/src/pickles/verifier.rs index 1c362fdff4..b57b9a6422 100644 --- a/o1vm/src/pickles/verifier.rs +++ b/o1vm/src/pickles/verifier.rs @@ -1,4 +1,4 @@ -use ark_ec::{AffineRepr, Group}; +use ark_ec::AffineRepr; use ark_ff::{Field, One, PrimeField, Zero}; use rand::thread_rng; @@ -31,23 +31,20 @@ use crate::{interpreters::mips::column::N_MIPS_SEL_COLS, E}; use kimchi_msm::columns::Column; type CommitmentColumns = WitnessColumns, [PolyComm; N_MIPS_SEL_COLS]>; -type EvaluationColumns = WitnessColumns< - <::Group as Group>::ScalarField, - [<::Group as Group>::ScalarField; N_MIPS_SEL_COLS], ->; +type EvaluationColumns = WitnessColumns; struct ColumnEval<'a, G: AffineRepr> { commitment: &'a CommitmentColumns, - zeta_eval: &'a EvaluationColumns, - zeta_omega_eval: &'a EvaluationColumns, + zeta_eval: &'a EvaluationColumns, + zeta_omega_eval: &'a EvaluationColumns, } -impl ColumnEvaluations<::ScalarField> for ColumnEval<'_, G> { +impl ColumnEvaluations for ColumnEval<'_, G> { type Column = Column; fn evaluate( &self, col: Self::Column, - ) -> Result::ScalarField>, ExprError> { + ) -> Result, ExprError> { let ColumnEval { commitment: _, zeta_eval, From 2f78e3778b1d87a7c6dcd94d1de743bfcb4ea1b9 Mon Sep 17 00:00:00 2001 From: Danny Willems Date: Fri, 1 Nov 2024 19:02:36 +0100 Subject: [PATCH 2/3] o1vm: remove old FIXME --- o1vm/src/pickles/prover.rs | 1 - o1vm/src/pickles/tests.rs | 3 +-- o1vm/src/pickles/verifier.rs | 5 ++--- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/o1vm/src/pickles/prover.rs b/o1vm/src/pickles/prover.rs index ebafbb695a..2f40787546 100644 --- a/o1vm/src/pickles/prover.rs +++ b/o1vm/src/pickles/prover.rs @@ -254,7 +254,6 @@ where // We compute the polynomial t(X) by dividing the constraints polynomial // by the vanishing polynomial, i.e. Z_H(X). let (quotient, rem) = expr_evaluation_interpolated - // FIXME: Should this be d8? .divide_by_vanishing_poly(domain.d1) .unwrap_or_else(fail_final_q_division); // As the constraints must be verified on H, the rest of the division diff --git a/o1vm/src/pickles/tests.rs b/o1vm/src/pickles/tests.rs index 422f10bc13..873609d604 100644 --- a/o1vm/src/pickles/tests.rs +++ b/o1vm/src/pickles/tests.rs @@ -111,8 +111,7 @@ fn test_small_circuit() { .unwrap(); let instant_before_verification = Instant::now(); - let verif = - verify::(domain, &srs, &vec![expr.clone()], &proof); + let verif = verify::(domain, &srs, &[expr.clone()], &proof); let instant_after_verification = Instant::now(); debug!( "Verification took: {} ms", diff --git a/o1vm/src/pickles/verifier.rs b/o1vm/src/pickles/verifier.rs index b57b9a6422..9057a89802 100644 --- a/o1vm/src/pickles/verifier.rs +++ b/o1vm/src/pickles/verifier.rs @@ -69,8 +69,7 @@ pub fn verify< >( domain: EvaluationDomains, srs: & as OpenProof>::SRS, - //FIXME: change vec to array - constraints: &Vec>, + constraints: &[E], proof: &Proof, ) -> bool where @@ -177,7 +176,7 @@ where }; let combined_expr = - Expr::combine_constraints(0..(constraints.len() as u32), constraints.clone()); + Expr::combine_constraints(0..(constraints.len() as u32), constraints.to_vec()); let numerator_zeta = PolishToken::evaluate( combined_expr.to_polish().as_slice(), From fd0e8b8a2439a2388af9bb6e0950b3471c347410 Mon Sep 17 00:00:00 2001 From: Danny Willems Date: Fri, 1 Nov 2024 19:13:14 +0100 Subject: [PATCH 3/3] o1vm: aesthetic --- o1vm/src/pickles/tests.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/o1vm/src/pickles/tests.rs b/o1vm/src/pickles/tests.rs index 873609d604..0260e06587 100644 --- a/o1vm/src/pickles/tests.rs +++ b/o1vm/src/pickles/tests.rs @@ -24,6 +24,7 @@ use mina_poseidon::{ use o1_utils::tests::make_test_rng; use poly_commitment::SRS; use strum::{EnumCount, IntoEnumIterator}; + #[test] fn test_regression_constraints_with_selectors() { let constraints = { @@ -75,6 +76,7 @@ fn test_regression_selectors_for_instructions() { fn zero_to_n_minus_one(n: usize) -> Vec { (0..n).map(|i| Fq::from((i) as u64)).collect() } + #[test] fn test_small_circuit() { let domain = EvaluationDomains::::create(8).unwrap();