Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[experiment] Speed things up #2040

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions optimism/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
rpcs.sh
snapshot-state*
10 changes: 5 additions & 5 deletions optimism/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use kimchi_optimism::{
keccak::column::{KeccakWitness, KeccakWitnessTrait, ZKVM_KECCAK_COLS},
mips::{
column::{MIPSWitness, MIPSWitnessTrait, MIPS_COLUMNS},
witness::{self as mips_witness, SCRATCH_SIZE},
witness::{self as mips_witness},
},
preimage_oracle::PreImageOracle,
proof, DOMAIN_SIZE,
Expand Down Expand Up @@ -78,10 +78,10 @@ pub fn main() -> ExitCode {
ark_ec::short_weierstrass_jacobian::GroupAffine<ark_bn254::g1::Parameters>,
>::default();

let mips_reset_pre_folding_witness = |witness_columns: &mut MIPSWitness<Vec<_>>| {
let _mips_reset_pre_folding_witness = |witness_columns: &mut MIPSWitness<Vec<_>>| {
let MIPSWitness { cols } = witness_columns;
// Resize without deallocating
cols.iter_mut().for_each(Vec::clear);
cols.iter_mut().for_each(Vec::<Fp>::clear);
};

let mut mips_current_pre_folding_witness = MIPSWitness {
Expand Down Expand Up @@ -144,7 +144,7 @@ pub fn main() -> ExitCode {
}

// TODO: unify witness of MIPS to include the instruction and the error
for i in 0..MIPS_COLUMNS {
/*for i in 0..MIPS_COLUMNS {
if i < SCRATCH_SIZE {
mips_current_pre_folding_witness.cols[i].push(env.scratch_state[i]);
} else if i == MIPS_COLUMNS - 2 {
Expand All @@ -165,7 +165,7 @@ pub fn main() -> ExitCode {
&mips_current_pre_folding_witness,
);
mips_reset_pre_folding_witness(&mut mips_current_pre_folding_witness);
}
}*/
}
if !mips_current_pre_folding_witness
.instruction_counter()
Expand Down
12 changes: 4 additions & 8 deletions optimism/src/mips/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub struct Env<Fp> {
pub registers: Registers<u32>,
pub registers_write_index: Registers<u64>,
pub scratch_state_idx: usize,
pub scratch_state: [Fp; SCRATCH_SIZE],
pub scratch_state: [u64; SCRATCH_SIZE],
pub halt: bool,
pub syscall_env: SyscallEnv,
pub preimage_oracle: PreImageOracle,
Expand All @@ -74,8 +74,8 @@ pub struct Env<Fp> {
pub hash_counter: u64,
}

fn fresh_scratch_state<Fp: Field, const N: usize>() -> [Fp; N] {
array::from_fn(|_| Fp::zero())
fn fresh_scratch_state<const N: usize>() -> [u64; N] {
array::from_fn(|_| 0)
}

const KUNIT: usize = 1024; // a kunit of memory is 1024 things (bytes, kilobytes, ...)
Expand Down Expand Up @@ -323,7 +323,7 @@ impl<Fp: Field> InterpreterEnv for Env<Fp> {
self.write_column(position, 0);
0
} else {
self.write_field_column(position, Fp::from(*x).inverse().unwrap());
self.write_column(position, 0);
1 // Placeholder value
}
}
Expand Down Expand Up @@ -809,10 +809,6 @@ impl<Fp: Field> Env<Fp> {
}

pub fn write_column(&mut self, column: Column, value: u64) {
self.write_field_column(column, value.into())
}

pub fn write_field_column(&mut self, column: Column, value: Fp) {
match column {
Column::ScratchState(idx) => self.scratch_state[idx] = value,
Column::InstructionCounter => panic!("Cannot overwrite the column {:?}", column),
Expand Down