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
32 changes: 18 additions & 14 deletions ceno_cli/src/commands/common_args/ceno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ use ceno_host::{CenoStdin, memory_from_file};
use ceno_zkvm::{
e2e::*,
scheme::{
constants::MAX_NUM_VARIABLES, create_backend, create_prover,
mock_prover::LkMultiplicityKey, verifier::ZKVMVerifier,
constants::MAX_NUM_VARIABLES,
create_backend, create_prover,
mock_prover::LkMultiplicityKey,
verifier::{RV32imMemStateConfig, ZKVMVerifier},
},
};
use clap::Args;
Expand Down Expand Up @@ -354,7 +356,7 @@ fn run_elf_inner<
compilation_options: &CompilationOptions,
elf_path: P,
checkpoint: Checkpoint,
) -> anyhow::Result<E2ECheckpointResult<E, PCS>> {
) -> anyhow::Result<E2ECheckpointResult<E, PCS, RV32imMemStateConfig>> {
let elf_path = elf_path.as_ref();
let elf_bytes =
std::fs::read(elf_path).context(format!("failed to read {}", elf_path.display()))?;
Expand Down Expand Up @@ -410,17 +412,19 @@ fn run_elf_inner<
);

let backend = create_backend(options.max_num_variables, options.security_level);
Ok(run_e2e_with_checkpoint::<E, PCS, _, _>(
create_prover(backend.clone()),
program,
platform,
multi_prover,
&hints,
&public_io,
options.max_steps,
checkpoint,
options.shard_id.map(|v| v as usize),
))
Ok(
run_e2e_with_checkpoint::<E, PCS, _, _, RV32imMemStateConfig>(
create_prover(backend.clone()),
program,
platform,
multi_prover,
&hints,
&public_io,
options.max_steps,
checkpoint,
options.shard_id.map(|v| v as usize),
),
)
}

fn keygen_inner<
Expand Down
7 changes: 5 additions & 2 deletions ceno_cli/src/commands/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use crate::utils::print_cargo_message;
use anyhow::{Context, bail};
use ceno_zkvm::{
e2e::{FieldType, PcsKind, verify},
scheme::{ZKVMProof, verifier::ZKVMVerifier},
scheme::{
ZKVMProof,
verifier::{RV32imMemStateConfig, ZKVMVerifier},
},
structs::ZKVMVerifyingKey,
};
use clap::Parser;
Expand Down Expand Up @@ -66,7 +69,7 @@ fn run_inner<E: ExtensionField, PCS: PolynomialCommitmentScheme<E> + Serialize>(
);

