Skip to content

Commit

Permalink
Check: is DynVolatileRamTable::max_len broken?
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasgoergens committed Dec 9, 2024
1 parent c4a6f09 commit d9cc59b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions ceno_zkvm/src/tables/ram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ impl DynVolatileRamTable for DynMemTable {
}
}

#[test]
fn test_dyn_mem_table() {
let mut params = ProgramParams::default();
params.platform.ram.start = 0;
params.platform.ram.end = 100;
let max_len_bytes = 4 * DynMemTable::max_len(&params);
assert_eq!(max_len_bytes, 128);
}

pub type DynMemCircuit<E> = DynVolatileRamCircuit<E, DynMemTable>;

#[derive(Clone)]
Expand Down
7 changes: 6 additions & 1 deletion ceno_zkvm/src/tables/ram/ram_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ pub trait DynVolatileRamTable {
fn max_len(params: &ProgramParams) -> usize {
let max_size =
(Self::end_addr(params) - Self::offset_addr(params)).div_ceil(WORD_SIZE as u32) as Addr;
1 << (u32::BITS - 1 - max_size.leading_zeros()) // prev_power_of_2
let max_len = 1 << (u32::BITS - 1 - max_size.leading_zeros()); // prev_power_of_2
assert!(
max_size as usize <= max_len,
"Did not round up {max_size} correctly, got {max_len}, which is smaller."
);
max_len
}

fn addr(params: &ProgramParams, entry_index: usize) -> Addr {
Expand Down

0 comments on commit d9cc59b

Please sign in to comment.