@@ -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
0 commit comments