Skip to content

Commit

Permalink
revert changes for padding, will follow up in separate work
Browse files Browse the repository at this point in the history
  • Loading branch information
martyall committed Jan 17, 2025
1 parent 3cbaf3c commit 54a9e0c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 137 deletions.
21 changes: 11 additions & 10 deletions o1vm/src/interpreters/mips/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,17 @@ impl<Fp: PrimeField, PreImageOracle: PreImageOracleT> Env<Fp, PreImageOracle> {
self.pp_info(&config.info_at, metadata, start);
self.snapshot_state_at(&config.snapshot_state_at);

// Force stops at given iteration
if self.should_trigger_at(&config.stop_at) {
self.halt = true;
println!(
"Halted as requested at step={} instruction={:?}",
self.normalized_instruction_counter(),
opcode
);
return opcode;
}

interpreter::interpret_instruction(self, opcode);

self.instruction_counter = self.next_instruction_counter();
Expand All @@ -1258,16 +1269,6 @@ impl<Fp: PrimeField, PreImageOracle: PreImageOracleT> Env<Fp, PreImageOracle> {
}
});

// Force stops at given iteration
if self.should_trigger_at(&config.stop_at) {
self.halt = true;
println!(
"Halted as requested at step={} instruction={:?}",
self.normalized_instruction_counter(),
opcode
);
}

// Integer division by MAX_ACC to obtain the actual instruction count
if self.halt {
debug!(
Expand Down
2 changes: 1 addition & 1 deletion o1vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ pub use ramlookup::{LookupMode as RAMLookupMode, RAMLookup};
/// `P(X, Y, Z) = q_x X + q_y Y + q_m X Y + q_o Z + q_c`
/// To represent this multi-variate polynomial using the expression framework,
/// we would use 3 different columns.
pub type E<F> = Expr<ConstantExpr<F, BerkeleyChallengeTerm>, Column<RelationColumnType>>;
pub(crate) type E<F> = Expr<ConstantExpr<F, BerkeleyChallengeTerm>, Column<RelationColumnType>>;
108 changes: 29 additions & 79 deletions o1vm/src/pickles/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ use o1vm::{
},
pickles::{proof::ProofInputs, prover, verifier},
preimage_oracle::{NullPreImageOracle, PreImageOracle, PreImageOracleT},
test_preimage_read, E,
test_preimage_read,
};
use poly_commitment::{ipa::SRS, SRS as _};
use rand::rngs::ThreadRng;
use std::{fs::File, io::BufReader, path::Path, process::ExitCode, time::Instant};

pub fn cannon_main(args: cli::cannon::RunArgs) {
Expand Down Expand Up @@ -159,87 +158,38 @@ pub fn cannon_main(args: cli::cannon::RunArgs) {
.push(Fp::from((mips_wit_env.selector - N_MIPS_REL_COLS) as u64));

if curr_proof_inputs.evaluations.instruction_counter.len() == domain_size {
prove_and_verify(domain_fp, &srs, &constraints, curr_proof_inputs, &mut rng);
let start_iteration = Instant::now();
debug!("Limit of {domain_size} reached. We make a proof, verify it (for testing) and start with a new chunk");
let proof = prover::prove::<
Vesta,
DefaultFqSponge<VestaParameters, PlonkSpongeConstantsKimchi>,
DefaultFrSponge<Fp, PlonkSpongeConstantsKimchi>,
_,
>(domain_fp, &srs, curr_proof_inputs, &constraints, &mut rng)
.unwrap();
// Check that the proof is correct. This is for testing purposes.
// Leaving like this for now.
debug!(
"Proof generated in {elapsed} μs",
elapsed = start_iteration.elapsed().as_micros()
);
{
let start_iteration = Instant::now();
let verif = verifier::verify::<
Vesta,
DefaultFqSponge<VestaParameters, PlonkSpongeConstantsKimchi>,
DefaultFrSponge<Fp, PlonkSpongeConstantsKimchi>,
>(domain_fp, &srs, &constraints, &proof);
debug!(
"Verification done in {elapsed} μs",
elapsed = start_iteration.elapsed().as_micros()
);
assert!(verif);
}

curr_proof_inputs = ProofInputs::new(domain_size);
}
}

if curr_proof_inputs.evaluations.instruction_counter.len() < domain_size {
debug!("Padding witness for proof generation");
pad(&mips_wit_env, &mut curr_proof_inputs, &mut rng);
prove_and_verify(domain_fp, &srs, &constraints, curr_proof_inputs, &mut rng);
}
}

fn prove_and_verify(
domain_fp: EvaluationDomains<Fp>,
srs: &SRS<Vesta>,
constraints: &[E<Fp>],
curr_proof_inputs: ProofInputs<Vesta>,
rng: &mut ThreadRng,
) {
let start_iteration = Instant::now();
let proof = prover::prove::<
Vesta,
DefaultFqSponge<VestaParameters, PlonkSpongeConstantsKimchi>,
DefaultFrSponge<Fp, PlonkSpongeConstantsKimchi>,
_,
>(domain_fp, srs, curr_proof_inputs, constraints, rng)
.unwrap();
debug!(
"Proof generated in {elapsed} μs",
elapsed = start_iteration.elapsed().as_micros()
);
let start_iteration = Instant::now();
let verif = verifier::verify::<
Vesta,
DefaultFqSponge<VestaParameters, PlonkSpongeConstantsKimchi>,
DefaultFrSponge<Fp, PlonkSpongeConstantsKimchi>,
>(domain_fp, srs, constraints, &proof);
debug!(
"Verification done in {elapsed} μs",
elapsed = start_iteration.elapsed().as_micros()
);
assert!(verif);
}

fn pad(
witness_env: &mips_witness::Env<Fp, Box<dyn PreImageOracleT>>,
curr_proof_inputs: &mut ProofInputs<Vesta>,
rng: &mut ThreadRng,
) {
let zero = Fp::zero();
// FIXME: Find a better way to get instruction selectors that doesn't
// reveal internals.
let noop_selector: Fp = {
let noop: usize = Instruction::NoOp.into();
Fp::from((noop - N_MIPS_REL_COLS) as u64)
};
curr_proof_inputs
.evaluations
.scratch
.iter_mut()
.for_each(|x| x.resize(x.capacity(), zero));
curr_proof_inputs
.evaluations
.scratch_inverse
.iter_mut()
.for_each(|x| x.resize(x.capacity(), zero));
curr_proof_inputs.evaluations.instruction_counter.resize(
curr_proof_inputs.evaluations.instruction_counter.capacity(),
Fp::from(witness_env.instruction_counter),
);
curr_proof_inputs
.evaluations
.error
.resize_with(curr_proof_inputs.evaluations.error.capacity(), || {
Fp::rand(rng)
});
curr_proof_inputs.evaluations.selector.resize(
curr_proof_inputs.evaluations.selector.capacity(),
noop_selector,
);
}

fn gen_state_json(arg: cli::cannon::GenStateJsonArgs) -> Result<(), String> {
Expand Down
47 changes: 0 additions & 47 deletions o1vm/test-mips-program-prover.sh

This file was deleted.

0 comments on commit 54a9e0c

Please sign in to comment.