diff --git a/extensions/rv32-adapters/src/eq_mod.rs b/extensions/rv32-adapters/src/eq_mod.rs index 802a14b19f..436cd47ea7 100644 --- a/extensions/rv32-adapters/src/eq_mod.rs +++ b/extensions/rv32-adapters/src/eq_mod.rs @@ -28,6 +28,7 @@ use openvm_circuit_primitives::bitwise_op_lookup::{ use openvm_circuit_primitives_derive::AlignedBorrow; use openvm_instructions::{ instruction::Instruction, + program::DEFAULT_PC_STEP, riscv::{RV32_MEMORY_AS, RV32_REGISTER_AS}, }; use openvm_rv32im_circuit::adapters::{ @@ -215,7 +216,7 @@ impl< ], cols.from_state, AB::F::from_canonical_usize(timestamp_delta), - (4, ctx.to_pc), + (DEFAULT_PC_STEP, ctx.to_pc), ) .eval(builder, ctx.instruction.is_valid.clone()); } @@ -377,7 +378,7 @@ impl< Ok(( ExecutionState { - pc: from_state.pc + 4, + pc: from_state.pc + DEFAULT_PC_STEP, timestamp: memory.timestamp(), }, Self::WriteRecord { from_state, rd }, diff --git a/extensions/rv32-adapters/src/heap.rs b/extensions/rv32-adapters/src/heap.rs index 68d01e742c..140407d1ca 100644 --- a/extensions/rv32-adapters/src/heap.rs +++ b/extensions/rv32-adapters/src/heap.rs @@ -19,6 +19,7 @@ use openvm_circuit_primitives::bitwise_op_lookup::{ }; use openvm_instructions::{ instruction::Instruction, + program::DEFAULT_PC_STEP, riscv::{RV32_CELL_BITS, RV32_MEMORY_AS, RV32_REGISTER_AS, RV32_REGISTER_NUM_LIMBS}, }; use openvm_rv32im_circuit::adapters::read_rv32_register; @@ -208,7 +209,7 @@ impl VmA ], cols.from_state, AB::F::from_canonical_usize(timestamp_delta), - (4, ctx.to_pc), + (DEFAULT_PC_STEP, ctx.to_pc), ) .eval(builder, ctx.instruction.is_valid); } @@ -267,7 +268,7 @@ impl VmAdapterC Ok(( ExecutionState { - pc: output.to_pc.unwrap_or(from_state.pc + 4), + pc: output.to_pc.unwrap_or(from_state.pc + DEFAULT_PC_STEP), timestamp: memory.timestamp(), }, from_state, diff --git a/extensions/rv32-adapters/src/vec_heap.rs b/extensions/rv32-adapters/src/vec_heap.rs index fb641d56e5..46b5bd4d7a 100644 --- a/extensions/rv32-adapters/src/vec_heap.rs +++ b/extensions/rv32-adapters/src/vec_heap.rs @@ -28,6 +28,7 @@ use openvm_circuit_primitives::bitwise_op_lookup::{ use openvm_circuit_primitives_derive::AlignedBorrow; use openvm_instructions::{ instruction::Instruction, + program::DEFAULT_PC_STEP, riscv::{RV32_MEMORY_AS, RV32_REGISTER_AS}, }; use openvm_rv32im_circuit::adapters::{ @@ -322,7 +323,7 @@ impl< ], cols.from_state, AB::F::from_canonical_usize(timestamp_delta), - (4, ctx.to_pc), + (DEFAULT_PC_STEP, ctx.to_pc), ) .eval(builder, ctx.instruction.is_valid.clone()); } @@ -437,7 +438,7 @@ impl< Ok(( ExecutionState { - pc: from_state.pc + 4, + pc: from_state.pc + DEFAULT_PC_STEP, timestamp: memory.timestamp(), }, Self::WriteRecord { from_state, writes }, diff --git a/extensions/rv32-adapters/src/vec_heap_two_reads.rs b/extensions/rv32-adapters/src/vec_heap_two_reads.rs index 94a61b45ff..acd15a26cd 100644 --- a/extensions/rv32-adapters/src/vec_heap_two_reads.rs +++ b/extensions/rv32-adapters/src/vec_heap_two_reads.rs @@ -28,6 +28,7 @@ use openvm_circuit_primitives::bitwise_op_lookup::{ use openvm_circuit_primitives_derive::AlignedBorrow; use openvm_instructions::{ instruction::Instruction, + program::DEFAULT_PC_STEP, riscv::{RV32_MEMORY_AS, RV32_REGISTER_AS}, }; use openvm_rv32im_circuit::adapters::{ @@ -353,7 +354,7 @@ impl< ], cols.from_state, AB::F::from_canonical_usize(timestamp_delta), - (4, ctx.to_pc), + (DEFAULT_PC_STEP, ctx.to_pc), ) .eval(builder, ctx.instruction.is_valid.clone()); } @@ -470,7 +471,7 @@ impl< Ok(( ExecutionState { - pc: from_state.pc + 4, + pc: from_state.pc + DEFAULT_PC_STEP, timestamp: memory.timestamp(), }, Self::WriteRecord { from_state, writes }, diff --git a/extensions/rv32im/circuit/src/adapters/alu.rs b/extensions/rv32im/circuit/src/adapters/alu.rs index 5fbd98ada6..a611c817dc 100644 --- a/extensions/rv32im/circuit/src/adapters/alu.rs +++ b/extensions/rv32im/circuit/src/adapters/alu.rs @@ -23,6 +23,7 @@ use openvm_circuit_primitives::utils::not; use openvm_circuit_primitives_derive::AlignedBorrow; use openvm_instructions::{ instruction::Instruction, + program::DEFAULT_PC_STEP, riscv::{RV32_IMM_AS, RV32_REGISTER_AS}, }; use openvm_stark_backend::{ @@ -184,7 +185,7 @@ impl VmAdapterAir for Rv32BaseAluAdapterAir { ], local.from_state, AB::F::from_canonical_usize(timestamp_delta), - (4, ctx.to_pc), + (DEFAULT_PC_STEP, ctx.to_pc), ) .eval(builder, ctx.instruction.is_valid); } @@ -267,7 +268,7 @@ impl VmAdapterChip for Rv32BaseAluAdapterChip { Ok(( ExecutionState { - pc: from_state.pc + 4, + pc: from_state.pc + DEFAULT_PC_STEP, timestamp: memory.timestamp(), }, Self::WriteRecord { from_state, rd }, diff --git a/extensions/rv32im/circuit/src/adapters/branch.rs b/extensions/rv32im/circuit/src/adapters/branch.rs index c5a0dff6de..9559262359 100644 --- a/extensions/rv32im/circuit/src/adapters/branch.rs +++ b/extensions/rv32im/circuit/src/adapters/branch.rs @@ -20,7 +20,9 @@ use openvm_circuit::{ }, }; use openvm_circuit_primitives_derive::AlignedBorrow; -use openvm_instructions::{instruction::Instruction, riscv::RV32_REGISTER_AS}; +use openvm_instructions::{ + instruction::Instruction, program::DEFAULT_PC_STEP, riscv::RV32_REGISTER_AS, +}; use openvm_stark_backend::{ interaction::InteractionBuilder, p3_air::BaseAir, @@ -137,7 +139,7 @@ impl VmAdapterAir for Rv32BranchAdapterAir { ], local.from_state, AB::F::from_canonical_usize(timestamp_delta), - (4, ctx.to_pc), + (DEFAULT_PC_STEP, ctx.to_pc), ) .eval(builder, ctx.instruction.is_valid); } @@ -190,7 +192,7 @@ impl VmAdapterChip for Rv32BranchAdapterChip { Ok(( ExecutionState { - pc: output.to_pc.unwrap_or(from_state.pc + 4), + pc: output.to_pc.unwrap_or(from_state.pc + DEFAULT_PC_STEP), timestamp: memory.timestamp(), }, Self::WriteRecord { from_state }, diff --git a/extensions/rv32im/circuit/src/adapters/hintstore.rs b/extensions/rv32im/circuit/src/adapters/hintstore.rs index 46b90f835b..1592ab17ed 100644 --- a/extensions/rv32im/circuit/src/adapters/hintstore.rs +++ b/extensions/rv32im/circuit/src/adapters/hintstore.rs @@ -25,6 +25,7 @@ use openvm_circuit_primitives::var_range::{VariableRangeCheckerBus, VariableRang use openvm_circuit_primitives_derive::AlignedBorrow; use openvm_instructions::{ instruction::Instruction, + program::DEFAULT_PC_STEP, riscv::{RV32_MEMORY_AS, RV32_REGISTER_AS}, }; use openvm_stark_backend::{ @@ -200,7 +201,7 @@ impl VmAdapterAir for Rv32HintStoreAdapterAir { let to_pc = ctx .to_pc - .unwrap_or(local_cols.from_state.pc + AB::F::from_canonical_u32(4)); + .unwrap_or(local_cols.from_state.pc + AB::F::from_canonical_u32(DEFAULT_PC_STEP)); self.execution_bridge .execute( ctx.instruction.opcode, @@ -295,7 +296,7 @@ impl VmAdapterChip for Rv32HintStoreAdapterChip { Ok(( ExecutionState { - pc: output.to_pc.unwrap_or(from_state.pc + 4), + pc: output.to_pc.unwrap_or(from_state.pc + DEFAULT_PC_STEP), timestamp: memory.timestamp(), }, Self::WriteRecord { diff --git a/extensions/rv32im/circuit/src/adapters/jalr.rs b/extensions/rv32im/circuit/src/adapters/jalr.rs index f6ca58039d..37e5b44bf5 100644 --- a/extensions/rv32im/circuit/src/adapters/jalr.rs +++ b/extensions/rv32im/circuit/src/adapters/jalr.rs @@ -21,7 +21,9 @@ use openvm_circuit::{ }; use openvm_circuit_primitives::utils::not; use openvm_circuit_primitives_derive::AlignedBorrow; -use openvm_instructions::{instruction::Instruction, riscv::RV32_REGISTER_AS}; +use openvm_instructions::{ + instruction::Instruction, program::DEFAULT_PC_STEP, riscv::RV32_REGISTER_AS, +}; use openvm_stark_backend::{ interaction::InteractionBuilder, p3_air::{AirBuilder, BaseAir}, @@ -146,7 +148,7 @@ impl VmAdapterAir for Rv32JalrAdapterAir { let to_pc = ctx .to_pc - .unwrap_or(local_cols.from_state.pc + AB::F::from_canonical_u32(4)); + .unwrap_or(local_cols.from_state.pc + AB::F::from_canonical_u32(DEFAULT_PC_STEP)); // regardless of `needs_write`, must always execute instruction when `is_valid`. self.execution_bridge @@ -223,7 +225,7 @@ impl VmAdapterChip for Rv32JalrAdapterChip { Ok(( ExecutionState { - pc: output.to_pc.unwrap_or(from_state.pc + 4), + pc: output.to_pc.unwrap_or(from_state.pc + DEFAULT_PC_STEP), timestamp: memory.timestamp(), }, Self::WriteRecord { from_state, rd }, diff --git a/extensions/rv32im/circuit/src/adapters/loadstore.rs b/extensions/rv32im/circuit/src/adapters/loadstore.rs index 7ea9c1cfed..a0bc94b50b 100644 --- a/extensions/rv32im/circuit/src/adapters/loadstore.rs +++ b/extensions/rv32im/circuit/src/adapters/loadstore.rs @@ -29,6 +29,7 @@ use openvm_circuit_primitives::{ use openvm_circuit_primitives_derive::AlignedBorrow; use openvm_instructions::{ instruction::Instruction, + program::DEFAULT_PC_STEP, riscv::{RV32_IMM_AS, RV32_REGISTER_AS}, UsizeOpcode, }; @@ -301,7 +302,7 @@ impl VmAdapterAir for Rv32LoadStoreAdapterAir { let to_pc = ctx .to_pc - .unwrap_or(local_cols.from_state.pc + AB::F::from_canonical_u32(4)); + .unwrap_or(local_cols.from_state.pc + AB::F::from_canonical_u32(DEFAULT_PC_STEP)); self.execution_bridge .execute( ctx.instruction.opcode, @@ -446,7 +447,7 @@ impl VmAdapterChip for Rv32LoadStoreAdapterChip { Ok(( ExecutionState { - pc: output.to_pc.unwrap_or(from_state.pc + 4), + pc: output.to_pc.unwrap_or(from_state.pc + DEFAULT_PC_STEP), timestamp: memory.timestamp(), }, Self::WriteRecord { diff --git a/extensions/rv32im/circuit/src/adapters/mul.rs b/extensions/rv32im/circuit/src/adapters/mul.rs index a9b61e96d5..04a634798a 100644 --- a/extensions/rv32im/circuit/src/adapters/mul.rs +++ b/extensions/rv32im/circuit/src/adapters/mul.rs @@ -20,7 +20,9 @@ use openvm_circuit::{ }, }; use openvm_circuit_primitives_derive::AlignedBorrow; -use openvm_instructions::{instruction::Instruction, riscv::RV32_REGISTER_AS}; +use openvm_instructions::{ + instruction::Instruction, program::DEFAULT_PC_STEP, riscv::RV32_REGISTER_AS, +}; use openvm_stark_backend::{ interaction::InteractionBuilder, p3_air::BaseAir, @@ -154,7 +156,7 @@ impl VmAdapterAir for Rv32MultAdapterAir { ], local.from_state, AB::F::from_canonical_usize(timestamp_delta), - (4, ctx.to_pc), + (DEFAULT_PC_STEP, ctx.to_pc), ) .eval(builder, ctx.instruction.is_valid); } @@ -216,7 +218,7 @@ impl VmAdapterChip for Rv32MultAdapterChip { Ok(( ExecutionState { - pc: from_state.pc + 4, + pc: from_state.pc + DEFAULT_PC_STEP, timestamp: memory.timestamp(), }, Self::WriteRecord { from_state, rd }, diff --git a/extensions/rv32im/circuit/src/adapters/rdwrite.rs b/extensions/rv32im/circuit/src/adapters/rdwrite.rs index 4e833e8ad1..0472046b7f 100644 --- a/extensions/rv32im/circuit/src/adapters/rdwrite.rs +++ b/extensions/rv32im/circuit/src/adapters/rdwrite.rs @@ -21,7 +21,9 @@ use openvm_circuit::{ }; use openvm_circuit_primitives::utils::not; use openvm_circuit_primitives_derive::AlignedBorrow; -use openvm_instructions::{instruction::Instruction, riscv::RV32_REGISTER_AS}; +use openvm_instructions::{ + instruction::Instruction, program::DEFAULT_PC_STEP, riscv::RV32_REGISTER_AS, +}; use openvm_stark_backend::{ interaction::InteractionBuilder, p3_air::{AirBuilder, BaseAir}, @@ -167,7 +169,7 @@ impl Rv32RdWriteAdapterAir { let to_pc = ctx .to_pc - .unwrap_or(local_cols.from_state.pc + AB::F::from_canonical_u32(4)); + .unwrap_or(local_cols.from_state.pc + AB::F::from_canonical_u32(DEFAULT_PC_STEP)); // regardless of `needs_write`, must always execute instruction when `is_valid`. self.execution_bridge .execute( @@ -274,7 +276,7 @@ impl VmAdapterChip for Rv32RdWriteAdapterChip { Ok(( ExecutionState { - pc: output.to_pc.unwrap_or(from_state.pc + 4), + pc: output.to_pc.unwrap_or(from_state.pc + DEFAULT_PC_STEP), timestamp: memory.timestamp(), }, Self::WriteRecord { @@ -338,7 +340,7 @@ impl VmAdapterChip for Rv32CondRdWriteAdapterChip { Ok(( ExecutionState { - pc: output.to_pc.unwrap_or(from_state.pc + 4), + pc: output.to_pc.unwrap_or(from_state.pc + DEFAULT_PC_STEP), timestamp: memory.timestamp(), }, Self::WriteRecord { from_state, rd }, diff --git a/extensions/rv32im/circuit/src/branch_lt/core.rs b/extensions/rv32im/circuit/src/branch_lt/core.rs index 4d13f71fe2..d5fe1480eb 100644 --- a/extensions/rv32im/circuit/src/branch_lt/core.rs +++ b/extensions/rv32im/circuit/src/branch_lt/core.rs @@ -13,7 +13,7 @@ use openvm_circuit_primitives::{ utils::not, }; use openvm_circuit_primitives_derive::AlignedBorrow; -use openvm_instructions::{instruction::Instruction, UsizeOpcode}; +use openvm_instructions::{instruction::Instruction, program::DEFAULT_PC_STEP, UsizeOpcode}; use openvm_rv32im_transpiler::BranchLessThanOpcode; use openvm_stark_backend::{ interaction::InteractionBuilder, @@ -157,7 +157,7 @@ where let to_pc = from_pc + cols.cmp_result * cols.imm - + not(cols.cmp_result) * AB::Expr::from_canonical_u8(4); + + not(cols.cmp_result) * AB::Expr::from_canonical_u32(DEFAULT_PC_STEP); AdapterAirContext { to_pc: Some(to_pc), diff --git a/extensions/rv32im/circuit/src/jal_lui/core.rs b/extensions/rv32im/circuit/src/jal_lui/core.rs index 9a61bd2295..17321584f2 100644 --- a/extensions/rv32im/circuit/src/jal_lui/core.rs +++ b/extensions/rv32im/circuit/src/jal_lui/core.rs @@ -12,7 +12,11 @@ use openvm_circuit_primitives::bitwise_op_lookup::{ BitwiseOperationLookupBus, BitwiseOperationLookupChip, }; use openvm_circuit_primitives_derive::AlignedBorrow; -use openvm_instructions::{instruction::Instruction, program::PC_BITS, UsizeOpcode}; +use openvm_instructions::{ + instruction::Instruction, + program::{DEFAULT_PC_STEP, PC_BITS}, + UsizeOpcode, +}; use openvm_rv32im_transpiler::Rv32JalLuiOpcode::{self, *}; use openvm_stark_backend::{ interaction::InteractionBuilder, @@ -103,11 +107,12 @@ where ); let intermed_val = rd[0] + intermed_val * AB::Expr::from_canonical_u32(1 << RV32_CELL_BITS); - builder - .when(is_jal) - .assert_eq(intermed_val, from_pc + AB::F::from_canonical_u32(4)); + builder.when(is_jal).assert_eq( + intermed_val, + from_pc + AB::F::from_canonical_u32(DEFAULT_PC_STEP), + ); - let to_pc = from_pc + is_lui * AB::F::from_canonical_u32(4) + is_jal * imm; + let to_pc = from_pc + is_lui * AB::F::from_canonical_u32(DEFAULT_PC_STEP) + is_jal * imm; let expected_opcode = is_lui * AB::F::from_canonical_u32(LUI as u32) + is_jal * AB::F::from_canonical_u32(JAL as u32) @@ -243,7 +248,9 @@ pub(super) fn run_jal_lui( ) -> (u32, [u32; RV32_REGISTER_NUM_LIMBS]) { match opcode { JAL => { - let rd_data = array::from_fn(|i| ((pc + 4) >> (8 * i)) & ((1 << RV32_CELL_BITS) - 1)); + let rd_data = array::from_fn(|i| { + ((pc + DEFAULT_PC_STEP) >> (8 * i)) & ((1 << RV32_CELL_BITS) - 1) + }); let next_pc = pc as i32 + imm; assert!(next_pc >= 0); (next_pc as u32, rd_data) @@ -253,7 +260,7 @@ pub(super) fn run_jal_lui( let rd = imm << 12; let rd_data = array::from_fn(|i| (rd >> (RV32_CELL_BITS * i)) & ((1 << RV32_CELL_BITS) - 1)); - (pc + 4, rd_data) + (pc + DEFAULT_PC_STEP, rd_data) } } } diff --git a/extensions/rv32im/circuit/src/jalr/core.rs b/extensions/rv32im/circuit/src/jalr/core.rs index f103c12cde..59b4733e45 100644 --- a/extensions/rv32im/circuit/src/jalr/core.rs +++ b/extensions/rv32im/circuit/src/jalr/core.rs @@ -13,7 +13,11 @@ use openvm_circuit_primitives::{ var_range::{VariableRangeCheckerBus, VariableRangeCheckerChip}, }; use openvm_circuit_primitives_derive::AlignedBorrow; -use openvm_instructions::{instruction::Instruction, program::PC_BITS, UsizeOpcode}; +use openvm_instructions::{ + instruction::Instruction, + program::{DEFAULT_PC_STEP, PC_BITS}, + UsizeOpcode, +}; use openvm_rv32im_transpiler::Rv32JalrOpcode::{self, *}; use openvm_stark_backend::{ interaction::InteractionBuilder, @@ -101,7 +105,7 @@ where acc + val * AB::Expr::from_canonical_u32(1 << ((i + 1) * RV32_CELL_BITS)) }); - let least_sig_limb = from_pc + AB::F::from_canonical_u32(4) - composed; + let least_sig_limb = from_pc + AB::F::from_canonical_u32(DEFAULT_PC_STEP) - composed; // rd_data is the final data needed let rd_data = array::from_fn(|i| { @@ -288,6 +292,6 @@ pub(super) fn run_jalr( assert!(to_pc < (1 << PC_BITS)); ( to_pc, - array::from_fn(|i: usize| ((pc + 4) >> (RV32_CELL_BITS * i)) & RV32_LIMB_MAX), + array::from_fn(|i: usize| ((pc + DEFAULT_PC_STEP) >> (RV32_CELL_BITS * i)) & RV32_LIMB_MAX), ) }