Skip to content

Commit

Permalink
o1vm/pickles: Compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Fizzixnerd committed Nov 15, 2024
1 parent d679a0c commit b285710
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 47 deletions.
1 change: 1 addition & 0 deletions msm/src/logup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ pub mod prover {
}

/// Represents the environment for the logup argument.
#[derive(Clone)]
pub struct Env<G: KimchiCurve, ID: LookupTableID> {
/// The polynomial of the multiplicities, indexed by the table ID.
pub lookup_counters_poly_d1: BTreeMap<ID, Vec<DensePolynomial<G::ScalarField>>>,
Expand Down
7 changes: 6 additions & 1 deletion o1vm/src/pickles/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use o1vm::{
witness::{self as mips_witness},
Instruction,
},
lookups::LookupTableIDs,
pickles::{proof::ProofInputs, prover, verifier},
preimage_oracle::PreImageOracle,
};
Expand All @@ -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();

Expand Down Expand Up @@ -95,7 +98,7 @@ pub fn main() -> ExitCode {
constraints
};

let mut curr_proof_inputs: ProofInputs<Vesta> = ProofInputs::new(DOMAIN_SIZE);
let mut curr_proof_inputs: ProofInputs<Vesta, ID> = 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
Expand Down Expand Up @@ -126,6 +129,7 @@ pub fn main() -> ExitCode {
DefaultFqSponge<VestaParameters, PlonkSpongeConstantsKimchi>,
DefaultFrSponge<Fp, PlonkSpongeConstantsKimchi>,
_,
ID,
>(domain_fp, &srs, curr_proof_inputs, &constraints, &mut rng)
.unwrap();
// FIXME: check that the proof is correct. This is for testing purposes.
Expand All @@ -138,6 +142,7 @@ pub fn main() -> ExitCode {
Vesta,
DefaultFqSponge<VestaParameters, PlonkSpongeConstantsKimchi>,
DefaultFrSponge<Fp, PlonkSpongeConstantsKimchi>,
ID,
>(domain_fp, &srs, &constraints, &proof);
assert!(verif);

Expand Down
2 changes: 1 addition & 1 deletion o1vm/src/pickles/proof.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -10,6 +9,7 @@ use poly_commitment::{ipa::OpeningProof, PolyComm};

use crate::interpreters::mips::column::N_MIPS_SEL_COLS;

#[derive(Clone)]
pub struct WitnessColumns<F, G: KimchiCurve, S, ID: LookupTableID> {
pub scratch: [F; crate::interpreters::mips::witness::SCRATCH_SIZE],
pub instruction_counter: F,
Expand Down
32 changes: 7 additions & 25 deletions o1vm/src/pickles/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
};

Expand Down Expand Up @@ -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(),
}
};

Expand All @@ -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(),
}
};

Expand All @@ -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 {
Expand Down Expand Up @@ -352,26 +340,20 @@ where
selector,
lookup_env,
} = &polys;
let eval = |poly: &DensePolynomial<G::ScalarField>| {
poly.evaluate(point)
};
let eval = |poly: &DensePolynomial<G::ScalarField>| poly.evaluate(point);
let scratch = scratch.par_iter().map(eval).collect::<Vec<_>>();
let selector = selector.par_iter().map(eval).collect::<Vec<_>>();
WitnessColumns {
scratch: scratch.try_into().unwrap(),
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<G::ScalarField, G, [G::ScalarField; N_MIPS_SEL_COLS], ID> =
evals(&zeta);

// All evaluations at ζω
let zeta_omega_evaluations: WitnessColumns<
Expand Down
59 changes: 39 additions & 20 deletions o1vm/src/pickles/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -35,33 +35,41 @@ use crate::{interpreters::mips::column::N_MIPS_SEL_COLS, E};
use kimchi_msm::{columns::Column, LookupTableID};

type Evals<F> = Evaluations<F, Radix2EvaluationDomain<F>>;
type CommitmentColumns<G: KimchiCurve, ID> =
WitnessColumns<PolyComm<G>, G, [PolyComm<G>; N_MIPS_SEL_COLS], ID>;
type EvaluationColumns<G: KimchiCurve, ID> =
WitnessColumns<Evals<G::ScalarField>, G, [Evals<G::ScalarField>; N_MIPS_SEL_COLS], ID>;
type CommitmentColumns<G, ID> = WitnessColumns<PolyComm<G>, G, [PolyComm<G>; N_MIPS_SEL_COLS], ID>;
type EvaluationColumns<G, ID> = WitnessColumns<
Evals<<G as AffineRepr>::ScalarField>,
G,
[Evals<<G as AffineRepr>::ScalarField>; N_MIPS_SEL_COLS],
ID,
>;

struct ColumnEval<'a, G: AffineRepr + KimchiCurve, ID: LookupTableID> {
commitment: &'a CommitmentColumns<G, ID>,
zeta_eval: &'a EvaluationColumns<G, ID>,
zeta_omega_eval: &'a EvaluationColumns<G, ID>,
}

impl<G: AffineRepr + KimchiCurve, ID: LookupTableID> ColumnEvaluations<Evals<G::ScalarField>>
impl<G: AffineRepr + KimchiCurve, ID: LookupTableID> ColumnEvaluations<G::ScalarField>
for ColumnEval<'_, G, ID>
{
type Column = Column;
fn evaluate(
&self,
col: Self::Column,
) -> Result<PointEvaluations<Evals<G::ScalarField>>, ExprError<Self::Column>> {
) -> Result<PointEvaluations<G::ScalarField>, ExprError<Self::Column>> {
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))
}
Expand Down Expand Up @@ -131,9 +139,20 @@ where
let omega = domain.d1.group_gen;
let zeta_omega = zeta * omega;

let to_eval_witness_columns = |witness_columns: WitnessColumns<G::ScalarField, G, [G::ScalarField; N_MIPS_SEL_COLS], ID>| {
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::<Vec<_>>();
let selector = selector.par_iter().map(to_evals).collect::<Vec<_>>();
WitnessColumns {
Expand All @@ -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
Expand Down Expand Up @@ -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
};
Expand Down

0 comments on commit b285710

Please sign in to comment.