Skip to content

Commit

Permalink
Merge pull request #1381 from o1-labs/feature/mips-columns
Browse files Browse the repository at this point in the history
Add support for scratch_state to MIPS VM
  • Loading branch information
mrmr1993 authored Dec 5, 2023
2 parents 21c2834 + 228b1b6 commit 82e3771
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions optimism/src/mips/column.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Column {
ScratchState(usize),
}
4 changes: 4 additions & 0 deletions optimism/src/mips/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ pub enum ITypeInstruction {
}

pub trait InterpreterEnv {
type Position;

fn alloc_scratch(&mut self) -> Self::Position;

type Variable: Clone
+ std::ops::Add<Self::Variable, Output = Self::Variable>
+ std::ops::Mul<Self::Variable, Output = Self::Variable>
Expand Down
1 change: 1 addition & 0 deletions optimism/src/mips/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod column;
pub mod interpreter;
pub mod registers;
pub mod witness;
15 changes: 15 additions & 0 deletions optimism/src/mips/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
PAGE_SIZE,
},
mips::{
column::Column,
interpreter::{
self, ITypeInstruction, Instruction, InstructionPart, InstructionParts, InterpreterEnv,
JTypeInstruction, RTypeInstruction,
Expand Down Expand Up @@ -98,6 +99,14 @@ fn memory_size(total: usize) -> String {
}

impl<Fp: Field> InterpreterEnv for Env<Fp> {
type Position = Column;

fn alloc_scratch(&mut self) -> Self::Position {
let scratch_idx = self.scratch_state_idx;
self.scratch_state_idx += 1;
Column::ScratchState(scratch_idx)
}

type Variable = u32;

fn overwrite_register_checked(
Expand Down Expand Up @@ -211,6 +220,12 @@ impl<Fp: Field> Env<Fp> {
}
}

pub fn write_column(&mut self, column: Column, value: u64) {
match column {
Column::ScratchState(idx) => self.scratch_state[idx] = value.into(),
}
}

pub fn get_memory_direct(&self, addr: u32) -> u8 {
let page = addr >> PAGE_ADDRESS_SIZE;
let page_address = (addr & PAGE_ADDRESS_MASK) as usize;
Expand Down

0 comments on commit 82e3771

Please sign in to comment.