Skip to content

Commit

Permalink
Snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasgoergens committed Jan 14, 2025
1 parent 4f56d31 commit 74e3d20
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 206 deletions.
50 changes: 50 additions & 0 deletions run_sorting
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
set -euxo pipefail

# Prep
(
(
cd ceno/examples
cargo build --release --example=quadratic_sorting
)
(
cd ceno
cargo build --release --bin e2e
)

mkdir --parents sorting-output/ceno
mkdir --parents sorting-output/sp1
)

(
cd sorting/program
cargo prove build
)
export MAX=12000
# export MAX="$((1 << 14))"

for N in $(shuf --input-range=1-${MAX}); do
for system in $(shuf --echo ceno sp1); do
output="sorting-output/${N}-$(date --iso-8601=ns --utc)/${system}"
mkdir --parents "${output}"
./run_${system}_sorting "${N}" "${output}"

done

done

output="output_time"

(
cd sorting/script

# export RUSTFLAGS="-C target-cpu=native -C target-feature=+avx512f"
# export RUSTFLAGS="-C target-cpu=native"
export RUST_LOG=info
# cargo clean
cargo build --release --bin sorting
/usr/bin/time --verbose --output="${output}" -- cargo run --release -- --n=$N --prove
echo "RUSTFLAGS=\'${RUSTFLAGS:-}\'"
echo "N=\'${N}'"
cat "${output}"
)
24 changes: 15 additions & 9 deletions run_sp1_sorting
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
#!/bin/bash
set -euxo pipefail
export N=$((1<<10))
output="output_time"

N="$1"

# We assume that "${output_dir}" exists.
export output_dir="$2"
test -d "${output_dir}"

output_time="$(realpath "${output_dir}/output_time")"
output_log="$(realpath "${output_dir}/log")"

(
cd sorting/program
cargo prove build
)
(
cd sorting/script

# export RUSTFLAGS="-C target-cpu=native -C target-feature=+avx512f"
# export RUSTFLAGS="-C target-cpu=native"
if grep --silent avx512 /proc/cpuinfo; then
export RUSTFLAGS="-C target-cpu=native -C target-feature=+avx512f"
else
export RUSTFLAGS="-C target-cpu=native"
fi
export RUST_LOG=info
# cargo clean
cargo build --release --bin sorting
/usr/bin/time --verbose --output="${output}" -- cargo run --release -- --n=$N --prove
echo "RUSTFLAGS=\'${RUSTFLAGS:-}\'"
echo "N=\'${N}'"
cat "${output}"
/usr/bin/time --verbose --output="${output_time}" -- cargo run --release -- --n="${N}" --prove | tee "${output_log}"
)
12 changes: 1 addition & 11 deletions sorting/Cargo.lock

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

4 changes: 0 additions & 4 deletions sorting/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
[workspace]
members = [
"lib",
"program",
"script",
]
resolver = "2"

[workspace.dependencies]
alloy-sol-types = "0.7.7"
7 changes: 0 additions & 7 deletions sorting/lib/Cargo.toml

This file was deleted.

9 changes: 0 additions & 9 deletions sorting/lib/src/lib.rs

This file was deleted.

3 changes: 1 addition & 2 deletions sorting/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ name = "sorting-program"
edition = "2021"

[dependencies]
alloy-sol-types = { workspace = true }
rand = "0.8.5"
sp1-zkvm = "3.0.0-rc4"
sorting-lib = { path = "../lib" }
28 changes: 6 additions & 22 deletions sorting/program/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,13 @@
#![no_main]
sp1_zkvm::entrypoint!(main);

use alloy_sol_types::SolType;
use sorting_lib::PublicValuesStruct;
use rand::Rng;

pub fn main() {
// Read an input to the program.
//
// Behind the scenes, this compiles down to a custom system call which handles reading inputs
// from the prover.
let n = sp1_zkvm::io::read::<u32>();
let n_: usize = n.try_into().unwrap();
// Sort a sequence of n pseudo-random numbers
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();

let median = scratch[n_ / 2];
let n: usize = sp1_zkvm::io::read::<u32>().try_into().unwrap();

// Encode the public values of the program.
let bytes = PublicValuesStruct::abi_encode(&PublicValuesStruct { n, median });

// Commit to the public values of the program. The final proof will have a commitment to all the
// bytes that were committed to.
sp1_zkvm::io::commit_slice(&bytes);
// Provide some random numbers to sort.
let mut rng = rand::thread_rng();
let mut scratch: Vec<u32> = (0..n).map(|_| rng.gen::<u32>()).collect::<Vec<_>>();
scratch.sort();
}
File renamed without changes.
6 changes: 0 additions & 6 deletions sorting/script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@ default-run = "sorting"
name = "sorting"
path = "src/bin/main.rs"

[[bin]]
name = "evm"
path = "src/bin/evm.rs"

[dependencies]
sp1-sdk = "3.0.0"
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
serde = { version = "1.0.200", default-features = false, features = ["derive"] }
clap = { version = "4.0", features = ["derive", "env"] }
tracing = "0.1.40"
hex = "0.4.3"
alloy-sol-types = { workspace = true }
sorting-lib = { path = "../lib" }

[build-dependencies]
sp1-helper = "3.0.0"
23 changes: 23 additions & 0 deletions sorting/script/output_time
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Command being timed: "cargo run --release -- --n=1024 --prove"
User time (seconds): 200.32
System time (seconds): 4.19
Percent of CPU this job got: 1904%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:10.73
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 4958420
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 256198
Voluntary context switches: 188637
Involuntary context switches: 188596
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
127 changes: 0 additions & 127 deletions sorting/script/src/bin/evm.rs

This file was deleted.

8 changes: 0 additions & 8 deletions sorting/script/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
//! RUST_LOG=info cargo run --release -- --prove
//! ```
use alloy_sol_types::SolType;
use clap::Parser;
use sorting_lib::PublicValuesStruct;
use sp1_sdk::{include_elf, ProverClient, SP1Stdin};

/// The ELF (executable and linkable format) file for the Succinct RISC-V zkVM.
Expand Down Expand Up @@ -58,12 +56,6 @@ fn main() {
let (output, report) = client.execute(sorting_ELF, stdin).run().unwrap();
println!("Program executed successfully.");

// Read the output.
let decoded = PublicValuesStruct::abi_decode(output.as_slice(), true).unwrap();
let PublicValuesStruct { n, median } = decoded;
println!("n: {}", n);
println!("median: {}", median);

// Record the number of cycles executed.
println!("Number of cycles: {}", report.total_instruction_count());
} else {
Expand Down

0 comments on commit 74e3d20

Please sign in to comment.