diff --git a/README.md b/README.md index c258245..921ea27 100644 --- a/README.md +++ b/README.md @@ -12,3 +12,4 @@ To run test, corresponding to zkVM of choise read - [Valida](./valida/README.md) - [SP1](./sp1/README.md) - [Nexus](./nexus/README.md) +- [RISC0](./risc0/README.md) diff --git a/risc0/README.md b/risc0/README.md new file mode 100644 index 0000000..fb64f81 --- /dev/null +++ b/risc0/README.md @@ -0,0 +1,31 @@ +# Test run instructions + +To run corresponding tests in `RISC0` some preparations have to be done. + +We assume, that one is in `risc0` folder. + +Firstly, move into [scripts_and_tools](./scripts_and_tools/) directory. + +Next, run + +```sh +./risc0_setup.sh +``` + +This will fetch all necessary components for benchmarking. + +Next, to prove execution we need to build one of the tests, we will use `simple_arithmetic_test` as an example. + +Run + +```sh +./risc0_bench_arithmetic.sh +``` + +This will compile benchmark, generate proof and prins statictics. + +Alternatively, for memory test, you can do + +```sh +./risc0_bench_memory.sh +``` \ No newline at end of file diff --git a/risc0/benchmark_tests/bench_programs/mem_bench.rs b/risc0/benchmark_tests/bench_programs/mem_alloc_vec_test.rs similarity index 100% rename from risc0/benchmark_tests/bench_programs/mem_bench.rs rename to risc0/benchmark_tests/bench_programs/mem_alloc_vec_test.rs diff --git a/risc0/benchmark_tests/bench_programs/perf_bench.rs b/risc0/benchmark_tests/bench_programs/simple_arithmetic_test.rs similarity index 94% rename from risc0/benchmark_tests/bench_programs/perf_bench.rs rename to risc0/benchmark_tests/bench_programs/simple_arithmetic_test.rs index f6bc0d2..a125be4 100644 --- a/risc0/benchmark_tests/bench_programs/perf_bench.rs +++ b/risc0/benchmark_tests/bench_programs/simple_arithmetic_test.rs @@ -20,7 +20,7 @@ pub fn new_jobs() -> Vec { let mut jobs = Vec::new(); for iterations in [100] { jobs.push(Job::new( - format!("simlpe_arithmetic_test-{iterations}"), + format!("simple_arithmetic_test-{iterations}"), risc0_benchmark_methods::SIMPLE_ARITHMETIC_TEST_ELF, risc0_benchmark_methods::SIMPLE_ARITHMETIC_TEST_ID.into(), to_vec(&iterations).unwrap(), diff --git a/risc0/benchmark_tests/main.rs b/risc0/benchmark_tests/main.rs new file mode 100644 index 0000000..3ad0825 --- /dev/null +++ b/risc0/benchmark_tests/main.rs @@ -0,0 +1,93 @@ +// Copyright 2024 RISC Zero, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This is based on zk-benchmarking: https://github.com/delendum-xyz/zk-benchmarking + +use std::path::PathBuf; + +use clap::{Parser, Subcommand}; +use enum_iterator::Sequence; +use risc0_benchmark::{benches::*, run_jobs, Job}; +use tracing_subscriber::EnvFilter; + +#[derive(Parser)] +#[command(author, version, about, long_about = None)] +struct Cli { + // CSV output file + #[arg(long, value_name = "FILE", default_value = "metrics.csv")] + out: PathBuf, + + #[command(subcommand)] + command: Option, +} + +#[derive(Eq, PartialEq, Subcommand, Sequence)] +enum Command { + All, + BigBlake2b, + BigBlake3, + BigKeccak, + BigSha2, + EcdsaVerify, + Ed25519Verify, + Fibonacci, + IterBlake2b, + IterBlake3, + IterKeccak, + IterSha2, + Membership, + Sudoku, + SimpleArithmeticTest, + MemAllocVecTest, +} + +impl Command { + fn get_jobs(&self) -> Vec { + match self { + Command::All => enum_iterator::all::() + .skip_while(|x| *x == Command::All) + .flat_map(|x| x.get_jobs()) + .collect(), + Command::BigBlake2b => big_blake2b::new_jobs(), + Command::BigBlake3 => big_blake3::new_jobs(), + Command::BigKeccak => big_keccak::new_jobs(), + Command::BigSha2 => big_sha2::new_jobs(), + Command::EcdsaVerify => ecdsa_verify::new_jobs(), + Command::Ed25519Verify => ed25519_verify::new_jobs(), + Command::Fibonacci => fibonacci::new_jobs(), + Command::IterBlake2b => iter_blake2b::new_jobs(), + Command::IterBlake3 => iter_blake3::new_jobs(), + Command::IterKeccak => iter_keccak::new_jobs(), + Command::IterSha2 => iter_sha2::new_jobs(), + Command::Membership => membership::new_jobs(), + Command::Sudoku => sudoku::new_jobs(), + Command::SimpleArithmeticTest => simple_arithmetic_test::new_jobs(), + Command::MemAllocVecTest => mem_alloc_vec_test::new_jobs(), + } + } +} + +fn init_logging() { + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); +} + +fn main() { + init_logging(); + + let cli = Cli::parse(); + let cmd = cli.command.unwrap_or(Command::All); + run_jobs(&cli.out, cmd.get_jobs()); +} diff --git a/risc0/benchmark_tests/mod.rs b/risc0/benchmark_tests/mod.rs new file mode 100644 index 0000000..28c7370 --- /dev/null +++ b/risc0/benchmark_tests/mod.rs @@ -0,0 +1,29 @@ +// Copyright 2024 RISC Zero, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +pub mod big_blake2b; +pub mod big_blake3; +pub mod big_keccak; +pub mod big_sha2; +pub mod ecdsa_verify; +pub mod ed25519_verify; +pub mod fibonacci; +pub mod iter_blake2b; +pub mod iter_blake3; +pub mod iter_keccak; +pub mod iter_sha2; +pub mod membership; +pub mod sudoku; +pub mod simple_arithmetic_test; +pub mod mem_alloc_vec_test; \ No newline at end of file diff --git a/risc0/scripts_and_tools/risc0_bench_arithmetic.sh b/risc0/scripts_and_tools/risc0_bench_arithmetic.sh new file mode 100644 index 0000000..26cc4f3 --- /dev/null +++ b/risc0/scripts_and_tools/risc0_bench_arithmetic.sh @@ -0,0 +1,3 @@ +cd risc0/benchmarks/ + cargo run --release -- simple-arithmetic-test +cd ../../ \ No newline at end of file diff --git a/risc0/scripts_and_tools/risc0_bench_memory.sh b/risc0/scripts_and_tools/risc0_bench_memory.sh new file mode 100644 index 0000000..e9eaeb6 --- /dev/null +++ b/risc0/scripts_and_tools/risc0_bench_memory.sh @@ -0,0 +1,3 @@ +cd risc0/benchmarks/ + cargo run --release -- mem-alloc-vec-test +cd ../../ \ No newline at end of file diff --git a/risc0/scripts_and_tools/risc0_setup.sh b/risc0/scripts_and_tools/risc0_setup.sh new file mode 100644 index 0000000..d82e6e9 --- /dev/null +++ b/risc0/scripts_and_tools/risc0_setup.sh @@ -0,0 +1,19 @@ +git clone https://github.com/risc0/risc0.git + +cp ../benchmark_tests/guest_programs/mem_alloc_vec_test.rs risc0/benchmarks/methods/guest/src/bin/ + +cp ../benchmark_tests/guest_programs/simple_arithmetic_test.rs risc0/benchmarks/methods/guest/src/bin/ + +cp ../benchmark_tests/bench_programs/mem_alloc_vec_test.rs risc0/benchmarks/src/benches/ + +cp ../benchmark_tests/bench_programs/simple_arithmetic_test.rs risc0/benchmarks/src/benches/ + +cd risc0/benchmarks/src/benches/ + rm -rf mod.rs + cd .. + rm -rf main.rs +cd ../../../ + +cp ../benchmark_tests/mod.rs risc0/benchmarks/src/benches/ + +cp ../benchmark_tests/main.rs risc0/benchmarks/src/ \ No newline at end of file