Skip to content

Commit 0ed7820

Browse files
authored
feat(new-execution): ignore register addr space for memory ops (#1798)
- Ignore register address space for memory hooks in E2 execution. Results in faster execution Benchmark comparison: https://github.com/axiom-crypto/openvm-reth-benchmark/actions/runs/15928295651 Resolves INT-4305
1 parent 8638194 commit 0ed7820

File tree

2 files changed

+26
-9
lines changed
  • crates
    • toolchain/instructions/src
    • vm/src/arch/execution_mode/metered

2 files changed

+26
-9
lines changed

crates/toolchain/instructions/src/riscv.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ pub const RV32_CELL_BITS: usize = 8;
55
pub const RV32_IMM_AS: u32 = 0;
66
pub const RV32_REGISTER_AS: u32 = 1;
77
pub const RV32_MEMORY_AS: u32 = 2;
8+
9+
pub const RV32_NUM_REGISTERS: usize = 32;

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use openvm_instructions::riscv::RV32_IMM_AS;
1+
use openvm_instructions::riscv::{
2+
RV32_IMM_AS, RV32_NUM_REGISTERS, RV32_REGISTER_AS, RV32_REGISTER_NUM_LIMBS,
3+
};
24

35
use super::{
46
memory_ctx::MemoryCtx,
@@ -27,7 +29,7 @@ impl<const PAGE_BITS: usize> MeteredCtx<PAGE_BITS> {
2729
widths: Vec<usize>,
2830
interactions: Vec<usize>,
2931
) -> Self {
30-
let (trace_heights, is_trace_height_constant): (Vec<u32>, Vec<bool>) =
32+
let (mut trace_heights, is_trace_height_constant): (Vec<u32>, Vec<bool>) =
3133
constant_trace_heights
3234
.iter()
3335
.map(|&constant_height| {
@@ -39,7 +41,7 @@ impl<const PAGE_BITS: usize> MeteredCtx<PAGE_BITS> {
3941
})
4042
.unzip();
4143

42-
let memory_ctx = MemoryCtx::new(
44+
let mut memory_ctx = MemoryCtx::new(
4345
has_public_values_chip,
4446
continuations_enabled,
4547
as_byte_alignment_bits,
@@ -55,6 +57,16 @@ impl<const PAGE_BITS: usize> MeteredCtx<PAGE_BITS> {
5557

5658
let segmentation_ctx = SegmentationCtx::new(air_names, widths, interactions);
5759

60+
// Add merkle height contributions for all registers
61+
if continuations_enabled {
62+
memory_ctx.update_boundary_merkle_heights(
63+
&mut trace_heights,
64+
RV32_REGISTER_AS,
65+
0,
66+
(RV32_NUM_REGISTERS * RV32_REGISTER_NUM_LIMBS) as u32,
67+
);
68+
}
69+
5870
Self {
5971
trace_heights,
6072
is_trace_height_constant,
@@ -115,6 +127,7 @@ impl<const PAGE_BITS: usize> MeteredCtx<PAGE_BITS> {
115127
}
116128

117129
impl<const PAGE_BITS: usize> E1E2ExecutionCtx for MeteredCtx<PAGE_BITS> {
130+
#[inline(always)]
118131
fn on_memory_operation(&mut self, address_space: u32, ptr: u32, size: u32) {
119132
debug_assert!(
120133
address_space != RV32_IMM_AS,
@@ -132,11 +145,13 @@ impl<const PAGE_BITS: usize> E1E2ExecutionCtx for MeteredCtx<PAGE_BITS> {
132145
.update_adapter_heights(&mut self.trace_heights, address_space, size_bits);
133146

134147
// Handle merkle tree updates
135-
self.memory_ctx.update_boundary_merkle_heights(
136-
&mut self.trace_heights,
137-
address_space,
138-
ptr,
139-
size,
140-
);
148+
if address_space != RV32_REGISTER_AS {
149+
self.memory_ctx.update_boundary_merkle_heights(
150+
&mut self.trace_heights,
151+
address_space,
152+
ptr,
153+
size,
154+
);
155+
}
141156
}
142157
}

0 commit comments

Comments
 (0)