diff --git a/o1vm/src/cli/cannon.rs b/o1vm/src/cli/cannon.rs index a8f8277550..245f9d1e61 100644 --- a/o1vm/src/cli/cannon.rs +++ b/o1vm/src/cli/cannon.rs @@ -105,6 +105,8 @@ impl From for VmConfiguration { pub struct RunArgs { #[arg(long = "preimage-db-dir", value_name = "PREIMAGE_DB_DIR")] pub preimage_db_dir: Option, + #[arg(long = "srs-cache", value_name = "SRS_CACHE")] + pub srs_cache: Option, // it's important that vm_cfg is last in order to properly parse the host field #[command(flatten)] pub vm_cfg: MipsVmConfigurationArgs, diff --git a/o1vm/src/interpreters/mips/column.rs b/o1vm/src/interpreters/mips/column.rs index 9af7f9ad16..a4925f7262 100644 --- a/o1vm/src/interpreters/mips/column.rs +++ b/o1vm/src/interpreters/mips/column.rs @@ -44,8 +44,9 @@ pub const SCRATCH_SIZE_INVERSE: usize = 12; pub const N_MIPS_REL_COLS: usize = SCRATCH_SIZE + SCRATCH_SIZE_INVERSE + 2; /// The number of witness columns used to store the instruction selectors. +/// NOTE: The +1 is coming from the NoOp instruction. pub const N_MIPS_SEL_COLS: usize = - RTypeInstruction::COUNT + JTypeInstruction::COUNT + ITypeInstruction::COUNT; + RTypeInstruction::COUNT + JTypeInstruction::COUNT + ITypeInstruction::COUNT + 1; /// All the witness columns used in MIPS pub const N_MIPS_COLS: usize = N_MIPS_REL_COLS + N_MIPS_SEL_COLS; diff --git a/o1vm/src/interpreters/mips/interpreter.rs b/o1vm/src/interpreters/mips/interpreter.rs index 0e77e9552a..8d42ddd9ec 100644 --- a/o1vm/src/interpreters/mips/interpreter.rs +++ b/o1vm/src/interpreters/mips/interpreter.rs @@ -976,7 +976,7 @@ pub fn interpret_instruction(env: &mut Env, instr: Instruct } } -pub fn interpret_noop(env: &mut env) { +pub fn interpret_noop(env: &mut Env) { let instruction_pointer = env.get_instruction_pointer(); let instruction = { let v0 = env.read_memory(&instruction_pointer); @@ -994,7 +994,7 @@ pub fn interpret_noop(env: &mut env) { }; env.range_check8(&opcode, 6); - env.assert_zero(&opcode); + env.assert_is_zero(opcode); } pub fn interpret_rtype(env: &mut Env, instr: RTypeInstruction) { diff --git a/o1vm/src/pickles/main.rs b/o1vm/src/pickles/main.rs index da9c858bce..62fcb1fa72 100644 --- a/o1vm/src/pickles/main.rs +++ b/o1vm/src/pickles/main.rs @@ -1,6 +1,6 @@ use ark_ff::UniformRand; use clap::Parser; -use kimchi::circuits::domains::EvaluationDomains; +use kimchi::{circuits::domains::EvaluationDomains, precomputed_srs::TestSRS}; use log::debug; use mina_curves::pasta::{Fp, Vesta, VestaParameters}; use mina_poseidon::{ @@ -48,10 +48,38 @@ pub fn cannon_main(args: cli::cannon::RunArgs) { let start = Start::create(state.step as usize); let domain_fp = EvaluationDomains::::create(DOMAIN_SIZE).unwrap(); - let srs: SRS = { - let srs = SRS::create(DOMAIN_SIZE); - srs.get_lagrange_basis(domain_fp.d1); - srs + + let srs: SRS = match &args.srs_cache { + Some(cache) => { + debug!("Loading SRS from cache {}", cache); + let file_path = Path::new(cache); + let file = File::open(file_path).expect("Error opening SRS cache file"); + let srs: SRS = { + // By convention, proof systems serializes a TestSRS with filename 'test_.srs'. + // The benefit of using this is you don't waste time verifying the SRS. + if file_path + .file_name() + .unwrap() + .to_str() + .unwrap() + .starts_with("test_") + { + let test_srs: TestSRS = rmp_serde::from_read(&file).unwrap(); + From::from(test_srs) + } else { + rmp_serde::from_read(&file).unwrap() + } + }; + debug!("SRS loaded successfully from cache"); + srs + } + None => { + debug!("No SRS cache provided. Creating SRS from scratch"); + let srs = SRS::create(DOMAIN_SIZE); + srs.get_lagrange_basis(domain_fp.d1); + debug!("SRS created successfully"); + srs + } }; // Initialize the environments @@ -140,6 +168,9 @@ pub fn cannon_main(args: cli::cannon::RunArgs) { curr_proof_inputs = ProofInputs::new(DOMAIN_SIZE); } } + if curr_proof_inputs.evaluations.instruction_counter.is_empty() { + debug!("Didn't create proof for the last chunk"); + } } fn gen_state_json(arg: cli::cannon::GenStateJsonArgs) -> Result<(), String> { diff --git a/o1vm/src/pickles/verifier.rs b/o1vm/src/pickles/verifier.rs index fbbaa912eb..d30abd2fe0 100644 --- a/o1vm/src/pickles/verifier.rs +++ b/o1vm/src/pickles/verifier.rs @@ -1,5 +1,6 @@ use ark_ec::AffineRepr; use ark_ff::{Field, One, PrimeField, Zero}; +use log::debug; use rand::thread_rng; use kimchi::{ @@ -262,6 +263,12 @@ where (res, zeta_i_n) }, ); - (quotient_zeta == numerator_zeta / (zeta.pow([domain.d1.size]) - G::ScalarField::one())) - && OpeningProof::verify(srs, &group_map, &mut [batch], &mut thread_rng()) + let c1 = quotient_zeta == numerator_zeta / (zeta.pow([domain.d1.size]) - G::ScalarField::one()); + debug!( + "Verification condition 1 (numerator_zeta vanishes on domain): {}", + c1 + ); + let c2 = OpeningProof::verify(srs, &group_map, &mut [batch], &mut thread_rng()); + debug!("Verification condition 2 (verify opening proof): {}", c2); + c1 && c2 }