let start = std::time::Instant::now();
let vk: ZKVMVerifyingKey<E, PCS> =
let vk: ZKVMVerifyingKey<E, PCS, RV32imMemStateConfig> =
bincode::deserialize_from(File::open(&args.vk).context("Failed to open vk file")?)
.context("Failed to deserialize vk file")?;
print_cargo_message(
Expand Down
15 changes: 9 additions & 6 deletions ceno_cli/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ use ceno_recursion::{
use ceno_zkvm::{
e2e::{MultiProver, run_e2e_proof, setup_program},
scheme::{
ZKVMProof, create_backend, create_prover, hal::ProverDevice,
mock_prover::LkMultiplicityKey, prover::ZKVMProver, verifier::ZKVMVerifier,
ZKVMProof, create_backend, create_prover,
hal::ProverDevice,
mock_prover::LkMultiplicityKey,
prover::ZKVMProver,
verifier::{RV32imMemStateConfig, ZKVMVerifier},
},
structs::{ZKVMProvingKey, ZKVMVerifyingKey},
};
Expand Down Expand Up @@ -51,7 +54,7 @@ pub struct Sdk<

// base(app) layer
pub zkvm_pk: Option<Arc<ZKVMProvingKey<E, PCS>>>,
pub zkvm_vk: Option<ZKVMVerifyingKey<E, PCS>>,
pub zkvm_vk: Option<ZKVMVerifyingKey<E, PCS, RV32imMemStateConfig>>,
pub zkvm_prover: Option<ZKVMProver<E, PCS, PB, PD>>,

// aggregation
Expand Down Expand Up @@ -104,7 +107,7 @@ where
}

// allow us to read the app vk from file and then set it
pub fn set_app_vk(&mut self, vk: ZKVMVerifyingKey<E, PCS>) {
pub fn set_app_vk(&mut self, vk: ZKVMVerifyingKey<E, PCS, RV32imMemStateConfig>) {
self.zkvm_vk = Some(vk);
}

Expand Down Expand Up @@ -164,7 +167,7 @@ where
self.zkvm_pk.clone().expect("zkvm pk is not set")
}

pub fn get_app_vk(&self) -> ZKVMVerifyingKey<E, PCS> {
pub fn get_app_vk(&self) -> ZKVMVerifyingKey<E, PCS, RV32imMemStateConfig> {
self.zkvm_vk.clone().expect("zkvm vk is not set")
}

Expand All @@ -176,7 +179,7 @@ where
self.agg_pk.as_ref().expect("agg pk is not set").get_vk()
}

pub fn create_zkvm_verifier(&self) -> ZKVMVerifier<E, PCS> {
pub fn create_zkvm_verifier(&self) -> ZKVMVerifier<E, PCS, RV32imMemStateConfig> {
let Some(app_vk) = self.zkvm_vk.clone() else {
panic!("empty zkvm vk");
};
Expand Down
47 changes: 24 additions & 23 deletions ceno_emul/src/platform.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use crate::addr::{Addr, RegIdx};
use core::fmt::{self, Formatter};
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use std::{collections::BTreeSet, fmt::Display, ops::Range, sync::Arc};

use crate::addr::{Addr, RegIdx};

/// The Platform struct holds the parameters of the VM.
/// It defines:
/// - the layout of virtual memory,
/// - special addresses, such as the initial PC,
/// - codes of environment calls.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Platform {
pub rom: Range<Addr>,
pub prog_data: Arc<BTreeSet<Addr>>,
Expand Down Expand Up @@ -58,51 +58,52 @@ impl Display for Platform {
}
}

/// alined with [`memory.x`]
// ┌───────────────────────────── 0x4000_0000 (end of _sheap, or heap)
/// aligned with [`memory.x`]
// ┌───────────────────────────── 0x4000_0000 (stack top)
// │
// │ HEAP (128 MB, grows upward)
// │ STACK (≈128 MB, grows downward)
// │ 0x3800_0000 .. 0x4000_0000
// │
// ├───────────────────────────── 0x3800_0000 (_sheap, align 0x800_0000)
// │ RAM (128 MB)
// ├───────────────────────────── 0x3800_0000 (stack base / pubio end)
// │
// │ PUBLIC I/O (128 MB)
// │ 0x3000_0000 .. 0x3800_0000
// ├───────────────────────────── 0x3000_0000 (RAM base / hints end)
// │
// ├───────────────────────────── 0x3000_0000 (pubio base / hints end)
// │
// │ HINTS (128 MB)
// │ 0x2800_0000 .. 0x3000_0000
// │
// │───────────────────────────── 0x2800_0000 (hint base / gap end)
// │───────────────────────────── 0x2800_0000 (hint start / gap end)
// │
// │ [Reserved gap: 128 MB for debug I/O]
// │ 0x2000_0000 .. 0x2800_0000
// │───────────────────────────── 0x2000_0000 (gap / stack end)
// │───────────────────────────── 0x2000_0000 (gap / heap end)
// │
// │ STACK (≈128 MB, grows downward)
// │ HEAP (128 MB, grows upward)
// │ 0x1800_0000 .. 0x2000_0000
// │
// ├───────────────────────────── 0x1800_0000 (stack base / pubio end)
// │
// │ PUBLIC I/O (128 MB)
// ├───────────────────────────── 0x1800_0000 (_sheap, align 0x800_0000)
// │ RAM (128 MB)
// │ 0x1000_0000 .. 0x1800_0000
// │
// ├───────────────────────────── 0x1000_0000 (pubio base / rom end)
// ├───────────────────────────── 0x1000_0000 (ram base / rom end)
// │
// │ ROM / TEXT / RODATA (128 MB)
// │ 0x0800_0000 .. 0x1000_0000
// │
// └───────────────────────────── 0x8000_0000 (rom base)
// └───────────────────────────── 0x0800_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.
// we make hints start from 0x2800_0000 thus reserve a 128MB gap for debug io
// at the end of stack
public_io: 0x3000_0000..0x3800_0000, // 128 MB
stack: 0x3800_0000..0x4000_4000, // stack grows downward 128MB, 0x4000 reserved for debug io.
// we make hints start from 0x2800_0000 thus reserve a 128MB gap (0x2000_0000..0x2800_0000)
// between the RAM payload and the hint data for debug io
hints: 0x2800_0000..0x3000_0000, // 128 MB
// heap grows upward, reserved 128 MB for it
// the beginning of heap address got bss/sbss data
// and the real heap start from 0x3800_0000
heap: 0x3000_0000..0x4000_0000,
// and the real heap start from 0x1800_0000
heap: 0x1000_0000..0x2000_0000,
unsafe_ecall_nop: false,
prog_data: Arc::new(BTreeSet::new()),
is_debug: false,
Expand Down
2 changes: 1 addition & 1 deletion ceno_emul/src/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl LatestAccesses {
Self {
store: DenseAddrSpace::new(
WordAddr::from(0u32),
ByteAddr::from(platform.heap.end).waddr(),
ByteAddr::from(platform.stack.end).waddr(),
),
len: 0,
#[cfg(any(test, debug_assertions))]
Expand Down
2 changes: 1 addition & 1 deletion ceno_emul/src/vm_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl<T: Tracer> VMState<T> {
program: program.clone(),
memory: DenseAddrSpace::new(
ByteAddr::from(platform.rom.start).waddr(),
ByteAddr::from(platform.heap.end).waddr(),
ByteAddr::from(platform.stack.end).waddr(),
),
registers: [0; VM_REG_COUNT],
halt_state: None,
Expand Down
Loading