Skip to content

Commit

Permalink
chore: remove magic bus idx 7
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpwang committed Jan 21, 2025
1 parent 9b0b7f4 commit dd0fa74
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
10 changes: 9 additions & 1 deletion crates/vm/src/arch/testing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use program::ProgramTester;
use rand::{rngs::StdRng, RngCore, SeedableRng};
use tracing::Level;

use super::{ExecutionBus, InstructionExecutor};
use super::{ExecutionBus, InstructionExecutor, SystemPort};
use crate::{
arch::{ExecutionState, MemoryConfig},
system::{
Expand Down Expand Up @@ -166,6 +166,14 @@ impl<F: PrimeField32> VmChipTestBuilder<F> {
}
}

pub fn system_port(&self) -> SystemPort {
SystemPort {
execution_bus: self.execution.bus,
program_bus: self.program.bus,
memory_bridge: self.memory_bridge(),
}
}

pub fn execution_bus(&self) -> ExecutionBus {
self.execution.bus
}
Expand Down
6 changes: 3 additions & 3 deletions extensions/native/circuit/src/extension.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use air::VerifyBatchBus;
use branch_native_adapter::BranchNativeAdapterChip;
use derive_more::derive::From;
use jal_native_adapter::JalNativeAdapterChip;
Expand Down Expand Up @@ -198,13 +199,12 @@ impl<F: PrimeField32> VmExtension<F> for Native {
)?;

let poseidon2_chip = NativePoseidon2Chip::new(
execution_bus,
program_bus,
memory_bridge,
builder.system_port(),
VerifyBatchOpcode::default_offset(),
Poseidon2Opcode::default_offset(),
offline_memory.clone(),
Poseidon2Config::default(),
VerifyBatchBus(builder.new_bus_idx()),
);
inventory.add_executor(
poseidon2_chip,
Expand Down
18 changes: 7 additions & 11 deletions extensions/native/circuit/src/poseidon2/chip.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use std::sync::{Arc, Mutex};

use openvm_circuit::{
arch::{ExecutionBridge, ExecutionBus, ExecutionError, ExecutionState, InstructionExecutor},
system::{
memory::{offline_checker::MemoryBridge, MemoryController, OfflineMemory, RecordId},
program::ProgramBus,
},
arch::{ExecutionBridge, ExecutionError, ExecutionState, InstructionExecutor, SystemPort},
system::memory::{MemoryController, OfflineMemory, RecordId},
};
use openvm_instructions::{instruction::Instruction, program::DEFAULT_PC_STEP, VmOpcode};
use openvm_native_compiler::{
Expand Down Expand Up @@ -161,18 +158,17 @@ impl<F: PrimeField32, const SBOX_REGISTERS: usize> Stateful<Vec<u8>>

impl<F: PrimeField32, const SBOX_REGISTERS: usize> NativePoseidon2Chip<F, SBOX_REGISTERS> {
pub fn new(
execution_bus: ExecutionBus,
program_bus: ProgramBus,
memory_bridge: MemoryBridge,
port: SystemPort,
verify_batch_offset: usize,
perm_pos2_offset: usize,
offline_memory: Arc<Mutex<OfflineMemory<F>>>,
poseidon2_config: Poseidon2Config<F>,
verify_batch_bus: VerifyBatchBus,
) -> Self {
let air = NativePoseidon2Air {
execution_bridge: ExecutionBridge::new(execution_bus, program_bus),
memory_bridge,
internal_bus: VerifyBatchBus(7),
execution_bridge: ExecutionBridge::new(port.execution_bus, port.program_bus),
memory_bridge: port.memory_bridge,
internal_bus: verify_batch_bus,
subair: Arc::new(Poseidon2SubAir::new(poseidon2_config.constants.into())),
verify_batch_offset,
simple_offset: perm_pos2_offset,
Expand Down
2 changes: 1 addition & 1 deletion extensions/native/circuit/src/poseidon2/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod air;
pub mod air;
pub mod chip;
mod columns;
#[cfg(test)]
Expand Down
13 changes: 7 additions & 6 deletions extensions/native/circuit/src/poseidon2/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ use openvm_stark_sdk::{
};
use rand::{rngs::StdRng, Rng};

use super::air::VerifyBatchBus;
use crate::{
poseidon2::{chip::NativePoseidon2Chip, CHUNK},
NativeConfig,
};

const VERIFY_BATCH_BUS: VerifyBatchBus = VerifyBatchBus(7);

fn compute_commit<F: Field>(
dim: &[usize],
opened: &[Vec<F>],
Expand Down Expand Up @@ -152,13 +155,12 @@ fn test<const N: usize>(cases: [Case; N]) {

let mut tester = VmChipTestBuilder::default();
let mut chip = NativePoseidon2Chip::<F, SBOX_REGISTERS>::new(
tester.execution_bus(),
tester.program_bus(),
tester.memory_bridge(),
tester.system_port(),
VerifyBatchOpcode::default_offset(),
Poseidon2Opcode::default_offset(),
tester.offline_memory_mutex_arc(),
Poseidon2Config::default(),
VERIFY_BATCH_BUS,
);

let mut rng = create_seeded_rng();
Expand Down Expand Up @@ -385,13 +387,12 @@ fn tester_with_random_poseidon2_ops(num_ops: usize) -> VmChipTester<BabyBearBlak

let mut tester = VmChipTestBuilder::default();
let mut chip = NativePoseidon2Chip::<F, SBOX_REGISTERS>::new(
tester.execution_bus(),
tester.program_bus(),
tester.memory_bridge(),
tester.system_port(),
VerifyBatchOpcode::default_offset(),
Poseidon2Opcode::default_offset(),
tester.offline_memory_mutex_arc(),
Poseidon2Config::default(),
VERIFY_BATCH_BUS,
);

let mut rng = create_seeded_rng();
Expand Down

0 comments on commit dd0fa74

Please sign in to comment.