Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ceno_cli/example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ fn main() {
panic!();
}

ceno_rt::commit(&cnt_primes);
ceno_rt::commit(&cnt_primes.to_le_bytes());
}
34 changes: 9 additions & 25 deletions ceno_cli/src/commands/common_args/ceno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,25 +169,9 @@ impl CenoOptions {
self.heap_size.next_multiple_of(WORD_SIZE as u32)
}

/// Read the public io into ceno stdin
pub fn read_public_io(&self) -> anyhow::Result<Vec<u32>> {
if let Some(public_io) = &self.public_io {
// if vector contains only one element, write it as a raw `u32`
// otherwise, write the entire vector
// in both cases, convert the resulting `CenoStdin` into a `Vec<u32>`
if public_io.len() == 1 {
CenoStdin::default()
.write(&public_io[0])
.map(|stdin| Into::<Vec<u32>>::into(&*stdin))
} else {
CenoStdin::default()
.write(public_io)
.map(|stdin| Into::<Vec<u32>>::into(&*stdin))
}
.context("failed to get public_io".to_string())
} else {
Ok(vec![])
}
/// Read raw public-io words; digesting happens later in the zkVM pipeline.
pub fn read_public_io(&self) -> Vec<u32> {
self.public_io.clone().unwrap_or_default()
}

/// Read the hints
Expand Down Expand Up @@ -367,14 +351,14 @@ fn run_elf_inner<
options.max_cycle_per_shard,
);

let public_io = options
.read_public_io()
.context("failed to read public io")?;
let public_io_digest_input = options.read_public_io();
let public_io_digest = public_io_words_to_digest_words(&public_io_digest_input);
tracing::debug!("public io digest words: {:?}", public_io_digest);
let public_io_size = options.public_io_size;
assert!(
public_io.len() <= public_io_size as usize / WORD_SIZE,
public_io_digest_input.len() <= public_io_size as usize / WORD_SIZE,
"require pub io length {} < max public_io_size {}",
public_io.len(),
public_io_digest_input.len(),
public_io_size as usize / WORD_SIZE
);

