Skip to content
Closed
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
9 changes: 2 additions & 7 deletions Cargo.lock

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

7 changes: 5 additions & 2 deletions ceno_zkvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ serde_json.workspace = true

base64 = "0.22"
ceno_emul = { path = "../ceno_emul" }
ceno-examples = { path = "../examples-builder" }
ceno_host = { path = "../ceno_host" }

ff_ext = { path = "../ff_ext" }
mpcs = { path = "../mpcs" }
multilinear_extensions = { version = "0", path = "../multilinear_extensions" }
Expand All @@ -40,7 +43,6 @@ tracing-subscriber.workspace = true
bincode = "1"
clap = { version = "4.5", features = ["derive"] }
generic_static = "0.2"
parse-size = "1.1"
rand.workspace = true
tempfile = "3.14"
thread_local = "1.1"
Expand All @@ -51,6 +53,7 @@ criterion.workspace = true
pprof2.workspace = true
proptest.workspace = true


[build-dependencies]
glob = "0.3"

Expand All @@ -70,4 +73,4 @@ name = "fibonacci"

[[bench]]
harness = false
name = "fibonacci_witness"
name = "fibonacci_witness"
25 changes: 13 additions & 12 deletions ceno_zkvm/src/bin/e2e.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use ceno_emul::{IterAddresses, Program, WORD_SIZE, Word};
use ceno_host::CenoStdin;
use ceno_zkvm::{
e2e::{Checkpoint, Preset, run_e2e_with_checkpoint, setup_platform},
with_panic_hook,
Expand All @@ -18,13 +19,6 @@ use transcript::{
BasicTranscript as Transcript, BasicTranscriptWithStat as TranscriptWithStat, StatisticRecorder,
};

fn parse_size(s: &str) -> Result<u32, parse_size::Error> {
parse_size::Config::new()
.with_binary()
.parse_size(s)
.map(|size| size as u32)
}

/// Prove the execution of a fixed RISC-V program.
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
Expand All @@ -51,12 +45,15 @@ struct Args {
#[arg(long)]
hints: Option<String>,

#[arg(long, default_value = "100")]
n: u32,

/// Stack size in bytes.
#[arg(long, default_value = "32k", value_parser = parse_size)]
#[arg(long, default_value = "32768")]
stack_size: u32,

/// Heap size in bytes.
#[arg(long, default_value = "2M", value_parser = parse_size)]
#[arg(long, default_value = "2097152")]
heap_size: u32,
}

Expand Down Expand Up @@ -104,7 +101,8 @@ fn main() {
.init();

tracing::info!("Loading ELF file: {}", &args.elf);
let elf_bytes = fs::read(&args.elf).expect("read elf file");
// let elf_bytes = fs::read(&args.elf).expect("read elf file");
let elf_bytes = ceno_examples::sorting;
let program = Program::load_elf(&elf_bytes, u32::MAX).unwrap();
let platform = setup_platform(
args.platform,
Expand All @@ -113,15 +111,18 @@ fn main() {
args.heap_size,
pub_io_size,
);
tracing::info!("Running on platform {:?} {}", args.platform, platform);
tracing::info!("Running on platform {:?} {:?}", args.platform, platform);
tracing::info!(
"Stack: {} bytes. Heap: {} bytes.",
args.stack_size,
args.heap_size
);

tracing::info!("Loading hints file: {:?}", args.hints);
let hints = memory_from_file(&args.hints);
// let hints = memory_from_file(&args.hints);
let mut hints = CenoStdin::default();
_ = hints.write(&args.n);
let hints: Vec<u32> = (&hints).into();
assert!(
hints.len() <= platform.hints.iter_addresses().len(),
"hints must fit in {} bytes",
Expand Down
2 changes: 1 addition & 1 deletion ceno_zkvm/src/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fn emulate_program(
}
})
.collect_vec();
debug_memory_ranges(&vm, &mem_final);
// debug_memory_ranges(&vm, &mem_final);

// Find the final public IO cycles.
let io_final = io_init
Expand Down
16 changes: 9 additions & 7 deletions examples/examples/sorting.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
extern crate ceno_rt;
use ceno_rt::println;
use core::fmt::Write;
use rkyv::vec::ArchivedVec;
use rkyv::Archived;

fn main() {
let input: &ArchivedVec<u32> = ceno_rt::read();
let mut scratch: Vec<u32> = input.to_vec();
let n: &Archived<u32> = ceno_rt::read();
let n: usize = (*n).try_into().unwrap();

// Initialize with some pseudo-random array to avoid large input
let mut scratch: Vec<u32> = vec![1; n];
for i in 1..n {
scratch[i] = ((scratch[i - 1]) * 17 + 19) & ((1 << 20) - 1);
}
scratch.sort();
// Print any output you feel like, eg the first element of the sorted vector:
println!("{}", scratch[0]);
}
5 changes: 5 additions & 0 deletions sorting/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# 'mock' for generating mock proofs locally, 'local' for generating proofs locally, 'network' for generating proofs using the proving network.
SP1_PROVER=local
# If using the proving network, set to your whitelisted private key. For more information, see:
# https://docs.succinct.xyz/prover-network/setup.html#key-setup
SP1_PRIVATE_KEY=
40 changes: 40 additions & 0 deletions sorting/.github/workflows/foundry-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Foundry Test

on:
workflow_dispatch:
push:
branches: [ main ]
pull_request:

env:
FOUNDRY_PROFILE: ci

jobs:
check:
strategy:
fail-fast: true

name: Foundry project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Run Forge build
run: |
cd contracts
forge --version
forge build --sizes
id: build

- name: Run Forge tests
run: |
cd contracts
forge test -vvv
id: test
39 changes: 39 additions & 0 deletions sorting/.github/workflows/prove.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build Program

on:
workflow_dispatch:
push:
branches: [main]
pull_request:

env:
FOUNDRY_PROFILE: ci

jobs:
check:
strategy:
fail-fast: true

name: Build
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.81.0

- name: Install SP1 toolchain
run: |
curl -L https://sp1.succinct.xyz | bash
~/.sp1/bin/sp1up
~/.sp1/bin/cargo-prove prove --version

- name: Build SP1 program
run: |
cd program
~/.sp1/bin/cargo-prove prove build
19 changes: 19 additions & 0 deletions sorting/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Cargo build
**/target

# Cargo config
.cargo

# Profile-guided optimization
/tmp
pgo-data.profdata

# MacOS nuisances
.DS_Store

# Proofs
**/proof-with-pis.json
**/proof-with-io.json

# Env
.env
Loading
Loading