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

Marc/track lookup arity #3002

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 o1vm/src/interpreters/mips/tests_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ where
lookup_multiplicities: LookupMultiplicities::new(),
lookup_state_idx: 0,
lookup_state: vec![],
lookup_arity: vec![],
selector: crate::interpreters::mips::column::N_MIPS_SEL_COLS,
halt: false,
// Keccak related
Expand Down
11 changes: 10 additions & 1 deletion o1vm/src/interpreters/mips/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ pub struct Env<Fp, PreImageOracle: PreImageOracleT> {
pub scratch_state_inverse: [Fp; SCRATCH_SIZE_INVERSE],
pub lookup_state_idx: usize,
pub lookup_state: Vec<Fp>,
// tracks the arity of every lookup
// [1,1,3] means that the lookup state is of size 5,
// containing two lookup of arity one and one of arity three.
pub lookup_arity: Vec<usize>,
pub halt: bool,
pub syscall_env: SyscallEnv,
pub selector: usize,
Expand Down Expand Up @@ -178,9 +182,11 @@ impl<Fp: PrimeField, PreImageOracle: PreImageOracleT> InterpreterEnv for Env<Fp,
}

fn add_lookup(&mut self, lookup: Lookup<Self::Variable>) {
let mut arity_counter = 0;
let mut add_value = |x: Fp| {
self.lookup_state_idx += 1;
self.lookup_state.push(x);
arity_counter += 1;
};
let Lookup {
table_id,
Expand All @@ -201,7 +207,7 @@ impl<Fp: PrimeField, PreImageOracle: PreImageOracleT> InterpreterEnv for Env<Fp,
for value in values.iter() {
add_value(*value);
}

// Update multiplicities
if let Some(idx) = table_id.ix_by_value(values.as_slice()) {
match table_id {
LookupTableIDs::PadLookup => self.lookup_multiplicities.pad_lookup[idx] += 1,
Expand All @@ -224,6 +230,8 @@ impl<Fp: PrimeField, PreImageOracle: PreImageOracleT> InterpreterEnv for Env<Fp,
LookupTableIDs::KeccakStepLookup => (),
}
}
//Update arity
self.lookup_arity.push(arity_counter);
}

fn instruction_counter(&self) -> Self::Variable {
Expand Down Expand Up @@ -963,6 +971,7 @@ impl<Fp: PrimeField, PreImageOracle: PreImageOracleT> Env<Fp, PreImageOracle> {
scratch_state_inverse: fresh_scratch_state(),
lookup_state_idx: 0,
lookup_state: vec![],
lookup_arity: vec![],
halt: state.exited,
syscall_env,
selector,
Expand Down
Loading