From b285710585766242352beec0faff57c66ad201f7 Mon Sep 17 00:00:00 2001 From: Matt Walker Date: Thu, 14 Nov 2024 20:49:18 -0500 Subject: [PATCH] o1vm/pickles: Compiles --- msm/src/logup.rs | 1 + o1vm/src/pickles/main.rs | 7 ++++- o1vm/src/pickles/proof.rs | 2 +- o1vm/src/pickles/prover.rs | 32 +++++-------------- o1vm/src/pickles/verifier.rs | 59 ++++++++++++++++++++++++------------ 5 files changed, 54 insertions(+), 47 deletions(-) diff --git a/msm/src/logup.rs b/msm/src/logup.rs index 117fc603a4..c0dedb57e9 100644 --- a/msm/src/logup.rs +++ b/msm/src/logup.rs @@ -512,6 +512,7 @@ pub mod prover { } /// Represents the environment for the logup argument. + #[derive(Clone)] pub struct Env { /// The polynomial of the multiplicities, indexed by the table ID. pub lookup_counters_poly_d1: BTreeMap>>, diff --git a/o1vm/src/pickles/main.rs b/o1vm/src/pickles/main.rs index 0ea1bf6bc0..371e411480 100644 --- a/o1vm/src/pickles/main.rs +++ b/o1vm/src/pickles/main.rs @@ -17,6 +17,7 @@ use o1vm::{ witness::{self as mips_witness}, Instruction, }, + lookups::LookupTableIDs, pickles::{proof::ProofInputs, prover, verifier}, preimage_oracle::PreImageOracle, }; @@ -28,6 +29,8 @@ use mina_curves::pasta::{Fp, Vesta}; pub const DOMAIN_SIZE: usize = 1 << 15; +type ID = LookupTableIDs; + pub fn main() -> ExitCode { let cli = cannon_cli::main_cli(); @@ -95,7 +98,7 @@ pub fn main() -> ExitCode { constraints }; - let mut curr_proof_inputs: ProofInputs = ProofInputs::new(DOMAIN_SIZE); + let mut curr_proof_inputs: ProofInputs = ProofInputs::new(DOMAIN_SIZE); while !mips_wit_env.halt { let _instr: Instruction = mips_wit_env.step(&configuration, &meta, &start); for (scratch, scratch_chunk) in mips_wit_env @@ -126,6 +129,7 @@ pub fn main() -> ExitCode { DefaultFqSponge, DefaultFrSponge, _, + ID, >(domain_fp, &srs, curr_proof_inputs, &constraints, &mut rng) .unwrap(); // FIXME: check that the proof is correct. This is for testing purposes. @@ -138,6 +142,7 @@ pub fn main() -> ExitCode { Vesta, DefaultFqSponge, DefaultFrSponge, + ID, >(domain_fp, &srs, &constraints, &proof); assert!(verif); diff --git a/o1vm/src/pickles/proof.rs b/o1vm/src/pickles/proof.rs index d42bc890a8..cf5c1480ff 100644 --- a/o1vm/src/pickles/proof.rs +++ b/o1vm/src/pickles/proof.rs @@ -1,6 +1,5 @@ use std::collections::BTreeMap; -use ark_poly::Radix2EvaluationDomain; use kimchi::{curve::KimchiCurve, proof::PointEvaluations}; use kimchi_msm::{ logup::{prover::Env as LookupEnv, LookupProof}, @@ -10,6 +9,7 @@ use poly_commitment::{ipa::OpeningProof, PolyComm}; use crate::interpreters::mips::column::N_MIPS_SEL_COLS; +#[derive(Clone)] pub struct WitnessColumns { pub scratch: [F; crate::interpreters::mips::witness::SCRATCH_SIZE], pub instruction_counter: F, diff --git a/o1vm/src/pickles/prover.rs b/o1vm/src/pickles/prover.rs index 32d00461b6..a75c2bfe6a 100644 --- a/o1vm/src/pickles/prover.rs +++ b/o1vm/src/pickles/prover.rs @@ -126,7 +126,7 @@ where instruction_counter: eval_col(instruction_counter), error: eval_col(error.clone()), selector: selector.try_into().unwrap(), - lookup_env: *lookup_env, + lookup_env: lookup_env.clone(), } }; @@ -157,7 +157,7 @@ where instruction_counter: comm(instruction_counter), error: comm(error), selector: selector.try_into().unwrap(), - lookup_env: *lookup_env, + lookup_env: lookup_env.clone(), } }; @@ -184,7 +184,7 @@ where instruction_counter: eval_d8(instruction_counter), error: eval_d8(error), selector: selector.try_into().unwrap(), - lookup_env: *lookup_env, + lookup_env: lookup_env.clone(), } }; @@ -210,18 +210,6 @@ where None }; - let max_degree = { - if lookup_env.is_none() { - constraints - .iter() - .map(|expr| expr.degree(1, 0)) - .max() - .unwrap_or(0) - } else { - 8 - } - }; - // Don't need to be absorbed. Already absorbed in logup::prover::Env::create // FIXME: remove clone let logup_commitments = Option::map(lookup_env.as_ref(), |lookup_env| LookupProof { @@ -352,9 +340,7 @@ where selector, lookup_env, } = &polys; - let eval = |poly: &DensePolynomial| { - poly.evaluate(point) - }; + let eval = |poly: &DensePolynomial| poly.evaluate(point); let scratch = scratch.par_iter().map(eval).collect::>(); let selector = selector.par_iter().map(eval).collect::>(); WitnessColumns { @@ -362,16 +348,12 @@ where instruction_counter: eval(instruction_counter), error: eval(error), selector: selector.try_into().unwrap(), - lookup_env: *lookup_env, + lookup_env: lookup_env.clone(), } }; // All evaluations at ζ - let zeta_evaluations: WitnessColumns< - G::ScalarField, - G, - [G::ScalarField; N_MIPS_SEL_COLS], - ID, - > = evals(&zeta); + let zeta_evaluations: WitnessColumns = + evals(&zeta); // All evaluations at ζω let zeta_omega_evaluations: WitnessColumns< diff --git a/o1vm/src/pickles/verifier.rs b/o1vm/src/pickles/verifier.rs index 65cc71bc73..606e09612c 100644 --- a/o1vm/src/pickles/verifier.rs +++ b/o1vm/src/pickles/verifier.rs @@ -9,13 +9,13 @@ use kimchi::{ circuits::{ berkeley_columns::BerkeleyChallenges, domains::EvaluationDomains, - expr::{ColumnEnvironment, ColumnEvaluations, Constants, Expr, ExprError, PolishToken}, + expr::{ColumnEvaluations, Constants, Expr, ExprError, PolishToken}, gate::CurrOrNext, }, curve::KimchiCurve, groupmap::GroupMap, plonk_sponge::FrSponge, - proof::PointEvaluations, snarky::api::Witness, + proof::PointEvaluations, }; use mina_poseidon::{sponge::ScalarChallenge, FqSponge}; use poly_commitment::{ @@ -35,10 +35,13 @@ use crate::{interpreters::mips::column::N_MIPS_SEL_COLS, E}; use kimchi_msm::{columns::Column, LookupTableID}; type Evals = Evaluations>; -type CommitmentColumns = - WitnessColumns, G, [PolyComm; N_MIPS_SEL_COLS], ID>; -type EvaluationColumns = - WitnessColumns, G, [Evals; N_MIPS_SEL_COLS], ID>; +type CommitmentColumns = WitnessColumns, G, [PolyComm; N_MIPS_SEL_COLS], ID>; +type EvaluationColumns = WitnessColumns< + Evals<::ScalarField>, + G, + [Evals<::ScalarField>; N_MIPS_SEL_COLS], + ID, +>; struct ColumnEval<'a, G: AffineRepr + KimchiCurve, ID: LookupTableID> { commitment: &'a CommitmentColumns, @@ -46,22 +49,27 @@ struct ColumnEval<'a, G: AffineRepr + KimchiCurve, ID: LookupTableID> { zeta_omega_eval: &'a EvaluationColumns, } -impl ColumnEvaluations> +impl ColumnEvaluations for ColumnEval<'_, G, ID> { type Column = Column; fn evaluate( &self, col: Self::Column, - ) -> Result>, ExprError> { + ) -> Result, ExprError> { let ColumnEval { commitment: _, zeta_eval, zeta_omega_eval, } = *self; - if let Some(&zeta) = get_column_eval(zeta_eval, &col) { - if let Some(&zeta_omega) = get_column_eval(zeta_omega_eval, &col) { - Ok(PointEvaluations { zeta, zeta_omega }) + if let Some(&ref zeta) = get_column_eval(zeta_eval, &col) { + if let Some(&ref zeta_omega) = get_column_eval(zeta_omega_eval, &col) { + assert!(zeta.evals.len() == 1); + assert!(zeta_omega.evals.len() == 1); + Ok(PointEvaluations { + zeta: zeta.evals[0], + zeta_omega: zeta_omega.evals[0], + }) } else { Err(ExprError::MissingEvaluation(col, CurrOrNext::Next)) } @@ -131,9 +139,20 @@ where let omega = domain.d1.group_gen; let zeta_omega = zeta * omega; - let to_eval_witness_columns = |witness_columns: WitnessColumns| { + let to_eval_witness_columns = |witness_columns: WitnessColumns< + G::ScalarField, + G, + [G::ScalarField; N_MIPS_SEL_COLS], + ID, + >| { let to_evals = |&x| Evaluations::from_vec_and_domain(vec![x], domain.d1.clone()); - let WitnessColumns {scratch, instruction_counter, error, selector, lookup_env} = witness_columns; + let WitnessColumns { + scratch, + instruction_counter, + error, + selector, + lookup_env, + } = witness_columns; let scratch = scratch.par_iter().map(to_evals).collect::>(); let selector = selector.par_iter().map(to_evals).collect::>(); WitnessColumns { @@ -147,8 +166,8 @@ where let column_eval = ColumnEval { commitment: commitments, - zeta_eval: &to_eval_witness_columns(*zeta_evaluations), - zeta_omega_eval: &to_eval_witness_columns(*zeta_omega_evaluations), + zeta_eval: &to_eval_witness_columns(zeta_evaluations.clone()), + zeta_omega_eval: &to_eval_witness_columns(zeta_omega_evaluations.clone()), }; // -- Absorb all commitments_and_evaluations @@ -237,17 +256,17 @@ where evaluations.push(Evaluation { commitment, evaluations: vec![ - point_evaluations.zeta.evals, - point_evaluations.zeta_omega.evals, + vec![point_evaluations.zeta], + vec![point_evaluations.zeta_omega], ], }) }); evaluations.push(Evaluation { commitment: proof.quotient_commitment.clone(), evaluations: vec![ - quotient_evaluations.zeta, - quotient_evaluations.zeta_omega, - ] + quotient_evaluations.zeta.clone(), + quotient_evaluations.zeta_omega.clone(), + ], }); evaluations };