Skip to content

Commit

Permalink
More cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Nashtare committed Apr 22, 2024
1 parent 1a8178e commit 8b15f0e
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 58 deletions.
14 changes: 0 additions & 14 deletions evm_arithmetization/src/cpu/kernel/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -924,20 +924,6 @@ impl<F: Field> State<F> for Interpreter<F> {
}
}

/// Inserts a preinitialized segment, given as a [Segment],
/// into the `preinitialized_segments` memory field.
fn insert_preinitialized_segment(&mut self, segment: Segment, values: MemorySegmentState) {
self.generation_state
.memory
.insert_preinitialized_segment(segment, values);
}

fn is_preinitialized_segment(&self, segment: usize) -> bool {
self.generation_state
.memory
.is_preinitialized_segment(segment)
}

fn incr_gas(&mut self, n: u64) {
self.generation_state.incr_gas(n);
}
Expand Down
29 changes: 7 additions & 22 deletions evm_arithmetization/src/generation/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use crate::memory::segments::Segment;
use crate::util::u256_to_usize;
use crate::witness::errors::ProgramError;
use crate::witness::memory::MemoryChannel::GeneralPurpose;
use crate::witness::memory::MemoryOpKind;
use crate::witness::memory::{MemoryAddress, MemoryContextState, MemoryOp, MemoryState};
use crate::witness::memory::{MemoryOpKind, MemorySegmentState};
use crate::witness::operation::{generate_exception, Operation};
use crate::witness::state::RegistersState;
use crate::witness::traces::{TraceCheckpoint, Traces};
Expand Down Expand Up @@ -85,8 +85,11 @@ pub(crate) trait State<F: Field> {

/// Checks whether we have reached the `halt` label in kernel mode.
fn at_halt(&self) -> bool {
let halt = KERNEL.global_labels["halt"];
let halt_final = KERNEL.global_labels["halt_final"];
let registers = self.get_registers();
registers.is_kernel && registers.program_counter == KERNEL.global_labels["halt"]
registers.is_kernel
&& (registers.program_counter == halt || registers.program_counter == halt_final)
}

/// Returns the context in which the jumpdest analysis should end.
Expand Down Expand Up @@ -153,13 +156,7 @@ pub(crate) trait State<F: Field> {
/// Return the offsets at which execution must halt
fn get_halt_offsets(&self) -> Vec<usize>;

/// Inserts a preinitialized segment, given as a [Segment],
/// into the `preinitialized_segments` memory field.
fn insert_preinitialized_segment(&mut self, segment: Segment, values: MemorySegmentState);

fn is_preinitialized_segment(&self, segment: usize) -> bool;

fn update_interpreter_final_registers(&mut self, final_registers: RegistersState) {}
fn update_interpreter_final_registers(&mut self, _final_registers: RegistersState) {}

fn get_full_memory(&self) -> Option<MemoryState> {
None
Expand All @@ -176,10 +173,8 @@ pub(crate) trait State<F: Field> {
{
let halt_offsets = self.get_halt_offsets();

let halt_pc = KERNEL.global_labels["halt"];
let halt_final_pc = KERNEL.global_labels["halt_final"];
let mut final_registers = RegistersState::default();
let mut final_mem = self.get_mut_generation_state().memory.clone();
let final_mem = self.get_generation_state().memory.clone();
let mut running = true;
let mut final_clock = 0;
loop {
Expand Down Expand Up @@ -499,16 +494,6 @@ impl<F: Field> State<F> for GenerationState<F> {
}
}

fn insert_preinitialized_segment(&mut self, _segment: Segment, _values: MemorySegmentState) {
panic!(
"A `GenerationState` cannot have a nonempty `preinitialized_segment` field in memory."
)
}

fn is_preinitialized_segment(&self, _segment: usize) -> bool {
false
}

fn incr_gas(&mut self, n: u64) {
self.registers.gas_used += n;
}
Expand Down
4 changes: 2 additions & 2 deletions evm_arithmetization/src/memory/memory_stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl<F: RichField + Extendable<D>, const D: usize> MemoryStark<F, D> {
/// a trace in column-major form.
/// Also generates the `STALE_CONTEXTS`, `STALE_CONTEXTS_FREQUENCIES` and
/// `MEM_AFTER_FILTER` columns.
fn generate_trace_col_major(trace_col_vecs: &mut [Vec<F>], stale_contexts: Vec<usize>) {
fn generate_trace_col_major(trace_col_vecs: &mut [Vec<F>]) {
let height = trace_col_vecs[0].len();
trace_col_vecs[COUNTER] = (0..height).map(|i| F::from_canonical_usize(i)).collect();

Expand Down Expand Up @@ -397,7 +397,7 @@ impl<F: RichField + Extendable<D>, const D: usize> MemoryStark<F, D> {
let mut trace_col_vecs = transpose(&trace_row_vecs);

// A few final generation steps, which work better in column-major form.
Self::generate_trace_col_major(&mut trace_col_vecs, stale_contexts);
Self::generate_trace_col_major(&mut trace_col_vecs);

let final_rows = transpose(&trace_col_vecs);

Expand Down
8 changes: 0 additions & 8 deletions evm_arithmetization/src/witness/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ use crate::cpu::kernel::aggregator::KERNEL;

const KERNEL_CONTEXT: usize = 0;

/// Structure for the state of the registers before and after
/// the current execution.
#[derive(Copy, Clone, Default)]
pub struct PublicRegisterStates {
registers_before: RegistersState,
registers_after: RegistersState,
}

#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)]
pub struct RegistersState {
pub program_counter: usize,
Expand Down
4 changes: 1 addition & 3 deletions evm_arithmetization/src/witness/transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::cpu::membus::NUM_GP_CHANNELS;
use crate::cpu::stack::{
EQ_STACK_BEHAVIOR, IS_ZERO_STACK_BEHAVIOR, JUMPI_OP, JUMP_OP, MIGHT_OVERFLOW, STACK_BEHAVIORS,
};
use crate::generation::state::{GenerationState, State};
use crate::generation::state::State;
use crate::memory::segments::Segment;
use crate::witness::errors::ProgramError;
use crate::witness::gas::gas_to_charge;
Expand Down Expand Up @@ -305,8 +305,6 @@ where
fn final_exception(&mut self) -> anyhow::Result<()> {
let checkpoint = self.checkpoint();

let gen_state = self.get_mut_generation_state();

let (row, _) = self.base_row();

generate_exception(EXC_STOP_CODE, self, row)
Expand Down
9 changes: 0 additions & 9 deletions evm_arithmetization/src/witness/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,6 @@ pub(crate) fn mem_write_log<F: Field>(
)
}

pub(crate) fn mem_write_log_timestamp_zero<F: Field>(
address: MemoryAddress,
state: &GenerationState<F>,
val: U256,
) -> MemoryOp {
// `Code` corresponds to channel number 0.
MemoryOp::new(MemoryChannel::Code, 0, address, MemoryOpKind::Write, val)
}

pub(crate) fn mem_read_code_with_log_and_fill<F: Field>(
address: MemoryAddress,
state: &GenerationState<F>,
Expand Down

0 comments on commit 8b15f0e

Please sign in to comment.