Skip to content

Commit

Permalink
setup failing prover example
Browse files Browse the repository at this point in the history
  • Loading branch information
martyall committed Jan 9, 2025
1 parent 1a8390a commit ac8aa29
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
2 changes: 2 additions & 0 deletions o1vm/src/cli/cannon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ impl From<MipsVmConfigurationArgs> for VmConfiguration {
pub struct RunArgs {
#[arg(long = "preimage-db-dir", value_name = "PREIMAGE_DB_DIR")]
pub preimage_db_dir: Option<String>,
#[arg(long = "srs-cache", value_name = "SRS_CACHE")]
pub srs_cache: Option<String>,
// it's important that vm_cfg is last in order to properly parse the host field
#[command(flatten)]
pub vm_cfg: MipsVmConfigurationArgs,
Expand Down
3 changes: 2 additions & 1 deletion o1vm/src/interpreters/mips/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions o1vm/src/interpreters/mips/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ pub fn interpret_instruction<Env: InterpreterEnv>(env: &mut Env, instr: Instruct
}
}

pub fn interpret_noop<Env: InterpreterEnv>(env: &mut env) {
pub fn interpret_noop<Env: InterpreterEnv>(env: &mut Env) {
let instruction_pointer = env.get_instruction_pointer();
let instruction = {
let v0 = env.read_memory(&instruction_pointer);
Expand All @@ -994,7 +994,7 @@ pub fn interpret_noop<Env: InterpreterEnv>(env: &mut env) {
};

env.range_check8(&opcode, 6);
env.assert_zero(&opcode);
env.assert_is_zero(opcode);
}

pub fn interpret_rtype<Env: InterpreterEnv>(env: &mut Env, instr: RTypeInstruction) {
Expand Down
41 changes: 36 additions & 5 deletions o1vm/src/pickles/main.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -48,10 +48,38 @@ pub fn cannon_main(args: cli::cannon::RunArgs) {
let start = Start::create(state.step as usize);

let domain_fp = EvaluationDomains::<Fp>::create(DOMAIN_SIZE).unwrap();
let srs: SRS<Vesta> = {
let srs = SRS::create(DOMAIN_SIZE);
srs.get_lagrange_basis(domain_fp.d1);
srs

let srs: SRS<Vesta> = 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<Vesta> = {
// By convention, proof systems serializes a TestSRS with filename 'test_<CURVE_NAME>.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<Vesta> = 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
Expand Down Expand Up @@ -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> {
Expand Down
11 changes: 9 additions & 2 deletions o1vm/src/pickles/verifier.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use ark_ec::AffineRepr;
use ark_ff::{Field, One, PrimeField, Zero};
use log::debug;
use rand::thread_rng;

use kimchi::{
Expand Down Expand Up @@ -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
}

0 comments on commit ac8aa29

Please sign in to comment.