Skip to content

Commit

Permalink
Remove increase_timestamp_to
Browse files Browse the repository at this point in the history
  • Loading branch information
zlangley committed Jan 6, 2025
1 parent 511b0a2 commit b3f809e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
8 changes: 0 additions & 8 deletions crates/vm/src/system/memory/controller/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,14 +594,6 @@ impl<F: PrimeField32> Memory<F> {
self.log.push(MemoryLogEntry::IncrementTimestampBy(amount))
}

pub fn increase_timestamp_to(&mut self, amount: u32) {
if amount == self.timestamp {
return;
}
assert!(amount > self.timestamp);
self.increment_timestamp_by(amount - self.timestamp);
}

pub fn timestamp(&self) -> u32 {
self.timestamp
}
Expand Down
4 changes: 0 additions & 4 deletions crates/vm/src/system/memory/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,6 @@ impl<F: PrimeField32> MemoryController<F> {
self.memory.increment_timestamp_by(change);
}

pub fn increase_timestamp_to(&mut self, timestamp: u32) {
self.memory.increase_timestamp_to(timestamp);
}

pub fn timestamp(&self) -> u32 {
self.memory.timestamp()
}
Expand Down
14 changes: 8 additions & 6 deletions extensions/keccak256/circuit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ impl<F: PrimeField32> InstructionExecutor<F> for KeccakVmChip<F> {
let local_opcode = Rv32KeccakOpcode::from_usize(opcode.local_opcode_idx(self.offset));
debug_assert_eq!(local_opcode, Rv32KeccakOpcode::KECCAK256);

debug_assert_eq!(from_state.timestamp, memory.timestamp());

let mut timestamp_delta = 3;
let (dst_read, dst) = read_rv32_register(memory, d, a);
let (src_read, src) = read_rv32_register(memory, d, b);
let (len_read, len) = read_rv32_register(memory, d, c);
Expand All @@ -168,6 +167,7 @@ impl<F: PrimeField32> InstructionExecutor<F> for KeccakVmChip<F> {
for block_idx in 0..num_blocks {
if block_idx != 0 {
memory.increment_timestamp_by(KECCAK_REGISTER_READS as u32);
timestamp_delta += KECCAK_REGISTER_READS as u32;
}
let mut reads = Vec::with_capacity(KECCAK_RATE_BYTES);

Expand All @@ -177,6 +177,7 @@ impl<F: PrimeField32> InstructionExecutor<F> for KeccakVmChip<F> {
if i < remaining_len {
let read =
memory.read::<RV32_REGISTER_NUM_LIMBS>(e, F::from_canonical_usize(src + i));

let chunk = read.1.map(|x| {
x.as_canonical_u32()
.try_into()
Expand All @@ -191,6 +192,7 @@ impl<F: PrimeField32> InstructionExecutor<F> for KeccakVmChip<F> {
} else {
memory.increment_timestamp();
}
timestamp_delta += 1;
}

let mut block = KeccakInputBlock {
Expand Down Expand Up @@ -223,6 +225,7 @@ impl<F: PrimeField32> InstructionExecutor<F> for KeccakVmChip<F> {
hasher.finalize(&mut output);
let dst = dst as usize;
let digest_writes: [_; KECCAK_DIGEST_WRITES] = from_fn(|i| {
timestamp_delta += 1;
memory
.write::<KECCAK_WORD_SIZE>(
e,
Expand All @@ -247,14 +250,13 @@ impl<F: PrimeField32> InstructionExecutor<F> for KeccakVmChip<F> {

// NOTE: Check this is consistent with KeccakVmAir::timestamp_change (we don't use it to avoid
// unnecessary conversions here)
let timestamp_change =
let total_timestamp_delta =
len + (KECCAK_REGISTER_READS + KECCAK_ABSORB_READS + KECCAK_DIGEST_WRITES) as u32;
let to_timestamp = from_state.timestamp + timestamp_change;
memory.increase_timestamp_to(to_timestamp);
memory.increment_timestamp_by(total_timestamp_delta - timestamp_delta);

Ok(ExecutionState {
pc: from_state.pc + DEFAULT_PC_STEP,
timestamp: to_timestamp,
timestamp: from_state.timestamp + total_timestamp_delta,
})
}

Expand Down

0 comments on commit b3f809e

Please sign in to comment.