Expand Down Expand Up @@ -416,7 +400,7 @@ fn run_elf_inner<
platform,
multi_prover,
&hints,
&public_io,
&public_io_digest_input,
options.max_steps,
checkpoint,
options.shard_id.map(|v| v as usize),
Expand Down
12 changes: 10 additions & 2 deletions ceno_cli/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,16 @@ where
shard_id: Option<usize>,
) -> Vec<ZKVMProof<E, PCS>> {
if let Some(zkvm_prover) = self.zkvm_prover.as_ref() {
let init_full_mem = zkvm_prover.setup_init_mem(&Vec::from(&hints), &Vec::from(&pub_io));
run_e2e_proof::<E, PCS, PB, PD>(zkvm_prover, &init_full_mem, max_steps, false, shard_id)
let public_io_words = Vec::from(&pub_io);
let init_full_mem = zkvm_prover.setup_init_mem(&Vec::from(&hints), &public_io_words);
run_e2e_proof::<E, PCS, PB, PD>(
zkvm_prover,
&init_full_mem,
&public_io_words,
max_steps,
false,
shard_id,
)
} else {
panic!("ZKVMProver is not initialized")
}
Expand Down
2 changes: 1 addition & 1 deletion ceno_emul/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub mod disassemble;
mod syscalls;
pub use syscalls::{
BLS12381_ADD, BLS12381_DECOMPRESS, BLS12381_DOUBLE, BN254_ADD, BN254_DOUBLE, BN254_FP_ADD,
BN254_FP_MUL, BN254_FP2_ADD, BN254_FP2_MUL, KECCAK_PERMUTE, SECP256K1_ADD,
BN254_FP_MUL, BN254_FP2_ADD, BN254_FP2_MUL, KECCAK_PERMUTE, PubIoCommitSpec, SECP256K1_ADD,
SECP256K1_DECOMPRESS, SECP256K1_DOUBLE, SECP256K1_SCALAR_INVERT, SECP256R1_ADD,
SECP256R1_DECOMPRESS, SECP256R1_DOUBLE, SECP256R1_SCALAR_INVERT, SHA_EXTEND, SyscallSpec,
UINT256_MUL,
Expand Down
33 changes: 10 additions & 23 deletions ceno_emul/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::addr::{Addr, RegIdx};
pub struct Platform {
pub rom: Range<Addr>,
pub prog_data: Arc<BTreeSet<Addr>>,
pub public_io: Range<Addr>,

pub stack: Range<Addr>,
pub heap: Range<Addr>,
Expand All @@ -34,7 +33,7 @@ impl Display for Platform {
write!(
f,
"Platform {{ rom: {:#x}..{:#x}, prog_data: {:#x}..{:#x}, stack: {:#x}..{:#x}, heap: {:#x}..{:#x}, \
public_io: {:#x}..{:#x}, hints: {:#x}..{:#x}, unsafe_ecall_nop: {} }}",
hints: {:#x}..{:#x}, unsafe_ecall_nop: {} }}",
self.rom.start,
self.rom.end,
prog_data
Expand All @@ -49,8 +48,6 @@ impl Display for Platform {
self.stack.end,
self.heap.start,
self.heap.end,
self.public_io.start,
self.public_io.end,
self.hints.start,
self.hints.end,
self.unsafe_ecall_nop
Expand Down Expand Up @@ -81,21 +78,21 @@ impl Display for Platform {
// │ STACK (≈128 MB, grows downward)
// │ 0x1800_0000 .. 0x2000_0000
// │
// ├───────────────────────────── 0x1800_0000 (stack base / pubio end)
// ├───────────────────────────── 0x1800_0000 (stack base)
// │
// │ PUBLIC I/O (128 MB)
// │ 0x1000_0000 .. 0x1800_0000
// │ STACK (stack-only memory window, includes reserved low-address area
// │ previously used for PUBLIC I/O)
// │ 0x1000_0000 .. 0x2000_0000
// │
// ├───────────────────────────── 0x1000_0000 (pubio base / rom end)
// ├───────────────────────────── 0x1000_0000 (stack base / rom end)
// │
// │ ROM / TEXT / RODATA (128 MB)
// │ 0x0800_0000 .. 0x1000_0000
// │
// └───────────────────────────── 0x8000_0000 (rom base)
pub static CENO_PLATFORM: Lazy<Platform> = Lazy::new(|| Platform {
rom: 0x0800_0000..0x1000_0000, // 128 MB
public_io: 0x1000_0000..0x1800_0000, // 128 MB
stack: 0x1800_0000..0x2000_4000, // stack grows downward 128MB, 0x4000 reserved for debug io.
rom: 0x0800_0000..0x1000_0000, // 128 MB
stack: 0x1000_0000..0x2000_4000, // stack grows downward, 0x4000 reserved for debug io.
// we make hints start from 0x2800_0000 thus reserve a 128MB gap for debug io
// at the end of stack
hints: 0x2800_0000..0x3000_0000, // 128 MB
Expand Down Expand Up @@ -123,10 +120,6 @@ impl Platform {
self.stack.contains(&addr) || self.heap.contains(&addr) || self.is_prog_data(addr)
}

pub fn is_pub_io(&self, addr: Addr) -> bool {
self.public_io.contains(&addr)
}

pub fn is_hints(&self, addr: Addr) -> bool {
self.hints.contains(&addr)
}
Expand Down Expand Up @@ -155,7 +148,7 @@ impl Platform {
}

pub fn can_write(&self, addr: Addr) -> bool {
self.is_ram(addr) || self.is_pub_io(addr) || self.is_hints(addr)
self.is_ram(addr) || self.is_hints(addr)
}

// Environment calls.
Expand Down Expand Up @@ -187,13 +180,7 @@ impl Platform {

/// Validate the platform configuration, range shall not overlap.
pub fn validate(&self) -> bool {
let mut ranges = [
&self.rom,
&self.stack,
&self.heap,
&self.public_io,
&self.hints,
];
let mut ranges = [&self.rom, &self.stack, &self.heap, &self.hints];
ranges.sort_by_key(|r| r.start);
for i in 0..ranges.len() - 1 {
if ranges[i].end > ranges[i + 1].start {
Expand Down
8 changes: 6 additions & 2 deletions ceno_emul/src/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use anyhow::Result;
pub mod bn254;
pub mod keccak_permute;
pub mod phantom;
pub mod pubio_commit;
pub mod secp256k1;
pub(crate) mod secp256r1;
pub mod sha256;
Expand All @@ -14,9 +15,11 @@ pub mod uint256;
pub use ceno_syscall::{
BLS12381_ADD, BLS12381_DECOMPRESS, BLS12381_DOUBLE, BN254_ADD, BN254_DOUBLE, BN254_FP_ADD,
BN254_FP_MUL, BN254_FP2_ADD, BN254_FP2_MUL, KECCAK_PERMUTE, PHANTOM_LOG_PC_CYCLE,
SECP256K1_ADD, SECP256K1_DECOMPRESS, SECP256K1_DOUBLE, SECP256K1_SCALAR_INVERT, SECP256R1_ADD,
SECP256R1_DECOMPRESS, SECP256R1_DOUBLE, SECP256R1_SCALAR_INVERT, SHA_EXTEND, UINT256_MUL,
PUB_IO_COMMIT, SECP256K1_ADD, SECP256K1_DECOMPRESS, SECP256K1_DOUBLE, SECP256K1_SCALAR_INVERT,
SECP256R1_ADD, SECP256R1_DECOMPRESS, SECP256R1_DOUBLE, SECP256R1_SCALAR_INVERT, SHA_EXTEND,
UINT256_MUL,
};
pub use pubio_commit::PubIoCommitSpec;

pub trait SyscallSpec {
const NAME: &'static str;
Expand Down Expand Up @@ -49,6 +52,7 @@ pub fn handle_syscall<T: Tracer>(vm: &VMState<T>, function_code: u32) -> Result<
BN254_FP2_ADD => Ok(bn254::bn254_fp2_add(vm)),
BN254_FP2_MUL => Ok(bn254::bn254_fp2_mul(vm)),
UINT256_MUL => Ok(uint256::uint256_mul(vm)),
PUB_IO_COMMIT => Ok(pubio_commit::pubio_commit(vm)),

// phantom syscall
PHANTOM_LOG_PC_CYCLE => Ok(phantom::log_pc_cycle(vm)),
Expand Down
33 changes: 33 additions & 0 deletions ceno_emul/src/syscalls/pubio_commit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use crate::{Change, EmuContext, Platform, Tracer, VMState, WriteOp, utils::MemoryView};

use super::{SyscallEffects, SyscallSpec, SyscallWitness};

const PUBIO_COMMIT_WORDS: usize = 8;

pub struct PubIoCommitSpec;
impl SyscallSpec for PubIoCommitSpec {
const NAME: &'static str = "PUB_IO_COMMIT";
const REG_OPS_COUNT: usize = 1;
const MEM_OPS_COUNT: usize = PUBIO_COMMIT_WORDS;
const CODE: u32 = ceno_syscall::PUB_IO_COMMIT;
}

/// Trace the PUB_IO_COMMIT syscall by reading 8 digest words from guest memory.
pub fn pubio_commit<T: Tracer>(vm: &VMState<T>) -> SyscallEffects {
let digest_ptr = vm.peek_register(Platform::reg_arg0());

let reg_ops = vec![WriteOp::new_register_op(
Platform::reg_arg0(),
Change::new(digest_ptr, digest_ptr),
0,
)];

let digest_view = MemoryView::<_, PUBIO_COMMIT_WORDS>::new(vm, digest_ptr);
let mem_ops = digest_view.mem_ops().to_vec();

assert_eq!(mem_ops.len(), PubIoCommitSpec::MEM_OPS_COUNT);
SyscallEffects {
witness: SyscallWitness::new(mem_ops, reg_ops),
next_pc: None,
}
}
8 changes: 1 addition & 7 deletions ceno_host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub fn run(
platform: Platform,
elf: &[u8],
hints: &CenoStdin,
public_io: Option<&CenoStdin>,
_public_io: Option<&CenoStdin>,
) -> Vec<Vec<u8>> {
let program = Program::load_elf(elf, u32::MAX).unwrap();
let platform = Platform {
Expand All @@ -124,20 +124,14 @@ pub fn run(
};

let hints: Vec<u32> = hints.into();
let pubio: Vec<u32> = public_io.map(|c| c.into()).unwrap_or_default();
let hints_range = platform.hints.clone();
let pubio_range = platform.public_io.clone();

let mut state = VMState::new(platform, Arc::new(program));

for (addr, value) in zip(hints_range.iter_addresses(), hints) {
state.init_memory(addr.into(), value);
}

for (addr, value) in zip(pubio_range.iter_addresses(), pubio) {
state.init_memory(addr.into(), value);
}

state
.iter_until_halt()
.collect::<Result<Vec<_>>>()
Expand Down
2 changes: 1 addition & 1 deletion ceno_recursion/src/aggregation/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl<C: Config> NonLeafVerifierVariables<C> {
// let expected_last_shard_id = Usize::uninit(builder);
// builder.assign(&expected_last_shard_id, pv.len() - Usize::from(1));

// let shard_id_fs = builder.get(&shard_raw_pi, SHARD_ID_IDX);
// let shard_id_fs = builder.get(&shard_pi, SHARD_ID_IDX);
// let shard_id_f = builder.get(&shard_id_fs, 0);
// let shard_id = Usize::Var(builder.cast_felt_to_var(shard_id_f));
// builder.assert_usize_eq(expected_last_shard_id, shard_id);
Expand Down
6 changes: 3 additions & 3 deletions ceno_recursion/src/aggregation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ impl CenoAggregationProver {
.collect();
let user_public_values: Vec<F> = zkvm_proof_inputs
.iter()
.flat_map(|p| p.raw_pi.to_vec())
.flat_map(|p| p.pi.to_vec())
.collect();
let leaf_inputs = chunk_ceno_leaf_proof_inputs(zkvm_proof_inputs);

Expand Down Expand Up @@ -398,7 +398,7 @@ impl CenoLeafVmVerifierConfig {

builder.cycle_tracker_start("Verify Ceno ZKVM Proof");
let zkvm_proof = ceno_leaf_input.proof;
let raw_pi = zkvm_proof.raw_pi.clone();
let pi = zkvm_proof.pi.clone();
let _calculated_shard_ec_sum = verify_zkvm_proof(&mut builder, zkvm_proof, &self.vk);
builder.cycle_tracker_end("Verify Ceno ZKVM Proof");

Expand All @@ -409,7 +409,7 @@ impl CenoLeafVmVerifierConfig {
builder.assign(&stark_pvs.app_commit[i], F::ZERO);
}

let pv = &raw_pi;
let pv = &pi;
let init_pc = builder.get(pv, INIT_PC_IDX);
let end_pc = builder.get(pv, END_PC_IDX);
let exit_code = builder.get(pv, EXIT_CODE_IDX);
Expand Down
Loading
Loading