Skip to content

Commit

Permalink
fix: examples and deps (#142)
Browse files Browse the repository at this point in the history
* fix: examples

* fix: example sha2
  • Loading branch information
eigmax authored Jul 6, 2024
1 parent 07bd0d2 commit 10dcb75
Show file tree
Hide file tree
Showing 37 changed files with 45 additions and 39 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
/Cargo.lock
/output
/examples/target
15 changes: 14 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
[workspace]
members = [
"runtime/*",
"prover",
"prover"
]
resolver = "2"


[profile.release]
opt-level = 3

[profile.bench]
opt-level = 3

[profile.fast]
inherits = "release"
debug = true
debug-assertions = true

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ In order to build the application, zkm requires a latest nightly toolchain. Just

# Running the examples

An end-to-end example has been presented in [examples](./examples).
An end-to-end example has been presented in [examples](./prover/examples).

# Guidance for external contributors

Expand Down
4 changes: 1 addition & 3 deletions prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,20 @@ rand = "0.8.5"
rand_chacha = "0.3.1"
once_cell = "1.13.0"
static_assertions = "1.1.0"
keccak-hash = "0.10.0"
byteorder = "1.5.0"
hex = "0.4"
hashbrown = { version = "0.14.0", default-features = false, features = ["ahash", "serde"] } # NOTE: When upgrading, see `ahash` dependency.
lazy_static = "1.4.0"

elf = { version = "0.7", default-features = false }

sysinfo = "0.30.7"

[dev-dependencies]
env_logger = "0.10.0"
keccak-hash = "0.10.0"
plonky2x = { git = "https://github.com/zkMIPS/succinctx.git", package = "plonky2x", branch = "zkm" }
plonky2x-derive = { git = "https://github.com/zkMIPS/succinctx.git", package = "plonky2x-derive", branch = "zkm" }
curta = { git ="https://github.com/zkMIPS/curta.git", branch = "zkm" }


[features]
test = []
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ name = "sha2-bench"
edition = "2021"

[dependencies]
zkm-runtime = { path = "../../runtime/entrypoint" }
zkm-runtime = { path = "../../../runtime/entrypoint" }
sha2 = { version = "0.10.8", default-features = false }
File renamed without changes.
File renamed without changes.
20 changes: 10 additions & 10 deletions examples/zkmips.rs → prover/examples/zkmips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ use plonky2x::backend::circuit::Groth16WrapperParameters;
use plonky2x::backend::wrapper::wrap::WrappedCircuit;
use plonky2x::frontend::builder::CircuitBuilder as WrapperBuilder;
use plonky2x::prelude::DefaultParameters;
use zkm::all_stark::AllStark;
use zkm::config::StarkConfig;
use zkm::cpu::kernel::assembler::segment_kernel;
use zkm::fixed_recursive_verifier::AllRecursiveCircuits;
use zkm::mips_emulator::state::{InstrumentedState, State, SEGMENT_STEPS};
use zkm::mips_emulator::utils::get_block_path;
use zkm::proof;
use zkm::proof::PublicValues;
use zkm::prover::prove;
use zkm::verifier::verify_proof;
use zkm_prover::all_stark::AllStark;
use zkm_prover::config::StarkConfig;
use zkm_prover::cpu::kernel::assembler::segment_kernel;
use zkm_prover::fixed_recursive_verifier::AllRecursiveCircuits;
use zkm_prover::mips_emulator::state::{InstrumentedState, State, SEGMENT_STEPS};
use zkm_prover::mips_emulator::utils::get_block_path;
use zkm_prover::proof;
use zkm_prover::proof::PublicValues;
use zkm_prover::prover::prove;
use zkm_prover::verifier::verify_proof;

const DEGREE_BITS_RANGE: [Range<usize>; 6] = [10..21, 12..22, 12..21, 8..21, 6..21, 13..23];

Expand Down
4 changes: 2 additions & 2 deletions prover/src/cpu/kernel/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,14 @@ mod test {
#[test]
fn load_and_check_mips_elf() {
env_logger::try_init().unwrap_or_default();
let mut reader = BufReader::new(File::open("../test-vectors/hello").unwrap());
let mut reader = BufReader::new(File::open("test-vectors/hello").unwrap());
let mut buffer = Vec::new();
reader.read_to_end(&mut buffer).unwrap();
let max_mem = 0x80000000;
let mut p: Program = Program::load_elf(&buffer, max_mem).unwrap();
log::info!("entry: {}", p.entry);

let real_blockpath = get_block_path("../test-vectors", "13284491", "input");
let real_blockpath = get_block_path("test-vectors", "13284491", "input");
log::info!("real block path: {}", real_blockpath);
p.load_block(&real_blockpath).unwrap();

Expand Down
8 changes: 4 additions & 4 deletions prover/src/mips_emulator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ mod tests {

#[test]
fn test_execute_hello() {
let path = PathBuf::from("../test-vectors/hello");
let path = PathBuf::from("test-vectors/hello");
let data = fs::read(path).expect("could not read file");
let file =
ElfBytes::<AnyEndian>::minimal_parse(data.as_slice()).expect("opening elf file failed");
Expand All @@ -75,7 +75,7 @@ mod tests {

#[test]
fn test_execute_rust_fib() {
let path = PathBuf::from("../test-vectors/rust_fib");
let path = PathBuf::from("test-vectors/rust_fib");
let data = fs::read(path).expect("could not read file");
let file =
ElfBytes::<AnyEndian>::minimal_parse(data.as_slice()).expect("opening elf file failed");
Expand All @@ -96,7 +96,7 @@ mod tests {
#[test]
#[ignore]
fn test_execute_minigeth() {
let path = PathBuf::from("../test-vectors/minigeth");
let path = PathBuf::from("test-vectors/minigeth");
let data = fs::read(path).expect("could not read file");
let file =
ElfBytes::<AnyEndian>::minimal_parse(data.as_slice()).expect("opening elf file failed");
Expand Down Expand Up @@ -131,7 +131,7 @@ mod tests {

#[test]
fn test_execute_split_hello() {
let path = PathBuf::from("../test-vectors/hello");
let path = PathBuf::from("test-vectors/hello");
let data = fs::read(path).expect("could not read file");
let file =
ElfBytes::<AnyEndian>::minimal_parse(data.as_slice()).expect("opening elf file failed");
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 11 additions & 10 deletions tests/simple_recursion.rs → prover/tests/simple_recursion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2::plonk::circuit_data::CircuitConfig;
use plonky2::plonk::config::PoseidonGoldilocksConfig;
use std::io::BufReader;
use zkm::all_stark::AllStark;
use zkm::config::StarkConfig;
use zkm::cpu::kernel::assembler::segment_kernel;
use zkm::fixed_recursive_verifier::AllRecursiveCircuits;
use zkm::mips_emulator::state::{InstrumentedState, State};
use zkm::mips_emulator::utils::get_block_path;
use zkm::proof::PublicValues;
use zkm_prover::all_stark::AllStark;
use zkm_prover::config::StarkConfig;
use zkm_prover::cpu::kernel::assembler::segment_kernel;
use zkm_prover::fixed_recursive_verifier::AllRecursiveCircuits;
use zkm_prover::mips_emulator::state::{InstrumentedState, State};
use zkm_prover::mips_emulator::utils::get_block_path;
use zkm_prover::proof::PublicValues;

use plonky2::util::timing::TimingTree;

Expand All @@ -32,7 +32,9 @@ fn split_elf_into_segs(
seg_size: usize,
) {
// 1. split ELF into segs
let data = fs::read(elf_path).expect("could not read file");
let data = fs::read(elf_path)
.map_err(|_| panic!("could not read file, {}", elf_path))
.unwrap();
let file =
ElfBytes::<AnyEndian>::minimal_parse(data.as_slice()).expect("opening elf file failed");
let (mut state, _) = State::load_elf(&file);
Expand Down Expand Up @@ -66,7 +68,6 @@ fn split_elf_into_segs(

// Tests proving two transactions, one of which with logs, and aggregating them.
#[test]
#[ignore = "Too slow"]
fn test_mips_with_aggreg_fibo() -> anyhow::Result<()> {
use plonky2x::backend::circuit::Groth16WrapperParameters;
use plonky2x::backend::wrapper::wrap::WrappedCircuit;
Expand Down Expand Up @@ -138,7 +139,7 @@ fn test_mips_with_aggreg_fibo() -> anyhow::Result<()> {
}

#[test]
#[ignore = "Too slow"]
#[ignore = "Two slow"]
fn test_mips_with_aggreg() -> anyhow::Result<()> {
use plonky2x::backend::circuit::Groth16WrapperParameters;
use plonky2x::backend::wrapper::wrap::WrappedCircuit;
Expand Down
2 changes: 0 additions & 2 deletions runtime/entrypoint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ zkm-precompiles = { path = "../precompiles" }
bincode = "1.3.3"
cfg-if = "1.0.0"
getrandom = { version = "0.2.14", features = ["custom"] }
once_cell = "1.19.0"
rand = "0.8.5"
serde = { version = "1.0.201", features = ["derive"] }
libm = { version = "0.2.8", optional = true }
sha2 = { version = "0.10.8" }
lazy_static = "1.4.0"

[features]
Expand Down
5 changes: 0 additions & 5 deletions runtime/precompiles/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ version = "0.1.0"
edition = "2021"

[dependencies]
anyhow = "1.0.83"
bincode = "1.3.3"
cfg-if = "1.0.0"
getrandom = { version = "0.2.14", features = ["custom"] }
hex = "0.4.3"
rand = "0.8.5"
serde = { version = "1.0.201", features = ["derive"] }
num = { version = "0.4.3" }

0 comments on commit 10dcb75

Please sign in to comment.