diff --git a/ceno_zkvm/examples/riscv_opcodes.rs b/ceno_zkvm/examples/riscv_opcodes.rs index 0711bd58f..67a314683 100644 --- a/ceno_zkvm/examples/riscv_opcodes.rs +++ b/ceno_zkvm/examples/riscv_opcodes.rs @@ -275,6 +275,7 @@ fn main() { ®_final, &mem_final, &public_io_final, + &[], ) .unwrap(); diff --git a/ceno_zkvm/src/bin/e2e.rs b/ceno_zkvm/src/bin/e2e.rs index a4a2b6087..550b1589d 100644 --- a/ceno_zkvm/src/bin/e2e.rs +++ b/ceno_zkvm/src/bin/e2e.rs @@ -260,6 +260,7 @@ fn main() { ®_final, &mem_final, &io_final, + &[], ) .unwrap(); // assign program circuit diff --git a/ceno_zkvm/src/instructions/riscv/rv32im/mmu.rs b/ceno_zkvm/src/instructions/riscv/rv32im/mmu.rs index 1b344a7aa..00ec9dccc 100644 --- a/ceno_zkvm/src/instructions/riscv/rv32im/mmu.rs +++ b/ceno_zkvm/src/instructions/riscv/rv32im/mmu.rs @@ -8,8 +8,8 @@ use crate::{ error::ZKVMError, structs::{ProgramParams, ZKVMConstraintSystem, ZKVMFixedTraces, ZKVMWitnesses}, tables::{ - MemFinalRecord, MemInitRecord, NonVolatileTable, PubIOCircuit, PubIOTable, RegTable, - RegTableCircuit, StaticMemCircuit, StaticMemTable, TableCircuit, + MemFinalRecord, MemInitRecord, NonVolatileTable, PrivateIOCircuit, PubIOCircuit, + PubIOTable, RegTable, RegTableCircuit, StaticMemCircuit, StaticMemTable, TableCircuit, }, }; @@ -20,6 +20,8 @@ pub struct MmuConfig { pub static_mem_config: as TableCircuit>::TableConfig, /// Initialization of public IO. pub public_io_config: as TableCircuit>::TableConfig, + /// Initialization of private IO. + pub private_io_config: as TableCircuit>::TableConfig, pub params: ProgramParams, } @@ -30,11 +32,13 @@ impl MmuConfig { let static_mem_config = cs.register_table_circuit::>(); let public_io_config = cs.register_table_circuit::>(); + let private_io_config = cs.register_table_circuit::>(); Self { reg_config, static_mem_config, public_io_config, + private_io_config, params: cs.params.clone(), } } @@ -48,9 +52,11 @@ impl MmuConfig { io_addrs: &[Addr], ) { assert!( - chain( + chain!( static_mem_init.iter().map(|record| record.addr), io_addrs.iter().copied(), + // TODO: optimize with min_max and Range. + self.params.platform.private_io.clone(), ) .all_unique(), "memory addresses must be unique" @@ -65,6 +71,7 @@ impl MmuConfig { ); fixed.register_table_circuit::>(cs, &self.public_io_config, io_addrs); + fixed.register_table_circuit::>(cs, &self.private_io_config, &()); } pub fn assign_table_circuit( @@ -74,6 +81,7 @@ impl MmuConfig { reg_final: &[MemFinalRecord], static_mem_final: &[MemFinalRecord], io_cycles: &[Cycle], + private_io_final: &[MemFinalRecord], ) -> Result<(), ZKVMError> { witness.assign_table_circuit::>(cs, &self.reg_config, reg_final)?; @@ -85,6 +93,12 @@ impl MmuConfig { witness.assign_table_circuit::>(cs, &self.public_io_config, io_cycles)?; + witness.assign_table_circuit::>( + cs, + &self.private_io_config, + private_io_final, + )?; + Ok(()) } diff --git a/ceno_zkvm/src/tables/ram.rs b/ceno_zkvm/src/tables/ram.rs index 88e968e69..f6fcb0282 100644 --- a/ceno_zkvm/src/tables/ram.rs +++ b/ceno_zkvm/src/tables/ram.rs @@ -34,25 +34,25 @@ impl DynVolatileRamTable for DynMemTable { pub type DynMemCircuit = DynVolatileRamCircuit; #[derive(Clone)] -pub struct PrivateMemTable; -impl DynVolatileRamTable for PrivateMemTable { +pub struct PrivateIOTable; +impl DynVolatileRamTable for PrivateIOTable { const RAM_TYPE: RAMType = RAMType::Memory; const V_LIMBS: usize = 1; // See `MemoryExpr`. const ZERO_INIT: bool = false; fn offset_addr(params: &ProgramParams) -> Addr { - params.platform.ram.start + params.platform.private_io.start } fn end_addr(params: &ProgramParams) -> Addr { - params.platform.ram.end + params.platform.private_io.end } fn name() -> &'static str { - "PrivateMemTable" + "PrivateIOTable" } } -pub type PrivateMemCircuit = DynVolatileRamCircuit; +pub type PrivateIOCircuit = DynVolatileRamCircuit; /// RegTable, fix size without offset #[derive(Clone)]