This commit is contained in:
Daniel Lubarov 2022-12-03 22:44:54 -08:00
parent 1303a83f7f
commit bffdc553dc
3 changed files with 23 additions and 13 deletions

View File

@ -74,6 +74,8 @@ pub(crate) fn generate_traces<F: RichField + Extendable<D>, const D: usize>(
timed!(timing, "simulate CPU", simulate_cpu(&mut state)); timed!(timing, "simulate CPU", simulate_cpu(&mut state));
log::info!("Trace lengths (before padding): {:?}", state.traces.checkpoint());
let read_metadata = |field| { let read_metadata = |field| {
state.memory.get(MemoryAddress::new( state.memory.get(MemoryAddress::new(
0, 0,

View File

@ -75,17 +75,20 @@ pub(crate) fn generate_binary_arithmetic_op<F: Field>(
let log_out = stack_push_log_and_fill(state, &mut row, operation.result())?; let log_out = stack_push_log_and_fill(state, &mut row, operation.result())?;
const LOOKUP_CHANNEL: usize = 2; if operator == arithmetic::BinaryOperator::Shl || operator == arithmetic::BinaryOperator::Shr {
let lookup_addr = MemoryAddress::new(0, Segment::ShiftTable, input0.low_u32() as usize); const LOOKUP_CHANNEL: usize = 2;
if input0.bits() <= 32 { let lookup_addr = MemoryAddress::new(0, Segment::ShiftTable, input0.low_u32() as usize);
let (_, read) = mem_read_gp_with_log_and_fill(LOOKUP_CHANNEL, lookup_addr, state, &mut row); if input0.bits() <= 32 {
state.traces.push_memory(read); let (_, read) =
} else { mem_read_gp_with_log_and_fill(LOOKUP_CHANNEL, lookup_addr, state, &mut row);
// The shift constraints still expect the address to be set, even though no read will occur. state.traces.push_memory(read);
let mut channel = &mut row.mem_channels[LOOKUP_CHANNEL]; } else {
channel.addr_context = F::from_canonical_usize(lookup_addr.context); // The shift constraints still expect the address to be set, even though no read will occur.
channel.addr_segment = F::from_canonical_usize(lookup_addr.segment); let mut channel = &mut row.mem_channels[LOOKUP_CHANNEL];
channel.addr_virtual = F::from_canonical_usize(lookup_addr.virt); channel.addr_context = F::from_canonical_usize(lookup_addr.context);
channel.addr_segment = F::from_canonical_usize(lookup_addr.segment);
channel.addr_virtual = F::from_canonical_usize(lookup_addr.virt);
}
} }
state.traces.push_arithmetic(operation); state.traces.push_arithmetic(operation);

View File

@ -18,6 +18,8 @@ use crate::{arithmetic, keccak, logic};
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct TraceCheckpoint { pub struct TraceCheckpoint {
pub(self) cpu_len: usize, pub(self) cpu_len: usize,
pub(self) keccak_len: usize,
pub(self) keccak_sponge_len: usize,
pub(self) logic_len: usize, pub(self) logic_len: usize,
pub(self) arithmetic_len: usize, pub(self) arithmetic_len: usize,
pub(self) memory_len: usize, pub(self) memory_len: usize,
@ -48,19 +50,22 @@ impl<T: Copy> Traces<T> {
pub fn checkpoint(&self) -> TraceCheckpoint { pub fn checkpoint(&self) -> TraceCheckpoint {
TraceCheckpoint { TraceCheckpoint {
cpu_len: self.cpu.len(), cpu_len: self.cpu.len(),
keccak_len: self.keccak_inputs.len(),
keccak_sponge_len: self.keccak_sponge_ops.len(),
logic_len: self.logic_ops.len(), logic_len: self.logic_ops.len(),
arithmetic_len: self.arithmetic.len(), arithmetic_len: self.arithmetic.len(),
memory_len: self.memory_ops.len(), memory_len: self.memory_ops.len(),
// TODO others
} }
} }
pub fn rollback(&mut self, checkpoint: TraceCheckpoint) { pub fn rollback(&mut self, checkpoint: TraceCheckpoint) {
self.cpu.truncate(checkpoint.cpu_len); self.cpu.truncate(checkpoint.cpu_len);
self.keccak_inputs.truncate(checkpoint.keccak_len);
self.keccak_sponge_ops
.truncate(checkpoint.keccak_sponge_len);
self.logic_ops.truncate(checkpoint.logic_len); self.logic_ops.truncate(checkpoint.logic_len);
self.arithmetic.truncate(checkpoint.arithmetic_len); self.arithmetic.truncate(checkpoint.arithmetic_len);
self.memory_ops.truncate(checkpoint.memory_len); self.memory_ops.truncate(checkpoint.memory_len);
// TODO others
} }
pub fn mem_ops_since(&self, checkpoint: TraceCheckpoint) -> &[MemoryOp] { pub fn mem_ops_since(&self, checkpoint: TraceCheckpoint) -> &[MemoryOp] {