Skip to content

Commit

Permalink
feat/private-input-2: assert priv_io length
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurélien Nicolas committed Nov 22, 2024
1 parent c7cd4b5 commit 4f15ceb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ceno_emul/src/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,17 @@ impl ops::AddAssign<u32> for ByteAddr {
}

pub trait IterAddresses {
fn iter_addresses(&self) -> impl Iterator<Item = Addr>;
fn iter_addresses(&self) -> impl ExactSizeIterator<Item = Addr>;
}

impl IterAddresses for Range<Addr> {
fn iter_addresses(&self) -> impl Iterator<Item = Addr> {
fn iter_addresses(&self) -> impl ExactSizeIterator<Item = Addr> {
self.clone().step_by(WORD_SIZE)
}
}

impl<'a, T: GetAddr> IterAddresses for &'a [T] {
fn iter_addresses(&self) -> impl Iterator<Item = Addr> {
fn iter_addresses(&self) -> impl ExactSizeIterator<Item = Addr> {
self.iter().map(T::get_addr)
}
}
Expand Down
6 changes: 6 additions & 0 deletions ceno_zkvm/src/bin/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct Args {
platform: Preset,

/// The private input or hints. This is a raw file mounted as a memory segment.
/// Zero-padded to the next power-of-two size.
#[arg(long)]
private_input: Option<String>,
}
Expand Down Expand Up @@ -102,6 +103,11 @@ fn main() {

tracing::info!("Loading private input file: {:?}", args.private_input);
let priv_io = memory_from_file(&args.private_input);
assert!(
priv_io.len() <= platform.private_io.iter_addresses().len(),
"private input must fit in {} bytes",
platform.private_io.len()
);
for (addr, value) in zip(platform.private_io.iter_addresses(), &priv_io) {
vm.init_memory(addr.into(), *value);
}
Expand Down

0 comments on commit 4f15ceb

Please sign in to comment.