Skip to content

Commit a1e4711

Browse files
committed
fix: lazy_update_boundary_heights needs to handle large initial accesses
1 parent 5de5b22 commit a1e4711

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

crates/vm/src/arch/execution_mode/metered/memory_ctx.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ pub struct MemoryCtx<const PAGE_BITS: usize> {
108108
continuations_enabled: bool,
109109
chunk: u32,
110110
chunk_bits: u32,
111+
/// The maximum access adapter block size in bits, i.e., log2(max_access_adapter_n).
112+
max_block_size_bits: u32,
111113
pub page_access_count: usize,
112114
// Note: 32 is the maximum access adapter size.
113115
pub addr_space_access_count: RVec<usize>,
@@ -130,6 +132,7 @@ impl<const PAGE_BITS: usize> MemoryCtx<PAGE_BITS> {
130132
adapter_offset: config.access_adapter_air_id_offset(),
131133
chunk,
132134
chunk_bits,
135+
max_block_size_bits: config.memory_config.max_access_adapter_n.ilog2(),
133136
memory_dimensions,
134137
continuations_enabled: config.continuation_enabled,
135138
page_access_count: 0,
@@ -271,11 +274,12 @@ impl<const PAGE_BITS: usize> MemoryCtx<PAGE_BITS> {
271274
// SAFETY: address_space is from 0 to len(), guaranteed to be in bounds
272275
let x = unsafe { *self.addr_space_access_count.get_unchecked(address_space) };
273276
if x > 0 {
274-
// After finalize, we'll need to read it in chunk-sized units for the merkle chip
277+
// After finalize, we'll need to read it in chunk-sized units for the merkle chip.
278+
// Use max_adapter_bits to account for worst-case block sizes during finalization.
275279
self.update_adapter_heights_batch(
276280
trace_heights,
277281
address_space as u32,
278-
self.chunk_bits,
282+
self.max_block_size_bits,
279283
(x << PAGE_BITS) as u32,
280284
);
281285
// SAFETY: address_space is from 0 to len(), guaranteed to be in bounds

crates/vm/src/system/memory/online.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub const INITIAL_TIMESTAMP: u32 = 0;
4646
pub const PAGE_SIZE: usize = 4096;
4747

4848
// Memory access constraints
49-
const MAX_BLOCK_SIZE: usize = 32;
49+
pub(crate) const MAX_BLOCK_SIZE: usize = 32;
5050
const MIN_ALIGN: usize = 1;
5151
const MAX_SEGMENTS: usize = MAX_BLOCK_SIZE / MIN_ALIGN;
5252

0 commit comments

Comments
 (0)