diff --git a/.config/nextest.toml b/.config/nextest.toml index 1cd2de9fe..1976f8c8c 100644 --- a/.config/nextest.toml +++ b/.config/nextest.toml @@ -16,10 +16,10 @@ limited = { max-threads = 4 } very-limited = { max-threads = 1 } [[profile.ci.overrides]] -filter = '(test(syscall::precompiles) | test(stark::machine) | test(test_verifier_export) | package(sphinx-recursion-program) | package(sphinx-recursion-circuit))' +filter = '(test(syscall::precompiles) | test(stark::machine) | package(sphinx-recursion-program) | package(sphinx-recursion-circuit))' test-group = 'limited' [[profile.ci.overrides]] -filter = '(test(test_e2e))' +filter = '(test(test_e2e) | test(test_verifier_export))' slow-timeout = { period = "1500s", terminate-after = 4 } test-group = 'very-limited' diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9d7bb335b..848106d45 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -87,6 +87,12 @@ jobs: perf: false - name: Install deps run: sudo apt update && sudo apt install cmake -y + - name: Install `sphinx-recursion-gnark-cli` CLI + run: | + cargo install --locked --force --path . + working-directory: ${{ github.workspace }}/recursion/gnark-cli + # TODO: run test-plonk-bn254 once the CLI is ready, + # which relies on an updated witness/constraints.json in the PR - name: Install `cargo prove` CLI run: | cargo install --locked --force --path ./cli @@ -171,7 +177,7 @@ jobs: - repo: zk-light-clients path: ethereum features: ethereum - - repo: loam + - repo: lurk path: "" steps: - uses: actions/checkout@v4 diff --git a/Cargo.lock b/Cargo.lock index 6bc253a64..e9e38d693 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -555,7 +555,7 @@ dependencies = [ "bitflags 2.5.0", "cexpr", "clang-sys", - "itertools 0.10.5", + "itertools 0.12.1", "lazy_static", "lazycell", "log", @@ -683,7 +683,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf88ba1141d185c399bee5288d850d63b8369520c1eafc32a0430b5b6c287bf4" dependencies = [ - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2", "tinyvec", ] @@ -896,7 +896,7 @@ dependencies = [ "hmac", "k256", "serde", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2", "thiserror", ] @@ -912,7 +912,7 @@ dependencies = [ "once_cell", "pbkdf2 0.12.2", "rand", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2", "thiserror", ] @@ -931,7 +931,7 @@ dependencies = [ "ripemd", "serde", "serde_derive", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2", "sha3", "thiserror", ] @@ -1379,7 +1379,7 @@ dependencies = [ "scrypt", "serde", "serde_json", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2", "sha3", "thiserror", "uuid", @@ -1622,7 +1622,7 @@ dependencies = [ "eth-keystore", "ethers-core", "rand", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2", "thiserror", "tracing", ] @@ -2229,7 +2229,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -2457,7 +2457,7 @@ dependencies = [ "ecdsa", "elliptic-curve", "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2", "signature", ] @@ -2520,7 +2520,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e310b3a6b5907f99202fcdb4960ff45b93735d7c7d96b760fcff8db2dc0e103d" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -2639,6 +2639,15 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "ntapi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" +dependencies = [ + "winapi", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -3313,6 +3322,12 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + [[package]] name = "plotters" version = "0.3.6" @@ -3472,12 +3487,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81bddcdb20abf9501610992b6759a4c888aef7d1a7247ef75e2404275ac24af1" dependencies = [ "anyhow", - "itertools 0.10.5", + "itertools 0.12.1", "proc-macro2", "quote", "syn 2.0.68", ] +[[package]] +name = "psm" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5787f7cda34e3033a72192c018bc5883100330f362ef279a8cbccfce8bb4e874" +dependencies = [ + "cc", +] + [[package]] name = "quick-error" version = "1.2.3" @@ -4053,7 +4077,7 @@ dependencies = [ "hmac", "pbkdf2 0.11.0", "salsa20", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2", ] [[package]] @@ -4244,16 +4268,6 @@ dependencies = [ "digest 0.10.7", ] -[[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest 0.10.7", -] - [[package]] name = "sha3" version = "0.10.8" @@ -4351,6 +4365,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "sphinx-build" +version = "0.1.0" +dependencies = [ + "anyhow", + "cargo_metadata", + "clap", +] + [[package]] name = "sphinx-cli" version = "1.0.0" @@ -4367,6 +4390,7 @@ dependencies = [ "reqwest 0.12.5", "serde", "serde_json", + "sphinx-build", "sphinx-core", "sphinx-prover", "sphinx-sdk", @@ -4420,6 +4444,7 @@ dependencies = [ "p3-symmetric", "p3-uni-stark", "p3-util", + "plain", "rand", "rayon-scan", "rrs-lib", @@ -4467,10 +4492,11 @@ version = "1.0.0" dependencies = [ "cargo_metadata", "chrono", + "sphinx-build", ] [[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", @@ -4518,7 +4544,7 @@ dependencies = [ "serde", "serde_json", "serial_test", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2", "size", "sphinx-core", "sphinx-primitives", @@ -4655,7 +4681,7 @@ dependencies = [ "rand", "serde", "serde_json", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2", "sphinx-core", "sphinx-recursion-compiler", "tempfile", @@ -4685,6 +4711,7 @@ dependencies = [ "sphinx-primitives", "sphinx-recursion-compiler", "sphinx-recursion-core", + "stacker", "tracing", ] @@ -4716,11 +4743,12 @@ dependencies = [ "reqwest-middleware", "serde", "serde_json", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2", "sphinx-core", "sphinx-prover", "strum", "strum_macros", + "sysinfo", "tempfile", "thiserror", "tokio", @@ -4736,15 +4764,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "p3-baby-bear", "p3-field", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", + "serde", + "sha2", + "sphinx-lib", "sphinx-primitives", ] @@ -4770,6 +4798,19 @@ dependencies = [ "der", ] +[[package]] +name = "stacker" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c886bd4480155fd3ef527d45e9ac8dd7118a898a46530b7b94c3e21866259fce" +dependencies = [ + "cc", + "cfg-if", + "libc", + "psm", + "winapi", +] + [[package]] name = "static_assertions" version = "1.1.0" @@ -4865,6 +4906,20 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +[[package]] +name = "sysinfo" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4115055da5f572fff541dd0c4e61b0262977f453cc9fe04be83aba25a89bdab" +dependencies = [ + "core-foundation-sys", + "libc", + "memchr", + "ntapi", + "rayon", + "windows", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -5591,6 +5646,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" +dependencies = [ + "windows-core 0.57.0", + "windows-targets 0.52.6", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -5600,6 +5665,49 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-core" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-implement" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.68", +] + +[[package]] +name = "windows-interface" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.68", +] + +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -5881,7 +5989,7 @@ dependencies = [ "pasta_curves 0.5.1", "rand", "serde", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2", "sha3", "subtle", ] diff --git a/Cargo.toml b/Cargo.toml index 274f79a71..99186b844 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = [ +members = [ "build", "cli", "core", "derive", @@ -89,6 +89,7 @@ nohash-hasher = "0.2.0" num = "0.4.3" num_cpus = "1.16.0" once_cell = "1.8.0" +plain = "0.2.3" proc-macro2 = "1.0" prost = "0.12" quote = "1.0" @@ -104,6 +105,7 @@ serde_with = "3.9.0" serial_test = "3.1.1" sha2 = "0.10.8" size = "0.4.1" +stacker = "0.1.0" strum = "0.26.3" strum_macros = "0.26.4" syn = "1.0" @@ -133,6 +135,7 @@ alloy-primitives = "0.7.7" alloy-sol-types = "0.7.7" downloader = { version = "0.2", default-features = false } ethers = { version = "2", default-features = false } +sysinfo = "0.31.2" [profile.dev-ci] inherits = "dev" diff --git a/Dockerfile.gnark-ffi b/Dockerfile.gnark-ffi index 3e0624d79..d4e87f29f 100644 --- a/Dockerfile.gnark-ffi +++ b/Dockerfile.gnark-ffi @@ -19,15 +19,15 @@ RUN rustup show COPY . /sp1 # Build the gnark-ffi CLI -WORKDIR /sp1/recursion/gnark-cli +WORKDIR /sphinx/recursion/gnark-cli RUN \ --mount=type=cache,target=target \ - cargo build --release && cp target/release/sp1-recursion-gnark-cli /gnark-cli + cargo build --release && cp target/release/sphinx-recursion-gnark-cli /gnark-cli FROM rustlang/rust:nightly-bullseye-slim COPY --from=rust-builder /gnark-cli /gnark-cli -LABEL org.opencontainers.image.source=https://github.com/succinctlabs/sp1 +LABEL org.opencontainers.image.source=https://github.com/argumentcomputer/sphinx ENTRYPOINT ["/gnark-cli"] \ No newline at end of file diff --git a/build/Cargo.toml b/build/Cargo.toml new file mode 100644 index 000000000..e4e7bf84e --- /dev/null +++ b/build/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "sphinx-build" +version = "0.1.0" +edition.workspace = true +repository.workspace = true +license.workspace = true + +[dependencies] +cargo_metadata = "0.18.1" +anyhow = { version = "1.0.83" } +clap = { version = "4.5.7", features = ["derive", "env"] } diff --git a/build/README.md b/build/README.md new file mode 100644 index 000000000..cc7620417 --- /dev/null +++ b/build/README.md @@ -0,0 +1,25 @@ +# sp1-build +Lightweight crate used to build SP1 programs. Internal crate that is exposed to users via `sp1-cli` and `sp1-helper`. + +Exposes `build_program`, which builds an SP1 program in the local environment or in a docker container with the specified parameters from `BuildArgs`. + +## Usage + +```rust +use sp1_build::build_program; + +build_program(&BuildArgs::default(), Some(program_dir)); +``` + +## Potential Issues + +If you attempt to build a program with Docker that depends on a local crate, and the crate is not in +the current workspace, you may run into issues with the docker build not being able to find the crate, as only the workspace root is mounted. + +``` +error: failed to load manifest for dependency `...` +``` + +To fix this, you can either: +1. Move the program into the workspace that contains the crate. +2. Build the crate locally instead. diff --git a/build/src/docker.rs b/build/src/docker.rs new file mode 100644 index 000000000..44ede299c --- /dev/null +++ b/build/src/docker.rs @@ -0,0 +1,74 @@ +use std::process::{exit, Command, Stdio}; + +use anyhow::{Context, Result}; +use cargo_metadata::camino::Utf8PathBuf; + +use crate::{get_program_build_args, get_rust_compiler_flags, BuildArgs}; + +/// Uses SP1_DOCKER_IMAGE environment variable if set, otherwise constructs the image to use based +/// on the provided tag. +fn get_docker_image(tag: &str) -> String { + std::env::var("SP1_DOCKER_IMAGE").unwrap_or_else(|_| { + let image_base = "ghcr.io/succinctlabs/sp1"; + format!("{}:{}", image_base, tag) + }) +} + +/// Creates a Docker command to build the program. +pub(crate) fn create_docker_command( + args: &BuildArgs, + program_dir: &Utf8PathBuf, + workspace_root: &Utf8PathBuf, +) -> Result { + let image = get_docker_image(&args.tag); + + // Check if docker is installed and running. + let docker_check = Command::new("docker") + .args(["info"]) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .status() + .context("failed to run docker command")?; + if !docker_check.success() { + eprintln!("docker is not installed or not running: https://docs.docker.com/get-docker/"); + exit(1); + } + + // Mount the entire workspace, and set the working directory to the program dir. Note: If the + // program dir has local dependencies outside of the workspace, building with Docker will fail. + let workspace_root_path = format!("{}:/root/program", workspace_root); + let program_dir_path = format!( + "/root/program/{}", + program_dir.strip_prefix(workspace_root).unwrap() + ); + + // Add docker-specific arguments. + let mut docker_args = vec![ + "run".to_string(), + "--rm".to_string(), + "--platform".to_string(), + "linux/amd64".to_string(), + "-v".to_string(), + workspace_root_path, + "-w".to_string(), + program_dir_path, + // TODO: remove once trim-paths is supported - https://github.com/rust-lang/rust/issues/111540 + "-e".to_string(), + "RUSTC_BOOTSTRAP=1".to_string(), // allows trim-paths. + "-e".to_string(), + "RUSTUP_TOOLCHAIN=succinct".to_string(), + "-e".to_string(), + format!("CARGO_ENCODED_RUSTFLAGS={}", get_rust_compiler_flags()), + "--entrypoint".to_string(), + "".to_string(), + image, + "cargo".to_string(), + ]; + + // Add the SP1 program build arguments. + docker_args.extend_from_slice(&get_program_build_args(args)); + + let mut command = Command::new("docker"); + command.current_dir(program_dir.clone()).args(&docker_args); + Ok(command) +} diff --git a/build/src/lib.rs b/build/src/lib.rs new file mode 100644 index 000000000..90aa8a434 --- /dev/null +++ b/build/src/lib.rs @@ -0,0 +1,299 @@ +mod docker; + +use clap::Parser; +use std::{ + fs, + io::{BufRead, BufReader}, + path::PathBuf, + process::{exit, Command, Stdio}, + thread, +}; + +use anyhow::{Context, Result}; +use cargo_metadata::camino::Utf8PathBuf; + +const BUILD_TARGET: &str = "riscv32im-succinct-zkvm-elf"; +const DEFAULT_TAG: &str = "latest"; +const DEFAULT_OUTPUT_DIR: &str = "elf"; +const HELPER_TARGET_SUBDIR: &str = "elf-compilation"; + +/// [`BuildArgs`] is a struct that holds various arguments used for building a program. +/// +/// This struct can be used to configure the build process, including options for using Docker, +/// specifying binary and ELF names, ignoring Rust version checks, and enabling specific features. +#[derive(Clone, Parser, Debug)] +pub struct BuildArgs { + #[clap(long, action, help = "Build using Docker for reproducible builds.")] + pub docker: bool, + #[clap( + long, + help = "The ghcr.io/succinctlabs/sp1 image tag to use when building with docker.", + default_value = DEFAULT_TAG + )] + pub tag: String, + #[clap(long, action, value_delimiter = ',', help = "Build with features.")] + pub features: Vec, + #[clap(long, action, help = "Ignore Rust version check.")] + pub ignore_rust_version: bool, + #[clap( + alias = "bin", + long, + action, + help = "If building a binary, specify the name.", + default_value = "" + )] + pub binary: String, + #[clap(long, action, help = "ELF binary name.", default_value = "")] + pub elf_name: String, + #[clap( + long, + action, + help = "The output directory for the built program.", + default_value = DEFAULT_OUTPUT_DIR + )] + pub output_directory: String, + #[clap( + long, + action, + help = "Lock the dependencies, ensures that Cargo.lock doesn't update." + )] + pub locked: bool, + #[clap(long, action, help = "Build without default features.")] + pub no_default_features: bool, +} + +// Implement default args to match clap defaults. +impl Default for BuildArgs { + fn default() -> Self { + Self { + docker: false, + tag: DEFAULT_TAG.to_string(), + features: vec![], + ignore_rust_version: false, + binary: "".to_string(), + elf_name: "".to_string(), + output_directory: DEFAULT_OUTPUT_DIR.to_string(), + locked: false, + no_default_features: false, + } + } +} + +/// Get the arguments to build the program with the arguments from the [`BuildArgs`] struct. +fn get_program_build_args(args: &BuildArgs) -> Vec { + let mut build_args = vec![ + "build".to_string(), + "--release".to_string(), + "--target".to_string(), + BUILD_TARGET.to_string(), + ]; + + if args.ignore_rust_version { + build_args.push("--ignore-rust-version".to_string()); + } + + if !args.binary.is_empty() { + build_args.push("--bin".to_string()); + build_args.push(args.binary.clone()); + } + + if !args.features.is_empty() { + build_args.push("--features".to_string()); + build_args.push(args.features.join(",")); + } + + if args.no_default_features { + build_args.push("--no-default-features".to_string()); + } + + if args.locked { + build_args.push("--locked".to_string()); + } + + build_args.push("-Ztrim-paths".to_string()); + + build_args +} + +/// Rust flags for compilation of C libraries. +fn get_rust_compiler_flags() -> String { + let rust_flags = [ + "-C", + "linker-plugin-lto", + "-C", + "debuginfo=none", + "-C", + "strip=symbols", + "-C", + "embed-bitcode=true", + "-C", + "passes=loweratomic", + "-C", + "opt-level=3", + "-C", + "lto=true", + "-C", + "codegen-units=1", + "-C", + "link-arg=-Ttext=0x00200800", + "-C", + "panic=abort", + ]; + rust_flags.join("\x1f") +} + +/// Get the command to build the program locally. +fn create_local_command(args: &BuildArgs, program_dir: &Utf8PathBuf) -> Command { + let mut command = Command::new("cargo"); + let canonicalized_program_dir = program_dir + .canonicalize() + .expect("Failed to canonicalize program directory"); + command + .current_dir(canonicalized_program_dir) + .env("RUSTUP_TOOLCHAIN", "succinct") + .env("CARGO_ENCODED_RUSTFLAGS", get_rust_compiler_flags()) + // TODO: remove once trim-paths is supported - https://github.com/rust-lang/rust/issues/111540 + .env("RUSTC_BOOTSTRAP", "1") // allows trim-paths. + .args(get_program_build_args(args)); + command +} + +/// Execute the command and handle the output depending on the context. +fn execute_command( + mut command: Command, + docker: bool, + program_metadata: &cargo_metadata::Metadata, +) -> Result<()> { + // Strip the rustc configuration, otherwise in the helper it will attempt to compile the SP1 + // program with the toolchain of the normal build process, rather than the Succinct toolchain. + command.env_remove("RUSTC"); + + // Set the target directory to a subdirectory of the program's target directory to avoid + // build conflicts with the parent process. If removed, programs that share the same target + // directory (i.e. same workspace) as the script will hang indefinitely due to a file lock + // when building in the helper. + // Source: https://github.com/rust-lang/cargo/issues/6412 + command.env( + "CARGO_TARGET_DIR", + program_metadata.target_directory.join(HELPER_TARGET_SUBDIR), + ); + + // Add necessary tags for stdout and stderr from the command. + let mut child = command + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .context("failed to spawn command")?; + let stdout = BufReader::new(child.stdout.take().unwrap()); + let stderr = BufReader::new(child.stderr.take().unwrap()); + + // Add prefix to the output of the process depending on the context. + let msg = match docker { + true => "[sphinx] [docker] ", + false => "[sphinx] ", + }; + + // Pipe stdout and stderr to the parent process with [docker] prefix + let stdout_handle = thread::spawn(move || { + stdout.lines().for_each(|line| { + println!("{} {}", msg, line.unwrap()); + }); + }); + stderr.lines().for_each(|line| { + eprintln!("{} {}", msg, line.unwrap()); + }); + stdout_handle.join().unwrap(); + + // Wait for the child process to finish and check the result. + let result = child.wait()?; + if !result.success() { + // Error message is already printed by cargo. + exit(result.code().unwrap_or(1)) + } + Ok(()) +} + +/// Copy the ELF to the specified output directory. +fn copy_elf_to_output_dir( + args: &BuildArgs, + program_metadata: &cargo_metadata::Metadata, +) -> Result { + let root_package = program_metadata.root_package(); + let root_package_name = root_package.as_ref().map(|p| &p.name); + + // The ELF is written to a target folder specified by the program's package. + let original_elf_path = program_metadata + .target_directory + .join(HELPER_TARGET_SUBDIR) + .join(BUILD_TARGET) + .join("release") + .join(root_package_name.unwrap()); + + // The order of precedence for the ELF name is: + // 1. --elf_name flag + // 2. --binary flag + -elf suffix (defaults to riscv32im-succinct-zkvm-elf) + let elf_name = if !args.elf_name.is_empty() { + args.elf_name.clone() + } else if !args.binary.is_empty() { + // TODO: In the future, change this to default to the package name. Will require updating + // docs and examples. + args.binary.clone() + } else { + BUILD_TARGET.to_string() + }; + + let elf_dir = program_metadata + .target_directory + .parent() + .unwrap() + .join(&args.output_directory); + fs::create_dir_all(&elf_dir)?; + let result_elf_path = elf_dir.join(elf_name); + + // Copy the ELF to the specified output directory. + fs::copy(original_elf_path, &result_elf_path)?; + + Ok(result_elf_path) +} + +/// Build a program with the specified [`BuildArgs`]. The `program_dir` is specified as an argument when +/// the program is built via `build_program` in sp1-helper. +/// +/// # Arguments +/// +/// * `args` - A reference to a `BuildArgs` struct that holds various arguments used for building the program. +/// * `program_dir` - An optional `PathBuf` specifying the directory of the program to be built. +/// +/// # Returns +/// +/// * `Result` - The path to the built program as a `Utf8PathBuf` on success, or an error on failure. +pub fn build_program(args: &BuildArgs, program_dir: Option) -> Result { + // If the program directory is not specified, use the current directory. + let program_dir = program_dir + .unwrap_or_else(|| std::env::current_dir().expect("Failed to get current directory.")); + let program_dir: Utf8PathBuf = program_dir + .try_into() + .expect("Failed to convert PathBuf to Utf8PathBuf"); + + // The root package name corresponds to the package name of the current directory. + let metadata_cmd = cargo_metadata::MetadataCommand::new(); + let metadata = metadata_cmd.exec().unwrap(); + + // Get the command corresponding to Docker or local build. + let cmd = if args.docker { + docker::create_docker_command(args, &program_dir, &metadata.workspace_root)? + } else { + create_local_command(args, &program_dir) + }; + + let program_metadata_file = program_dir.join("Cargo.toml"); + let mut program_metadata_cmd = cargo_metadata::MetadataCommand::new(); + let program_metadata = program_metadata_cmd + .manifest_path(program_metadata_file) + .exec() + .unwrap(); + + execute_command(cmd, args.docker, &program_metadata)?; + + copy_elf_to_output_dir(args, &program_metadata) +} diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 7b61d814c..cefab582c 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -12,6 +12,7 @@ vergen = { workspace = true, features = ["build", "git", "git2"] } anyhow = { workspace = true, features = ["backtrace"] } cargo_metadata = { workspace = true } clap = { workspace = true, features = ["derive", "env"] } +sphinx-build = { path = "../build" } sphinx-prover = { path = "../prover" } sphinx-sdk = { path = "../sdk" } sphinx-core = { path = "../core" } diff --git a/cli/src/build.rs b/cli/src/build.rs index abadcd757..27788cd23 100644 --- a/cli/src/build.rs +++ b/cli/src/build.rs @@ -1,3 +1,6 @@ +use anyhow::{Context, Result}; +use cargo_metadata::camino::Utf8PathBuf; +use clap::Parser; use std::{ fs, io::{BufRead, BufReader}, @@ -5,21 +8,26 @@ use std::{ thread, }; -use anyhow::{Context, Result}; -use cargo_metadata::camino::Utf8PathBuf; -use clap::Parser; - -fn get_docker_image() -> String { - // Get the docker image name from the environment variable - std::env::var("SP1_DOCKER_IMAGE") - .unwrap_or_else(|_| "ghcr.io/succinctlabs/sp1:latest".to_string()) +/// Uses SP1_DOCKER_IMAGE environment variable if set, otherwise constructs the image to use based +/// on the provided tag. +fn get_docker_image(tag: &str) -> String { + std::env::var("SP1_DOCKER_IMAGE").unwrap_or_else(|_| { + let image_base = "ghcr.io/succinctlabs/sp1"; + format!("{}:{}", image_base, tag) + }) } #[derive(Parser)] pub(crate) struct BuildArgs { #[clap(long, action, help = "Ignore Rust version check.")] pub(crate) docker: bool, - #[clap(long, action, help = "Ignore Rust version check.")] + #[clap( + long, + help = "The ghcr.io/succinctlabs/sp1 image tag to use when building with docker.", + default_value = "latest" + )] + pub(crate) tag: String, + #[clap(long, action, help = "Ignore the rust version check.")] pub(crate) ignore_rust_version: bool, } @@ -31,7 +39,7 @@ pub(crate) fn build_program(args: &BuildArgs) -> Result { let build_target = "riscv32im-succinct-zkvm-elf"; if args.docker { - let image = get_docker_image(); + let image = get_docker_image(&args.tag); let docker_check = Command::new("docker") .args(["info"]) @@ -41,7 +49,9 @@ pub(crate) fn build_program(args: &BuildArgs) -> Result { .context("failed to run docker command")?; if !docker_check.success() { - eprintln!("Docker is not installed or not running."); + eprintln!( + "docker is not installed or not running: https://docs.docker.com/get-docker/" + ); exit(1); } @@ -49,6 +59,8 @@ pub(crate) fn build_program(args: &BuildArgs) -> Result { let mut child_args = vec![ "run", "--rm", + "--platform", + "linux/amd64", "-v", workspace_root_path.as_str(), image.as_str(), diff --git a/cli/src/commands/build.rs b/cli/src/commands/build.rs index 0a7aa4944..834a319cc 100644 --- a/cli/src/commands/build.rs +++ b/cli/src/commands/build.rs @@ -1,7 +1,6 @@ use anyhow::Result; use clap::Parser; - -use crate::build::{build_program, BuildArgs}; +use sphinx_build::{build_program, BuildArgs}; #[derive(Parser)] #[command(name = "build", about = "Build a program")] @@ -15,7 +14,7 @@ pub struct BuildCmd { impl BuildCmd { pub fn run(&self) -> Result<()> { - build_program(&self.build_args)?; + build_program(&self.build_args, None)?; Ok(()) } diff --git a/cli/src/commands/install_toolchain.rs b/cli/src/commands/install_toolchain.rs index c7461e335..529a0b495 100644 --- a/cli/src/commands/install_toolchain.rs +++ b/cli/src/commands/install_toolchain.rs @@ -20,7 +20,10 @@ use crate::{ name = "install-toolchain", about = "Install the cargo-prove toolchain." )] -pub struct InstallToolchainCmd {} +pub struct InstallToolchainCmd { + #[arg(short, long, env = "GITHUB_TOKEN")] + pub token: Option, +} impl InstallToolchainCmd { pub fn run(&self) -> Result<()> { @@ -37,8 +40,23 @@ impl InstallToolchainCmd { )); } - // Setup client. - let client = Client::builder().user_agent("Mozilla/5.0").build()?; + // Setup client with optional token. + let client_builder = Client::builder().user_agent("Mozilla/5.0"); + let client = if let Some(ref token) = self.token { + client_builder + .default_headers({ + let mut headers = reqwest::header::HeaderMap::new(); + headers.insert( + reqwest::header::AUTHORIZATION, + reqwest::header::HeaderValue::from_str(&format!("token {}", token)) + .unwrap(), + ); + headers + }) + .build()? + } else { + client_builder.build()? + }; // Setup variables. let root_dir = home_dir().unwrap().join(".sp1"); diff --git a/cli/src/commands/new.rs b/cli/src/commands/new.rs index bf1aa9900..2f4607b99 100644 --- a/cli/src/commands/new.rs +++ b/cli/src/commands/new.rs @@ -12,6 +12,10 @@ pub struct NewCmd { /// Whether to create the project with template EVM contracts. #[arg(long, action)] evm: bool, + + /// Version of sp1-project-template to use (branch or tag). + #[arg(long, default_value = "main")] + version: String, } const TEMPLATE_REPOSITORY_URL: &str = "https://github.com/succinctlabs/sp1-project-template"; @@ -25,9 +29,11 @@ impl NewCmd { fs::create_dir(&self.name)?; } - // Clone the repository. + // Clone the repository with the specified version. let output = Command::new("git") .arg("clone") + .arg("--branch") + .arg(&self.version) .arg(TEMPLATE_REPOSITORY_URL) .arg(root.as_os_str()) .arg("--recurse-submodules") diff --git a/cli/src/commands/prove.rs b/cli/src/commands/prove.rs index 8151703f8..163635942 100644 --- a/cli/src/commands/prove.rs +++ b/cli/src/commands/prove.rs @@ -3,14 +3,12 @@ use std::{env, fs::File, io::Read, path::PathBuf, str::FromStr, time::Instant}; use anstyle::*; use anyhow::Result; use clap::Parser; +use sphinx_build::{build_program, BuildArgs}; use sphinx_core::utils::{setup_logger, setup_tracer}; use sphinx_prover::SphinxStdin; use sphinx_sdk::ProverClient; -use crate::{ - build::{build_program, BuildArgs}, - util::{elapsed, write_status}, -}; +use crate::util::{elapsed, write_status}; #[derive(Debug, Clone)] enum Input { @@ -75,7 +73,7 @@ pub struct ProveCmd { impl ProveCmd { pub fn run(&self) -> Result<()> { - let elf_path = build_program(&self.build_args)?; + let elf_path = build_program(&self.build_args, None)?; if !self.profile { match env::var("RUST_LOG") { diff --git a/cli/src/lib.rs b/cli/src/lib.rs index bec3e85a9..985f23e42 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -1,4 +1,3 @@ -mod build; pub mod commands; mod util; @@ -70,7 +69,7 @@ pub async fn get_toolchain_download_url(client: &Client, target: String) -> Stri .json::() .await .unwrap(); - let tag = json["tag_name"].as_str().expect("Failed to download Succinct toolchain. Likely caused by GitHub rate limiting. Please try again."); + let tag = json["tag_name"].as_str().expect("Failed to download Succinct toolchain. Likely caused by GitHub rate limiting. Please try again using the --token flag. Docs: https://docs.succinct.xyz/getting-started/install.html#troubleshooting"); let url = format!( "https://github.com/succinctlabs/rust/releases/download/{}/rust-toolchain-{}.tar.gz", diff --git a/core/Cargo.toml b/core/Cargo.toml index 6a8ad6f0c..3102baa54 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -48,6 +48,7 @@ hex = { workspace = true } hybrid-array = { workspace = true } k256 = { workspace = true, features = ["expose-field"] } num_cpus = { workspace = true } +plain = { workspace = true } serial_test = { workspace = true } serde_with = { workspace = true } size = { workspace = true } diff --git a/core/benches/fibonacci.rs b/core/benches/fibonacci.rs index 09c2e0994..c3aa3462e 100644 --- a/core/benches/fibonacci.rs +++ b/core/benches/fibonacci.rs @@ -4,7 +4,7 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion}; use sphinx_core::{ io::SphinxStdin, runtime::{Program, Runtime}, - stark::RiscvAir, + stark::{DefaultProver, RiscvAir}, utils::{prove, prove_simple, BabyBearPoseidon2, SphinxCoreOpts}, }; @@ -72,8 +72,10 @@ pub fn criterion_benchmark(c: &mut Criterion) { runtime }, |runtime| { - let _ = - prove_simple(black_box(machine.config().clone()), black_box(runtime)); + let _ = prove_simple::<_, DefaultProver<_, _>>( + black_box(machine.config().clone()), + black_box(runtime), + ); }, criterion::BatchSize::LargeInput, ) @@ -97,7 +99,7 @@ pub fn criterion_benchmark(c: &mut Criterion) { format!("{}:{}", p.split('/').last().unwrap(), cycles), |b| { b.iter(|| { - prove( + prove::<_, DefaultProver<_, _>>( black_box(&program), &SphinxStdin::new(), BabyBearPoseidon2::new(), diff --git a/core/benches/main.rs b/core/benches/main.rs index 70cd4b977..ff688e1b5 100644 --- a/core/benches/main.rs +++ b/core/benches/main.rs @@ -1,6 +1,7 @@ -use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use criterion::{criterion_group, criterion_main, Criterion}; use sphinx_core::io::SphinxStdin; use sphinx_core::runtime::{Program, Runtime}; +use sphinx_core::stark::DefaultProver; use sphinx_core::utils::{prove, BabyBearPoseidon2, SphinxCoreOpts}; #[allow(unreachable_code)] @@ -20,8 +21,8 @@ pub fn criterion_benchmark(c: &mut Criterion) { format!("main:{}:{}", p.split('/').last().unwrap(), cycles), |b| { b.iter(|| { - prove( - black_box(&program), + prove::<_, DefaultProver<_, _>>( + &program, &SphinxStdin::new(), BabyBearPoseidon2::new(), SphinxCoreOpts::default(), diff --git a/core/src/air/machine.rs b/core/src/air/machine.rs index da71e27db..3b4b54a74 100644 --- a/core/src/air/machine.rs +++ b/core/src/air/machine.rs @@ -5,10 +5,7 @@ use p3_field::Field; use p3_matrix::dense::RowMajorMatrix; pub use sphinx_derive::MachineAir; -use crate::{ - runtime::Program, - stark::{Indexed, MachineRecord}, -}; +use crate::{runtime::Program, stark::MachineRecord}; /// A description of the events related to this AIR. pub trait WithEvents<'a>: Sized { @@ -22,7 +19,7 @@ pub trait WithEvents<'a>: Sized { /// Chip, as specified by its `WithEvents` trait implementation. /// /// The name is inspired by (but not conformant to) functional optics ( https://doi.org/10.1145/1232420.1232424 ) -pub trait EventLens WithEvents<'b>>: Indexed { +pub trait EventLens WithEvents<'b>> { fn events(&self) -> >::Events; } @@ -71,19 +68,12 @@ where } } -impl<'a, T, R, F> Indexed for Proj<'a, T, R, F> -where - T: for<'b> WithEvents<'b>, - R: EventLens + Indexed, -{ - fn index(&self) -> u32 { - self.record.index() - } -} //////////////// end of shenanigans destined for the derive macros. //////////////// /// An AIR that is part of a multi table AIR arithmetization. -pub trait MachineAir: BaseAir + for<'a> WithEvents<'a> { +pub trait MachineAir: + BaseAir + for<'a> WithEvents<'a> + 'static + Send + Sync +{ /// The execution record containing events for producing the air trace. type Record: MachineRecord + EventLens; diff --git a/core/src/air/public_values.rs b/core/src/air/public_values.rs index 36c18b681..ab64bec8b 100644 --- a/core/src/air/public_values.rs +++ b/core/src/air/public_values.rs @@ -1,7 +1,8 @@ use core::fmt::Debug; use core::mem::size_of; -use std::array; -use std::iter::once; +use plain::Plain; +use std::borrow::Borrow; +use std::borrow::BorrowMut; use itertools::Itertools; use p3_field::{AbstractField, PrimeField32}; @@ -20,6 +21,7 @@ pub const POSEIDON_NUM_WORDS: usize = 8; /// The PublicValues struct is used to store all of a shard proof's public values. #[derive(Serialize, Deserialize, Clone, Copy, Default, Debug)] +#[repr(C)] pub struct PublicValues { /// The hash of all the bytes that the guest program has written to public values. pub committed_value_digest: [W; PV_DIGEST_NUM_WORDS], @@ -40,75 +42,53 @@ pub struct PublicValues { /// The shard number. pub shard: T, + + /// The execution shard number. + pub execution_shard: T, + + /// The bits of the largest address that is witnessed for initialization in the previous shard. + pub previous_init_addr_bits: [T; 32], + + /// The largest address that is witnessed for initialization in the current shard. + pub last_init_addr_bits: [T; 32], + + /// The bits of the largest address that is witnessed for finalization in the previous shard. + pub previous_finalize_addr_bits: [T; 32], + + /// The bits of the largest address that is witnessed for finalization in the current shard. + pub last_finalize_addr_bits: [T; 32], } +// SAFE: PublicValues satisfies all the requirements of `Plain`. +unsafe impl Plain for PublicValues {} + impl PublicValues { + pub fn from_bytes(buf: &[u8]) -> &PublicValues { + plain::from_bytes(buf).expect("The buffer is either too short or not aligned!") + } + /// Convert the public values into a vector of field elements. This function will pad the vector /// to the maximum number of public values. pub fn to_vec(&self) -> Vec { - let mut ret = self - .committed_value_digest - .iter() - .flat_map(|w| Word::::from(*w).into_iter()) - .chain( - self.deferred_proofs_digest - .iter() - .cloned() - .map(F::from_canonical_u32), - ) - .chain(once(F::from_canonical_u32(self.start_pc))) - .chain(once(F::from_canonical_u32(self.next_pc))) - .chain(once(F::from_canonical_u32(self.exit_code))) - .chain(once(F::from_canonical_u32(self.shard))) - .collect_vec(); - - assert!( - ret.len() <= PROOF_MAX_NUM_PVS, - "Too many public values: {}", - ret.len() - ); - - ret.resize(PROOF_MAX_NUM_PVS, F::zero()); + let mut ret = vec![F::zero(); PROOF_MAX_NUM_PVS]; + let field_values = PublicValues::, F>::from(*self); + let ret_ref_mut: &mut PublicValues, F> = ret.as_mut_slice().borrow_mut(); + *ret_ref_mut = field_values; ret } -} - -impl PublicValues, T> { - /// Convert a vector of field elements into a PublicValues struct. - pub fn from_vec(data: &[T]) -> Self { - let mut iter = data.iter().cloned(); - let committed_value_digest = array::from_fn(|_| (&mut iter).collect()); - - let deferred_proofs_digest = iter - .by_ref() - .take(POSEIDON_NUM_WORDS) - .collect_vec() - .try_into() - .unwrap(); - - // Collecting the remaining items into a tuple. Note that it is only getting the first - // four items, as the rest would be padded values. - let remaining_items = iter.collect_vec(); - assert!( - remaining_items.len() >= 4, - "Invalid number of items in the serialized vector." - ); - - let [start_pc, next_pc, exit_code, shard] = match &remaining_items.as_slice()[0..4] { - [start_pc, next_pc, exit_code, shard] => [start_pc, next_pc, exit_code, shard], - _ => unreachable!(), - }; - - Self { - committed_value_digest, - deferred_proofs_digest, - start_pc: start_pc.to_owned(), - next_pc: next_pc.to_owned(), - exit_code: exit_code.to_owned(), - shard: shard.to_owned(), - } + pub fn reset(&self) -> Self { + let mut copy = *self; + copy.shard = 0; + copy.execution_shard = 0; + copy.start_pc = 0; + copy.next_pc = 0; + copy.previous_init_addr_bits = [0; 32]; + copy.last_init_addr_bits = [0; 32]; + copy.previous_finalize_addr_bits = [0; 32]; + copy.last_finalize_addr_bits = [0; 32]; + copy } } @@ -122,6 +102,78 @@ impl PublicValues, F> { } } +impl Borrow, T>> for [T] { + fn borrow(&self) -> &PublicValues, T> { + let size = std::mem::size_of::, u8>>(); + debug_assert!(self.len() >= size); + let slice = &self[0..size]; + let (prefix, shorts, _suffix) = unsafe { slice.align_to::, T>>() }; + debug_assert!(prefix.is_empty(), "Alignment should match"); + debug_assert_eq!(shorts.len(), 1); + &shorts[0] + } +} + +impl BorrowMut, T>> for [T] { + fn borrow_mut(&mut self) -> &mut PublicValues, T> { + let size = std::mem::size_of::, u8>>(); + debug_assert!(self.len() >= size); + let slice = &mut self[0..size]; + let (prefix, shorts, _suffix) = unsafe { slice.align_to_mut::, T>>() }; + debug_assert!(prefix.is_empty(), "Alignment should match"); + debug_assert_eq!(shorts.len(), 1); + &mut shorts[0] + } +} + +impl From> for PublicValues, F> { + fn from(value: PublicValues) -> Self { + let PublicValues { + committed_value_digest, + deferred_proofs_digest, + start_pc, + next_pc, + exit_code, + shard, + execution_shard, + previous_init_addr_bits, + last_init_addr_bits, + previous_finalize_addr_bits, + last_finalize_addr_bits, + } = value; + + let committed_value_digest: [_; PV_DIGEST_NUM_WORDS] = + core::array::from_fn(|i| Word::from(committed_value_digest[i])); + + let deferred_proofs_digest: [_; POSEIDON_NUM_WORDS] = + core::array::from_fn(|i| F::from_canonical_u32(deferred_proofs_digest[i])); + + let start_pc = F::from_canonical_u32(start_pc); + let next_pc = F::from_canonical_u32(next_pc); + let exit_code = F::from_canonical_u32(exit_code); + let shard = F::from_canonical_u32(shard); + let execution_shard = F::from_canonical_u32(execution_shard); + let previous_init_addr_bits = previous_init_addr_bits.map(F::from_canonical_u32); + let last_init_addr_bits = last_init_addr_bits.map(F::from_canonical_u32); + let previous_finalize_addr_bits = previous_finalize_addr_bits.map(F::from_canonical_u32); + let last_finalize_addr_bits = last_finalize_addr_bits.map(F::from_canonical_u32); + + Self { + committed_value_digest, + deferred_proofs_digest, + start_pc, + next_pc, + exit_code, + shard, + execution_shard, + previous_init_addr_bits, + last_init_addr_bits, + previous_finalize_addr_bits, + last_finalize_addr_bits, + } + } +} + #[cfg(test)] mod tests { use crate::air::public_values; diff --git a/core/src/alu/add_sub/mod.rs b/core/src/alu/add_sub/mod.rs index 9bac38900..7275eedba 100644 --- a/core/src/alu/add_sub/mod.rs +++ b/core/src/alu/add_sub/mod.rs @@ -3,22 +3,23 @@ use core::{ mem::size_of, }; +use hashbrown::HashMap; +use itertools::Itertools; use p3_air::{Air, AirBuilder, BaseAir}; -use p3_field::AbstractField; -use p3_field::PrimeField; +use p3_field::{AbstractField, PrimeField}; use p3_matrix::dense::RowMajorMatrix; use p3_matrix::Matrix; -use p3_maybe_rayon::prelude::ParallelIterator; use p3_maybe_rayon::prelude::ParallelSlice; +use p3_maybe_rayon::prelude::{ParallelBridge, ParallelIterator}; use sphinx_derive::AlignedBorrow; -use crate::{ - air::{AluAirBuilder, EventLens, MachineAir, WithEvents, Word}, - operations::AddOperation, - runtime::{ExecutionRecord, Opcode, Program}, - stark::MachineRecord, - utils::pad_to_power_of_two, -}; +use crate::air::Word; +use crate::air::{AluAirBuilder, EventLens, MachineAir, WithEvents}; +use crate::bytes::event::ByteRecord; +use crate::bytes::ByteLookupEvent; +use crate::operations::AddOperation; +use crate::runtime::{ExecutionRecord, Opcode, Program}; +use crate::utils::pad_to_power_of_two; use super::AluEvent; @@ -85,7 +86,7 @@ impl MachineAir for AddSubChip { fn generate_trace>( &self, input: &EL, - output: &mut Self::Record, + _: &mut Self::Record, ) -> RowMajorMatrix { let (add_events, sub_events) = input.events(); // Generate the rows for the trace. @@ -95,44 +96,26 @@ impl MachineAir for AddSubChip { .chain(sub_events.iter()) .collect::>(); - let rows_and_records = merged_events + let row_batches = merged_events .par_chunks(chunk_size) .map(|events| { - let mut record = ExecutionRecord::default(); let rows = events .iter() .map(|event| { let mut row = [F::zero(); NUM_ADD_SUB_COLS]; let cols: &mut AddSubCols = row.as_mut_slice().borrow_mut(); - let is_add = event.opcode == Opcode::ADD; - cols.shard = F::from_canonical_u32(event.shard); - cols.channel = F::from_canonical_u32(event.channel); - cols.is_add = F::from_bool(is_add); - cols.is_sub = F::from_bool(!is_add); - - let operand_1 = if is_add { event.b } else { event.a }; - let operand_2 = event.c; - - cols.add_operation.populate( - &mut record, - event.shard, - event.channel, - operand_1, - operand_2, - ); - cols.operand_1 = Word::from(operand_1); - cols.operand_2 = Word::from(operand_2); + let mut blu = Vec::new(); + self.event_to_row(event, cols, &mut blu); row }) .collect::>(); - (rows, record) + rows }) .collect::>(); let mut rows: Vec<[F; NUM_ADD_SUB_COLS]> = vec![]; - for mut row_and_record in rows_and_records { - rows.extend(row_and_record.0); - output.append(&mut row_and_record.1); + for row_batch in row_batches { + rows.extend(row_batch); } // Convert the trace to a row major matrix. @@ -154,11 +137,59 @@ impl MachineAir for AddSubChip { trace } + fn generate_dependencies>(&self, input: &EL, output: &mut Self::Record) { + let (add_events, sub_events) = input.events(); + let chunk_size = std::cmp::max((add_events.len() + sub_events.len()) / num_cpus::get(), 1); + + let event_iter = add_events + .chunks(chunk_size) + .chain(sub_events.chunks(chunk_size)); + + let blu_batches = event_iter + .par_bridge() + .map(|events| { + let mut blu: HashMap> = HashMap::new(); + for event in events.iter() { + let mut row = [F::zero(); NUM_ADD_SUB_COLS]; + let cols: &mut AddSubCols = row.as_mut_slice().borrow_mut(); + self.event_to_row(event, cols, &mut blu); + } + blu + }) + .collect::>(); + + output.add_sharded_byte_lookup_events(blu_batches.iter().collect_vec()); + } + fn included(&self, shard: &Self::Record) -> bool { !shard.add_events.is_empty() || !shard.sub_events.is_empty() } } +impl AddSubChip { + /// Create a row from an event. + fn event_to_row( + &self, + event: &AluEvent, + cols: &mut AddSubCols, + blu: &mut impl ByteRecord, + ) { + let is_add = event.opcode == Opcode::ADD; + cols.shard = F::from_canonical_u32(event.shard); + cols.channel = F::from_canonical_u32(event.channel); + cols.is_add = F::from_bool(is_add); + cols.is_sub = F::from_bool(!is_add); + + let operand_1 = if is_add { event.b } else { event.a }; + let operand_2 = event.c; + + cols.add_operation + .populate(blu, event.shard, event.channel, operand_1, operand_2); + cols.operand_1 = Word::from(operand_1); + cols.operand_2 = Word::from(operand_2); + } +} + impl BaseAir for AddSubChip { fn width(&self) -> usize { NUM_ADD_SUB_COLS diff --git a/core/src/alu/bitwise/mod.rs b/core/src/alu/bitwise/mod.rs index 8230cc273..feb45d031 100644 --- a/core/src/alu/bitwise/mod.rs +++ b/core/src/alu/bitwise/mod.rs @@ -3,12 +3,14 @@ use core::{ mem::size_of, }; +use hashbrown::HashMap; +use itertools::Itertools; use p3_air::AirBuilder; use p3_air::{Air, BaseAir}; -use p3_field::AbstractField; -use p3_field::PrimeField; +use p3_field::{AbstractField, PrimeField}; use p3_matrix::dense::RowMajorMatrix; use p3_matrix::Matrix; +use p3_maybe_rayon::prelude::{IntoParallelRefIterator, ParallelIterator, ParallelSlice}; use sphinx_derive::AlignedBorrow; use crate::air::{AluAirBuilder, ByteAirBuilder, MachineAir}; @@ -75,42 +77,16 @@ impl MachineAir for BitwiseChip { fn generate_trace>( &self, input: &EL, - output: &mut ExecutionRecord, + _: &mut ExecutionRecord, ) -> RowMajorMatrix { - // Generate the trace rows for each event. let rows = input .events() - .iter() + .par_iter() .map(|event| { let mut row = [F::zero(); NUM_BITWISE_COLS]; let cols: &mut BitwiseCols = row.as_mut_slice().borrow_mut(); - let a = event.a.to_le_bytes(); - let b = event.b.to_le_bytes(); - let c = event.c.to_le_bytes(); - - cols.shard = F::from_canonical_u32(event.shard); - cols.channel = F::from_canonical_u32(event.channel); - cols.a = Word::from(event.a); - cols.b = Word::from(event.b); - cols.c = Word::from(event.c); - - cols.is_xor = F::from_bool(event.opcode == Opcode::XOR); - cols.is_or = F::from_bool(event.opcode == Opcode::OR); - cols.is_and = F::from_bool(event.opcode == Opcode::AND); - - for ((b_a, b_b), b_c) in a.into_iter().zip(b).zip(c) { - let byte_event = ByteLookupEvent { - shard: event.shard, - channel: event.channel, - opcode: ByteOpcode::try_from(event.opcode).unwrap(), - a1: u32::from(b_a), - a2: 0, - b: u32::from(b_b), - c: u32::from(b_c), - }; - output.add_byte_lookup_event(byte_event); - } - + let mut blu = Vec::new(); + self.event_to_row(event, cols, &mut blu); row }) .collect::>(); @@ -133,11 +109,68 @@ impl MachineAir for BitwiseChip { trace } + fn generate_dependencies>(&self, input: &EL, output: &mut ExecutionRecord) { + let chunk_size = std::cmp::max(input.events().len() / num_cpus::get(), 1); + + let blu_batches = input + .events() + .par_chunks(chunk_size) + .map(|events| { + let mut blu: HashMap> = HashMap::new(); + for event in events.iter() { + let mut row = [F::zero(); NUM_BITWISE_COLS]; + let cols: &mut BitwiseCols = row.as_mut_slice().borrow_mut(); + self.event_to_row(event, cols, &mut blu); + } + blu + }) + .collect::>(); + + output.add_sharded_byte_lookup_events(blu_batches.iter().collect_vec()); + } + fn included(&self, shard: &Self::Record) -> bool { !shard.bitwise_events.is_empty() } } +impl BitwiseChip { + /// Create a row from an event. + fn event_to_row( + &self, + event: &AluEvent, + cols: &mut BitwiseCols, + blu: &mut impl ByteRecord, + ) { + let a = event.a.to_le_bytes(); + let b = event.b.to_le_bytes(); + let c = event.c.to_le_bytes(); + + cols.shard = F::from_canonical_u32(event.shard); + cols.channel = F::from_canonical_u32(event.channel); + cols.a = Word::from(event.a); + cols.b = Word::from(event.b); + cols.c = Word::from(event.c); + + cols.is_xor = F::from_bool(event.opcode == Opcode::XOR); + cols.is_or = F::from_bool(event.opcode == Opcode::OR); + cols.is_and = F::from_bool(event.opcode == Opcode::AND); + + for ((b_a, b_b), b_c) in a.into_iter().zip(b).zip(c) { + let byte_event = ByteLookupEvent { + shard: event.shard, + channel: event.channel, + opcode: ByteOpcode::try_from(event.opcode).unwrap(), + a1: u32::from(b_a), + a2: 0, + b: u32::from(b_b), + c: u32::from(b_c), + }; + blu.add_byte_lookup_event(byte_event); + } + } +} + impl BaseAir for BitwiseChip { fn width(&self) -> usize { NUM_BITWISE_COLS diff --git a/core/src/alu/divrem/mod.rs b/core/src/alu/divrem/mod.rs index 576f4afa5..79ed68a99 100644 --- a/core/src/alu/divrem/mod.rs +++ b/core/src/alu/divrem/mod.rs @@ -214,7 +214,7 @@ pub struct DivRemCols { } impl<'a> WithEvents<'a> for DivRemChip { - type Events = (&'a [AluEvent], &'a HashMap); + type Events = (&'a [AluEvent], &'a HashMap); } impl MachineAir for DivRemChip { diff --git a/core/src/alu/lt/mod.rs b/core/src/alu/lt/mod.rs index 551d77ff6..28792fcb0 100644 --- a/core/src/alu/lt/mod.rs +++ b/core/src/alu/lt/mod.rs @@ -3,7 +3,8 @@ use core::{ mem::size_of, }; -use itertools::izip; +use hashbrown::HashMap; +use itertools::{izip, Itertools}; use p3_air::{Air, AirBuilder, BaseAir}; use p3_field::Field; use p3_field::{AbstractField, PrimeField32}; @@ -115,114 +116,21 @@ impl MachineAir for LtChip { fn generate_trace>( &self, input: &EL, - output: &mut ExecutionRecord, + _: &mut ExecutionRecord, ) -> RowMajorMatrix { // Generate the trace rows for each event. - let (rows, new_byte_lookup_events): (Vec<_>, Vec<_>) = input + let rows: Vec<_> = input .events() .par_iter() .map(|event| { let mut row = [F::zero(); NUM_LT_COLS]; let mut new_byte_lookup_events: Vec = Vec::new(); let cols: &mut LtCols = row.as_mut_slice().borrow_mut(); - let a = event.a.to_le_bytes(); - let b = event.b.to_le_bytes(); - let c = event.c.to_le_bytes(); - - cols.shard = F::from_canonical_u32(event.shard); - cols.channel = F::from_canonical_u32(event.channel); - cols.a = Word(a.map(F::from_canonical_u8)); - cols.b = Word(b.map(F::from_canonical_u8)); - cols.c = Word(c.map(F::from_canonical_u8)); - - // If this is SLT, mask the MSB of b & c before computing cols.bits. - let masked_b = b[3] & 0x7f; - let masked_c = c[3] & 0x7f; - cols.b_masked = F::from_canonical_u8(masked_b); - cols.c_masked = F::from_canonical_u8(masked_c); - - // Send the masked interaction. - new_byte_lookup_events.add_byte_lookup_event(ByteLookupEvent { - shard: event.shard, - channel: event.channel, - opcode: ByteOpcode::AND, - a1: u32::from(masked_b), - a2: 0, - b: u32::from(b[3]), - c: 0x7f_u32, - }); - new_byte_lookup_events.add_byte_lookup_event(ByteLookupEvent { - shard: event.shard, - channel: event.channel, - opcode: ByteOpcode::AND, - a1: u32::from(masked_c), - a2: 0, - b: u32::from(c[3]), - c: 0x7f_u32, - }); - - let mut b_comp = b; - let mut c_comp = c; - if event.opcode == Opcode::SLT { - b_comp[3] = masked_b; - c_comp[3] = masked_c; - } - cols.sltu = F::from_bool(b_comp < c_comp); - cols.is_comp_eq = F::from_bool(b_comp == c_comp); - - // Set the byte equality flags. - for (b_byte, c_byte, flag) in izip!( - b_comp.iter().rev(), - c_comp.iter().rev(), - cols.byte_flags.iter_mut().rev() - ) { - if c_byte != b_byte { - *flag = F::one(); - cols.sltu = F::from_bool(b_byte < c_byte); - let b_byte = F::from_canonical_u8(*b_byte); - let c_byte = F::from_canonical_u8(*c_byte); - cols.not_eq_inv = (b_byte - c_byte).inverse(); - cols.comparison_bytes = [b_byte, c_byte]; - break; - } - } + self.event_to_row(event, cols, &mut new_byte_lookup_events); - cols.msb_b = F::from_canonical_u8((b[3] >> 7) & 1); - cols.msb_c = F::from_canonical_u8((c[3] >> 7) & 1); - cols.is_sign_eq = if event.opcode == Opcode::SLT { - F::from_bool((b[3] >> 7) == (c[3] >> 7)) - } else { - F::one() - }; - - cols.is_slt = F::from_bool(event.opcode == Opcode::SLT); - cols.is_sltu = F::from_bool(event.opcode == Opcode::SLTU); - - cols.bit_b = cols.msb_b * cols.is_slt; - cols.bit_c = cols.msb_c * cols.is_slt; - - assert_eq!( - cols.a[0], - cols.bit_b * (F::one() - cols.bit_c) + cols.is_sign_eq * cols.sltu - ); - - new_byte_lookup_events.add_byte_lookup_event(ByteLookupEvent { - shard: event.shard, - channel: event.channel, - opcode: ByteOpcode::LTU, - a1: cols.sltu.as_canonical_u32(), - a2: 0, - b: cols.comparison_bytes[0].as_canonical_u32(), - c: cols.comparison_bytes[1].as_canonical_u32(), - }); - - (row, new_byte_lookup_events) + row }) - .unzip(); - - for byte_lookup_events in new_byte_lookup_events { - output.add_byte_lookup_events(byte_lookup_events); - } + .collect::>(); // Convert the trace to a row major matrix. let mut trace = @@ -241,11 +149,132 @@ impl MachineAir for LtChip { trace } + fn generate_dependencies>(&self, input: &EL, output: &mut ExecutionRecord) { + let chunk_size = std::cmp::max(input.events().len() / num_cpus::get(), 1); + + let blu_batches = input + .events() + .par_chunks(chunk_size) + .map(|events| { + let mut blu: HashMap> = HashMap::new(); + for event in events.iter() { + let mut row = [F::zero(); NUM_LT_COLS]; + let cols: &mut LtCols = row.as_mut_slice().borrow_mut(); + self.event_to_row(event, cols, &mut blu); + } + blu + }) + .collect::>(); + + output.add_sharded_byte_lookup_events(blu_batches.iter().collect_vec()); + } + fn included(&self, shard: &Self::Record) -> bool { !shard.lt_events.is_empty() } } +impl LtChip { + /// Create a row from an event. + fn event_to_row( + &self, + event: &AluEvent, + cols: &mut LtCols, + blu: &mut impl ByteRecord, + ) { + let a = event.a.to_le_bytes(); + let b = event.b.to_le_bytes(); + let c = event.c.to_le_bytes(); + + cols.shard = F::from_canonical_u32(event.shard); + cols.channel = F::from_canonical_u32(event.channel); + cols.a = Word(a.map(F::from_canonical_u8)); + cols.b = Word(b.map(F::from_canonical_u8)); + cols.c = Word(c.map(F::from_canonical_u8)); + + // If this is SLT, mask the MSB of b & c before computing cols.bits. + let masked_b = b[3] & 0x7f; + let masked_c = c[3] & 0x7f; + cols.b_masked = F::from_canonical_u8(masked_b); + cols.c_masked = F::from_canonical_u8(masked_c); + + // Send the masked interaction. + blu.add_byte_lookup_event(ByteLookupEvent { + shard: event.shard, + channel: event.channel, + opcode: ByteOpcode::AND, + a1: u32::from(masked_b), + a2: 0, + b: u32::from(b[3]), + c: 0x7f, + }); + blu.add_byte_lookup_event(ByteLookupEvent { + shard: event.shard, + channel: event.channel, + opcode: ByteOpcode::AND, + a1: u32::from(masked_c), + a2: 0, + b: u32::from(c[3]), + c: 0x7f, + }); + + let mut b_comp = b; + let mut c_comp = c; + if event.opcode == Opcode::SLT { + b_comp[3] = masked_b; + c_comp[3] = masked_c; + } + cols.sltu = F::from_bool(b_comp < c_comp); + cols.is_comp_eq = F::from_bool(b_comp == c_comp); + + // Set the byte equality flags. + for (b_byte, c_byte, flag) in izip!( + b_comp.iter().rev(), + c_comp.iter().rev(), + cols.byte_flags.iter_mut().rev() + ) { + if c_byte != b_byte { + *flag = F::one(); + cols.sltu = F::from_bool(b_byte < c_byte); + let b_byte = F::from_canonical_u8(*b_byte); + let c_byte = F::from_canonical_u8(*c_byte); + cols.not_eq_inv = (b_byte - c_byte).inverse(); + cols.comparison_bytes = [b_byte, c_byte]; + break; + } + } + + cols.msb_b = F::from_canonical_u8((b[3] >> 7) & 1); + cols.msb_c = F::from_canonical_u8((c[3] >> 7) & 1); + cols.is_sign_eq = if event.opcode == Opcode::SLT { + F::from_bool((b[3] >> 7) == (c[3] >> 7)) + } else { + F::one() + }; + + cols.is_slt = F::from_bool(event.opcode == Opcode::SLT); + cols.is_sltu = F::from_bool(event.opcode == Opcode::SLTU); + + cols.bit_b = cols.msb_b * cols.is_slt; + cols.bit_c = cols.msb_c * cols.is_slt; + + assert_eq!( + cols.a[0], + cols.bit_b * (F::one() - cols.bit_c) + cols.is_sign_eq * cols.sltu + ); + + blu.add_byte_lookup_event(ByteLookupEvent { + shard: event.shard, + channel: event.channel, + opcode: ByteOpcode::LTU, + a1: cols.sltu.as_canonical_u32(), + a2: 0, + b: cols.comparison_bytes[0].as_canonical_u32(), + c: cols.comparison_bytes[1].as_canonical_u32(), + }); + } +} + impl BaseAir for LtChip { fn width(&self) -> usize { NUM_LT_COLS diff --git a/core/src/alu/mod.rs b/core/src/alu/mod.rs index 6b18f35b3..2be688ace 100644 --- a/core/src/alu/mod.rs +++ b/core/src/alu/mod.rs @@ -22,7 +22,7 @@ use crate::runtime::Opcode; #[derive(Debug, Clone, Copy, Serialize, Deserialize)] pub struct AluEvent { /// The lookup id of the event. - pub lookup_id: usize, + pub lookup_id: u128, /// The shard number, used for byte lookup table. pub shard: u32, @@ -45,7 +45,7 @@ pub struct AluEvent { // The second input operand. pub c: u32, - pub sub_lookups: [usize; 6], + pub sub_lookups: [u128; 6], } impl AluEvent { @@ -65,12 +65,12 @@ impl AluEvent { } } -pub fn create_alu_lookup_id() -> usize { +pub fn create_alu_lookup_id() -> u128 { let mut rng = rand::thread_rng(); rng.gen() } -pub fn create_alu_lookups() -> [usize; 6] { +pub fn create_alu_lookups() -> [u128; 6] { let mut rng = rand::thread_rng(); [ rng.gen(), diff --git a/core/src/alu/sll/mod.rs b/core/src/alu/sll/mod.rs index 364aa59b0..2985f8232 100644 --- a/core/src/alu/sll/mod.rs +++ b/core/src/alu/sll/mod.rs @@ -35,16 +35,19 @@ use core::{ mem::size_of, }; +use hashbrown::HashMap; +use itertools::Itertools; use p3_air::{Air, AirBuilder, BaseAir}; -use p3_field::AbstractField; -use p3_field::PrimeField; +use p3_field::{AbstractField, PrimeField}; use p3_matrix::dense::RowMajorMatrix; use p3_matrix::Matrix; +use p3_maybe_rayon::prelude::{ParallelIterator, ParallelSlice}; use sphinx_derive::AlignedBorrow; use crate::air::{AluAirBuilder, ByteAirBuilder, MachineAir, WordAirBuilder}; use crate::air::{EventLens, WithEvents, Word}; use crate::bytes::event::ByteRecord; +use crate::bytes::ByteLookupEvent; use crate::disassembler::WORD_SIZE; use crate::runtime::{ExecutionRecord, Opcode, Program}; use crate::utils::pad_to_power_of_two; @@ -120,7 +123,7 @@ impl MachineAir for ShiftLeft { fn generate_trace>( &self, input: &EL, - output: &mut ExecutionRecord, + _: &mut ExecutionRecord, ) -> RowMajorMatrix { // Generate the trace rows for each event. let mut rows: Vec<[F; NUM_SHIFT_LEFT_COLS]> = vec![]; @@ -128,61 +131,8 @@ impl MachineAir for ShiftLeft { for event in shift_left_events.iter() { let mut row = [F::zero(); NUM_SHIFT_LEFT_COLS]; let cols: &mut ShiftLeftCols = row.as_mut_slice().borrow_mut(); - let a = event.a.to_le_bytes(); - let b = event.b.to_le_bytes(); - let c = event.c.to_le_bytes(); - cols.shard = F::from_canonical_u32(event.shard); - cols.channel = F::from_canonical_u32(event.channel); - cols.a = Word(a.map(F::from_canonical_u8)); - cols.b = Word(b.map(F::from_canonical_u8)); - cols.c = Word(c.map(F::from_canonical_u8)); - cols.is_real = F::one(); - for i in 0..BYTE_SIZE { - cols.c_least_sig_byte[i] = F::from_canonical_u32((event.c >> i) & 1); - } - - // Variables for bit shifting. - let num_bits_to_shift = event.c as usize % BYTE_SIZE; - for i in 0..BYTE_SIZE { - cols.shift_by_n_bits[i] = F::from_bool(num_bits_to_shift == i); - } - - let bit_shift_multiplier = 1u32 << num_bits_to_shift; - cols.bit_shift_multiplier = F::from_canonical_u32(bit_shift_multiplier); - - let mut carry = 0u32; - let base = 1u32 << BYTE_SIZE; - let mut bit_shift_result = [0u8; WORD_SIZE]; - let mut bit_shift_result_carry = [0u8; WORD_SIZE]; - for i in 0..WORD_SIZE { - let v = u32::from(b[i]) * bit_shift_multiplier + carry; - carry = v / base; - bit_shift_result[i] = (v % base) as u8; - bit_shift_result_carry[i] = carry as u8; - } - cols.bit_shift_result = bit_shift_result.map(F::from_canonical_u8); - cols.bit_shift_result_carry = bit_shift_result_carry.map(F::from_canonical_u8); - - // Variables for byte shifting. - let num_bytes_to_shift = (event.c & 0b11111) as usize / BYTE_SIZE; - for i in 0..WORD_SIZE { - cols.shift_by_n_bytes[i] = F::from_bool(num_bytes_to_shift == i); - } - - // Range checks. - { - output.add_u8_range_checks(event.shard, event.channel, &bit_shift_result); - output.add_u8_range_checks(event.shard, event.channel, &bit_shift_result_carry); - } - - // Sanity check. - for i in num_bytes_to_shift..WORD_SIZE { - debug_assert_eq!( - cols.bit_shift_result[i - num_bytes_to_shift], - F::from_canonical_u8(a[i]) - ); - } - + let mut blu = Vec::new(); + self.event_to_row(event, cols, &mut blu); rows.push(row); } @@ -219,11 +169,96 @@ impl MachineAir for ShiftLeft { trace } + fn generate_dependencies>(&self, input: &EL, output: &mut ExecutionRecord) { + let chunk_size = std::cmp::max(input.events().len() / num_cpus::get(), 1); + + let blu_batches = input + .events() + .par_chunks(chunk_size) + .map(|events| { + let mut blu: HashMap> = HashMap::new(); + for event in events.iter() { + let mut row = [F::zero(); NUM_SHIFT_LEFT_COLS]; + let cols: &mut ShiftLeftCols = row.as_mut_slice().borrow_mut(); + self.event_to_row(event, cols, &mut blu); + } + blu + }) + .collect::>(); + + output.add_sharded_byte_lookup_events(blu_batches.iter().collect_vec()); + } + fn included(&self, shard: &Self::Record) -> bool { !shard.shift_left_events.is_empty() } } +impl ShiftLeft { + /// Create a row from an event. + fn event_to_row( + &self, + event: &AluEvent, + cols: &mut ShiftLeftCols, + blu: &mut impl ByteRecord, + ) { + let a = event.a.to_le_bytes(); + let b = event.b.to_le_bytes(); + let c = event.c.to_le_bytes(); + cols.shard = F::from_canonical_u32(event.shard); + cols.channel = F::from_canonical_u32(event.channel); + cols.a = Word(a.map(F::from_canonical_u8)); + cols.b = Word(b.map(F::from_canonical_u8)); + cols.c = Word(c.map(F::from_canonical_u8)); + cols.is_real = F::one(); + for i in 0..BYTE_SIZE { + cols.c_least_sig_byte[i] = F::from_canonical_u32((event.c >> i) & 1); + } + + // Variables for bit shifting. + let num_bits_to_shift = event.c as usize % BYTE_SIZE; + for i in 0..BYTE_SIZE { + cols.shift_by_n_bits[i] = F::from_bool(num_bits_to_shift == i); + } + + let bit_shift_multiplier = 1u32 << num_bits_to_shift; + cols.bit_shift_multiplier = F::from_canonical_u32(bit_shift_multiplier); + + let mut carry = 0u32; + let base = 1u32 << BYTE_SIZE; + let mut bit_shift_result = [0u8; WORD_SIZE]; + let mut bit_shift_result_carry = [0u8; WORD_SIZE]; + for i in 0..WORD_SIZE { + let v = u32::from(b[i]) * bit_shift_multiplier + carry; + carry = v / base; + bit_shift_result[i] = (v % base) as u8; + bit_shift_result_carry[i] = carry as u8; + } + cols.bit_shift_result = bit_shift_result.map(F::from_canonical_u8); + cols.bit_shift_result_carry = bit_shift_result_carry.map(F::from_canonical_u8); + + // Variables for byte shifting. + let num_bytes_to_shift = (event.c & 0b11111) as usize / BYTE_SIZE; + for i in 0..WORD_SIZE { + cols.shift_by_n_bytes[i] = F::from_bool(num_bytes_to_shift == i); + } + + // Range checks. + { + blu.add_u8_range_checks(event.shard, event.channel, &bit_shift_result); + blu.add_u8_range_checks(event.shard, event.channel, &bit_shift_result_carry); + } + + // Sanity check. + for i in num_bytes_to_shift..WORD_SIZE { + debug_assert_eq!( + cols.bit_shift_result[i - num_bytes_to_shift], + F::from_canonical_u8(a[i]) + ); + } + } +} + impl BaseAir for ShiftLeft { fn width(&self) -> usize { NUM_SHIFT_LEFT_COLS diff --git a/core/src/alu/sr/mod.rs b/core/src/alu/sr/mod.rs index f56b002c0..3b3e716fa 100644 --- a/core/src/alu/sr/mod.rs +++ b/core/src/alu/sr/mod.rs @@ -43,16 +43,16 @@ mod utils; -use core::{ - borrow::{Borrow, BorrowMut}, - mem::size_of, -}; - +use core::borrow::{Borrow, BorrowMut}; +use core::mem::size_of; +use hashbrown::HashMap; +use itertools::Itertools; use p3_air::{Air, AirBuilder, BaseAir}; use p3_field::AbstractField; use p3_field::PrimeField; use p3_matrix::dense::RowMajorMatrix; use p3_matrix::Matrix; +use p3_maybe_rayon::prelude::{ParallelIterator, ParallelSlice}; use sphinx_derive::AlignedBorrow; use crate::air::{AluAirBuilder, ByteAirBuilder, MachineAir, WordAirBuilder}; @@ -152,7 +152,7 @@ impl MachineAir for ShiftRightChip { fn generate_trace>( &self, input: &EL, - output: &mut ExecutionRecord, + _: &mut ExecutionRecord, ) -> RowMajorMatrix { // Generate the trace rows for each event. let mut rows: Vec<[F; NUM_SHIFT_RIGHT_COLS]> = Vec::new(); @@ -161,112 +161,8 @@ impl MachineAir for ShiftRightChip { assert!(event.opcode == Opcode::SRL || event.opcode == Opcode::SRA); let mut row = [F::zero(); NUM_SHIFT_RIGHT_COLS]; let cols: &mut ShiftRightCols = row.as_mut_slice().borrow_mut(); - // Initialize cols with basic operands and flags derived from the current event. - { - cols.shard = F::from_canonical_u32(event.shard); - cols.channel = F::from_canonical_u32(event.channel); - cols.a = Word::from(event.a); - cols.b = Word::from(event.b); - cols.c = Word::from(event.c); - - cols.b_msb = F::from_canonical_u32((event.b >> 31) & 1); - - cols.is_srl = F::from_bool(event.opcode == Opcode::SRL); - cols.is_sra = F::from_bool(event.opcode == Opcode::SRA); - - cols.is_real = F::one(); - - for i in 0..BYTE_SIZE { - cols.c_least_sig_byte[i] = F::from_canonical_u32((event.c >> i) & 1); - } - - // Insert the MSB lookup event. - let most_significant_byte = event.b.to_le_bytes()[WORD_SIZE - 1]; - output.add_byte_lookup_events(vec![ByteLookupEvent { - shard: event.shard, - channel: event.channel, - opcode: ByteOpcode::MSB, - a1: u32::from((most_significant_byte >> 7) & 1), - a2: 0, - b: u32::from(most_significant_byte), - c: 0, - }]); - } - - let num_bytes_to_shift = nb_bytes_to_shift(event.c); - let num_bits_to_shift = nb_bits_to_shift(event.c); - - // Byte shifting. - let mut byte_shift_result = [0u8; LONG_WORD_SIZE]; - { - for i in 0..WORD_SIZE { - cols.shift_by_n_bytes[i] = F::from_bool(num_bytes_to_shift == i); - } - let sign_extended_b = { - if event.opcode == Opcode::SRA { - // Sign extension is necessary only for arithmetic right shift. - i64::from(event.b as i32).to_le_bytes() - } else { - u64::from(event.b).to_le_bytes() - } - }; - - for i in 0..LONG_WORD_SIZE { - if i + num_bytes_to_shift < LONG_WORD_SIZE { - byte_shift_result[i] = sign_extended_b[i + num_bytes_to_shift]; - } - } - cols.byte_shift_result = byte_shift_result.map(F::from_canonical_u8); - } - - // Bit shifting. - { - for i in 0..BYTE_SIZE { - cols.shift_by_n_bits[i] = F::from_bool(num_bits_to_shift == i); - } - let carry_multiplier = 1 << (8 - num_bits_to_shift); - let mut last_carry = 0u32; - let mut bit_shift_result = [0u8; LONG_WORD_SIZE]; - let mut shr_carry_output_carry = [0u8; LONG_WORD_SIZE]; - let mut shr_carry_output_shifted_byte = [0u8; LONG_WORD_SIZE]; - for i in (0..LONG_WORD_SIZE).rev() { - let (shift, carry) = shr_carry(byte_shift_result[i], num_bits_to_shift as u8); - - let byte_event = ByteLookupEvent { - shard: event.shard, - channel: event.channel, - opcode: ByteOpcode::ShrCarry, - a1: u32::from(shift), - a2: u32::from(carry), - b: u32::from(byte_shift_result[i]), - c: num_bits_to_shift as u32, - }; - output.add_byte_lookup_event(byte_event); - - shr_carry_output_carry[i] = carry; - shr_carry_output_shifted_byte[i] = shift; - bit_shift_result[i] = - ((u32::from(shift) + last_carry * carry_multiplier) & 0xff) as u8; - last_carry = u32::from(carry); - } - cols.bit_shift_result = bit_shift_result.map(F::from_canonical_u8); - cols.shr_carry_output_carry = shr_carry_output_carry.map(F::from_canonical_u8); - cols.shr_carry_output_shifted_byte = - shr_carry_output_shifted_byte.map(F::from_canonical_u8); - for i in 0..WORD_SIZE { - debug_assert_eq!(cols.a[i], cols.bit_shift_result[i].clone()); - } - // Range checks. - output.add_u8_range_checks(event.shard, event.channel, &byte_shift_result); - output.add_u8_range_checks(event.shard, event.channel, &bit_shift_result); - output.add_u8_range_checks(event.shard, event.channel, &shr_carry_output_carry); - output.add_u8_range_checks( - event.shard, - event.channel, - &shr_carry_output_shifted_byte, - ); - } - + let mut blu = Vec::new(); + self.event_to_row(event, cols, &mut blu); rows.push(row); } @@ -305,11 +201,143 @@ impl MachineAir for ShiftRightChip { trace } + fn generate_dependencies>(&self, input: &EL, output: &mut ExecutionRecord) { + let chunk_size = std::cmp::max(input.events().len() / num_cpus::get(), 1); + + let blu_batches = input + .events() + .par_chunks(chunk_size) + .map(|events| { + let mut blu: HashMap> = HashMap::new(); + for event in events.iter() { + let mut row = [F::zero(); NUM_SHIFT_RIGHT_COLS]; + let cols: &mut ShiftRightCols = row.as_mut_slice().borrow_mut(); + self.event_to_row(event, cols, &mut blu); + } + blu + }) + .collect::>(); + + output.add_sharded_byte_lookup_events(blu_batches.iter().collect_vec()); + } + fn included(&self, shard: &Self::Record) -> bool { !shard.shift_right_events.is_empty() } } +impl ShiftRightChip { + /// Create a row from an event. + fn event_to_row( + &self, + event: &AluEvent, + cols: &mut ShiftRightCols, + blu: &mut impl ByteRecord, + ) { + // Initialize cols with basic operands and flags derived from the current event. + { + cols.shard = F::from_canonical_u32(event.shard); + cols.channel = F::from_canonical_u32(event.channel); + cols.a = Word::from(event.a); + cols.b = Word::from(event.b); + cols.c = Word::from(event.c); + + cols.b_msb = F::from_canonical_u32((event.b >> 31) & 1); + + cols.is_srl = F::from_bool(event.opcode == Opcode::SRL); + cols.is_sra = F::from_bool(event.opcode == Opcode::SRA); + + cols.is_real = F::one(); + + for i in 0..BYTE_SIZE { + cols.c_least_sig_byte[i] = F::from_canonical_u32((event.c >> i) & 1); + } + + // Insert the MSB lookup event. + let most_significant_byte = event.b.to_le_bytes()[WORD_SIZE - 1]; + blu.add_byte_lookup_events(vec![ByteLookupEvent { + shard: event.shard, + channel: event.channel, + opcode: ByteOpcode::MSB, + a1: u32::from((most_significant_byte >> 7) & 1), + a2: 0, + b: u32::from(most_significant_byte), + c: 0, + }]); + } + + let num_bytes_to_shift = nb_bytes_to_shift(event.c); + let num_bits_to_shift = nb_bits_to_shift(event.c); + + // Byte shifting. + let mut byte_shift_result = [0u8; LONG_WORD_SIZE]; + { + for i in 0..WORD_SIZE { + cols.shift_by_n_bytes[i] = F::from_bool(num_bytes_to_shift == i); + } + let sign_extended_b = { + if event.opcode == Opcode::SRA { + // Sign extension is necessary only for arithmetic right shift. + i64::from(event.b as i32).to_le_bytes() + } else { + u64::from(event.b).to_le_bytes() + } + }; + + for i in 0..LONG_WORD_SIZE { + if i + num_bytes_to_shift < LONG_WORD_SIZE { + byte_shift_result[i] = sign_extended_b[i + num_bytes_to_shift]; + } + } + cols.byte_shift_result = byte_shift_result.map(F::from_canonical_u8); + } + + // Bit shifting. + { + for i in 0..BYTE_SIZE { + cols.shift_by_n_bits[i] = F::from_bool(num_bits_to_shift == i); + } + let carry_multiplier = 1 << (8 - num_bits_to_shift); + let mut last_carry = 0u32; + let mut bit_shift_result = [0u8; LONG_WORD_SIZE]; + let mut shr_carry_output_carry = [0u8; LONG_WORD_SIZE]; + let mut shr_carry_output_shifted_byte = [0u8; LONG_WORD_SIZE]; + for i in (0..LONG_WORD_SIZE).rev() { + let (shift, carry) = shr_carry(byte_shift_result[i], num_bits_to_shift as u8); + + let byte_event = ByteLookupEvent { + shard: event.shard, + channel: event.channel, + opcode: ByteOpcode::ShrCarry, + a1: u32::from(shift), + a2: u32::from(carry), + b: u32::from(byte_shift_result[i]), + c: num_bits_to_shift as u32, + }; + blu.add_byte_lookup_event(byte_event); + + shr_carry_output_carry[i] = carry; + shr_carry_output_shifted_byte[i] = shift; + bit_shift_result[i] = + ((u32::from(shift) + last_carry * carry_multiplier) & 0xff) as u8; + last_carry = u32::from(carry); + } + cols.bit_shift_result = bit_shift_result.map(F::from_canonical_u8); + cols.shr_carry_output_carry = shr_carry_output_carry.map(F::from_canonical_u8); + cols.shr_carry_output_shifted_byte = + shr_carry_output_shifted_byte.map(F::from_canonical_u8); + for i in 0..WORD_SIZE { + debug_assert_eq!(cols.a[i], cols.bit_shift_result[i].clone()); + } + // Range checks. + blu.add_u8_range_checks(event.shard, event.channel, &byte_shift_result); + blu.add_u8_range_checks(event.shard, event.channel, &bit_shift_result); + blu.add_u8_range_checks(event.shard, event.channel, &shr_carry_output_carry); + blu.add_u8_range_checks(event.shard, event.channel, &shr_carry_output_shifted_byte); + } + } +} + impl BaseAir for ShiftRightChip { fn width(&self) -> usize { NUM_SHIFT_RIGHT_COLS diff --git a/core/src/bytes/event.rs b/core/src/bytes/event.rs index 362c1876c..017f22a85 100644 --- a/core/src/bytes/event.rs +++ b/core/src/bytes/event.rs @@ -1,10 +1,15 @@ +use hashbrown::HashMap; +use itertools::Itertools; use p3_field::PrimeField32; +use p3_maybe_rayon::prelude::{ + IndexedParallelIterator, IntoParallelRefIterator, IntoParallelRefMutIterator, ParallelIterator, +}; use serde::{Deserialize, Serialize}; use super::ByteOpcode; /// A byte lookup event. -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] pub struct ByteLookupEvent { /// The shard number, used for byte lookup table. pub shard: u32, @@ -33,6 +38,11 @@ pub trait ByteRecord { /// Adds a new `ByteLookupEvent` to the record. fn add_byte_lookup_event(&mut self, blu_event: ByteLookupEvent); + fn add_sharded_byte_lookup_events( + &mut self, + sharded_blu_events_vec: Vec<&HashMap>>, + ); + /// Adds a list of `ByteLookupEvent`s to the record. #[inline] fn add_byte_lookup_events(&mut self, blu_events: Vec) { @@ -146,4 +156,85 @@ impl ByteRecord for Vec { fn add_byte_lookup_event(&mut self, blu_event: ByteLookupEvent) { self.push(blu_event); } + + fn add_sharded_byte_lookup_events( + &mut self, + _: Vec<&HashMap>>, + ) { + todo!() + } +} + +impl ByteRecord for HashMap> { + #[inline] + fn add_byte_lookup_event(&mut self, blu_event: ByteLookupEvent) { + self.entry(blu_event.shard) + .or_default() + .entry(blu_event) + .and_modify(|e| *e += 1) + .or_insert(1); + } + + fn add_sharded_byte_lookup_events( + &mut self, + new_events: Vec<&HashMap>>, + ) { + add_sharded_byte_lookup_events(self, new_events); + } +} + +pub(crate) fn add_sharded_byte_lookup_events( + sharded_blu_events: &mut HashMap>, + new_events: Vec<&HashMap>>, +) { + // new_sharded_blu_map is a map of shard -> Vec multiplicities>. + // We want to collect the new events in this format so that we can do parallel aggregation + // per shard. + let mut new_sharded_blu_map: HashMap>> = + HashMap::new(); + for new_sharded_blu_events in new_events { + for (shard, new_blu_map) in new_sharded_blu_events { + new_sharded_blu_map + .entry(*shard) + .or_insert(Vec::new()) + .push(new_blu_map); + } + } + + // Collect all the shard numbers. + let shards: Vec = new_sharded_blu_map.keys().copied().collect_vec(); + + // Move ownership of self's per shard blu maps into a vec. This is so that we + // can do parallel aggregation per shard. + let mut self_blu_maps: Vec> = Vec::new(); + for shard in shards.iter() { + let blu = sharded_blu_events.remove(shard); + + match blu { + Some(blu) => { + self_blu_maps.push(blu); + } + None => { + self_blu_maps.push(HashMap::new()); + } + } + } + + // Increment self's byte lookup events multiplicity. + shards + .par_iter() + .zip_eq(self_blu_maps.par_iter_mut()) + .for_each(|(shard, self_blu_map)| { + let blu_map_vec = new_sharded_blu_map.get(shard).unwrap(); + for blu_map in blu_map_vec.iter() { + for (blu_event, count) in blu_map.into_iter() { + *self_blu_map.entry(*blu_event).or_insert(0) += count; + } + } + }); + + // Move ownership of the blu maps back to self. + for (shard, blu) in shards.into_iter().zip(self_blu_maps.into_iter()) { + sharded_blu_events.insert(shard, blu); + } } diff --git a/core/src/bytes/trace.rs b/core/src/bytes/trace.rs index 0d9cbfbfa..d612fff57 100644 --- a/core/src/bytes/trace.rs +++ b/core/src/bytes/trace.rs @@ -1,7 +1,7 @@ use std::borrow::BorrowMut; use hashbrown::HashMap; -use p3_field::Field; +use p3_field::{Field, PrimeField32}; use p3_matrix::dense::RowMajorMatrix; use super::{ @@ -9,7 +9,7 @@ use super::{ ByteChip, ByteLookupEvent, }; use crate::{ - air::{EventLens, MachineAir, WithEvents}, + air::{EventLens, MachineAir, PublicValues, WithEvents, Word}, bytes::ByteOpcode, runtime::{ExecutionRecord, Program}, }; @@ -17,11 +17,15 @@ use crate::{ pub const NUM_ROWS: usize = 1 << 16; impl<'a, F: Field> WithEvents<'a> for ByteChip { - // the byte lookups - type Events = &'a HashMap>; + type Events = ( + // the byte lookups + &'a HashMap>, + // the public values + PublicValues, F>, + ); } -impl MachineAir for ByteChip { +impl MachineAir for ByteChip { type Record = ExecutionRecord; type Program = Program; @@ -57,8 +61,10 @@ impl MachineAir for ByteChip { NUM_BYTE_MULT_COLS, ); - let shard = input.index(); - for (lookup, mult) in input.events()[&shard].iter() { + let (events, pv) = input.events(); + + let shard = pv.execution_shard.as_canonical_u32(); + for (lookup, mult) in events.get(&shard).unwrap_or(&HashMap::new()).iter() { let row = if lookup.opcode != ByteOpcode::U16Range { ((lookup.b << 8) + lookup.c) as usize } else { @@ -69,7 +75,7 @@ impl MachineAir for ByteChip { let cols: &mut ByteMultCols = trace.row_mut(row).borrow_mut(); cols.mult_channels[channel].multiplicities[index] += F::from_canonical_usize(*mult); - cols.shard = F::from_canonical_u32(shard); + cols.shard = pv.execution_shard; } trace diff --git a/core/src/cpu/air/ecall.rs b/core/src/cpu/air/ecall.rs index 1cbb630f8..c41f31073 100644 --- a/core/src/cpu/air/ecall.rs +++ b/core/src/cpu/air/ecall.rs @@ -5,7 +5,7 @@ use crate::air::{AluAirBuilder, BaseAirBuilder, PublicValues, WordAirBuilder}; use crate::cpu::air::{Word, POSEIDON_NUM_WORDS, PV_DIGEST_NUM_WORDS}; use crate::cpu::columns::{CpuCols, OpcodeSelectorCols}; use crate::memory::MemoryCols; -use crate::operations::IsZeroOperation; +use crate::operations::{BabyBearWordRangeChecker, IsZeroOperation}; use crate::runtime::SyscallCode; use crate::stark::CpuChip; @@ -62,7 +62,7 @@ impl CpuChip { syscall_id - AB::Expr::from_canonical_u32(SyscallCode::ENTER_UNCONSTRAINED.syscall_id()), ecall_cols.is_enter_unconstrained, - is_ecall_instruction, + is_ecall_instruction.into(), ); ecall_cols.is_enter_unconstrained.result }; @@ -73,7 +73,7 @@ impl CpuChip { builder, syscall_id - AB::Expr::from_canonical_u32(SyscallCode::HINT_LEN.syscall_id()), ecall_cols.is_hint_len, - is_ecall_instruction, + is_ecall_instruction.into(), ); ecall_cols.is_hint_len.result }; @@ -89,6 +89,21 @@ impl CpuChip { .when(is_ecall_instruction) .when_not(is_enter_unconstrained + is_hint_len) .assert_word_eq(local.op_a_val(), local.op_a_access.prev_value); + + // Verify value of ecall_range_check_operand column. + builder.assert_eq( + local.ecall_range_check_operand, + is_ecall_instruction + * (ecall_cols.is_halt.result + ecall_cols.is_commit_deferred_proofs.result), + ); + + // Babybear range check the operand_to_check word. + BabyBearWordRangeChecker::::range_check::( + builder, + ecall_cols.operand_to_check, + ecall_cols.operand_range_check_cols, + local.ecall_range_check_operand.into(), + ); } /// Constraints related to the COMMIT and COMMIT_DEFERRED_PROOFS instructions. @@ -161,13 +176,18 @@ impl CpuChip { .when(local.selectors.is_ecall * is_commit) .assert_word_eq(expected_pv_digest_word, *digest_word); - let expected_deferred_proofs_digest_word = + let expected_deferred_proofs_digest_element = builder.index_array(deferred_proofs_digest, &ecall_columns.index_bitmap); + // Verify that the operand that was range checked is digest_word. + builder + .when(local.selectors.is_ecall * is_commit_deferred_proofs.clone()) + .assert_word_eq(*digest_word, ecall_columns.operand_to_check); + builder .when(local.selectors.is_ecall * is_commit_deferred_proofs) .assert_eq( - expected_deferred_proofs_digest_word, + expected_deferred_proofs_digest_element, digest_word.reduce::(), ); } @@ -190,6 +210,12 @@ impl CpuChip { builder.when(is_halt.clone()).assert_zero(local.next_pc); + // Verify that the operand that was range checked is op_b. + let ecall_columns = local.opcode_specific_columns.ecall(); + builder + .when(is_halt.clone()) + .assert_word_eq(local.op_b_val(), ecall_columns.operand_to_check); + builder.when(is_halt.clone()).assert_eq( local.op_b_access.value().reduce::(), public_values.exit_code.clone(), @@ -216,7 +242,7 @@ impl CpuChip { builder, syscall_id - AB::Expr::from_canonical_u32(SyscallCode::HALT.syscall_id()), ecall_cols.is_halt, - is_ecall_instruction, + is_ecall_instruction.into(), ); ecall_cols.is_halt.result }; @@ -245,7 +271,7 @@ impl CpuChip { builder, syscall_id - AB::Expr::from_canonical_u32(SyscallCode::COMMIT.syscall_id()), ecall_cols.is_commit, - is_ecall_instruction, + is_ecall_instruction.into(), ); ecall_cols.is_commit.result }; @@ -259,7 +285,7 @@ impl CpuChip { SyscallCode::COMMIT_DEFERRED_PROOFS.syscall_id(), ), ecall_cols.is_commit_deferred_proofs, - is_ecall_instruction, + is_ecall_instruction.into(), ); ecall_cols.is_commit_deferred_proofs.result }; diff --git a/core/src/cpu/air/mod.rs b/core/src/cpu/air/mod.rs index 3a0b02989..d14cc1f88 100644 --- a/core/src/cpu/air/mod.rs +++ b/core/src/cpu/air/mod.rs @@ -4,7 +4,6 @@ pub mod memory; pub mod register; use core::borrow::Borrow; -use itertools::Itertools as _; use p3_air::Air; use p3_air::AirBuilder; use p3_air::AirBuilderWithPublicValues; @@ -21,6 +20,7 @@ use crate::air::PublicValues; use crate::air::Word; use crate::air::POSEIDON_NUM_WORDS; use crate::air::PV_DIGEST_NUM_WORDS; +use crate::air::SPHINX_PROOF_NUM_PV_ELTS; use crate::bytes::ByteOpcode; use crate::cpu::columns::OpcodeSelectorCols; use crate::cpu::columns::{CpuCols, NUM_CPU_COLS}; @@ -42,13 +42,10 @@ where let (local, next) = (main.row_slice(0), main.row_slice(1)); let local: &CpuCols = (*local).borrow(); let next: &CpuCols = (*next).borrow(); - let public_values = PublicValues::, AB::Expr>::from_vec( - &builder - .public_values() - .iter() - .map(|elm| (*elm).into()) - .collect_vec(), - ); + let public_values_slice: [AB::Expr; SPHINX_PROOF_NUM_PV_ELTS] = + core::array::from_fn(|i| builder.public_values()[i].into()); + let public_values: &PublicValues, AB::Expr> = + public_values_slice.as_slice().borrow(); // Program constraints. builder.send_program( @@ -115,7 +112,7 @@ where ); // HALT ecall and UNIMPL instruction. - self.eval_halt_unimpl(builder, local, next, &public_values); + self.eval_halt_unimpl(builder, local, next, public_values); // Check that the shard and clk is updated correctly. self.eval_shard_clk(builder, local, next); @@ -124,7 +121,7 @@ where self.eval_pc(builder, local, next, is_branch_instruction.clone()); // Check public values constraints. - self.eval_public_values(builder, local, next, &public_values); + self.eval_public_values(builder, local, next, public_values); // Check that the is_real flag is correct. self.eval_is_real(builder, local, next); @@ -385,7 +382,7 @@ impl CpuChip { // Verify the public value's shard. builder .when(local.is_real) - .assert_eq(public_values.shard.clone(), local.shard); + .assert_eq(public_values.execution_shard.clone(), local.shard); // Verify the public value's start pc. builder diff --git a/core/src/cpu/columns/ecall.rs b/core/src/cpu/columns/ecall.rs index 4eea13672..c1fdd7051 100644 --- a/core/src/cpu/columns/ecall.rs +++ b/core/src/cpu/columns/ecall.rs @@ -1,7 +1,10 @@ use sphinx_derive::AlignedBorrow; use std::mem::size_of; -use crate::{air::PV_DIGEST_NUM_WORDS, operations::IsZeroOperation}; +use crate::{ + air::{Word, PV_DIGEST_NUM_WORDS}, + operations::{BabyBearWordRangeChecker, IsZeroOperation}, +}; pub const NUM_ECALL_COLS: usize = size_of::>(); @@ -29,4 +32,10 @@ pub struct EcallCols { /// The nonce of the syscall operation. pub syscall_nonce: T, + + /// Columns to babybear range check the halt/commit_deferred_proofs operand. + pub operand_range_check_cols: BabyBearWordRangeChecker, + + /// The operand value to babybear range check. + pub operand_to_check: Word, } diff --git a/core/src/cpu/columns/mod.rs b/core/src/cpu/columns/mod.rs index 1db967c10..b72d1105e 100644 --- a/core/src/cpu/columns/mod.rs +++ b/core/src/cpu/columns/mod.rs @@ -104,6 +104,9 @@ pub struct CpuCols { /// The result of selectors.is_ecall * the send_to_table column for the ECALL opcode. pub ecall_mul_send_to_table: T, + /// The result of selectors.is_ecall * (is_halt || is_commit_deferred_proofs) + pub ecall_range_check_operand: T, + /// This is true for all instructions that are not jumps, branches, and halt. Those instructions /// may move the program counter to a non sequential instruction. pub is_sequential_instr: T, diff --git a/core/src/cpu/event.rs b/core/src/cpu/event.rs index 93f4e48e0..8095cbc0b 100644 --- a/core/src/cpu/event.rs +++ b/core/src/cpu/event.rs @@ -51,14 +51,14 @@ pub struct CpuEvent { /// Exit code called with halt. pub exit_code: u32, - pub alu_lookup_id: usize, - pub syscall_lookup_id: usize, - pub memory_add_lookup_id: usize, - pub memory_sub_lookup_id: usize, - pub branch_gt_lookup_id: usize, - pub branch_lt_lookup_id: usize, - pub branch_add_lookup_id: usize, - pub jump_jal_lookup_id: usize, - pub jump_jalr_lookup_id: usize, - pub auipc_lookup_id: usize, + pub alu_lookup_id: u128, + pub syscall_lookup_id: u128, + pub memory_add_lookup_id: u128, + pub memory_sub_lookup_id: u128, + pub branch_gt_lookup_id: u128, + pub branch_lt_lookup_id: u128, + pub branch_add_lookup_id: u128, + pub jump_jal_lookup_id: u128, + pub jump_jalr_lookup_id: u128, + pub auipc_lookup_id: u128, } diff --git a/core/src/cpu/mod.rs b/core/src/cpu/mod.rs index fbb391487..c9c513ab6 100644 --- a/core/src/cpu/mod.rs +++ b/core/src/cpu/mod.rs @@ -5,6 +5,9 @@ pub mod trace; pub use event::*; +/// The maximum log degree of the CPU chip to avoid lookup multiplicity overflow. +pub const MAX_CPU_LOG_DEGREE: usize = 22; + /// A chip that implements the CPU. #[derive(Default)] pub struct CpuChip; diff --git a/core/src/cpu/trace.rs b/core/src/cpu/trace.rs index 46873ff54..268239826 100644 --- a/core/src/cpu/trace.rs +++ b/core/src/cpu/trace.rs @@ -1,14 +1,14 @@ use hashbrown::HashMap; -use p3_maybe_rayon::prelude::ParallelBridge; +use itertools::Itertools; use std::array; use std::borrow::BorrowMut; use p3_field::{PrimeField, PrimeField32}; use p3_matrix::dense::RowMajorMatrix; use p3_maybe_rayon::prelude::IntoParallelRefMutIterator; +use p3_maybe_rayon::prelude::ParallelBridge; use p3_maybe_rayon::prelude::ParallelIterator; use p3_maybe_rayon::prelude::ParallelSlice; -use p3_maybe_rayon::prelude::ParallelSliceMut; use tracing::instrument; use super::columns::{CPU_COL_MAP, NUM_CPU_COLS}; @@ -29,7 +29,7 @@ use crate::runtime::{ExecutionRecord, Opcode, Program}; use crate::runtime::{MemoryRecordEnum, SyscallCode}; impl<'a> WithEvents<'a> for CpuChip { - type Events = (&'a [CpuEvent], &'a HashMap); + type Events = (&'a [CpuEvent], &'a HashMap); } impl MachineAir for CpuChip { @@ -60,7 +60,13 @@ impl MachineAir for CpuChip { .for_each(|(j, row)| { let idx = i * chunk_size + j; let cols: &mut CpuCols = row.borrow_mut(); - self.event_to_row(&events[idx], nonce_lookup, cols); + let mut byte_lookup_events = Vec::new(); + self.event_to_row( + &events[idx], + nonce_lookup, + cols, + &mut byte_lookup_events, + ); }); }); @@ -75,23 +81,23 @@ impl MachineAir for CpuChip { #[instrument(name = "generate cpu dependencies", level = "debug", skip_all)] fn generate_dependencies>(&self, input: &EL, output: &mut ExecutionRecord) { - // Generate the trace rows for each event. let (events, _) = input.events(); + // Generate the trace rows for each event. let chunk_size = std::cmp::max(events.len() / num_cpus::get(), 1); + let (alu_events, blu_events): (Vec<_>, Vec<_>) = events .par_chunks(chunk_size) .map(|ops: &[CpuEvent]| { let mut alu = HashMap::new(); - let mut blu: Vec<_> = Vec::with_capacity(ops.len() * 8); - for op in ops { + // The blu map stores shard -> map(byte lookup event -> multiplicity). + let mut blu: HashMap> = HashMap::new(); + for op in ops.iter() { let mut row = [F::zero(); NUM_CPU_COLS]; let cols: &mut CpuCols = row.as_mut_slice().borrow_mut(); - let (alu_events, blu_events) = - self.event_to_row::(op, &HashMap::new(), cols); + let alu_events = self.event_to_row::(op, &HashMap::new(), cols, &mut blu); alu_events.into_iter().for_each(|(key, value)| { alu.entry(key).or_insert(Vec::default()).extend(value); }); - blu.extend(blu_events); } (alu, blu) }) @@ -101,16 +107,11 @@ impl MachineAir for CpuChip { output.add_alu_events(alu_events_chunk); } - let mut blu_events = blu_events.into_iter().flatten().collect::>(); - blu_events.par_sort_unstable_by_key(|event| (event.shard, event.opcode)); - - for blu_event in blu_events { - output.add_byte_lookup_event(blu_event); - } + output.add_sharded_byte_lookup_events(blu_events.iter().collect_vec()); } - fn included(&self, _: &Self::Record) -> bool { - true + fn included(&self, input: &Self::Record) -> bool { + !input.cpu_events.is_empty() } } @@ -119,14 +120,14 @@ impl CpuChip { fn event_to_row( &self, event: &CpuEvent, - nonce_lookup: &HashMap, + nonce_lookup: &HashMap, cols: &mut CpuCols, - ) -> (HashMap>, Vec) { + blu_events: &mut impl ByteRecord, + ) -> HashMap> { let mut new_alu_events = HashMap::new(); - let mut new_blu_events = Vec::new(); // Populate shard and clk columns. - self.populate_shard_clk(cols, event, &mut new_blu_events); + self.populate_shard_clk(cols, event, blu_events); // Populate the nonce. cols.nonce = F::from_canonical_u32( @@ -147,16 +148,13 @@ impl CpuChip { // Populate memory accesses for a, b, and c. if let Some(record) = event.a_record { - cols.op_a_access - .populate(event.channel, record, &mut new_blu_events); + cols.op_a_access.populate(event.channel, record, blu_events); } if let Some(MemoryRecordEnum::Read(record)) = event.b_record { - cols.op_b_access - .populate(event.channel, record, &mut new_blu_events); + cols.op_b_access.populate(event.channel, record, blu_events); } if let Some(MemoryRecordEnum::Read(record)) = event.c_record { - cols.op_c_access - .populate(event.channel, record, &mut new_blu_events); + cols.op_c_access.populate(event.channel, record, blu_events); } // Populate range checks for a. @@ -168,7 +166,7 @@ impl CpuChip { .iter() .map(|x| x.as_canonical_u32()) .collect::>(); - new_blu_events.push(ByteLookupEvent { + blu_events.add_byte_lookup_event(ByteLookupEvent { shard: event.shard, channel: event.channel, opcode: U8Range, @@ -177,7 +175,7 @@ impl CpuChip { b: a_bytes[0], c: a_bytes[1], }); - new_blu_events.push(ByteLookupEvent { + blu_events.add_byte_lookup_event(ByteLookupEvent { shard: event.shard, channel: event.channel, opcode: U8Range, @@ -193,17 +191,11 @@ impl CpuChip { if let Some(record) = event.memory_record { memory_columns .memory_access - .populate(event.channel, record, &mut new_blu_events) + .populate(event.channel, record, blu_events) } // Populate memory, branch, jump, and auipc specific fields. - self.populate_memory( - cols, - event, - &mut new_alu_events, - &mut new_blu_events, - nonce_lookup, - ); + self.populate_memory(cols, event, &mut new_alu_events, blu_events, nonce_lookup); self.populate_branch(cols, event, &mut new_alu_events, nonce_lookup); self.populate_jump(cols, event, &mut new_alu_events, nonce_lookup); self.populate_auipc(cols, event, &mut new_alu_events, nonce_lookup); @@ -218,7 +210,7 @@ impl CpuChip { // Assert that the instruction is not a no-op. cols.is_real = F::one(); - (new_alu_events, new_blu_events) + new_alu_events } /// Populates the shard, channel, and clk related rows. @@ -226,7 +218,7 @@ impl CpuChip { &self, cols: &mut CpuCols, event: &CpuEvent, - new_blu_events: &mut Vec, + blu_events: &mut impl ByteRecord, ) { cols.shard = F::from_canonical_u32(event.shard); cols.channel = F::from_canonical_u32(event.channel); @@ -239,7 +231,7 @@ impl CpuChip { cols.channel_selectors.populate(event.channel); - new_blu_events.push(ByteLookupEvent::new( + blu_events.add_byte_lookup_event(ByteLookupEvent::new( event.shard, event.channel, U16Range, @@ -248,7 +240,7 @@ impl CpuChip { 0, 0, )); - new_blu_events.push(ByteLookupEvent::new( + blu_events.add_byte_lookup_event(ByteLookupEvent::new( event.shard, event.channel, U16Range, @@ -257,7 +249,7 @@ impl CpuChip { 0, 0, )); - new_blu_events.push(ByteLookupEvent::new( + blu_events.add_byte_lookup_event(ByteLookupEvent::new( event.shard, event.channel, U8Range, @@ -274,8 +266,8 @@ impl CpuChip { cols: &mut CpuCols, event: &CpuEvent, new_alu_events: &mut HashMap>, - new_blu_events: &mut Vec, - nonce_lookup: &HashMap, + blu_events: &mut impl ByteRecord, + nonce_lookup: &HashMap, ) { if !matches!( event.instruction.opcode, @@ -408,7 +400,7 @@ impl CpuChip { // Add event to byte lookup for byte range checking each byte in the memory addr let addr_bytes = memory_addr.to_le_bytes(); for byte_pair in addr_bytes.chunks_exact(2) { - new_blu_events.push(ByteLookupEvent { + blu_events.add_byte_lookup_event(ByteLookupEvent { shard: event.shard, channel: event.channel, opcode: U8Range, @@ -426,7 +418,7 @@ impl CpuChip { cols: &mut CpuCols, event: &CpuEvent, alu_events: &mut HashMap>, - nonce_lookup: &HashMap, + nonce_lookup: &HashMap, ) { if event.instruction.is_branch_instruction() { let branch_columns = cols.opcode_specific_columns.branch_mut(); @@ -555,7 +547,7 @@ impl CpuChip { cols: &mut CpuCols, event: &CpuEvent, alu_events: &mut HashMap>, - nonce_lookup: &HashMap, + nonce_lookup: &HashMap, ) { if event.instruction.is_jump_instruction() { let jump_columns = cols.opcode_specific_columns.jump_mut(); @@ -632,7 +624,7 @@ impl CpuChip { cols: &mut CpuCols, event: &CpuEvent, alu_events: &mut HashMap>, - nonce_lookup: &HashMap, + nonce_lookup: &HashMap, ) { if matches!(event.instruction.opcode, Opcode::AUIPC) { let auipc_columns = cols.opcode_specific_columns.auipc_mut(); @@ -670,7 +662,7 @@ impl CpuChip { &self, cols: &mut CpuCols, event: &CpuEvent, - nonce_lookup: &HashMap, + nonce_lookup: &HashMap, ) -> bool { let mut is_halt = false; @@ -734,6 +726,21 @@ impl CpuChip { ); is_halt = syscall_id == F::from_canonical_u32(SyscallCode::HALT.syscall_id()); + + // For halt and commit deferred proofs syscalls, we need to baby bear range check one of + // it's operands. + if is_halt { + ecall_cols.operand_to_check = event.b.into(); + ecall_cols.operand_range_check_cols.populate(event.b); + cols.ecall_range_check_operand = F::one(); + } + + if syscall_id == F::from_canonical_u32(SyscallCode::COMMIT_DEFERRED_PROOFS.syscall_id()) + { + ecall_cols.operand_to_check = event.c.into(); + ecall_cols.operand_range_check_cols.populate(event.c); + cols.ecall_range_check_operand = F::one(); + } } is_halt @@ -773,6 +780,7 @@ mod tests { use crate::runtime::tests::ssz_withdrawals_program; use crate::runtime::{tests::simple_program, Runtime}; + use crate::stark::DefaultProver; use crate::utils::{run_test, setup_logger, SphinxCoreOpts}; // #[test] @@ -834,6 +842,6 @@ mod tests { fn prove_trace() { setup_logger(); let program = simple_program(); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } } diff --git a/core/src/io.rs b/core/src/io.rs index e7291c0b7..6884d80d8 100644 --- a/core/src/io.rs +++ b/core/src/io.rs @@ -97,7 +97,7 @@ impl SphinxPublicValues { } } - pub fn bytes(&self) -> String { + pub fn raw(&self) -> String { format!("0x{}", hex::encode(self.buffer.data.clone())) } diff --git a/core/src/lib.rs b/core/src/lib.rs index dbb93c9c9..fbad13b33 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -30,4 +30,4 @@ use stark::StarkGenericConfig; /// This string should be updated whenever any step in verifying an SP1 proof changes, including /// core, recursion, and plonk-bn254. This string is used to download SP1 artifacts and the gnark /// docker image. -pub const SPHINX_CIRCUIT_VERSION: &str = "v1.0.8-testnet"; +pub const SPHINX_CIRCUIT_VERSION: &str = "v1.0.0-rc.1"; diff --git a/core/src/lookup/debug.rs b/core/src/lookup/debug.rs index 53e82554f..9bc49fd27 100644 --- a/core/src/lookup/debug.rs +++ b/core/src/lookup/debug.rs @@ -213,10 +213,9 @@ where #[cfg(test)] mod test { - use super::debug_interactions_with_all_chips; use crate::{ - lookup::InteractionKind, - runtime::{Program, Runtime, ShardingConfig}, + lookup::{debug_interactions_with_all_chips, InteractionKind}, + runtime::{Program, Runtime}, stark::RiscvAir, utils::{setup_logger, tests::FIBONACCI_ELF, BabyBearPoseidon2, SphinxCoreOpts}, }; @@ -230,7 +229,13 @@ mod test { let (pk, _) = machine.setup(&program); let mut runtime = Runtime::new(program, SphinxCoreOpts::default()); runtime.run().unwrap(); - let shards = machine.shard(runtime.record, &ShardingConfig::default()); + let opts = SphinxCoreOpts::default(); + machine.generate_dependencies(&mut runtime.records, &opts); + + let mut shards = runtime.records; + shards.iter_mut().enumerate().for_each(|(i, shard)| { + shard.public_values.shard = (i + 1) as u32; + }); let ok = debug_interactions_with_all_chips( &machine, &pk, diff --git a/core/src/memory/global.rs b/core/src/memory/global.rs index 61e1f09eb..91d8b01fc 100644 --- a/core/src/memory/global.rs +++ b/core/src/memory/global.rs @@ -1,57 +1,63 @@ use core::borrow::{Borrow, BorrowMut}; use core::mem::size_of; use std::array; +use std::marker::PhantomData; -use p3_air::BaseAir; use p3_air::{Air, AirBuilder}; -use p3_field::AbstractField; -use p3_field::PrimeField; +use p3_air::{AirBuilderWithPublicValues, BaseAir}; +use p3_field::{AbstractField, PrimeField32}; use p3_matrix::dense::RowMajorMatrix; use p3_matrix::Matrix; use sphinx_derive::AlignedBorrow; use super::MemoryInitializeFinalizeEvent; -use crate::air::{AirInteraction, BaseAirBuilder}; -use crate::air::{EventLens, MachineAir, WithEvents}; -use crate::operations::BabyBearBitDecomposition; +use crate::air::{AirInteraction, BaseAirBuilder, EventLens, PublicValues, WithEvents, Word}; +use crate::air::{MachineAir, SPHINX_PROOF_NUM_PV_ELTS}; +use crate::operations::{AssertLtColsBits, BabyBearBitDecomposition, IsZeroOperation}; use crate::runtime::{ExecutionRecord, Program}; use crate::utils::pad_to_power_of_two; /// The type of memory chip that is being initialized. -#[derive(PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum MemoryChipType { Initialize, Finalize, } /// A memory chip that can initialize or finalize values in memory. -pub struct MemoryChip { +pub struct MemoryChip { pub kind: MemoryChipType, + _marker: PhantomData, } -impl MemoryChip { +impl MemoryChip { /// Creates a new memory chip with a certain type. - pub const fn new(kind: MemoryChipType) -> Self { - Self { kind } + pub fn new(kind: MemoryChipType) -> Self { + Self { + kind, + _marker: PhantomData, + } } } -impl BaseAir for MemoryChip { +impl BaseAir for MemoryChip { fn width(&self) -> usize { NUM_MEMORY_INIT_COLS } } -impl<'a> WithEvents<'a> for MemoryChip { +impl<'a, F: 'a> WithEvents<'a> for MemoryChip { type Events = ( // initialize events &'a [MemoryInitializeFinalizeEvent], // finalize events &'a [MemoryInitializeFinalizeEvent], + // the public values + PublicValues, F>, ); } -impl MachineAir for MemoryChip { +impl MachineAir for MemoryChip { type Record = ExecutionRecord; type Program = Program; @@ -68,11 +74,20 @@ impl MachineAir for MemoryChip { input: &EL, _output: &mut ExecutionRecord, ) -> RowMajorMatrix { - let mut memory_events: Vec = match self.kind { - MemoryChipType::Initialize => input.events().0, - MemoryChipType::Finalize => input.events().1, - } - .to_vec(); + let (mem_init_events, mem_final_events, pv) = input.events(); + + let mut memory_events = match self.kind { + MemoryChipType::Initialize => mem_init_events.to_vec(), + MemoryChipType::Finalize => mem_final_events.to_vec(), + }; + + let previous_addr_bits = match self.kind { + MemoryChipType::Initialize => pv.previous_init_addr_bits.map(|f| f.as_canonical_u32()), + MemoryChipType::Finalize => { + pv.previous_finalize_addr_bits.map(|f| f.as_canonical_u32()) + } + }; + memory_events.sort_by_key(|event| event.addr); let rows: Vec<[F; NUM_MEMORY_INIT_COLS]> = (0..memory_events.len()) // OPT: change this to par_iter .map(|i| { @@ -93,25 +108,34 @@ impl MachineAir for MemoryChip { cols.value = array::from_fn(|i| F::from_canonical_u32((value >> i) & 1)); cols.is_real = F::from_canonical_u32(used); - if i != memory_events.len() - 1 { - let next_addr = memory_events[i + 1].addr; - assert_ne!(next_addr, addr); - - cols.addr_bits.populate(addr); - - cols.seen_diff_bits[0] = F::zero(); - for j in 0..32 { - let rev_j = 32 - j - 1; - let next_bit = ((next_addr >> rev_j) & 1) == 1; - let local_bit = ((addr >> rev_j) & 1) == 1; - cols.match_bits[j] = - F::from_bool((local_bit && next_bit) || (!local_bit && !next_bit)); - cols.seen_diff_bits[j + 1] = cols.seen_diff_bits[j] - + (F::one() - cols.seen_diff_bits[j]) * (F::one() - cols.match_bits[j]); - cols.not_match_and_not_seen_diff_bits[j] = - (F::one() - cols.match_bits[j]) * (F::one() - cols.seen_diff_bits[j]); + if i == 0 { + let prev_addr = previous_addr_bits + .iter() + .enumerate() + .map(|(j, bit)| bit * (1 << j)) + .sum::(); + cols.is_prev_addr_zero.populate(prev_addr); + cols.is_first_comp = F::from_bool(prev_addr != 0); + if prev_addr != 0 { + debug_assert!(prev_addr < addr, "prev_addr {} < addr {}", prev_addr, addr); + let addr_bits: [_; 32] = array::from_fn(|i| (addr >> i) & 1); + cols.lt_cols.populate(&previous_addr_bits, &addr_bits); } - assert_eq!(cols.seen_diff_bits[cols.seen_diff_bits.len() - 1], F::one()); + } + + if i != 0 { + let prev_is_real = memory_events[i - 1].used; + cols.is_next_comp = F::from_canonical_u32(prev_is_real); + let previous_addr = memory_events[i - 1].addr; + assert_ne!(previous_addr, addr); + + let addr_bits: [_; 32] = array::from_fn(|i| (addr >> i) & 1); + let prev_addr_bits: [_; 32] = array::from_fn(|i| (previous_addr >> i) & 1); + cols.lt_cols.populate(&prev_addr_bits, &addr_bits); + } + + if i == memory_events.len() - 1 { + cols.is_last_addr = F::one(); } row @@ -148,30 +172,36 @@ pub struct MemoryInitCols { /// The address of the memory access. pub addr: T, + /// Comparison assertions for address to be strictly increasing. + pub lt_cols: AssertLtColsBits, + /// A bit decomposition of `addr`. pub addr_bits: BabyBearBitDecomposition, - // Whether the i'th bit matches the next addr's bit. - pub match_bits: [T; 32], - - // Whether we've seen a different bit in the comparison. - pub seen_diff_bits: [T; 33], - - // Whether the i'th bit doesn't match the next addr's bit and we haven't seen a diff bitn yet. - pub not_match_and_not_seen_diff_bits: [T; 32], - /// The value of the memory access. pub value: [T; 32], /// Whether the memory access is a real access. pub is_real: T, + + /// Whether or not we are making the assertion `addr < addr_next`. + pub is_next_comp: T, + + /// A witness to assert whether or not we the previous address is zero. + pub is_prev_addr_zero: IsZeroOperation, + + /// Auxilary column, equal to `(1 - is_prev_addr_zero.result) * is_first_row`. + pub is_first_comp: T, + + /// A flag to inidicate the last non-padded address. An auxiliary column needed for degree 3. + pub is_last_addr: T, } pub(crate) const NUM_MEMORY_INIT_COLS: usize = size_of::>(); -impl Air for MemoryChip +impl Air for MemoryChip where - AB: BaseAirBuilder, + AB: AirBuilderWithPublicValues + BaseAirBuilder, { fn eval(&self, builder: &mut AB) { let main = builder.main(); @@ -219,76 +249,6 @@ where )); } - // We want to assert addr < addr'. Assume seen_diff_0 = 0. - // - // match_i = (addr_i & addr'_i) || (!addr_i & !addr'_i) - // => - // match_i == addr_i * addr_i + (1 - addr_i) * (1 - addr'_i) - // - // when !match_i and !seen_diff_i, then enforce (addr_i == 0) and (addr'_i == 1). - // if seen_diff_i: - // seen_diff_{i+1} = 1 - // else: - // seen_diff_{i+1} = !match_i - // => - // builder.when(!match_i * !seen_diff_i).assert_zero(addr_i) - // builder.when(!match_i * !seen_diff_i).assert_one(addr'_i) - // seen_diff_bit_{i+1} == seen_diff_i + (1-seen_diff_i) * (1 - match_i) - // - // at the end of the algorithm, assert that we've seen a diff bit. - // => - // seen_diff_bit_{last} == 1 - - // Assert that we start with assuming that we haven't seen a diff bit. - builder.assert_zero(local.seen_diff_bits[0]); - - for i in 0..local.addr_bits.bits.len() { - // Compute the i'th msb bit's index. - let rev_i = local.addr_bits.bits.len() - i - 1; - - // Compute whether the i'th msb bit matches. - let match_i = local.addr_bits.bits[rev_i] * next.addr_bits.bits[rev_i] - + (AB::Expr::one() - local.addr_bits.bits[rev_i]) - * (AB::Expr::one() - next.addr_bits.bits[rev_i]); - builder - .when_transition() - .when(next.is_real) - .assert_eq(match_i.clone(), local.match_bits[i]); - - // Compute whether it's not a match and we haven't seen a diff bit. - let not_match_and_not_seen_diff_i = (AB::Expr::one() - local.match_bits[i]) - * (AB::Expr::one() - local.seen_diff_bits[i]); - builder.when_transition().when(next.is_real).assert_eq( - local.not_match_and_not_seen_diff_bits[i], - not_match_and_not_seen_diff_i, - ); - - // If the i'th msb bit doesn't match and it's the first time we've seen a diff bit, - // then enforce that the next bit is one and the current bit is zero. - builder - .when_transition() - .when(local.not_match_and_not_seen_diff_bits[i]) - .when(next.is_real) - .assert_zero(local.addr_bits.bits[rev_i]); - builder - .when_transition() - .when(local.not_match_and_not_seen_diff_bits[i]) - .when(next.is_real) - .assert_one(next.addr_bits.bits[rev_i]); - - // Update the seen diff bits. - builder.when_transition().assert_eq( - local.seen_diff_bits[i + 1], - local.seen_diff_bits[i] + local.not_match_and_not_seen_diff_bits[i], - ); - } - - // Assert that on rows where the next row is real, we've seen a diff bit. - builder - .when_transition() - .when(next.is_real) - .assert_one(local.seen_diff_bits[local.addr_bits.bits.len()]); - // Canonically decompose the address into bits so we can do comparisons. BabyBearBitDecomposition::::range_check( builder, @@ -297,28 +257,156 @@ where local.is_real.into(), ); + // Assertion for increasing address. We need to make two types of less-than assertions, + // first we ned to assert that the addr < addr' when the next row is real. Then we need to + // make assertions with regards to public values. + // + // If the chip is a `MemoryInit`: + // - In the first row, we need to assert that previous_init_addr < addr. + // - In the last real row, we need to assert that addr = last_init_addr. + // + // If the chip is a `MemoryFinalize`: + // - In the first row, we need to assert that previous_finalize_addr < addr. + // - In the last real row, we need to assert that addr = last_finalize_addr. + + // Assert that addr < addr' when the next row is real. + builder + .when_transition() + .assert_eq(next.is_next_comp, next.is_real); + next.lt_cols.eval( + builder, + &local.addr_bits.bits, + &next.addr_bits.bits, + &next.is_next_comp, + ); + // Assert that the real rows are all padded to the top. builder .when_transition() .when_not(local.is_real) .assert_zero(next.is_real); + // Make assertions for the initial comparison. + + // We want to constrain that the `adrr` in the first row is larger than the previous + // initialized/finalized address, unless the previous address is zero. Since the previous + // address is either zero or constrained by a different shard, we know it's an element of + // the field, so we can get an element from the bit decomposition with no concern for + // overflow. + + let local_addr_bits = local.addr_bits.bits; + + let public_values_array: [AB::Expr; SPHINX_PROOF_NUM_PV_ELTS] = + array::from_fn(|i| builder.public_values()[i].into()); + let public_values: &PublicValues, AB::Expr> = + public_values_array.as_slice().borrow(); + + let prev_addr_bits = match self.kind { + MemoryChipType::Initialize => &public_values.previous_init_addr_bits, + MemoryChipType::Finalize => &public_values.previous_finalize_addr_bits, + }; + + // Since the previous address is either zero or constrained by a different shard, we know + // it's an element of the field, so we can get an element from the bit decomposition with + // no concern for overflow. + let prev_addr = prev_addr_bits + .iter() + .enumerate() + .map(|(i, bit)| bit.clone() * AB::F::from_wrapped_u32(1 << i)) + .sum::(); + + // Constrain the is_prev_addr_zero operation only in the first row. + let is_first_row = builder.is_first_row(); + IsZeroOperation::::eval(builder, prev_addr, local.is_prev_addr_zero, is_first_row); + + // Constrain the is_first_comp column. + builder.assert_bool(local.is_first_comp); + builder.when_first_row().assert_eq( + local.is_first_comp, + AB::Expr::one() - local.is_prev_addr_zero.result, + ); + + // Ensure at least one real row. + builder.when_first_row().assert_one(local.is_real); + + // Constrain the inequality assertion in the first row. + local.lt_cols.eval( + builder, + prev_addr_bits, + &local_addr_bits, + &local.is_first_comp, + ); + + // Insure that there are no duplicate initializations by assuring there is exactly one + // initialization event of the zero address. This is done by assuring that when the previous + // address is zero, then the first row address is also zero, and that the second row is also + // real, and the less than comparison is being made. + builder + .when_first_row() + .when(local.is_prev_addr_zero.result) + .assert_zero(local.addr); + builder + .when_first_row() + .when(local.is_prev_addr_zero.result) + .assert_one(next.is_real); + // Ensure that in the address zero case the comparison is being made so that there is an + // address bigger than zero being committed to. + builder + .when_first_row() + .when(local.is_prev_addr_zero.result) + .assert_one(next.is_next_comp); + + // Make assertions for specific types of memory chips. + if self.kind == MemoryChipType::Initialize { builder .when(local.is_real) .assert_eq(local.timestamp, AB::F::one()); } + // Constraints related to register %x0. + // Register %x0 should always be 0. See 2.6 Load and Store Instruction on - // P.18 of the RISC-V spec. To ensure that, we expect that the first row of the Initialize - // and Finalize global memory chip is for register %x0 (i.e. addr = 0x0), and that those rows - // have a value of 0. Additionally, in the CPU air, we ensure that whenever op_a is set to - // %x0, its value is 0. - if self.kind == MemoryChipType::Initialize || self.kind == MemoryChipType::Finalize { - builder.when_first_row().assert_zero(local.addr); - for i in 0..32 { - builder.when_first_row().assert_zero(local.value[i]); - } + // P.18 of the RISC-V spec. To ensure that, we will constain that the value is zero + // whenever the `is_first_comp` flag is set to to zero as well. This guarantees that the + // presence of this flag asserts the initialization/finalization of %x0 to zero. + // + // **Remark**: it is up to the verifier to ensure that this flag is set to zero exactly + // once, this can be constrained by the public values setting `previous_init_addr_bits` or + // `previous_finalize_addr_bits` to zero. + for i in 0..32 { + builder + .when_first_row() + .when_not(local.is_first_comp) + .assert_zero(local.value[i]); + } + + // Make assertions for the final value. We need to connect the final valid address to the + // correspinding `last_addr` value. + let last_addr_bits = match self.kind { + MemoryChipType::Initialize => &public_values.last_init_addr_bits, + MemoryChipType::Finalize => &public_values.last_finalize_addr_bits, + }; + // The last address is either: + // - It's the last row and `is_real` is set to one. + // - The flag `is_real` is set to one and the next `is_real` is set to zero. + + // Constrain the `is_last_addr` flag. + builder.when_transition().assert_eq( + local.is_last_addr, + local.is_real * (AB::Expr::one() - next.is_real), + ); + + // Constrain the last address bits to be equal to the corresponding `last_addr_bits` value. + for (local_bit, pub_bit) in local.addr_bits.bits.iter().zip(last_addr_bits.iter()) { + builder + .when_last_row() + .when(local.is_real) + .assert_eq(*local_bit, pub_bit.clone()); + builder + .when_transition() + .when(local.is_last_addr) + .assert_eq(*local_bit, pub_bit.clone()); } } } @@ -330,11 +418,9 @@ mod tests { use crate::lookup::{debug_interactions_with_all_chips, InteractionKind}; use crate::runtime::tests::simple_program; use crate::runtime::Runtime; - use crate::stark::MachineRecord; - use crate::stark::{RiscvAir, StarkGenericConfig}; + use crate::stark::RiscvAir; use crate::syscall::precompiles::sha256::extend_tests::sha_extend_program; use crate::utils::{setup_logger, BabyBearPoseidon2, SphinxCoreOpts}; - use crate::utils::{uni_stark_prove as prove, uni_stark_verify as verify}; use p3_baby_bear::BabyBear; #[test] @@ -344,13 +430,13 @@ mod tests { runtime.run().unwrap(); let shard = runtime.record.clone(); - let chip: MemoryChip = MemoryChip::new(MemoryChipType::Initialize); + let chip: MemoryChip = MemoryChip::new(MemoryChipType::Initialize); let trace: RowMajorMatrix = chip.generate_trace(&shard, &mut ExecutionRecord::default()); println!("{:?}", trace.values); - let chip: MemoryChip = MemoryChip::new(MemoryChipType::Finalize); + let chip: MemoryChip = MemoryChip::new(MemoryChipType::Finalize); let trace: RowMajorMatrix = chip.generate_trace(&shard, &mut ExecutionRecord::default()); println!("{:?}", trace.values); @@ -360,25 +446,6 @@ mod tests { } } - #[test] - fn test_memory_prove_babybear() { - let config = BabyBearPoseidon2::new(); - let mut challenger = config.challenger(); - - let program = simple_program(); - let mut runtime = Runtime::new(program, SphinxCoreOpts::default()); - runtime.run().unwrap(); - - let chip = MemoryChip::new(MemoryChipType::Initialize); - - let trace: RowMajorMatrix = - chip.generate_trace(&runtime.record, &mut ExecutionRecord::default()); - let proof = prove::(&config, &chip, &mut challenger, trace); - - let mut challenger = config.challenger(); - verify(&config, &chip, &mut challenger, &proof).unwrap(); - } - #[test] fn test_memory_lookup_interactions() { setup_logger(); @@ -389,11 +456,11 @@ mod tests { let machine: crate::stark::StarkMachine> = RiscvAir::machine(BabyBearPoseidon2::new()); let (pkey, _) = machine.setup(&program_clone); - let shards = machine.shard( - runtime.record, - &::Config::default(), - ); - assert_eq!(shards.len(), 1); + let opts = SphinxCoreOpts::default(); + machine.generate_dependencies(&mut runtime.records, &opts); + + let shards = runtime.records; + assert_eq!(shards.len(), 2); debug_interactions_with_all_chips::>( &machine, &pkey, @@ -411,11 +478,11 @@ mod tests { runtime.run().unwrap(); let machine = RiscvAir::machine(BabyBearPoseidon2::new()); let (pkey, _) = machine.setup(&program_clone); - let shards = machine.shard( - runtime.record, - &::Config::default(), - ); - assert_eq!(shards.len(), 1); + let opts = SphinxCoreOpts::default(); + machine.generate_dependencies(&mut runtime.records, &opts); + + let shards = runtime.records; + assert_eq!(shards.len(), 2); debug_interactions_with_all_chips::>( &machine, &pkey, diff --git a/core/src/memory/mod.rs b/core/src/memory/mod.rs index 4246db14c..90198d541 100644 --- a/core/src/memory/mod.rs +++ b/core/src/memory/mod.rs @@ -26,7 +26,7 @@ impl MemoryInitializeFinalizeEvent { Self { addr, value, - shard: 0, + shard: 1, timestamp: 1, used: if used { 1 } else { 0 }, } diff --git a/core/src/memory/program.rs b/core/src/memory/program.rs index 16298154a..ff706e1f4 100644 --- a/core/src/memory/program.rs +++ b/core/src/memory/program.rs @@ -1,15 +1,17 @@ use core::borrow::{Borrow, BorrowMut}; use core::mem::size_of; use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, PairBuilder}; -use p3_field::AbstractField; -use p3_field::PrimeField; +use p3_field::{AbstractField, PrimeField32}; use p3_matrix::dense::RowMajorMatrix; use p3_matrix::Matrix; use std::collections::BTreeMap; +use std::marker::PhantomData; use sphinx_derive::AlignedBorrow; -use crate::air::{AirInteraction, BaseAirBuilder, EventLens, PublicValues, WithEvents}; +use crate::air::{ + AirInteraction, BaseAirBuilder, EventLens, PublicValues, WithEvents, SPHINX_PROOF_NUM_PV_ELTS, +}; use crate::air::{MachineAir, Word}; use crate::operations::IsZeroOperation; use crate::runtime::{ExecutionRecord, Program}; @@ -45,19 +47,19 @@ pub struct MemoryProgramMultCols { /// receives each row in the first shard. This prevents any of these addresses from being /// overwritten through the normal MemoryInit. #[derive(Default)] -pub struct MemoryProgramChip; +pub struct MemoryProgramChip(PhantomData); -impl MemoryProgramChip { - pub const fn new() -> Self { - Self {} +impl MemoryProgramChip { + pub fn new() -> Self { + Self(PhantomData) } } -impl<'a> WithEvents<'a> for MemoryProgramChip { - type Events = &'a BTreeMap; +impl<'a, F: 'a> WithEvents<'a> for MemoryProgramChip { + type Events = (&'a BTreeMap, PublicValues, F>); } -impl MachineAir for MemoryProgramChip { +impl MachineAir for MemoryProgramChip { type Record = ExecutionRecord; type Program = Program; @@ -111,9 +113,10 @@ impl MachineAir for MemoryProgramChip { input: &EL, _output: &mut ExecutionRecord, ) -> RowMajorMatrix { - let program_memory_addrs = input.events().keys().copied().collect::>(); + let (events, pv) = input.events(); + let program_memory_addrs = events.keys().copied().collect::>(); - let mult = if input.index() == 1 { + let mult = if pv.shard == F::one() { F::one() } else { F::zero() @@ -126,7 +129,8 @@ impl MachineAir for MemoryProgramChip { let mut row = [F::zero(); NUM_MEMORY_PROGRAM_MULT_COLS]; let cols: &mut MemoryProgramMultCols = row.as_mut_slice().borrow_mut(); cols.multiplicity = mult; - cols.is_first_shard.populate(input.index() - 1); + cols.is_first_shard + .populate(pv.shard.as_canonical_u32() - 1); row }) .collect::>(); @@ -148,13 +152,13 @@ impl MachineAir for MemoryProgramChip { } } -impl BaseAir for MemoryProgramChip { +impl BaseAir for MemoryProgramChip { fn width(&self) -> usize { NUM_MEMORY_PROGRAM_MULT_COLS } } -impl Air for MemoryProgramChip +impl Air for MemoryProgramChip where AB: BaseAirBuilder + PairBuilder + AirBuilderWithPublicValues, { @@ -169,18 +173,15 @@ where let mult_local: &MemoryProgramMultCols = (*mult_local).borrow(); // Get shard from public values and evaluate whether it is the first shard. - let public_values = PublicValues::, AB::Expr>::from_vec( - &builder - .public_values() - .iter() - .map(|elm| (*elm).into()) - .collect::>(), - ); + let public_values_slice: [AB::Expr; SPHINX_PROOF_NUM_PV_ELTS] = + core::array::from_fn(|i| builder.public_values()[i].into()); + let public_values: &PublicValues, AB::Expr> = + public_values_slice.as_slice().borrow(); // Constrain `is_first_shard` to be 1 if and only if the shard is the first shard. IsZeroOperation::::eval( builder, - public_values.shard - AB::F::one(), + public_values.shard.clone() - AB::F::one(), mult_local.is_first_shard, prep_local.is_real.into(), ); diff --git a/core/src/operations/and.rs b/core/src/operations/and.rs index a803dfdaa..69f781bfd 100644 --- a/core/src/operations/and.rs +++ b/core/src/operations/and.rs @@ -7,7 +7,6 @@ use crate::bytes::event::ByteRecord; use crate::bytes::ByteLookupEvent; use crate::bytes::ByteOpcode; use crate::disassembler::WORD_SIZE; -use crate::runtime::ExecutionRecord; /// A set of columns needed to compute the and of two words. #[derive(AlignedBorrow, Default, Debug, Clone, Copy)] @@ -20,7 +19,7 @@ pub struct AndOperation { impl AndOperation { pub fn populate( &mut self, - record: &mut ExecutionRecord, + record: &mut impl ByteRecord, shard: u32, channel: u32, x: u32, diff --git a/core/src/operations/is_zero.rs b/core/src/operations/is_zero.rs index d9187a507..2fc401691 100644 --- a/core/src/operations/is_zero.rs +++ b/core/src/operations/is_zero.rs @@ -38,17 +38,13 @@ impl IsZeroOperation { u32::from(a == F::zero()) } - pub fn eval, Ea, Ereal>( + pub fn eval>( builder: &mut AB, - a: Ea, + a: AB::Expr, cols: IsZeroOperation, - is_real: Ereal, - ) where - Ea: Into, - Ereal: Into, - { - let mut builder_is_real = builder.when(is_real.into()); - let a = a.into(); + is_real: AB::Expr, + ) { + let mut builder_is_real = builder.when(is_real); // 1. Input == 0 => is_zero = 1 regardless of the inverse. // 2. Input != 0 diff --git a/core/src/operations/lt.rs b/core/src/operations/lt.rs new file mode 100644 index 000000000..50fee7955 --- /dev/null +++ b/core/src/operations/lt.rs @@ -0,0 +1,251 @@ +use itertools::izip; + +use p3_air::AirBuilder; +use p3_field::AbstractField; +use p3_field::PrimeField32; + +use sphinx_derive::AlignedBorrow; + +use crate::air::BaseAirBuilder; +use crate::{ + bytes::{event::ByteRecord, ByteLookupEvent, ByteOpcode}, + stark::SphinxAirBuilder, +}; + +/// Operation columns for verifying that an element is within the range `[0, modulus)`. +#[derive(Debug, Clone, Copy, AlignedBorrow)] +#[repr(C)] +pub struct AssertLtColsBytes { + /// Boolean flags to indicate the first byte in which the element is smaller than the modulus. + pub(crate) byte_flags: [T; N], + + pub(crate) a_comparison_byte: T, + pub(crate) b_comparison_byte: T, +} + +impl AssertLtColsBytes { + pub fn populate( + &mut self, + record: &mut impl ByteRecord, + shard: u32, + channel: u32, + a: &[u8], + b: &[u8], + ) { + let mut byte_flags = vec![0u8; N]; + + for (a_byte, b_byte, flag) in + izip!(a.iter().rev(), b.iter().rev(), byte_flags.iter_mut().rev()) + { + assert!(a_byte <= b_byte); + if a_byte < b_byte { + *flag = 1; + self.a_comparison_byte = F::from_canonical_u8(*a_byte); + self.b_comparison_byte = F::from_canonical_u8(*b_byte); + record.add_byte_lookup_event(ByteLookupEvent { + opcode: ByteOpcode::LTU, + shard, + channel, + a1: 1, + a2: 0, + b: u32::from(*a_byte), + c: u32::from(*b_byte), + }); + break; + } + } + + for (byte, flag) in izip!(byte_flags.iter(), self.byte_flags.iter_mut()) { + *flag = F::from_canonical_u8(*byte); + } + } +} + +impl AssertLtColsBytes { + pub fn eval< + AB: SphinxAirBuilder, + Ea: Into + Clone, + Eb: Into + Clone, + >( + &self, + builder: &mut AB, + a: &[Ea], + b: &[Eb], + shard: impl Into + Clone, + channel: impl Into + Clone, + is_real: impl Into + Clone, + ) where + V: Into, + { + // The byte flags give a specification of which byte is `first_eq`, i,e, the first most + // significant byte for which the element `a` is smaller than `b`. To verify the + // less-than claim we need to check that: + // * For all bytes until `first_eq` the element `a` byte is equal to the `b` byte. + // * For the `first_eq` byte the `a`` byte is smaller than the `b`byte. + // * all byte flags are boolean. + // * only one byte flag is set to one, and the rest are set to zero. + + // Check the flags are of valid form. + + // Verrify that only one flag is set to one. + let mut sum_flags: AB::Expr = AB::Expr::zero(); + for &flag in self.byte_flags.iter() { + // Assert that the flag is boolean. + builder.assert_bool(flag); + // Add the flag to the sum. + sum_flags += flag.into(); + } + // Assert that the sum is equal to one. + builder.when(is_real.clone()).assert_one(sum_flags); + + // Check the less-than condition. + + // A flag to indicate whether an equality check is necessary (this is for all bytes from + // most significant until the first inequality. + let mut is_inequality_visited = AB::Expr::zero(); + + // The bytes of the modulus. + + let a: [AB::Expr; N] = core::array::from_fn(|i| a[i].clone().into()); + let b: [AB::Expr; N] = core::array::from_fn(|i| b[i].clone().into()); + + let mut first_lt_byte = AB::Expr::zero(); + let mut b_comparison_byte = AB::Expr::zero(); + for (a_byte, b_byte, &flag) in + izip!(a.iter().rev(), b.iter().rev(), self.byte_flags.iter().rev()) + { + // Once the byte flag was set to one, we turn off the quality check flag. + // We can do this by calculating the sum of the flags since only `1` is set to `1`. + is_inequality_visited += flag.into(); + + first_lt_byte += a_byte.clone() * flag; + b_comparison_byte += b_byte.clone() * flag; + + builder + .when_not(is_inequality_visited.clone()) + .when(is_real.clone()) + .assert_eq(a_byte.clone(), b_byte.clone()); + } + + builder + .when(is_real.clone()) + .assert_eq(self.a_comparison_byte, first_lt_byte); + builder + .when(is_real.clone()) + .assert_eq(self.b_comparison_byte, b_comparison_byte); + + // Send the comparison interaction. + builder.send_byte( + ByteOpcode::LTU.as_field::(), + AB::F::one(), + self.a_comparison_byte, + self.b_comparison_byte, + shard, + channel, + is_real, + ) + } +} + +/// Operation columns for verifying that an element is within the range `[0, modulus)`. +#[derive(Debug, Clone, Copy, AlignedBorrow)] +#[repr(C)] +pub struct AssertLtColsBits { + /// Boolean flags to indicate the first byte in which the element is smaller than the modulus. + pub(crate) bit_flags: [T; N], +} + +impl AssertLtColsBits { + pub fn populate(&mut self, a: &[u32], b: &[u32]) { + let mut bit_flags = vec![0u8; N]; + + for (a_bit, b_bit, flag) in + izip!(a.iter().rev(), b.iter().rev(), bit_flags.iter_mut().rev()) + { + assert!(a_bit <= b_bit); + debug_assert!(*a_bit == 0 || *a_bit == 1); + debug_assert!(*b_bit == 0 || *b_bit == 1); + if a_bit < b_bit { + *flag = 1; + break; + } + } + + for (bit, flag) in izip!(bit_flags.iter(), self.bit_flags.iter_mut()) { + *flag = F::from_canonical_u8(*bit); + } + } +} + +impl AssertLtColsBits { + pub fn eval< + AB: BaseAirBuilder, + Ea: Into + Clone, + Eb: Into + Clone, + >( + &self, + builder: &mut AB, + a: &[Ea], + b: &[Eb], + is_real: &(impl Into + Clone), + ) where + V: Into, + { + // The bit flags give a specification of which bit is `first_lt`, i,e, the first most + // significant bit for which the element `a` is smaller than `b`. To verify the + // less-than claim we need to check that: + // * For all bytes until `first_lt` the element `a` byte is equal to the `b` byte. + // * For the `first_lt` bit the `a`` bit is smaller than the `b` bit. + // * all bit flags are boolean. + // * only one bit flag is set to one, and the rest are set to zero. + + // Check the flags are of valid form. + + // Verrify that only one flag is set to one. + let mut sum_flags: AB::Expr = AB::Expr::zero(); + for &flag in self.bit_flags.iter() { + // Assert that the flag is boolean. + builder.assert_bool(flag); + // Add the flag to the sum. + sum_flags += flag.into(); + } + // Assert that the sum is equal to one. + builder.when(is_real.clone()).assert_one(sum_flags); + + // Check the less-than condition. + + // A flag to indicate whether an equality check is necessary (this is for all bits from + // most significant until the first inequality. + let mut is_inequality_visited = AB::Expr::zero(); + + // The bits of the elements. + let a: [AB::Expr; N] = core::array::from_fn(|i| a[i].clone().into()); + let b: [AB::Expr; N] = core::array::from_fn(|i| b[i].clone().into()); + + // Calculate the bit which is the first inequality. + let mut a_comparison_bit = AB::Expr::zero(); + let mut b_comparison_bit = AB::Expr::zero(); + for (a_bit, b_bit, &flag) in + izip!(a.iter().rev(), b.iter().rev(), self.bit_flags.iter().rev()) + { + // Once the bit flag was set to one, we turn off the quality check flag. + // We can do this by calculating the sum of the flags since only `1` is set to `1`. + is_inequality_visited += flag.into(); + + a_comparison_bit += a_bit.clone() * flag; + b_comparison_bit += b_bit.clone() * flag; + + builder + .when(is_real.clone()) + .when_not(is_inequality_visited.clone()) + .assert_eq(a_bit.clone(), b_bit.clone()); + } + + builder + .when(is_real.clone()) + .assert_eq(a_comparison_bit, AB::F::zero()); + builder + .when(is_real.clone()) + .assert_eq(b_comparison_bit, AB::F::one()); + } +} diff --git a/core/src/operations/mod.rs b/core/src/operations/mod.rs index e3fbcc78b..394daf906 100644 --- a/core/src/operations/mod.rs +++ b/core/src/operations/mod.rs @@ -16,6 +16,7 @@ mod fixed_shift_right; mod is_equal_word; mod is_zero; mod is_zero_word; +mod lt; mod not; mod or; mod xor; @@ -31,6 +32,7 @@ pub use fixed_shift_right::*; pub use is_equal_word::*; pub use is_zero::*; pub use is_zero_word::*; +pub use lt::*; pub use not::*; pub use or::*; pub use xor::*; diff --git a/core/src/program/mod.rs b/core/src/program/mod.rs index db54778c3..532373dcd 100644 --- a/core/src/program/mod.rs +++ b/core/src/program/mod.rs @@ -3,6 +3,7 @@ use core::{ mem::size_of, }; use hashbrown::HashMap; +use std::marker::PhantomData; use p3_air::{Air, BaseAir, PairBuilder}; use p3_field::PrimeField; @@ -10,7 +11,7 @@ use p3_matrix::{dense::RowMajorMatrix, Matrix}; use sphinx_derive::AlignedBorrow; use crate::{ - air::{EventLens, MachineAir, ProgramAirBuilder, WithEvents}, + air::{EventLens, MachineAir, ProgramAirBuilder, PublicValues, WithEvents, Word}, cpu::{ columns::{InstructionCols, OpcodeSelectorCols}, CpuEvent, @@ -44,24 +45,26 @@ pub struct ProgramMultiplicityCols { /// A chip that implements addition for the opcodes ADD and ADDI. #[derive(Default)] -pub struct ProgramChip; +pub struct ProgramChip(PhantomData); -impl ProgramChip { - pub const fn new() -> Self { - Self {} +impl ProgramChip { + pub fn new() -> Self { + Self(PhantomData) } } -impl<'a> WithEvents<'a> for ProgramChip { +impl<'a, F: 'a> WithEvents<'a> for ProgramChip { type Events = ( // CPU events &'a [CpuEvent], // the Program &'a Program, + // the public values + PublicValues, F>, ); } -impl MachineAir for ProgramChip { +impl MachineAir for ProgramChip { type Record = ExecutionRecord; type Program = Program; @@ -75,6 +78,7 @@ impl MachineAir for ProgramChip { } fn generate_preprocessed_trace(&self, program: &Self::Program) -> Option> { + debug_assert!(!program.instructions.is_empty(), "empty program"); let rows = program .instructions .clone() @@ -119,7 +123,7 @@ impl MachineAir for ProgramChip { ) -> RowMajorMatrix { // Generate the trace rows for each event. - let (cpu_events, program) = input.events(); + let (cpu_events, program, pv) = input.events(); // Collect the number of times each instruction is called from the cpu events. // Store it as a map of PC -> count. let mut instruction_counts = HashMap::new(); @@ -140,7 +144,7 @@ impl MachineAir for ProgramChip { let pc = program.pc_base + (i as u32 * 4); let mut row = [F::zero(); NUM_PROGRAM_MULT_COLS]; let cols: &mut ProgramMultiplicityCols = row.as_mut_slice().borrow_mut(); - cols.shard = F::from_canonical_u32(input.index()); + cols.shard = pv.execution_shard; cols.multiplicity = F::from_canonical_usize(*instruction_counts.get(&pc).unwrap_or(&0)); row @@ -164,13 +168,13 @@ impl MachineAir for ProgramChip { } } -impl BaseAir for ProgramChip { +impl BaseAir for ProgramChip { fn width(&self) -> usize { NUM_PROGRAM_MULT_COLS } } -impl Air for ProgramChip +impl Air for ProgramChip where AB: ProgramAirBuilder + PairBuilder, { diff --git a/core/src/runtime/context.rs b/core/src/runtime/context.rs index 4fad2f5f3..8f400f476 100644 --- a/core/src/runtime/context.rs +++ b/core/src/runtime/context.rs @@ -7,9 +7,15 @@ use super::{hookify, BoxedHook, HookEnv, HookRegistry, SubproofVerifier}; #[derive(Clone, Default)] pub struct SphinxContext<'a> { /// The registry of hooks invokable from inside SP1. - /// `None` denotes the default list of hooks. + /// + /// Note: `None` denotes the default list of hooks. pub hook_registry: Option>, + + /// The verifier for verifying subproofs. pub subproof_verifier: Option>, + + /// The maximum number of cpu cycles to use for execution. + pub max_cycles: Option, } #[derive(Clone, Default)] @@ -17,6 +23,7 @@ pub struct SphinxContextBuilder<'a> { no_default_hooks: bool, hook_registry_entries: Vec<(u32, BoxedHook<'a>)>, subproof_verifier: Option>, + max_cycles: Option, } impl<'a> SphinxContext<'a> { @@ -52,9 +59,11 @@ impl<'a> SphinxContextBuilder<'a> { HookRegistry { table } }); let subproof_verifier = take(&mut self.subproof_verifier); + let cycle_limit = take(&mut self.max_cycles); SphinxContext { hook_registry, subproof_verifier, + max_cycles: cycle_limit, } } @@ -91,6 +100,12 @@ impl<'a> SphinxContextBuilder<'a> { self.subproof_verifier = Some(subproof_verifier); self } + + /// Set the maximum number of cpu cycles to use for execution. + pub fn max_cycles(&mut self, max_cycles: u64) -> &mut Self { + self.max_cycles = Some(max_cycles); + self + } } #[cfg(test)] @@ -104,9 +119,11 @@ mod tests { let SphinxContext { hook_registry, subproof_verifier, + max_cycles: cycle_limit, } = SphinxContext::builder().build(); assert!(hook_registry.is_none()); assert!(subproof_verifier.is_none()); + assert!(cycle_limit.is_none()); } #[test] diff --git a/core/src/runtime/hooks.rs b/core/src/runtime/hooks.rs index 50e3c4d84..587da744d 100644 --- a/core/src/runtime/hooks.rs +++ b/core/src/runtime/hooks.rs @@ -131,6 +131,7 @@ pub fn hook_ecrecover(_env: HookEnv<'_, '_>, buf: &[u8]) -> Vec> { pub(crate) mod tests { use crate::{ runtime::Program, + stark::DefaultProver, utils::{self, tests::ECRECOVER_ELF}, }; @@ -138,7 +139,7 @@ pub(crate) mod tests { #[test] pub(crate) fn hook_fds_match() { - use sphinx_zkvm::precompiles::io; + use sphinx_zkvm::lib::io; assert_eq!(FD_ECRECOVER_HOOK, io::FD_ECRECOVER_HOOK) } @@ -157,6 +158,6 @@ pub(crate) mod tests { fn test_ecrecover_program_prove() { utils::setup_logger(); let program = Program::from(ECRECOVER_ELF); - utils::run_test(program).unwrap(); + utils::run_test::>(program).unwrap(); } } diff --git a/core/src/runtime/io.rs b/core/src/runtime/io.rs index a5c132d8c..fcbf467ab 100644 --- a/core/src/runtime/io.rs +++ b/core/src/runtime/io.rs @@ -59,6 +59,7 @@ impl<'a> Runtime<'a> { pub(crate) mod tests { use super::*; use crate::runtime::Program; + use crate::stark::DefaultProver; use crate::utils::tests::IO_ELF; use crate::utils::{self, prove_simple, BabyBearBlake3, SphinxCoreOpts}; use serde::Deserialize; @@ -115,6 +116,6 @@ pub(crate) mod tests { runtime.write_stdin(&points.1); runtime.run().unwrap(); let config = BabyBearBlake3::new(); - prove_simple(config, runtime).unwrap(); + prove_simple::<_, DefaultProver<_, _>>(config, runtime).unwrap(); } } diff --git a/core/src/runtime/mod.rs b/core/src/runtime/mod.rs index 4817a916c..beb4cc5bc 100644 --- a/core/src/runtime/mod.rs +++ b/core/src/runtime/mod.rs @@ -28,8 +28,8 @@ use subproof::{DefaultSubproofVerifier, SubproofVerifier}; pub use syscall::*; pub use utils::*; -use hashbrown::hash_map::Entry; use hashbrown::HashMap; +use std::collections::hash_map::Entry; use std::fs::File; use std::io::BufWriter; use std::io::Write; @@ -58,9 +58,12 @@ pub struct Runtime<'a> { /// The state of the execution. pub state: ExecutionState, - /// The trace of the execution. + /// The current trace of the execution that is being collected. pub record: ExecutionRecord, + /// The collected records, split by cpu cycles. + pub records: Vec, + /// The memory accesses for the current cycle. pub memory_accesses: MemoryAccessRecord, @@ -84,12 +87,16 @@ pub struct Runtime<'a> { /// the unconstrained block. The only thing preserved is writes to the input stream. pub unconstrained: bool, + /// The state of the runtime when in unconstrained mode. pub(crate) unconstrained_state: ForkState, + /// The mapping between syscall codes and their implementations. pub syscall_map: HashMap>, + /// The maximum number of cycles for a syscall. pub max_syscall_cycles: u32, + /// Whether to emit events during execution. pub emit_events: bool, /// Report of the program execution. @@ -103,6 +110,12 @@ pub struct Runtime<'a> { /// Registry of hooks, to be invoked by writing to certain file descriptors. pub hook_registry: HookRegistry<'a>, + + // The options for the runtime. + pub opts: SphinxCoreOpts, + + /// The maximum number of cpu cycles to use for execution. + pub max_cycles: Option, } #[derive(Error, Debug)] @@ -115,6 +128,8 @@ pub enum ExecutionError { UnsupportedSyscall(u32), #[error("breakpoint encountered")] Breakpoint(), + #[error("exceeded cycle limit of {0}")] + ExceededCycleLimit(u64), #[error("got unimplemented as opcode")] Unimplemented(), } @@ -163,6 +178,7 @@ impl<'a> Runtime<'a> { Self { record, + records: vec![], state: ExecutionState::new(program.pc_start), program, memory_accesses: MemoryAccessRecord::default(), @@ -180,6 +196,8 @@ impl<'a> Runtime<'a> { print_report: false, subproof_verifier, hook_registry, + opts, + max_cycles: context.max_cycles, } } @@ -198,13 +216,9 @@ impl<'a> Runtime<'a> { } /// Recover runtime state from a program and existing execution state. - pub fn recover(program: Program, state: ExecutionState, opts: SphinxCoreOpts) -> Self { - let mut runtime = Self::new(program, opts); + pub fn recover(program: &Program, state: ExecutionState, opts: SphinxCoreOpts) -> Self { + let mut runtime = Self::new(program.clone(), opts); runtime.state = state; - let index: u32 = (runtime.state.global_clk / u64::from(runtime.shard_size / 4)) - .try_into() - .unwrap(); - runtime.record.index = index + 1; runtime } @@ -434,8 +448,8 @@ impl<'a> Runtime<'a> { memory_store_value: Option, record: MemoryAccessRecord, exit_code: u32, - lookup_id: usize, - syscall_lookup_id: usize, + lookup_id: u128, + syscall_lookup_id: u128, ) { let cpu_event = CpuEvent { shard, @@ -469,7 +483,7 @@ impl<'a> Runtime<'a> { } /// Emit an ALU event. - fn emit_alu(&mut self, clk: u32, opcode: Opcode, a: u32, b: u32, c: u32, lookup_id: usize) { + fn emit_alu(&mut self, clk: u32, opcode: Opcode, a: u32, b: u32, c: u32, lookup_id: u128) { let event = AluEvent { lookup_id, shard: self.shard(), @@ -540,7 +554,7 @@ impl<'a> Runtime<'a> { a: u32, b: u32, c: u32, - lookup_id: usize, + lookup_id: u128, ) { self.rw(rd, a); if self.emit_events { @@ -868,6 +882,24 @@ impl<'a> Runtime<'a> { next_pc = precompile_next_pc; self.state.clk += precompile_cycles; exit_code = returned_exit_code; + + // Update the syscall counts. + let syscall_count = self.state.syscall_counts.entry(syscall).or_insert(0); + let (threshold, multiplier) = match syscall { + SyscallCode::KECCAK_PERMUTE => { + (self.opts.split_opts.keccak_split_threshold, 24) + } + SyscallCode::SHA_EXTEND => { + (self.opts.split_opts.sha_extend_split_threshold, 48) + } + SyscallCode::SHA_COMPRESS => { + (self.opts.split_opts.sha_compress_split_threshold, 80) + } + _ => (self.opts.split_opts.deferred_shift_threshold, 1), + }; + let nonce = (((*syscall_count as usize) % threshold) * multiplier) as u32; + self.record.nonce_lookup.insert(syscall_lookup_id, nonce); + *syscall_count += 1; } Opcode::EBREAK => { return Err(ExecutionError::Breakpoint()); @@ -993,18 +1025,35 @@ impl<'a> Runtime<'a> { self.state.current_shard += 1; self.state.clk = 0; self.state.channel = 0; + + self.bump_record(); + } + + // If the cycle limit is exceeded, return an error. + if let Some(max_cycles) = self.max_cycles { + if self.state.global_clk >= max_cycles { + return Err(ExecutionError::ExceededCycleLimit(max_cycles)); + } } Ok(self.state.pc.wrapping_sub(self.program.pc_base) >= (self.program.instructions.len() * 4) as u32) } + pub fn bump_record(&mut self) { + let removed_record = + std::mem::replace(&mut self.record, ExecutionRecord::new(self.program.clone())); + let public_values = removed_record.public_values; + self.record.public_values = public_values; + self.records.push(removed_record); + } + /// Execute up to `self.shard_batch_size` cycles, returning the events emitted and whether the program ended. - pub fn execute_record(&mut self) -> Result<(ExecutionRecord, bool), ExecutionError> { + pub fn execute_record(&mut self) -> Result<(Vec, bool), ExecutionError> { self.emit_events = true; self.print_report = true; let done = self.execute()?; - Ok((std::mem::take(&mut self.record), done)) + Ok((std::mem::take(&mut self.records), done)) } /// Execute up to `self.shard_batch_size` cycles, returning a copy of the prestate and whether the program ended. @@ -1058,6 +1107,12 @@ impl<'a> Runtime<'a> { /// Executes up to `self.shard_batch_size` cycles of the program, returning whether the program has finished. fn execute(&mut self) -> Result { + // Get the program. + let program = self.program.clone(); + + // Get the current shard. + let start_shard = self.state.current_shard; + // If it's the first cycle, initialize the program. if self.state.global_clk == 0 { self.initialize(); @@ -1082,8 +1137,41 @@ impl<'a> Runtime<'a> { } } + // Get the final public values. + let public_values = self.record.public_values; + + // Push the remaining execution record, if there are any CPU events. + if !self.record.cpu_events.is_empty() { + self.bump_record(); + } + if done { self.postprocess(); + + // Push the remaining execution record with memory initialize & finalize events. + self.bump_record(); + } + + // Set the global public values for all shards. + let mut last_next_pc = 0; + let mut last_exit_code = 0; + for (i, record) in self.records.iter_mut().enumerate() { + record.program = program.clone(); + record.public_values = public_values; + record.public_values.committed_value_digest = public_values.committed_value_digest; + record.public_values.deferred_proofs_digest = public_values.deferred_proofs_digest; + record.public_values.execution_shard = start_shard + i as u32; + if !record.cpu_events.is_empty() { + record.public_values.start_pc = record.cpu_events[0].pc; + record.public_values.next_pc = record.cpu_events.last().unwrap().next_pc; + record.public_values.exit_code = record.cpu_events.last().unwrap().exit_code; + last_next_pc = record.public_values.next_pc; + last_exit_code = record.public_values.exit_code; + } else { + record.public_values.start_pc = last_next_pc; + record.public_values.next_pc = last_next_pc; + record.public_values.exit_code = last_exit_code; + } } Ok(done) @@ -1111,7 +1199,9 @@ impl<'a> Runtime<'a> { } // Ensure that all proofs and input bytes were read, otherwise warn the user. - assert!(self.state.proof_stream_ptr == self.state.proof_stream.len(), "Not all proofs were read. Proving will fail during recursion. Did you pass too many proofs in or forget to call verify_sp1_proof?"); + assert!(self.state.proof_stream_ptr == self.state.proof_stream.len(), + "Not all proofs were read. Proving will fail during recursion. Did you pass too many proofs in or forget to call verify_sp1_proof?" + ); if self.state.input_stream_ptr != self.state.input_stream.len() { log::warn!("Not all input bytes were read."); } @@ -1177,7 +1267,7 @@ pub mod tests { use crate::{ runtime::Register, utils::{ - tests::{FIBONACCI_ELF, PANIC_ELF, SSZ_WITHDRAWALS_ELF}, + tests::{FIBONACCI_ELF, KECCAK_PERMUTE_ELF, PANIC_ELF}, SphinxCoreOpts, }, }; @@ -1196,7 +1286,7 @@ pub mod tests { } pub fn ssz_withdrawals_program() -> Program { - Program::from(SSZ_WITHDRAWALS_ELF) + Program::from(KECCAK_PERMUTE_ELF) } pub fn panic_program() -> Program { diff --git a/core/src/runtime/record.rs b/core/src/runtime/record.rs index d21c7c28c..977e4ce65 100644 --- a/core/src/runtime/record.rs +++ b/core/src/runtime/record.rs @@ -1,4 +1,6 @@ use hashbrown::HashMap; +use itertools::EitherOrBoth; +use itertools::Itertools; use p3_field::Field; use std::mem::take; use std::sync::Arc; @@ -6,22 +8,34 @@ use std::sync::Arc; use p3_field::AbstractField; use serde::{Deserialize, Serialize}; -use super::{program::Program, Opcode}; +use super::program::Program; +use super::Opcode; +use crate::air::PublicValues; +use crate::air::Word; +use crate::alu::AluEvent; +use crate::bytes::event::add_sharded_byte_lookup_events; +use crate::bytes::event::ByteRecord; +use crate::bytes::ByteLookupEvent; +use crate::cpu::CpuEvent; use crate::runtime::MemoryInitializeFinalizeEvent; use crate::runtime::MemoryRecordEnum; use crate::stark::MachineRecord; +use crate::stark::{ + AddSubChip, BitwiseChip, ByteChip, CpuChip, DivRemChip, Ed25519Parameters, EdAddAssignChip, + EdDecompressChip, KeccakPermuteChip, LtChip, MemoryChip, MulChip, ProgramChip, ShaCompressChip, + ShaExtendChip, ShiftLeft, ShiftRightChip, WeierstrassAddAssignChip, + WeierstrassDoubleAssignChip, +}; use crate::syscall::precompiles::edwards::EdDecompressEvent; use crate::syscall::precompiles::keccak256::KeccakPermuteEvent; use crate::syscall::precompiles::sha256::{ShaCompressEvent, ShaExtendEvent}; use crate::syscall::precompiles::{ECAddEvent, ECDoubleEvent}; use crate::utils::SphinxCoreOpts; use crate::{ - air::{EventLens, PublicValues}, - alu::AluEvent, - bytes::{event::ByteRecord, ByteLookupEvent}, + air::EventLens, memory::MemoryProgramChip, operations::field::params::FieldParameters, - stark::Indexed, + stark::PublicValued, syscall::precompiles::{ bls12_381::{ g1_decompress::{Bls12381G1DecompressChip, Bls12381G1DecompressEvent}, @@ -41,23 +55,12 @@ use crate::{ }, }, }; -use crate::{ - cpu::CpuEvent, - stark::{ - AddSubChip, BitwiseChip, ByteChip, CpuChip, DivRemChip, Ed25519Parameters, EdAddAssignChip, - EdDecompressChip, KeccakPermuteChip, LtChip, MemoryChip, MulChip, ProgramChip, - ShaCompressChip, ShaExtendChip, ShiftLeft, ShiftRightChip, WeierstrassAddAssignChip, - WeierstrassDoubleAssignChip, - }, -}; -/// A record of the execution of a program. Contains event data for everything that happened during -/// the execution of the shard. +/// A record of the execution of a program. +/// +/// The trace of the execution is represented as a list of "events" that occur every cycle. #[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct ExecutionRecord { - /// The index of the shard. - pub index: u32, - /// The program. pub program: Arc, @@ -132,7 +135,7 @@ pub struct ExecutionRecord { /// The public values. pub public_values: PublicValues, - pub nonce_lookup: HashMap, + pub nonce_lookup: HashMap, } // Event lenses connect the record to the events relative to a particular chip @@ -180,7 +183,10 @@ impl EventLens for ExecutionRecord { impl EventLens> for ExecutionRecord { fn events(&self) -> as crate::air::WithEvents<'_>>::Events { - &self.byte_lookups + ( + &self.byte_lookups, + ::public_values(self), + ) } } @@ -190,21 +196,32 @@ impl EventLens for ExecutionRecord { } } -impl EventLens for ExecutionRecord { - fn events(&self) -> >::Events { - (&self.memory_initialize_events, &self.memory_finalize_events) +impl EventLens> for ExecutionRecord { + fn events(&self) -> as crate::air::WithEvents<'_>>::Events { + ( + &self.memory_initialize_events, + &self.memory_finalize_events, + ::public_values(self), + ) } } -impl EventLens for ExecutionRecord { - fn events(&self) -> >::Events { - &self.program.memory_image +impl EventLens> for ExecutionRecord { + fn events(&self) -> as crate::air::WithEvents<'_>>::Events { + ( + &self.program.memory_image, + ::public_values(self), + ) } } -impl EventLens for ExecutionRecord { - fn events(&self) -> >::Events { - (&self.cpu_events, &self.program) +impl EventLens> for ExecutionRecord { + fn events(&self) -> as crate::air::WithEvents<'_>>::Events { + ( + &self.cpu_events, + &self.program, + ::public_values(self), + ) } } @@ -318,73 +335,35 @@ impl EventLens> for ExecutionRecord { } } -pub struct ShardingConfig { - pub shard_size: usize, - pub add_len: usize, - pub mul_len: usize, - pub sub_len: usize, - pub bitwise_len: usize, - pub shift_left_len: usize, - pub shift_right_len: usize, - pub divrem_len: usize, - pub lt_len: usize, - pub field_len: usize, - pub keccak_len: usize, - pub secp256k1_add_len: usize, - pub secp256k1_double_len: usize, - pub bn254_add_len: usize, - pub bn254_double_len: usize, - pub bls12381_g1_add_len: usize, - pub bls12381_g1_double_len: usize, - pub bls12381_fp_len: usize, - pub bls12381_fp2_len: usize, +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct SplitOpts { + pub deferred_shift_threshold: usize, + pub keccak_split_threshold: usize, + pub sha_extend_split_threshold: usize, + pub sha_compress_split_threshold: usize, + pub memory_split_threshold: usize, } -impl ShardingConfig { - pub const fn shard_size(&self) -> usize { - self.shard_size - } -} - -impl Default for ShardingConfig { - fn default() -> Self { - let shard_size = SphinxCoreOpts::default().shard_size; +impl SplitOpts { + pub fn new(deferred_shift_threshold: usize) -> Self { Self { - shard_size, - add_len: shard_size, - sub_len: shard_size, - bitwise_len: shard_size, - shift_left_len: shard_size, - divrem_len: shard_size, - lt_len: shard_size, - mul_len: shard_size, - shift_right_len: shard_size, - field_len: shard_size * 4, - keccak_len: shard_size, - secp256k1_add_len: shard_size, - secp256k1_double_len: shard_size, - bn254_add_len: shard_size, - bn254_double_len: shard_size, - bls12381_g1_add_len: shard_size, - bls12381_g1_double_len: shard_size, - bls12381_fp_len: shard_size, - bls12381_fp2_len: shard_size, + deferred_shift_threshold, + keccak_split_threshold: deferred_shift_threshold / 24, + sha_extend_split_threshold: deferred_shift_threshold / 48, + sha_compress_split_threshold: deferred_shift_threshold / 80, + memory_split_threshold: deferred_shift_threshold, } } } -impl Indexed for ExecutionRecord { - fn index(&self) -> u32 { - self.index +impl PublicValued for ExecutionRecord { + fn public_values(&self) -> PublicValues, F> { + PublicValues::from(self.public_values) } } impl MachineRecord for ExecutionRecord { - type Config = ShardingConfig; - - fn set_index(&mut self, index: u32) { - self.index = index; - } + type Config = SphinxCoreOpts; fn stats(&self) -> HashMap { let mut stats = HashMap::new(); @@ -465,6 +444,23 @@ impl MachineRecord for ExecutionRecord { "bls12381_g2_double_events".to_string(), self.bls12381_g2_double_events.len(), ); + stats.insert( + "memory_initialize_events".to_string(), + self.memory_initialize_events.len(), + ); + stats.insert( + "memory_finalize_events".to_string(), + self.memory_finalize_events.len(), + ); + if !self.cpu_events.is_empty() { + let shard = self.cpu_events[0].shard; + stats.insert( + "byte_lookups".to_string(), + self.byte_lookups.get(&shard).map_or(0, |v| v.len()), + ); + } + // Filter out the empty events. + stats.retain(|_, v| *v != 0); stats } @@ -511,20 +507,10 @@ impl MachineRecord for ExecutionRecord { self.bls12381_g2_double_events .append(&mut other.bls12381_g2_double_events); - // Merge the byte lookups. - for (shard, events_map) in take(&mut other.byte_lookups) { - match self.byte_lookups.get_mut(&shard) { - Some(existing) => { - // If there's already a map for this shard, update counts for each event. - for (event, count) in events_map.iter() { - *existing.entry(event.clone()).or_insert(0) += count; - } - } - None => { - // If there isn't a map for this shard, insert the whole map. - self.byte_lookups.insert(shard, events_map); - } - } + if self.byte_lookups.is_empty() { + self.byte_lookups = take(&mut other.byte_lookups); + } else { + self.add_sharded_byte_lookup_events(vec![&other.byte_lookups]); } self.memory_initialize_events @@ -533,336 +519,62 @@ impl MachineRecord for ExecutionRecord { .append(&mut other.memory_finalize_events); } - fn shard(mut self, config: &ShardingConfig) -> Vec { - // Get the number of CPU events. - let num_cpu_events = self.cpu_events.len(); - - // Create empty shards that we will fill in. - let mut shards: Vec = Vec::new(); - - // Iterate throught he CPU events and fill in the shards. - let mut start_idx = 0; - let mut current_shard = self.cpu_events[0].shard; - for (i, cpu_event) in self.cpu_events.iter().enumerate() { - let at_last_event = i == num_cpu_events - 1; - if cpu_event.shard != current_shard || at_last_event { - let last_idx = if at_last_event { i + 1 } else { i }; - - // Fill in the shard. - let mut shard = ExecutionRecord::default(); - shard.index = current_shard; - shard.cpu_events = self.cpu_events[start_idx..last_idx].to_vec(); - shard.program = self.program.clone(); - - // Byte lookups are already sharded, so put this shard's lookups in. - let current_byte_lookups = - self.byte_lookups.remove(¤t_shard).unwrap_or_default(); - shard - .byte_lookups - .insert(current_shard, current_byte_lookups); - let last_shard_cpu_event = shard.cpu_events.last().unwrap(); - - // Set the public_values_digest for all shards. For the vast majority of the time, only the last shard - // will read the public values. But in some very rare edge cases, the last two shards will - // read it (e.g. when the halt instruction is the only instruction in the last shard). - // It seems overly complex to set the public_values_digest for the last two shards, so we just set it - // for all of the shards. - shard.public_values.committed_value_digest = - self.public_values.committed_value_digest; - shard.public_values.deferred_proofs_digest = - self.public_values.deferred_proofs_digest; - shard.public_values.shard = current_shard; - shard.public_values.start_pc = shard.cpu_events[0].pc; - shard.public_values.next_pc = last_shard_cpu_event.next_pc; - shard.public_values.exit_code = last_shard_cpu_event.exit_code; - shards.push(shard); - - if !(at_last_event) { - start_idx = i; - current_shard += 1; - } - } - } - - // Shard the ADD events. - for (add_chunk, shard) in take(&mut self.add_events) - .chunks_mut(config.add_len) - .zip(shards.iter_mut()) - { - shard.add_events.extend_from_slice(add_chunk); - for (i, event) in add_chunk.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, i as u32); - } - } - - // Shard the SUB events. - for (sub_chunk, shard) in take(&mut self.sub_events) - .chunks_mut(config.sub_len) - .zip(shards.iter_mut()) - { - shard.sub_events.extend_from_slice(sub_chunk); - for (i, event) in sub_chunk.iter().enumerate() { - self.nonce_lookup - .insert(event.lookup_id, shard.add_events.len() as u32 + i as u32); - } - } - - // Shard the MUL events. - for (mul_chunk, shard) in take(&mut self.mul_events) - .chunks_mut(config.mul_len) - .zip(shards.iter_mut()) - { - shard.mul_events.extend_from_slice(mul_chunk); - for (i, event) in mul_chunk.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, i as u32); - } - } - - // Shard the bitwise events. - for (bitwise_chunk, shard) in take(&mut self.bitwise_events) - .chunks_mut(config.bitwise_len) - .zip(shards.iter_mut()) - { - shard.bitwise_events.extend_from_slice(bitwise_chunk); - for (i, event) in bitwise_chunk.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, i as u32); - } - } - - // Shard the shift left events. - for (shift_left_chunk, shard) in take(&mut self.shift_left_events) - .chunks_mut(config.shift_left_len) - .zip(shards.iter_mut()) - { - shard.shift_left_events.extend_from_slice(shift_left_chunk); - for (i, event) in shift_left_chunk.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, i as u32); - } - } - - // Shard the shift right events. - for (shift_right_chunk, shard) in take(&mut self.shift_right_events) - .chunks_mut(config.shift_right_len) - .zip(shards.iter_mut()) - { - shard - .shift_right_events - .extend_from_slice(shift_right_chunk); - for (i, event) in shift_right_chunk.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, i as u32); - } - } - - // Shard the divrem events. - for (divrem_chunk, shard) in take(&mut self.divrem_events) - .chunks_mut(config.divrem_len) - .zip(shards.iter_mut()) - { - shard.divrem_events.extend_from_slice(divrem_chunk); - for (i, event) in divrem_chunk.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, i as u32); - } - } - - // Shard the LT events. - for (lt_chunk, shard) in take(&mut self.lt_events) - .chunks_mut(config.lt_len) - .zip(shards.iter_mut()) - { - shard.lt_events.extend_from_slice(lt_chunk); - for (i, event) in lt_chunk.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, i as u32); - } - } - - // Keccak-256 permute events. - for (keccak_chunk, shard) in take(&mut self.keccak_permute_events) - .chunks_mut(config.keccak_len) - .zip(shards.iter_mut()) - { - shard.keccak_permute_events.extend_from_slice(keccak_chunk); - for (i, event) in keccak_chunk.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, (i * 24) as u32); - } - } + fn register_nonces(&mut self, _opts: &Self::Config) { + self.add_events.iter().enumerate().for_each(|(i, event)| { + self.nonce_lookup.insert(event.lookup_id, i as u32); + }); - // secp256k1 curve add events. - for (secp256k1_add_chunk, shard) in take(&mut self.secp256k1_add_events) - .chunks_mut(config.secp256k1_add_len) - .zip(shards.iter_mut()) - { - shard - .secp256k1_add_events - .extend_from_slice(secp256k1_add_chunk); - for (i, event) in secp256k1_add_chunk.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, i as u32); - } - } + self.sub_events.iter().enumerate().for_each(|(i, event)| { + self.nonce_lookup + .insert(event.lookup_id, (self.add_events.len() + i) as u32); + }); - // secp256k1 curve double events. - for (secp256k1_double_chunk, shard) in take(&mut self.secp256k1_double_events) - .chunks_mut(config.secp256k1_double_len) - .zip(shards.iter_mut()) - { - shard - .secp256k1_double_events - .extend_from_slice(secp256k1_double_chunk); - for (i, event) in secp256k1_double_chunk.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, i as u32); - } - } + self.mul_events.iter().enumerate().for_each(|(i, event)| { + self.nonce_lookup.insert(event.lookup_id, i as u32); + }); - // bn254 curve add events. - for (bn254_add_chunk, shard) in take(&mut self.bn254_add_events) - .chunks_mut(config.bn254_add_len) - .zip(shards.iter_mut()) - { - shard.bn254_add_events.extend_from_slice(bn254_add_chunk); - for (i, event) in bn254_add_chunk.iter().enumerate() { + self.bitwise_events + .iter() + .enumerate() + .for_each(|(i, event)| { self.nonce_lookup.insert(event.lookup_id, i as u32); - } - } + }); - // bn254 curve double events. - for (bn254_double_chunk, shard) in take(&mut self.bn254_double_events) - .chunks_mut(config.bn254_double_len) - .zip(shards.iter_mut()) - { - shard - .bn254_double_events - .extend_from_slice(bn254_double_chunk); - for (i, event) in bn254_double_chunk.iter().enumerate() { + self.shift_left_events + .iter() + .enumerate() + .for_each(|(i, event)| { self.nonce_lookup.insert(event.lookup_id, i as u32); - } - } + }); - // BLS12-381 curve add events. - for (bls12381_g1_add_chunk, shard) in take(&mut self.bls12381_g1_add_events) - .chunks_mut(config.bls12381_g1_add_len) - .zip(shards.iter_mut()) - { - shard - .bls12381_g1_add_events - .extend_from_slice(bls12381_g1_add_chunk); - for (i, event) in bls12381_g1_add_chunk.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, i as u32); - } - } - - // BLS12-381 curve double events. - for (bls12381_g1_double_chunk, shard) in take(&mut self.bls12381_g1_double_events) - .chunks_mut(config.bls12381_g1_double_len) - .zip(shards.iter_mut()) - { - shard - .bls12381_g1_double_events - .extend_from_slice(bls12381_g1_double_chunk); - for (i, event) in bls12381_g1_double_chunk.iter().enumerate() { + self.shift_right_events + .iter() + .enumerate() + .for_each(|(i, event)| { self.nonce_lookup.insert(event.lookup_id, i as u32); - } - } + }); - // BLS12-381 Fp and Fp2 events - for (bls12381_fp_chunk, shard) in take(&mut self.bls12381_fp_events) - .chunks_mut(config.bls12381_fp_len) - .zip(shards.iter_mut()) - { - shard - .bls12381_fp_events - .extend_from_slice(bls12381_fp_chunk); - for (i, event) in bls12381_fp_chunk.iter().enumerate() { + self.divrem_events + .iter() + .enumerate() + .for_each(|(i, event)| { self.nonce_lookup.insert(event.lookup_id, i as u32); - } - } - for (bls12381_fp2_chunk, shard) in take(&mut self.bls12381_fp2_events) - .chunks_mut(config.bls12381_fp2_len) - .zip(shards.iter_mut()) - { - shard - .bls12381_fp2_events - .extend_from_slice(bls12381_fp2_chunk); - for (i, event) in bls12381_fp2_chunk.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, i as u32); - } - } + }); - // Put the precompile events in the first shard. - let first = shards.first_mut().unwrap(); - - // SHA-256 extend events. - first.sha_extend_events = take(&mut self.sha_extend_events); - for (i, event) in first.sha_extend_events.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, (i * 48) as u32); - } - - // SHA-256 compress events. - first.sha_compress_events = take(&mut self.sha_compress_events); - for (i, event) in first.sha_compress_events.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, (i * 80) as u32); - } - - // Edwards curve add events. - first.ed_add_events = take(&mut self.ed_add_events); - for (i, event) in first.ed_add_events.iter().enumerate() { + self.lt_events.iter().enumerate().for_each(|(i, event)| { self.nonce_lookup.insert(event.lookup_id, i as u32); - } - - // Edwards curve decompress events. - first.ed_decompress_events = take(&mut self.ed_decompress_events); - for (i, event) in first.ed_decompress_events.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, i as u32); - } - - // K256 curve decompress events. - first.secp256k1_decompress_events = take(&mut self.secp256k1_decompress_events); - for (i, event) in first.secp256k1_decompress_events.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, i as u32); - } - - // Bls12-381 decompress events. - first.bls12381_g1_decompress_events = take(&mut self.bls12381_g1_decompress_events); - for (i, event) in first.bls12381_g1_decompress_events.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, i as u32); - } - - // Bls12-381 G2Affine addition events. - first.bls12381_g2_add_events = take(&mut self.bls12381_g2_add_events); - for (i, event) in first.bls12381_g2_add_events.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, i as u32); - } - - // Bls12-381 G2Affine doubling events. - first.bls12381_g2_double_events = take(&mut self.bls12381_g2_double_events); - for (i, event) in first.bls12381_g2_double_events.iter().enumerate() { - self.nonce_lookup.insert(event.lookup_id, i as u32); - } - - // Put MemoryInit / MemoryFinalize events in the last shard. - let last = shards.last_mut().unwrap(); - last.memory_initialize_events - .extend_from_slice(&self.memory_initialize_events); - last.memory_finalize_events - .extend_from_slice(&self.memory_finalize_events); - - // Copy the nonce lookup to all shards. - for shard in shards.iter_mut() { - shard.nonce_lookup.clone_from(&self.nonce_lookup); - } - - shards + }); } /// Retrieves the public values. This method is needed for the `MachineRecord` trait, since - /// the public values digest is used by the prover. fn public_values(&self) -> Vec { self.public_values.to_vec() } } impl ExecutionRecord { - pub fn new(index: u32, program: Arc) -> Self { + pub fn new(program: Arc) -> Self { Self { - index, program, ..Default::default() } @@ -906,6 +618,207 @@ impl ExecutionRecord { } } } + + /// Take out events from the [ExecutionRecord] that should be deferred to a separate shard. + /// + /// Note: we usually defer events that would increase the recursion cost significantly if + /// included in every shard. + pub fn defer(&mut self) -> ExecutionRecord { + ExecutionRecord { + keccak_permute_events: take(&mut self.keccak_permute_events), + secp256k1_add_events: take(&mut self.secp256k1_add_events), + secp256k1_double_events: take(&mut self.secp256k1_double_events), + bn254_add_events: take(&mut self.bn254_add_events), + bn254_double_events: take(&mut self.bn254_double_events), + bls12381_g1_add_events: take(&mut self.bls12381_g1_add_events), + bls12381_g1_double_events: take(&mut self.bls12381_g1_double_events), + sha_extend_events: take(&mut self.sha_extend_events), + sha_compress_events: take(&mut self.sha_compress_events), + ed_add_events: take(&mut self.ed_add_events), + ed_decompress_events: take(&mut self.ed_decompress_events), + secp256k1_decompress_events: take(&mut self.secp256k1_decompress_events), + bls12381_g1_decompress_events: take(&mut self.bls12381_g1_decompress_events), + memory_initialize_events: take(&mut self.memory_initialize_events), + memory_finalize_events: take(&mut self.memory_finalize_events), + ..Default::default() + } + } + + /// Splits the deferred [ExecutionRecord] into multiple [ExecutionRecord]s, each which contain + /// a "reasonable" number of deferred events. + pub fn split(&mut self, last: bool, opts: SplitOpts) -> Vec { + let mut shards = Vec::new(); + + macro_rules! split_events { + ($self:ident, $events:ident, $shards:ident, $threshold:expr, $exact:expr) => { + let events = std::mem::take(&mut $self.$events); + let chunks = events.chunks_exact($threshold); + if !$exact { + $self.$events = chunks.remainder().to_vec(); + } else { + let remainder = chunks.remainder().to_vec(); + if !remainder.is_empty() { + $shards.push(ExecutionRecord { + $events: chunks.remainder().to_vec(), + program: self.program.clone(), + ..Default::default() + }); + } + } + let mut event_shards = chunks + .map(|chunk| ExecutionRecord { + $events: chunk.to_vec(), + program: self.program.clone(), + ..Default::default() + }) + .collect::>(); + $shards.append(&mut event_shards); + }; + } + + split_events!( + self, + keccak_permute_events, + shards, + opts.keccak_split_threshold, + last + ); + split_events!( + self, + secp256k1_add_events, + shards, + opts.deferred_shift_threshold, + last + ); + split_events!( + self, + secp256k1_double_events, + shards, + opts.deferred_shift_threshold, + last + ); + split_events!( + self, + bn254_add_events, + shards, + opts.deferred_shift_threshold, + last + ); + split_events!( + self, + bn254_double_events, + shards, + opts.deferred_shift_threshold, + last + ); + split_events!( + self, + bls12381_g1_add_events, + shards, + opts.deferred_shift_threshold, + last + ); + split_events!( + self, + bls12381_g1_double_events, + shards, + opts.deferred_shift_threshold, + last + ); + split_events!( + self, + sha_extend_events, + shards, + opts.sha_extend_split_threshold, + last + ); + split_events!( + self, + sha_compress_events, + shards, + opts.sha_compress_split_threshold, + last + ); + split_events!( + self, + ed_add_events, + shards, + opts.deferred_shift_threshold, + last + ); + split_events!( + self, + ed_decompress_events, + shards, + opts.deferred_shift_threshold, + last + ); + split_events!( + self, + secp256k1_decompress_events, + shards, + opts.deferred_shift_threshold, + last + ); + split_events!( + self, + bls12381_g1_decompress_events, + shards, + opts.deferred_shift_threshold, + last + ); + + if last { + self.memory_initialize_events + .sort_by_key(|event| event.addr); + self.memory_finalize_events.sort_by_key(|event| event.addr); + + let mut init_addr_bits = [0; 32]; + let mut finalize_addr_bits = [0; 32]; + for mem_chunks in self + .memory_initialize_events + .chunks(opts.memory_split_threshold) + .zip_longest( + self.memory_finalize_events + .chunks(opts.memory_split_threshold), + ) + { + let (mem_init_chunk, mem_finalize_chunk) = match mem_chunks { + EitherOrBoth::Both(mem_init_chunk, mem_finalize_chunk) => { + (mem_init_chunk, mem_finalize_chunk) + } + EitherOrBoth::Left(mem_init_chunk) => (mem_init_chunk, [].as_slice()), + EitherOrBoth::Right(mem_finalize_chunk) => ([].as_slice(), mem_finalize_chunk), + }; + let mut shard = ExecutionRecord::default(); + shard.program = self.program.clone(); + shard + .memory_initialize_events + .extend_from_slice(mem_init_chunk); + shard.public_values.previous_init_addr_bits = init_addr_bits; + if let Some(last_event) = mem_init_chunk.last() { + let last_init_addr_bits = core::array::from_fn(|i| (last_event.addr >> i) & 1); + init_addr_bits = last_init_addr_bits; + } + shard.public_values.last_init_addr_bits = init_addr_bits; + + shard + .memory_finalize_events + .extend_from_slice(mem_finalize_chunk); + shard.public_values.previous_finalize_addr_bits = finalize_addr_bits; + if let Some(last_event) = mem_finalize_chunk.last() { + let last_finalize_addr_bits = + core::array::from_fn(|i| (last_event.addr >> i) & 1); + finalize_addr_bits = last_finalize_addr_bits; + } + shard.public_values.last_finalize_addr_bits = finalize_addr_bits; + + shards.push(shard); + } + } + + shards + } } impl ByteRecord for ExecutionRecord { @@ -917,6 +830,14 @@ impl ByteRecord for ExecutionRecord { .entry(blu_event) .or_insert(0) += 1 } + + #[inline] + fn add_sharded_byte_lookup_events( + &mut self, + new_events: Vec<&HashMap>>, + ) { + add_sharded_byte_lookup_events(&mut self.byte_lookups, new_events); + } } #[derive(Debug, Copy, Clone, Default)] @@ -926,3 +847,6 @@ pub struct MemoryAccessRecord { pub c: Option, pub memory: Option, } + +/// The threshold for splitting deferred events. +pub const DEFERRED_SPLIT_THRESHOLD: usize = 1 << 19; diff --git a/core/src/runtime/state.rs b/core/src/runtime/state.rs index 11cf7ff3b..6559819b3 100644 --- a/core/src/runtime/state.rs +++ b/core/src/runtime/state.rs @@ -1,16 +1,20 @@ -use hashbrown::HashMap; +use std::{ + fs::File, + io::{Seek, Write}, +}; use nohash_hasher::BuildNoHashHasher; use serde::{Deserialize, Serialize}; use serde_with::serde_as; +use std::collections::HashMap; +use super::{ExecutionRecord, MemoryAccessRecord, MemoryRecord, SyscallCode}; +use crate::utils::{deserialize_hashmap_as_vec, serialize_hashmap_as_vec}; use crate::{ stark::{ShardProof, StarkVerifyingKey}, utils::BabyBearPoseidon2, }; -use super::{ExecutionRecord, MemoryAccessRecord, MemoryRecord}; - /// Holds data describing the current state of a program's execution. #[serde_as] #[derive(Debug, Clone, Default, Serialize, Deserialize)] @@ -34,10 +38,18 @@ pub struct ExecutionState { /// The memory which instructions operate over. Values contain the memory value and last shard /// + timestamp that each memory address was accessed. + #[serde( + serialize_with = "serialize_hashmap_as_vec", + deserialize_with = "deserialize_hashmap_as_vec" + )] pub memory: HashMap>, /// Uninitialized memory addresses that have a specific value they should be initialized with. /// SyscallHintRead uses this to write hint data into uninitialized memory. + #[serde( + serialize_with = "serialize_hashmap_as_vec", + deserialize_with = "deserialize_hashmap_as_vec" + )] pub uninitialized_memory: HashMap>, /// A stream of input values (global to the entire program). @@ -60,6 +72,9 @@ pub struct ExecutionState { /// A ptr to the current position in the public values stream, incremented when reading from public_values_stream. pub public_values_stream_ptr: usize, + + /// Keeps track of how many times a certain syscall has been called. + pub syscall_counts: HashMap, } impl ExecutionState { @@ -79,6 +94,7 @@ impl ExecutionState { public_values_stream_ptr: 0, proof_stream: Vec::new(), proof_stream_ptr: 0, + syscall_counts: HashMap::new(), } } } @@ -107,3 +123,13 @@ pub(crate) struct ForkState { // Emit events from original state pub(crate) emit_events: bool, } + +impl ExecutionState { + pub fn save(&self, file: &mut File) -> std::io::Result<()> { + let mut writer = std::io::BufWriter::new(file); + bincode::serialize_into(&mut writer, self).unwrap(); + writer.flush()?; + writer.seek(std::io::SeekFrom::Start(0))?; + Ok(()) + } +} diff --git a/core/src/runtime/syscall.rs b/core/src/runtime/syscall.rs index 8b6c68e59..d52ab3aea 100644 --- a/core/src/runtime/syscall.rs +++ b/core/src/runtime/syscall.rs @@ -2,6 +2,7 @@ use hashbrown::HashMap; use std::fmt; use std::sync::Arc; +use serde::{Deserialize, Serialize}; use strum_macros::EnumIter; use crate::runtime::{Register, Runtime}; @@ -38,7 +39,9 @@ use super::{ExecutionRecord, MemoryReadRecord, MemoryWriteRecord}; /// - The second byte is 0/1 depending on whether the syscall has a separate table. This is used /// in the CPU table to determine whether to lookup the syscall using the syscall interaction. /// - The third byte is the number of additional cycles the syscall uses. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, EnumIter, Ord, PartialOrd)] +#[derive( + Debug, Copy, Clone, PartialEq, Eq, Hash, EnumIter, Ord, PartialOrd, Serialize, Deserialize, +)] #[allow(non_camel_case_types)] pub enum SyscallCode { /// Halts the program. @@ -199,7 +202,7 @@ pub struct SyscallContext<'a, 'b> { /// This is the exit_code used for the HALT syscall pub(crate) exit_code: u32, pub(crate) rt: &'a mut Runtime<'b>, - pub syscall_lookup_id: usize, + pub syscall_lookup_id: u128, } impl<'a, 'b> SyscallContext<'a, 'b> { diff --git a/core/src/stark/air.rs b/core/src/stark/air.rs index 7a2f08c46..765c5196a 100644 --- a/core/src/stark/air.rs +++ b/core/src/stark/air.rs @@ -51,7 +51,7 @@ pub(crate) mod riscv_chips { #[record_type = "crate::runtime::ExecutionRecord"] pub enum RiscvAir { /// An AIR that contains a preprocessed program table and a lookup for the instructions. - Program(ProgramChip), + Program(ProgramChip), /// An AIR for the RISC-V CPU. Each row represents a cpu cycle. Cpu(CpuChip), /// An AIR for the RISC-V Add and SUB instruction. @@ -71,11 +71,11 @@ pub enum RiscvAir { /// A lookup table for byte operations. ByteLookup(ByteChip), /// A table for initializing the memory state. - MemoryInit(MemoryChip), + MemoryInit(MemoryChip), /// A table for finalizing the memory state. - MemoryFinal(MemoryChip), + MemoryFinal(MemoryChip), /// A table for initializing the program memory. - ProgramMemory(MemoryProgramChip), + ProgramMemory(MemoryProgramChip), /// A precompile for sha256 extend. Sha256Extend(ShaExtendChip), /// A precompile for sha256 compress. @@ -125,7 +125,7 @@ impl RiscvAir { let mut chips = vec![]; let cpu = CpuChip; chips.push(RiscvAir::Cpu(cpu)); - let program = ProgramChip; + let program = ProgramChip::new(); chips.push(RiscvAir::Program(program)); let sha_extend = ShaExtendChip; chips.push(RiscvAir::Sha256Extend(sha_extend)); diff --git a/core/src/stark/config.rs b/core/src/stark/config.rs index 8f87b534d..b2d79152c 100644 --- a/core/src/stark/config.rs +++ b/core/src/stark/config.rs @@ -46,7 +46,7 @@ pub type PcsProverData = <::Pcs as Pcs< pub type Challenge = ::Challenge; pub type Challenger = ::Challenger; -pub trait StarkGenericConfig: Send + Sync + Serialize + DeserializeOwned + Clone { +pub trait StarkGenericConfig: 'static + Send + Sync + Serialize + DeserializeOwned + Clone { type Val: PrimeField; type Domain: PolynomialSpace + Sync + Send; diff --git a/core/src/stark/machine.rs b/core/src/stark/machine.rs index 212f9a8de..9c4609bad 100644 --- a/core/src/stark/machine.rs +++ b/core/src/stark/machine.rs @@ -4,6 +4,7 @@ use p3_air::Air; use p3_challenger::CanObserve; use p3_challenger::FieldChallenger; use p3_commit::Pcs; +use p3_field::AbstractExtensionField; use p3_field::AbstractField; use p3_field::Field; use p3_field::PrimeField32; @@ -23,20 +24,16 @@ use super::Dom; use crate::air::MachineAir; use crate::air::MachineProgram; use crate::lookup::debug_interactions_with_all_chips; -use crate::lookup::InteractionBuilder; use crate::lookup::InteractionKind; -use crate::stark::record::{Indexed, MachineRecord}; +use crate::stark::record::MachineRecord; use crate::stark::DebugConstraintBuilder; -use crate::stark::ProverConstraintFolder; use crate::stark::ShardProof; use crate::stark::VerifierConstraintFolder; -use crate::utils::SphinxCoreOpts; use super::Chip; use super::Com; use super::MachineProof; use super::PcsProverData; -use super::Prover; use super::StarkGenericConfig; use super::Val; use super::VerificationError; @@ -241,54 +238,24 @@ impl>> StarkMachine { ) } - pub fn shard( + pub fn generate_dependencies( &self, - mut record: A::Record, - config: &::Config, - ) -> Vec { - // Get the local and global chips. + records: &mut [A::Record], + opts: &::Config, + ) { let chips = self.chips(); - - // Generate the trace for each chip to collect events emitted from chips with dependencies. - tracing::debug_span!("collect record events from chips").in_scope(|| { - chips.iter().for_each(|chip| { - let mut output = A::Record::default(); - output.set_index(record.index()); - chip.as_ref().generate_dependencies(&record, &mut output); - record.append(&mut output); - }) - }); - - // Display some statistics about the workload. - let stats = record.stats(); - log::debug!("shard: {:?}", stats); - - // For each chip, shard the events into segments. - record.shard(config) - } - - /// Prove the execution record is valid. - /// - /// Given a proving key `pk` and a matching execution record `record`, this function generates - /// a STARK proof that the execution record is valid. - pub fn prove>( - &self, - pk: &StarkProvingKey, - record: A::Record, - challenger: &mut SC::Challenger, - opts: SphinxCoreOpts, - ) -> MachineProof - where - A: for<'a> Air> - + Air>> - + for<'a> Air> - + for<'a> Air, SC::Challenge>>, - { - let shards = tracing::info_span!("shard_record") - .in_scope(|| self.shard(record, &::Config::default())); - - tracing::info_span!("prove_shards") - .in_scope(|| P::prove_shards(self, pk, shards, challenger, opts)) + records.iter_mut().for_each(|record| { + for chip in chips.iter() { + tracing::debug_span!("chip dependencies", chip = chip.as_ref().name()).in_scope( + || { + let mut output = A::Record::default(); + chip.as_ref().generate_dependencies(record, &mut output); + record.append(&mut output); + }, + ); + } + tracing::debug_span!("register nonces").in_scope(|| record.register_nonces(opts)); + }) } pub const fn config(&self) -> &SC { @@ -323,7 +290,7 @@ impl>> StarkMachine { tracing::debug_span!("verify shard proofs").in_scope(|| { for (i, shard_proof) in proof.shard_proofs.iter().enumerate() { - tracing::debug_span!("verifying shard", segment = i).in_scope(|| { + tracing::debug_span!("verifying shard", shard = i).in_scope(|| { let chips = self .shard_chips_ordered(&shard_proof.chip_ordering) .collect::>(); @@ -334,7 +301,7 @@ impl>> StarkMachine { &mut challenger.clone(), shard_proof, ) - .map_err(MachineVerificationError::InvalidSegmentProof) + .map_err(MachineVerificationError::InvalidShardProof) })?; } @@ -355,19 +322,25 @@ impl>> StarkMachine { } #[instrument("debug constraints", level = "debug", skip_all)] - pub fn debug_constraints(&self, pk: &StarkProvingKey, record: A::Record) - where + pub fn debug_constraints( + &self, + pk: &StarkProvingKey, + records: Vec, + challenger: &mut SC::Challenger, + ) where SC::Val: PrimeField32, A: for<'a> Air, SC::Challenge>>, { - tracing::debug!("sharding the execution record"); - let shards = self.shard(record, &::Config::default()); - tracing::debug!("checking constraints for each shard"); + // Obtain the challenges used for the permutation argument. + let mut permutation_challenges: Vec = Vec::new(); + for _ in 0..2 { + permutation_challenges.push(challenger.sample_ext_element()); + } + let mut cumulative_sum = SC::Challenge::zero(); - for shard in shards.iter() { - let mut challenger = self.config().challenger(); + for shard in records.iter() { // Filter the chips based on what is used. let chips = self.shard_chips(shard).collect::>(); @@ -389,13 +362,6 @@ impl>> StarkMachine { .zip(pre_traces) .collect::>(); - // Get a permutation challenge. - // Obtain the challenges used for the permutation argument. - let mut permutation_challenges: Vec = Vec::new(); - for _ in 0..2 { - permutation_challenges.push(challenger.sample_ext_element()); - } - // Generate the permutation traces. let mut permutation_traces = Vec::with_capacity(chips.len()); let mut cumulative_sums = Vec::with_capacity(chips.len()); @@ -424,7 +390,8 @@ impl>> StarkMachine { // Compute some statistics. for i in 0..chips.len() { let trace_width = traces[i].0.width(); - let permutation_width = permutation_traces[i].width(); + let permutation_width = permutation_traces[i].width() + * >::D; let total_width = trace_width + permutation_width; tracing::debug!( "{:<11} | Main Cols = {:<5} | Perm Cols = {:<5} | Rows = {:<10} | Cells = {:<10}", @@ -448,7 +415,7 @@ impl>> StarkMachine { &traces[i].0, &permutation_traces[i], &permutation_challenges, - &shard.public_values(), + &MachineRecord::public_values(shard), ); } }); @@ -459,7 +426,7 @@ impl>> StarkMachine { debug_interactions_with_all_chips::( self, pk, - &shards, + &records, &InteractionKind::all_kinds(), ); panic!("Cumulative sum is not zero"); @@ -468,7 +435,7 @@ impl>> StarkMachine { } pub enum MachineVerificationError { - InvalidSegmentProof(VerificationError), + InvalidShardProof(VerificationError), InvalidGlobalProof(VerificationError), NonZeroCumulativeSum, InvalidPublicValuesDigest, @@ -477,13 +444,15 @@ pub enum MachineVerificationError { InvalidPublicValues(&'static str), TooManyShards, InvalidChipOccurence(String), + MissingCpuInFirstShard, + CpuLogDegreeTooLarge(usize), } impl Debug for MachineVerificationError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - MachineVerificationError::InvalidSegmentProof(e) => { - write!(f, "Invalid segment proof: {:?}", e) + MachineVerificationError::InvalidShardProof(e) => { + write!(f, "Invalid shard proof: {:?}", e) } MachineVerificationError::InvalidGlobalProof(e) => { write!(f, "Invalid global proof: {:?}", e) @@ -509,6 +478,12 @@ impl Debug for MachineVerificationError { MachineVerificationError::InvalidChipOccurence(s) => { write!(f, "Invalid chip occurence: {}", s) } + MachineVerificationError::MissingCpuInFirstShard => { + write!(f, "Missing CPU in first shard") + } + MachineVerificationError::CpuLogDegreeTooLarge(log_degree) => { + write!(f, "CPU log degree too large: {}", log_degree) + } } } } @@ -524,8 +499,6 @@ impl std::error::Error for MachineVerificationError #[cfg(test)] pub mod tests { - use serial_test::serial; - use crate::io::SphinxStdin; use crate::runtime::tests::fibonacci_program; use crate::runtime::tests::simple_memory_program; @@ -534,6 +507,7 @@ pub mod tests { use crate::runtime::Instruction; use crate::runtime::Opcode; use crate::runtime::Program; + use crate::stark::DefaultProver; use crate::stark::RiscvAir; use crate::stark::StarkProvingKey; use crate::stark::StarkVerifyingKey; @@ -547,7 +521,7 @@ pub mod tests { fn test_simple_prove() { setup_logger(); let program = simple_program(); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } #[test] @@ -569,7 +543,7 @@ pub mod tests { Instruction::new(*shift_op, 31, 29, 3, false, false), ]; let program = Program::new(instructions, 0, 0); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } } } @@ -583,7 +557,7 @@ pub mod tests { Instruction::new(Opcode::SUB, 31, 30, 29, false, false), ]; let program = Program::new(instructions, 0, 0); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } #[test] @@ -595,7 +569,7 @@ pub mod tests { Instruction::new(Opcode::ADD, 31, 30, 29, false, false), ]; let program = Program::new(instructions, 0, 0); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } #[test] @@ -617,7 +591,7 @@ pub mod tests { Instruction::new(*mul_op, 31, 30, 29, false, false), ]; let program = Program::new(instructions, 0, 0); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } } } @@ -633,7 +607,7 @@ pub mod tests { Instruction::new(*lt_op, 31, 30, 29, false, false), ]; let program = Program::new(instructions, 0, 0); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } } @@ -649,7 +623,7 @@ pub mod tests { Instruction::new(*bitwise_op, 31, 30, 29, false, false), ]; let program = Program::new(instructions, 0, 0); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } } @@ -672,17 +646,16 @@ pub mod tests { Instruction::new(*div_rem_op, 31, 29, 30, false, false), ]; let program = Program::new(instructions, 0, 0); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } } } #[test] - #[serial] - fn test_fibonacci_prove() { + fn test_fibonacci_prove_simple() { setup_logger(); let program = fibonacci_program(); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } #[test] @@ -694,7 +667,7 @@ pub mod tests { let mut opts = SphinxCoreOpts::default(); opts.shard_size = 1024; opts.shard_batch_size = 2; - prove(&program, &stdin, BabyBearPoseidon2::new(), opts).unwrap(); + prove::<_, DefaultProver<_, _>>(&program, &stdin, BabyBearPoseidon2::new(), opts).unwrap(); } #[test] @@ -705,7 +678,7 @@ pub mod tests { setup_logger(); let program = fibonacci_program(); let stdin = SphinxStdin::new(); - prove( + prove::<_, DefaultProver<_, _>>( &program, &stdin, BabyBearPoseidon2::new(), @@ -716,14 +689,16 @@ pub mod tests { #[test] fn test_simple_memory_program_prove() { + setup_logger(); let program = simple_memory_program(); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } #[test] fn test_ssz_withdrawal() { + setup_logger(); let program = ssz_withdrawals_program(); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } #[test] diff --git a/core/src/stark/prover.rs b/core/src/stark/prover.rs index 067f94edd..7d57f4e9c 100644 --- a/core/src/stark/prover.rs +++ b/core/src/stark/prover.rs @@ -1,38 +1,120 @@ -use std::{ - cmp::Reverse, - marker::PhantomData, - sync::atomic::{AtomicU32, Ordering}, -}; +use serde::de::DeserializeOwned; +use serde::Serialize; +use std::cmp::Reverse; +use std::error::Error; use itertools::Itertools; use p3_air::Air; use p3_challenger::{CanObserve, FieldChallenger}; use p3_commit::Pcs; use p3_commit::PolynomialSpace; -use p3_field::ExtensionField; use p3_field::PrimeField32; use p3_field::{AbstractExtensionField, AbstractField}; use p3_matrix::dense::RowMajorMatrix; use p3_matrix::Matrix; use p3_maybe_rayon::prelude::*; use p3_util::log2_strict_usize; -use serde::de::DeserializeOwned; -use serde::Serialize; -use super::{quotient_values, PcsProverData, StarkMachine, Val}; +use super::{quotient_values, StarkMachine, Val}; use super::{types::*, StarkGenericConfig}; use super::{Com, OpeningProof}; use super::{StarkProvingKey, VerifierConstraintFolder}; use crate::air::MachineAir; use crate::lookup::InteractionBuilder; use crate::stark::record::MachineRecord; -use crate::stark::Indexed; +use crate::stark::DebugConstraintBuilder; use crate::stark::MachineChip; use crate::stark::PackedChallenge; +use crate::stark::PcsProverData; use crate::stark::ProverConstraintFolder; +use crate::stark::StarkVerifyingKey; use crate::utils::SphinxCoreOpts; -fn chunk_vec(mut vec: Vec, chunk_size: usize) -> Vec> { +pub trait MachineProver>: + 'static + Send + Sync +{ + type Error: Error + Send + Sync; + + /// Create a new prover from a given machine. + fn new(machine: StarkMachine) -> Self; + + /// A reference to the machine that this prover is using. + fn machine(&self) -> &StarkMachine; + + /// Calculate the main commitment for a given record. + fn commit(&self, record: &A::Record) -> Com; + + /// Commit and generate a proof for a given record, using the given challenger. + fn commit_and_open( + &self, + pk: &StarkProvingKey, + record: A::Record, + challenger: &mut SC::Challenger, + ) -> Result, Self::Error>; + + /// Generate a proof for the given records. + fn prove( + &self, + pk: &StarkProvingKey, + records: Vec, + challenger: &mut SC::Challenger, + opts: ::Config, + ) -> Result, Self::Error> + where + A: for<'a> Air, SC::Challenge>>; + + /// The stark config for the machine. + fn config(&self) -> &SC { + self.machine().config() + } + + fn num_pv_elts(&self) -> usize { + self.machine().num_pv_elts() + } + + fn shard_chips<'a, 'b>( + &'a self, + shard: &'b A::Record, + ) -> impl Iterator> + where + 'a: 'b, + SC: 'b, + { + self.machine().shard_chips(shard) + } + + fn setup(&self, program: &A::Program) -> (StarkProvingKey, StarkVerifyingKey) { + self.machine().setup(program) + } + + /// Update the challenger with the given shard data + fn update( + &self, + challenger: &mut SC::Challenger, + commitment: Com, + public_values: &[SC::Val], + ) { + // Observe the commitment. + challenger.observe(commitment); + // Observe the public values. + challenger.observe_slice(public_values); + } + + fn debug_constraints( + &self, + pk: &StarkProvingKey, + records: Vec, + challenger: &mut SC::Challenger, + ) where + SC::Val: PrimeField32, + A: for<'a> Air, SC::Challenge>>, + { + self.machine().debug_constraints(pk, records, challenger) + } +} + +#[allow(dead_code)] +pub fn chunk_vec(mut vec: Vec, chunk_size: usize) -> Vec> { let mut result = Vec::new(); while !vec.is_empty() { let current_chunk_size = std::cmp::min(chunk_size, vec.len()); @@ -42,155 +124,155 @@ fn chunk_vec(mut vec: Vec, chunk_size: usize) -> Vec> { result } -pub trait Prover>> { - fn prove_shards( - machine: &StarkMachine, - pk: &StarkProvingKey, - shards: Vec, - challenger: &mut SC::Challenger, - opts: SphinxCoreOpts, - ) -> MachineProof - where - A: for<'a> Air> - + Air>> - + for<'a> Air>; +pub struct DefaultProver { + machine: StarkMachine, +} + +#[derive(Debug, Clone, Copy)] +pub struct DefaultProverError; + +impl std::fmt::Display for DefaultProverError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "DefaultProverError") + } } -impl Prover for LocalProver +impl Error for DefaultProverError {} + +impl MachineProver for DefaultProver where + SC: 'static + StarkGenericConfig + Send + Sync, + A: MachineAir + + for<'a> Air> + + Air>> + + for<'a> Air>, + A::Record: MachineRecord, SC::Val: PrimeField32, - SC: StarkGenericConfig + Send + Sync, - SC::Challenger: Clone, Com: Send + Sync, PcsProverData: Send + Sync, OpeningProof: Send + Sync, ShardMainData: Serialize + DeserializeOwned, - A: MachineAir>, + SC::Challenger: Clone, { - fn prove_shards( - machine: &StarkMachine, + type Error = DefaultProverError; + + fn new(machine: StarkMachine) -> Self { + Self { machine } + } + + fn machine(&self) -> &StarkMachine { + &self.machine + } + + fn commit(&self, record: &A::Record) -> Com { + self.commit_main(record).main_commit + } + + /// Prove the execution record is valid. + /// + /// Given a proving key `pk` and a matching execution record `record`, this function generates + /// a STARK proof that the execution record is valid. + fn prove( + &self, pk: &StarkProvingKey, - shards: Vec, + mut records: Vec, challenger: &mut SC::Challenger, - opts: SphinxCoreOpts, - ) -> MachineProof + opts: ::Config, + ) -> Result, Self::Error> where - A: for<'a> Air> - + Air>> - + for<'a> Air>, + A: for<'a> Air, SC::Challenge>>, { + let chips = self.machine().chips(); + for record in records.iter_mut() { + for chip in chips.iter() { + let mut output = A::Record::default(); + chip.as_ref().generate_dependencies(record, &mut output); + record.append(&mut output); + } + record.register_nonces(&opts); + } + // Observe the preprocessed commitment. pk.observe_into(challenger); - // Generate and commit the traces for each segment. - let (shard_commits, shard_data) = Self::commit_shards(machine, &shards, opts); + + // Generate and commit the traces for each shard. + let shard_data = records + .into_par_iter() + .map(|record| self.commit_main(&record)) + .collect::>(); // Observe the challenges for each segment. tracing::debug_span!("observing all challenges").in_scope(|| { - shard_commits - .into_iter() - .zip(shards.iter()) - .for_each(|(commitment, shard)| { - challenger.observe(commitment); - challenger - .observe_slice(&shard.public_values::()[0..machine.num_pv_elts()]); - }); + for data in shard_data.iter() { + challenger.observe(data.main_commit.clone()); + challenger.observe_slice(&data.public_values[0..self.num_pv_elts()]); + } }); - let finished = AtomicU32::new(0); - - // Generate a proof for each segment. Note that we clone the challenger so we can observe - // identical global challenges across the segments. - let chunking_multiplier = opts.shard_chunking_multiplier; - let chunk_size = std::cmp::max(chunking_multiplier * shards.len() / num_cpus::get(), 1); - let config = machine.config(); - let reconstruct_commitments = opts.reconstruct_commitments; - let shard_data_chunks = chunk_vec(shard_data, chunk_size); - let shard_chunks = chunk_vec(shards, chunk_size); - let parent_span = tracing::debug_span!("open_shards"); - let shard_proofs = parent_span.in_scope(|| { - shard_data_chunks + let shard_proofs = tracing::info_span!("prove_shards").in_scope(|| { + shard_data .into_par_iter() - .zip(shard_chunks.into_par_iter()) - .map(|(data, shards)| { - data.into_iter() - .zip(shards) - .map(|(data, shard)| { - tracing::debug_span!(parent: &parent_span, "prove shard opening") - .in_scope(|| { - let idx = shard.index() as usize; - let data = if reconstruct_commitments { - Self::commit_main(config, machine, &shard, idx) - } else { - data.materialize() - .expect("failed to materialize shard main data") - }; - let ordering = data.chip_ordering.clone(); - let chips = - machine.shard_chips_ordered(&ordering).collect::>(); - let proof = Self::prove_shard( - config, - pk, - &chips, - data, - &mut challenger.clone(), - ); - finished.fetch_add(1, Ordering::Relaxed); - proof - }) - }) - .collect::>() - }) - .flatten() - .collect::>() - }); + .map(|data| self.prove_shard(pk, data, &mut challenger.clone())) + .collect::, _>>() + })?; - MachineProof { shard_proofs } + Ok(MachineProof { shard_proofs }) } -} -pub struct LocalProver(PhantomData, PhantomData); + /// Prove the program for the given shard and given a commitment to the main data. + fn commit_and_open( + &self, + pk: &StarkProvingKey, + record: A::Record, + challenger: &mut ::Challenger, + ) -> Result, Self::Error> { + let shard_data = self.commit_main(&record); + self.prove_shard(pk, shard_data, challenger) + } +} -impl LocalProver +impl DefaultProver where - SC: StarkGenericConfig, - SC::Challenger: Clone, - A: MachineAir, + SC: 'static + StarkGenericConfig + Send + Sync, + A: MachineAir + + for<'a> Air> + + Air>> + + for<'a> Air>, + A::Record: MachineRecord, + SC::Val: PrimeField32, Com: Send + Sync, PcsProverData: Send + Sync, + OpeningProof: Send + Sync, ShardMainData: Serialize + DeserializeOwned, + SC::Challenger: Clone, { - pub fn commit_main( - config: &SC, - machine: &StarkMachine, - shard: &A::Record, - index: usize, - ) -> ShardMainData { + fn commit_main(&self, shard: &A::Record) -> ShardMainData { // Filter the chips based on what is used. - let shard_chips = machine.shard_chips(shard).collect::>(); + let shard_chips = self.shard_chips(shard).collect::>(); // For each chip, generate the trace. let parent_span = tracing::debug_span!("generate traces for shard"); let mut named_traces = parent_span.in_scope(|| { - shard_chips - .par_iter() - .map(|chip| { - let chip_name = chip.as_ref().name(); - - // We need to create an outer span here because, for some reason, - // the #[instrument] macro on the chip impl isn't attaching its span to `parent_span` - // to avoid the unnecessary span, remove the #[instrument] macro. - let trace = - tracing::debug_span!(parent: &parent_span, "generate trace for chip", %chip_name) - .in_scope(|| chip.as_ref().generate_trace(shard, &mut A::Record::default())); - (chip_name, trace) - }) - .collect::>() - }); + shard_chips + .par_iter() + .map(|chip| { + let chip_name = chip.as_ref().name(); + + // We need to create an outer span here because, for some reason, + // the #[instrument] macro on the chip impl isn't attaching its span to `parent_span` + // to avoid the unnecessary span, remove the #[instrument] macro. + let trace = + tracing::debug_span!(parent: &parent_span, "generate trace for chip", %chip_name) + .in_scope(|| chip.as_ref().generate_trace(shard, &mut A::Record::default())); + (chip_name, trace) + }) + .collect::>() + }); // Order the chips and traces by trace size (biggest first), and get the ordering map. named_traces.sort_by_key(|(_, trace)| Reverse(trace.height())); - let pcs = config.pcs(); + let pcs = self.config().pcs(); let domains_and_traces = named_traces .iter() @@ -220,27 +302,22 @@ where main_commit, main_data, chip_ordering, - index, public_values: shard.public_values(), } } - /// Prove the program for the given shard and given a commitment to the main data. - pub fn prove_shard( - config: &SC, + #[allow(clippy::unnecessary_wraps)] + fn prove_shard( + &self, pk: &StarkProvingKey, - chips: &[&MachineChip], mut shard_data: ShardMainData, challenger: &mut SC::Challenger, - ) -> ShardProof - where - Val: PrimeField32, - SC: Send + Sync, - ShardMainData: DeserializeOwned, - A: for<'a> Air> - + Air>> - + for<'a> Air>, - { + ) -> Result, DefaultProverError> { + let chips = self + .machine() + .shard_chips_ordered(&shard_data.chip_ordering) + .collect::>(); + let config = self.machine().config(); // Get the traces. let traces = &mut shard_data.traces; @@ -528,7 +605,7 @@ where ) .collect::>(); - ShardProof:: { + Ok(ShardProof:: { commitment: ShardCommitment { main_commit: shard_data.main_commit.clone(), permutation_commit, @@ -540,61 +617,6 @@ where opening_proof, chip_ordering: shard_data.chip_ordering, public_values: shard_data.public_values, - } - } - - pub fn commit_shards( - machine: &StarkMachine, - shards: &[A::Record], - opts: SphinxCoreOpts, - ) -> (Vec>, Vec>) - where - F: PrimeField32, - EF: ExtensionField, - SC: StarkGenericConfig + Send + Sync, - SC::Challenger: Clone, - PcsProverData: Send + Sync, - ShardMainData: Serialize + DeserializeOwned, - { - let config = machine.config(); - - // Get the number of shards that is the threshold for saving shards to disk instead of - // keeping all the shards in memory. - let reconstruct_commitments = opts.reconstruct_commitments; - let finished = AtomicU32::new(0); - let chunk_size = std::cmp::max(shards.len() / num_cpus::get(), 1); - let parent_span = tracing::debug_span!("commit to all shards"); - let (commitments, shard_main_data): (Vec<_>, Vec<_>) = parent_span.in_scope(|| { - shards - .par_chunks(chunk_size) - .map(|shard_batch| { - shard_batch - .iter() - .map(|shard| { - tracing::debug_span!(parent: &parent_span, "commit to shard").in_scope( - || { - let index = shard.index(); - let data = - Self::commit_main(config, machine, shard, index as usize); - finished.fetch_add(1, Ordering::Relaxed); - let commitment = data.main_commit.clone(); - let data = if reconstruct_commitments { - ShardMainDataWrapper::Empty() - } else { - data.to_in_memory() - }; - (commitment, data) - }, - ) - }) - .collect::>() - }) - .flatten() - .collect::>() - .into_iter() - .unzip() - }); - - (commitments, shard_main_data) + }) } } diff --git a/core/src/stark/record.rs b/core/src/stark/record.rs index 00f14f5cb..9d94f96be 100644 --- a/core/src/stark/record.rs +++ b/core/src/stark/record.rs @@ -2,20 +2,20 @@ use hashbrown::HashMap; use p3_field::AbstractField; -pub trait Indexed { - fn index(&self) -> u32; -} +use crate::air::{PublicValues, Word}; -pub trait MachineRecord: Default + Sized + Send + Sync + Clone + Indexed { - type Config: Default; +pub trait PublicValued { + fn public_values(&self) -> PublicValues, F>; +} - fn set_index(&mut self, index: u32); +pub trait MachineRecord: Default + Sized + Send + Sync + Clone { + type Config: 'static + Copy + Send + Sync; fn stats(&self) -> HashMap; fn append(&mut self, other: &mut Self); - fn shard(self, config: &Self::Config) -> Vec; + fn register_nonces(&mut self, _opts: &Self::Config) {} fn public_values(&self) -> Vec; } diff --git a/core/src/stark/types.rs b/core/src/stark/types.rs index f0f8b2cd0..74e491189 100644 --- a/core/src/stark/types.rs +++ b/core/src/stark/types.rs @@ -1,18 +1,10 @@ +use std::fmt::Debug; + use hashbrown::HashMap; -use std::{ - fmt::Debug, - fs::File, - io::{BufReader, BufWriter, Seek}, -}; - -use bincode::{deserialize_from, Error}; -use p3_matrix::{ - dense::{RowMajorMatrix, RowMajorMatrixView}, - stack::VerticalPair, -}; -use serde::{de::DeserializeOwned, Deserialize, Serialize}; -use size::Size; -use tracing::trace; +use p3_matrix::dense::RowMajorMatrix; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use serde::{Deserialize, Serialize}; use super::{Challenge, Com, OpeningProof, PcsProverData, StarkGenericConfig, Val}; @@ -26,7 +18,6 @@ pub struct ShardMainData { pub main_commit: Com, pub main_data: PcsProverData, pub chip_ordering: HashMap, - pub index: usize, pub public_values: Vec, } @@ -36,7 +27,6 @@ impl ShardMainData { main_commit: Com, main_data: PcsProverData, chip_ordering: HashMap, - index: usize, public_values: Vec>, ) -> Self { Self { @@ -44,54 +34,9 @@ impl ShardMainData { main_commit, main_data, chip_ordering, - index, public_values, } } - - pub fn save(&self, file: File) -> Result, Error> - where - ShardMainData: Serialize, - { - let mut writer = BufWriter::new(&file); - bincode::serialize_into(&mut writer, self)?; - drop(writer); - let metadata = file.metadata()?; - let bytes_written = metadata.len(); - trace!( - "wrote {} while saving ShardMainData", - Size::from_bytes(bytes_written) - ); - Ok(ShardMainDataWrapper::TempFile(file, bytes_written)) - } - - pub const fn to_in_memory(self) -> ShardMainDataWrapper { - ShardMainDataWrapper::InMemory(self) - } -} - -pub enum ShardMainDataWrapper { - InMemory(ShardMainData), - TempFile(File, u64), - Empty(), -} - -impl ShardMainDataWrapper { - pub fn materialize(self) -> Result, Error> - where - ShardMainData: DeserializeOwned, - { - match self { - Self::InMemory(data) => Ok(data), - Self::TempFile(file, _) => { - let mut buffer = BufReader::new(&file); - buffer.seek(std::io::SeekFrom::Start(0))?; - let data = deserialize_from(&mut buffer)?; - Ok(data) - } - Self::Empty() => unreachable!(), - } - } } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -125,7 +70,7 @@ pub struct ShardOpenedValues { /// The maximum number of elements that can be stored in the public values vec. Both SP1 and recursive /// proofs need to pad their public_values vec to this length. This is required since the recursion /// verification program expects the public values vec to be fixed length. -pub const PROOF_MAX_NUM_PVS: usize = 241; +pub const PROOF_MAX_NUM_PVS: usize = 370; #[derive(Serialize, Deserialize, Clone)] #[serde(bound = "")] @@ -159,6 +104,23 @@ impl ShardProof { .map(|c| c.cumulative_sum) .sum() } + + pub fn log_degree_cpu(&self) -> usize { + let idx = self.chip_ordering.get("CPU").expect("CPU chip not found"); + self.opened_values.chips[*idx].log_degree + } + + pub fn contains_cpu(&self) -> bool { + self.chip_ordering.contains_key("CPU") + } + + pub fn contains_memory_init(&self) -> bool { + self.chip_ordering.contains_key("MemoryInit") + } + + pub fn contains_memory_finalize(&self) -> bool { + self.chip_ordering.contains_key("MemoryFinalize") + } } #[derive(Serialize, Deserialize, Clone)] diff --git a/core/src/stark/verifier.rs b/core/src/stark/verifier.rs index 463cedc11..29998ce6c 100644 --- a/core/src/stark/verifier.rs +++ b/core/src/stark/verifier.rs @@ -51,7 +51,9 @@ impl>> Verifier { let pcs = config.pcs(); - assert_eq!(chips.len(), opened_values.chips.len()); + if chips.len() != opened_values.chips.len() { + return Err(VerificationError::ChipOpeningLengthMismatch); + } let log_degrees = opened_values .chips @@ -199,14 +201,6 @@ impl>> Verifier { .map_err(|_e| VerificationError::OodEvaluationMismatch(chip.as_ref().name()))?; } - let nb_cpu_chips = chips - .iter() - .filter(|chip| chip.as_ref().name() == "CPU") - .count(); - if nb_cpu_chips != 1 { - return Err(VerificationError::MissingCpuChip); - } - Ok(()) } @@ -419,6 +413,7 @@ pub enum VerificationError { /// The shape of the opening arguments is invalid. OpeningShapeError(String, OpeningShapeError), MissingCpuChip, + ChipOpeningLengthMismatch, } impl Debug for OpeningShapeError { @@ -485,6 +480,9 @@ impl Debug for VerificationError { VerificationError::MissingCpuChip => { write!(f, "Missing CPU chip") } + VerificationError::ChipOpeningLengthMismatch => { + write!(f, "Chip opening length mismatch") + } } } } @@ -504,6 +502,9 @@ impl Display for VerificationError { VerificationError::MissingCpuChip => { write!(f, "Missing CPU chip in shard") } + VerificationError::ChipOpeningLengthMismatch => { + write!(f, "Chip opening length mismatch") + } } } } diff --git a/core/src/syscall/hint.rs b/core/src/syscall/hint.rs index 5d286bfbe..b0846495e 100644 --- a/core/src/syscall/hint.rs +++ b/core/src/syscall/hint.rs @@ -17,10 +17,11 @@ impl SyscallHintLen { impl Syscall for SyscallHintLen { fn execute(&self, ctx: &mut SyscallContext<'_, '_>, _arg1: u32, _arg2: u32) -> Option { - assert!( - ctx.rt.state.input_stream_ptr < ctx.rt.state.input_stream.len(), - "not enough vecs in hint input stream" - ); + assert!(ctx.rt.state.input_stream_ptr < ctx.rt.state.input_stream.len(), + "failed reading stdin due to insufficient input data: input_stream_ptr={}, input_stream_len={}", + ctx.rt.state.input_stream_ptr, + ctx.rt.state.input_stream.len() + ); Some(ctx.rt.state.input_stream[ctx.rt.state.input_stream_ptr].len() as u32) } } @@ -42,10 +43,11 @@ impl SyscallHintRead { impl Syscall for SyscallHintRead { fn execute(&self, ctx: &mut SyscallContext<'_, '_>, ptr: u32, len: u32) -> Option { - assert!( - ctx.rt.state.input_stream_ptr < ctx.rt.state.input_stream.len(), - "not enough vecs in hint input stream" - ); + assert!(ctx.rt.state.input_stream_ptr < ctx.rt.state.input_stream.len(), + "failed reading stdin due to insufficient input data: input_stream_ptr={}, input_stream_len={}", + ctx.rt.state.input_stream_ptr, + ctx.rt.state.input_stream.len() + ); let vec = &ctx.rt.state.input_stream[ctx.rt.state.input_stream_ptr]; ctx.rt.state.input_stream_ptr += 1; assert!( @@ -89,6 +91,7 @@ mod tests { use crate::{ io::SphinxStdin, runtime::Program, + stark::DefaultProver, utils::{prove, setup_logger, BabyBearPoseidon2, SphinxCoreOpts}, }; @@ -110,6 +113,7 @@ mod tests { let program = Program::from(HINT_IO_ELF); let config = BabyBearPoseidon2::new(); - prove(&program, &stdin, config, SphinxCoreOpts::default()).unwrap(); + prove::<_, DefaultProver<_, _>>(&program, &stdin, config, SphinxCoreOpts::default()) + .unwrap(); } } diff --git a/core/src/syscall/precompiles/bls12_381/g1_decompress.rs b/core/src/syscall/precompiles/bls12_381/g1_decompress.rs index 6b827fb17..7a7a2ab21 100644 --- a/core/src/syscall/precompiles/bls12_381/g1_decompress.rs +++ b/core/src/syscall/precompiles/bls12_381/g1_decompress.rs @@ -67,7 +67,7 @@ pub fn bls12_381_g1_decompress(bytes_be: &[u8]) -> AffinePoint>(program); let mut decompressed_g1 = vec![]; // decompressed G1 occupies 96 bytes or 24 words (8 bytes each): 96 / 8 = 24 @@ -721,7 +721,8 @@ mod tests { let inputs = SphinxStdin::from(&pt_compressed[..]); let mut public_values = - run_test_io(Program::from(BLS12381_G1_DECOMPRESS_ELF), &inputs).unwrap(); + run_test_io::>(Program::from(BLS12381_G1_DECOMPRESS_ELF), &inputs) + .unwrap(); let mut result = [0; 96]; public_values.read_slice(&mut result); assert_eq!(result, pt_uncompressed); @@ -738,8 +739,11 @@ mod tests { let inputs = SphinxStdin::from(&pt_compressed[..]); - let mut public_values = - run_test_io(Program::from(BLS12381_G1_DECOMPRESS_ELF), &inputs).unwrap(); + let mut public_values = run_test_io::>( + Program::from(BLS12381_G1_DECOMPRESS_ELF), + &inputs, + ) + .unwrap(); let mut result = [0; 96]; public_values.read_slice(&mut result); assert_eq!(result, pt_uncompressed); @@ -755,7 +759,7 @@ mod tests { .unwrap() .to_uncompressed(); - let mut public_values = run_test_io( + let mut public_values = run_test_io::>( Program::from(BLS12381_G1_DECOMPRESS_ELF), &SphinxStdin::from(&compressed), ) diff --git a/core/src/syscall/precompiles/bls12_381/g2_add.rs b/core/src/syscall/precompiles/bls12_381/g2_add.rs index f9c2dd814..b568d1898 100644 --- a/core/src/syscall/precompiles/bls12_381/g2_add.rs +++ b/core/src/syscall/precompiles/bls12_381/g2_add.rs @@ -138,7 +138,7 @@ impl Bls12381G2AffineAddChip { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Bls12381G2AffineAddEvent { - pub lookup_id: usize, + pub lookup_id: u128, pub clk: u32, pub shard: u32, pub channel: u32, @@ -615,6 +615,7 @@ where #[cfg(test)] mod tests { use crate::runtime::{Instruction, Opcode, SyscallCode}; + use crate::stark::DefaultProver; use crate::utils::ec::weierstrass::bls12_381::fp_to_biguint; use crate::utils::tests::BLS12381_G2_ADD_ELF; use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; @@ -683,7 +684,7 @@ mod tests { setup_logger(); let program = risc_v_program(a_ptr, b_ptr, a_words, b_words); - let (_, memory) = run_test_with_memory_inspection(program); + let (_, memory) = run_test_with_memory_inspection::>(program); let mut result = vec![]; // Fp / BigUint is encoded as a 12 u32 words. G2Affine point has 4 Fp elements, so we read 4 * 12 words from the memory for i in 0..48 { @@ -808,6 +809,6 @@ mod tests { fn test_bls12381_g2_addition_precompile_elf() { setup_logger(); let program = Program::from(BLS12381_G2_ADD_ELF); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } } diff --git a/core/src/syscall/precompiles/bls12_381/g2_double.rs b/core/src/syscall/precompiles/bls12_381/g2_double.rs index f523fcf43..67be41f1a 100644 --- a/core/src/syscall/precompiles/bls12_381/g2_double.rs +++ b/core/src/syscall/precompiles/bls12_381/g2_double.rs @@ -155,7 +155,7 @@ impl Bls12381G2AffineDoubleChip { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Bls12381G2AffineDoubleEvent { - pub(crate) lookup_id: usize, + pub(crate) lookup_id: u128, clk: u32, shard: u32, channel: u32, @@ -574,6 +574,7 @@ where #[cfg(test)] mod tests { use crate::runtime::{Instruction, Opcode, SyscallCode}; + use crate::stark::DefaultProver; use crate::utils::ec::weierstrass::bls12_381::fp_to_biguint; use crate::utils::tests::BLS12381_G2_DOUBLE_ELF; use crate::utils::{run_test, run_test_with_memory_inspection, setup_logger}; @@ -630,7 +631,7 @@ mod tests { setup_logger(); let program = risc_v_program(p_ptr, words); - let (_, memory) = run_test_with_memory_inspection(program); + let (_, memory) = run_test_with_memory_inspection::>(program); let mut result = vec![]; // Fp / BigUint is encoded as a 12 u32 words. G2Affine point has 4 Fp elements, so we read 4 * 12 words from the memory @@ -696,6 +697,6 @@ mod tests { fn test_bls12381_g2_double_precompile_elf() { setup_logger(); let program = Program::from(BLS12381_G2_DOUBLE_ELF); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } } diff --git a/core/src/syscall/precompiles/edwards/ed_add.rs b/core/src/syscall/precompiles/edwards/ed_add.rs index da5c6ae34..c903d2462 100644 --- a/core/src/syscall/precompiles/edwards/ed_add.rs +++ b/core/src/syscall/precompiles/edwards/ed_add.rs @@ -4,7 +4,9 @@ use core::{ }; use std::{fmt::Debug, marker::PhantomData}; +use hashbrown::HashMap; use hybrid_array::{typenum::Unsigned, Array}; +use itertools::Itertools; use num::BigUint; use num::Zero; @@ -16,9 +18,10 @@ use p3_matrix::dense::RowMajorMatrix; use p3_matrix::Matrix; use p3_maybe_rayon::prelude::IntoParallelRefIterator; use p3_maybe_rayon::prelude::ParallelIterator; +use p3_maybe_rayon::prelude::ParallelSlice; use sphinx_derive::AlignedBorrow; -use crate::air::BaseAirBuilder; +use crate::air::{AluAirBuilder, EventLens, MemoryAirBuilder, WithEvents}; use crate::bytes::ByteLookupEvent; use crate::memory::MemoryReadCols; use crate::memory::MemoryWriteCols; @@ -33,10 +36,8 @@ use crate::runtime::ExecutionRecord; use crate::runtime::Program; use crate::runtime::Syscall; use crate::runtime::SyscallCode; -use crate::syscall::precompiles::create_ec_add_event; use crate::syscall::precompiles::SyscallContext; -use crate::syscall::precompiles::DEFAULT_NUM_LIMBS_T; -use crate::syscall::precompiles::WORDS_CURVEPOINT; +use crate::syscall::precompiles::{create_ec_add_event, ECAddEvent}; use crate::utils::ec::edwards::ed25519::Ed25519BaseField; use crate::utils::ec::edwards::EdwardsParameters; use crate::utils::ec::AffinePoint; @@ -44,11 +45,11 @@ use crate::utils::ec::BaseLimbWidth; use crate::utils::ec::EllipticCurve; use crate::utils::limbs_from_prev_access; use crate::utils::pad_rows; -use crate::{air::MachineAir, utils::ec::EllipticCurveParameters}; use crate::{ - air::{AluAirBuilder, EventLens, MemoryAirBuilder, WithEvents}, - syscall::precompiles::ECAddEvent, + air::BaseAirBuilder, + operations::field::params::{DEFAULT_NUM_LIMBS_T, WORDS_CURVEPOINT}, }; +use crate::{air::MachineAir, utils::ec::EllipticCurveParameters}; use crate::{bytes::event::ByteRecord, utils::limbs_from_access}; pub const NUM_ED_ADD_COLS: usize = size_of::>(); @@ -176,69 +177,22 @@ where fn generate_trace>( &self, input: &EL, - output: &mut ExecutionRecord, + _: &mut ExecutionRecord, ) -> RowMajorMatrix { - let (mut rows, new_byte_lookup_events): (Vec>, Vec>) = input + let mut rows = input .events() .par_iter() .map(|event| { - let mut row = vec![F::zero(); size_of::>()]; + let mut row = [F::zero(); NUM_ED_ADD_COLS]; let cols: &mut EdAddAssignCols = row.as_mut_slice().borrow_mut(); - - // Decode affine points. - let p = &event.p; - let q = &event.q; - let p = AffinePoint::::from_words_le(p); - let (p_x, p_y) = (p.x, p.y); - let q = AffinePoint::::from_words_le(q); - let (q_x, q_y) = (q.x, q.y); - - // Populate basic columns. - cols.is_real = F::one(); - cols.shard = F::from_canonical_u32(event.shard); - cols.channel = F::from_canonical_u32(event.channel); - cols.clk = F::from_canonical_u32(event.clk); - cols.p_ptr = F::from_canonical_u32(event.p_ptr); - cols.q_ptr = F::from_canonical_u32(event.q_ptr); - - let mut new_byte_lookup_events = Vec::new(); - Self::populate_field_ops( - &mut new_byte_lookup_events, - event.shard, - event.channel, - cols, - &p_x, - &p_y, - &q_x, - &q_y, - ); - - // Populate the memory access columns. - for i in 0..WORDS_CURVEPOINT::>::USIZE { - cols.q_access[i].populate( - event.channel, - event.q_memory_records[i], - &mut new_byte_lookup_events, - ); - } - for i in 0..WORDS_CURVEPOINT::>::USIZE { - cols.p_access[i].populate( - event.channel, - event.p_memory_records[i], - &mut new_byte_lookup_events, - ); - } - - (row, new_byte_lookup_events) + let mut blu = Vec::new(); + self.event_to_row(event, cols, &mut blu); + row }) - .unzip(); - - for byte_lookup_events in new_byte_lookup_events { - output.add_byte_lookup_events(byte_lookup_events); - } + .collect::>(); pad_rows(&mut rows, || { - let mut row = vec![F::zero(); size_of::>()]; + let mut row = [F::zero(); NUM_ED_ADD_COLS]; let cols: &mut EdAddAssignCols = row.as_mut_slice().borrow_mut(); let zero = BigUint::zero(); Self::populate_field_ops(&mut vec![], 0, 0, cols, &zero, &zero, &zero, &zero); @@ -261,11 +215,77 @@ where trace } + fn generate_dependencies>(&self, input: &EL, output: &mut ExecutionRecord) { + let chunk_size = std::cmp::max(input.events().len() / num_cpus::get(), 1); + + let blu_batches = input + .events() + .par_chunks(chunk_size) + .map(|events| { + let mut blu: HashMap> = HashMap::new(); + for event in events.iter() { + let mut row = [F::zero(); NUM_ED_ADD_COLS]; + let cols: &mut EdAddAssignCols = + row.as_mut_slice().borrow_mut(); + self.event_to_row(event, cols, &mut blu); + } + blu + }) + .collect::>(); + + output.add_sharded_byte_lookup_events(blu_batches.iter().collect_vec()); + } + fn included(&self, shard: &Self::Record) -> bool { !shard.ed_add_events.is_empty() } } +impl EdAddAssignChip { + /// Create a row from an event. + fn event_to_row( + &self, + event: &ECAddEvent, + cols: &mut EdAddAssignCols, + blu: &mut impl ByteRecord, + ) { + // Decode affine points. + let p = &event.p; + let q = &event.q; + let p = AffinePoint::::from_words_le(p); + let (p_x, p_y) = (p.x, p.y); + let q = AffinePoint::::from_words_le(q); + let (q_x, q_y) = (q.x, q.y); + + // Populate basic columns. + cols.is_real = F::one(); + cols.shard = F::from_canonical_u32(event.shard); + cols.channel = F::from_canonical_u32(event.channel); + cols.clk = F::from_canonical_u32(event.clk); + cols.p_ptr = F::from_canonical_u32(event.p_ptr); + cols.q_ptr = F::from_canonical_u32(event.q_ptr); + + Self::populate_field_ops( + blu, + event.shard, + event.channel, + cols, + &p_x, + &p_y, + &q_x, + &q_y, + ); + + // Populate the memory access columns. + for i in 0..WORDS_CURVEPOINT::>::USIZE { + cols.q_access[i].populate(event.channel, event.q_memory_records[i], blu); + } + for i in 0..WORDS_CURVEPOINT::>::USIZE { + cols.p_access[i].populate(event.channel, event.p_memory_records[i], blu); + } + } +} + impl BaseAir for EdAddAssignChip { fn width(&self) -> usize { size_of::>() @@ -430,23 +450,22 @@ where #[cfg(test)] mod tests { - use crate::{ - utils, - utils::tests::{ED25519_ELF, ED_ADD_ELF}, - Program, - }; + use crate::stark::DefaultProver; + use crate::utils; + use crate::utils::tests::{ED25519_ELF, ED_ADD_ELF}; + use crate::Program; #[test] fn test_ed_add_simple() { utils::setup_logger(); let program = Program::from(ED_ADD_ELF); - utils::run_test(program).unwrap(); + utils::run_test::>(program).unwrap(); } #[test] fn test_ed25519_program() { utils::setup_logger(); let program = Program::from(ED25519_ELF); - utils::run_test(program).unwrap(); + utils::run_test::>(program).unwrap(); } } diff --git a/core/src/syscall/precompiles/edwards/ed_decompress.rs b/core/src/syscall/precompiles/edwards/ed_decompress.rs index 6446d301b..dbf0cb22c 100644 --- a/core/src/syscall/precompiles/edwards/ed_decompress.rs +++ b/core/src/syscall/precompiles/edwards/ed_decompress.rs @@ -52,7 +52,7 @@ use crate::utils::words_to_bytes_le; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct EdDecompressEvent { - pub lookup_id: usize, + pub lookup_id: u128, pub shard: u32, pub channel: u32, pub clk: u32, @@ -469,16 +469,14 @@ where pub mod tests { use crate::{ runtime::Program, - utils::{ - tests::ED_DECOMPRESS_ELF, - {self}, - }, + stark::DefaultProver, + utils::{self, tests::ED_DECOMPRESS_ELF}, }; #[test] fn test_ed_decompress() { utils::setup_logger(); let program = Program::from(ED_DECOMPRESS_ELF); - utils::run_test(program).unwrap(); + utils::run_test::>(program).unwrap(); } } diff --git a/core/src/syscall/precompiles/field/mod.rs b/core/src/syscall/precompiles/field/mod.rs index dacec7b8b..b13866157 100644 --- a/core/src/syscall/precompiles/field/mod.rs +++ b/core/src/syscall/precompiles/field/mod.rs @@ -80,7 +80,7 @@ impl FieldMulSyscall { /// Fp operation event. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct FieldEvent { - pub lookup_id: usize, + pub lookup_id: u128, pub shard: u32, pub channel: u32, pub clk: u32, @@ -401,29 +401,30 @@ impl BaseAir for FieldChip { #[cfg(test)] mod tests { use crate::{ - utils, + stark::DefaultProver, utils::tests::{BLS12381_FP_ADD_ELF, BLS12381_FP_MUL_ELF, BLS12381_FP_SUB_ELF}, + utils::{run_test, setup_logger}, Program, }; #[test] fn test_bls12381_fp_add_simple() { - utils::setup_logger(); + setup_logger(); let program = Program::from(BLS12381_FP_ADD_ELF); - utils::run_test(program).unwrap(); + run_test::>(program).unwrap(); } #[test] fn test_bls12381_fp_mul_simple() { - utils::setup_logger(); + setup_logger(); let program = Program::from(BLS12381_FP_MUL_ELF); - utils::run_test(program).unwrap(); + run_test::>(program).unwrap(); } #[test] fn test_bls12381_fp_sub_simple() { - utils::setup_logger(); + setup_logger(); let program = Program::from(BLS12381_FP_SUB_ELF); - utils::run_test(program).unwrap(); + run_test::>(program).unwrap(); } } diff --git a/core/src/syscall/precompiles/keccak256/air.rs b/core/src/syscall/precompiles/keccak256/air.rs index 932a08b3c..18b485d2e 100644 --- a/core/src/syscall/precompiles/keccak256/air.rs +++ b/core/src/syscall/precompiles/keccak256/air.rs @@ -153,7 +153,7 @@ where mod test { use crate::io::{SphinxPublicValues, SphinxStdin}; use crate::runtime::Program; - use crate::stark::{RiscvAir, StarkGenericConfig}; + use crate::stark::{DefaultProver, RiscvAir, StarkGenericConfig}; use crate::utils::SphinxCoreOpts; use crate::utils::{prove, setup_logger, tests::KECCAK256_ELF, BabyBearPoseidon2}; @@ -190,7 +190,8 @@ mod test { let program = Program::from(KECCAK256_ELF); let (proof, public_values) = - prove(&program, &stdin, config, SphinxCoreOpts::default()).unwrap(); + prove::<_, DefaultProver<_, _>>(&program, &stdin, config, SphinxCoreOpts::default()) + .unwrap(); let mut public_values = SphinxPublicValues::from(&public_values); let config = BabyBearPoseidon2::new(); diff --git a/core/src/syscall/precompiles/keccak256/mod.rs b/core/src/syscall/precompiles/keccak256/mod.rs index 641d34d1e..e4df97fdb 100644 --- a/core/src/syscall/precompiles/keccak256/mod.rs +++ b/core/src/syscall/precompiles/keccak256/mod.rs @@ -15,7 +15,7 @@ const STATE_NUM_WORDS: usize = STATE_SIZE * 2; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct KeccakPermuteEvent { - pub lookup_id: usize, + pub lookup_id: u128, pub shard: u32, pub channel: u32, pub clk: u32, @@ -47,6 +47,7 @@ impl Default for KeccakPermuteChip { #[cfg(test)] pub mod permute_tests { use crate::runtime::SyscallCode; + use crate::stark::DefaultProver; use crate::utils::{run_test, SphinxCoreOpts}; use crate::{ runtime::{Instruction, Opcode, Program, Runtime}, @@ -91,13 +92,13 @@ pub mod permute_tests { utils::setup_logger(); let program = keccak_permute_program(); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } #[test] fn test_keccak_permute_program_prove() { utils::setup_logger(); let program = Program::from(KECCAK_PERMUTE_ELF); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } } diff --git a/core/src/syscall/precompiles/keccak256/trace.rs b/core/src/syscall/precompiles/keccak256/trace.rs index 039ea415f..8c11746fb 100644 --- a/core/src/syscall/precompiles/keccak256/trace.rs +++ b/core/src/syscall/precompiles/keccak256/trace.rs @@ -130,7 +130,6 @@ impl MachineAir for KeccakPermuteChip { let mut rows: Vec<[F; NUM_KECCAK_MEM_COLS]> = vec![]; for (mut row, mut record) in rows_and_records { rows.append(&mut row); - record.index = output.index; output.append(&mut record); } diff --git a/core/src/syscall/precompiles/mod.rs b/core/src/syscall/precompiles/mod.rs index d85d25e4b..83651858b 100644 --- a/core/src/syscall/precompiles/mod.rs +++ b/core/src/syscall/precompiles/mod.rs @@ -22,7 +22,7 @@ use crate::{ /// Elliptic curve add event. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ECAddEvent { - pub lookup_id: usize, + pub lookup_id: u128, pub shard: u32, pub channel: u32, pub clk: u32, @@ -83,7 +83,7 @@ pub fn create_ec_add_event( /// Elliptic curve double event. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ECDoubleEvent { - pub lookup_id: usize, + pub lookup_id: u128, pub shard: u32, pub channel: u32, pub clk: u32, diff --git a/core/src/syscall/precompiles/quad_field/mod.rs b/core/src/syscall/precompiles/quad_field/mod.rs index 95ecd2dfa..d98dd9ee3 100644 --- a/core/src/syscall/precompiles/quad_field/mod.rs +++ b/core/src/syscall/precompiles/quad_field/mod.rs @@ -104,7 +104,7 @@ impl QuadFieldMulSyscall { /// Fp2 operation event. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct QuadFieldEvent { - pub lookup_id: usize, + pub lookup_id: u128, pub shard: u32, pub channel: u32, pub clk: u32, @@ -478,8 +478,11 @@ where #[cfg(test)] mod tests { use crate::{ - utils, - utils::tests::{BLS12381_FP2_ADD_ELF, BLS12381_FP2_MUL_ELF, BLS12381_FP2_SUB_ELF}, + stark::DefaultProver, + utils::{ + self, run_test, + tests::{BLS12381_FP2_ADD_ELF, BLS12381_FP2_MUL_ELF, BLS12381_FP2_SUB_ELF}, + }, Program, }; @@ -487,20 +490,20 @@ mod tests { fn test_bls12381_fp2_add_simple() { utils::setup_logger(); let program = Program::from(BLS12381_FP2_ADD_ELF); - utils::run_test(program).unwrap(); + run_test::>(program).unwrap(); } #[test] fn test_bls12381_fp2_sub_simple() { utils::setup_logger(); let program = Program::from(BLS12381_FP2_SUB_ELF); - utils::run_test(program).unwrap(); + run_test::>(program).unwrap(); } #[test] fn test_bls12381_fp2_mul_simple() { utils::setup_logger(); let program = Program::from(BLS12381_FP2_MUL_ELF); - utils::run_test(program).unwrap(); + run_test::>(program).unwrap(); } } diff --git a/core/src/syscall/precompiles/secp256k1/decompress.rs b/core/src/syscall/precompiles/secp256k1/decompress.rs index 55fba4b43..07dea4c10 100644 --- a/core/src/syscall/precompiles/secp256k1/decompress.rs +++ b/core/src/syscall/precompiles/secp256k1/decompress.rs @@ -63,7 +63,7 @@ pub fn secp256k1_decompress(bytes_be: &[u8], sign: u32) -> AffinePoint>(Program::from(SECP256K1_DECOMPRESS_ELF), &inputs) + .unwrap(); let mut result = [0; 65]; public_values.read_slice(&mut result); assert_eq!(result, decompressed); diff --git a/core/src/syscall/precompiles/sha256/compress/mod.rs b/core/src/syscall/precompiles/sha256/compress/mod.rs index 47401a25b..dcf3749b3 100644 --- a/core/src/syscall/precompiles/sha256/compress/mod.rs +++ b/core/src/syscall/precompiles/sha256/compress/mod.rs @@ -20,7 +20,7 @@ pub const SHA_COMPRESS_K: [u32; 64] = [ #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ShaCompressEvent { - pub lookup_id: usize, + pub lookup_id: u128, pub shard: u32, pub channel: u32, pub clk: u32, @@ -54,6 +54,7 @@ pub mod compress_tests { use crate::{ runtime::{Instruction, Opcode, Program, SyscallCode}, + stark::DefaultProver, utils::{run_test, setup_logger, tests::SHA_COMPRESS_ELF}, }; @@ -93,13 +94,13 @@ pub mod compress_tests { fn prove_babybear() { setup_logger(); let program = sha_compress_program(); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } #[test] fn test_sha_compress_program() { setup_logger(); let program = Program::from(SHA_COMPRESS_ELF); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } } diff --git a/core/src/syscall/precompiles/sha256/compress/trace.rs b/core/src/syscall/precompiles/sha256/compress/trace.rs index 4b314f2b1..31a40d97f 100644 --- a/core/src/syscall/precompiles/sha256/compress/trace.rs +++ b/core/src/syscall/precompiles/sha256/compress/trace.rs @@ -1,8 +1,11 @@ use std::borrow::BorrowMut; +use hashbrown::HashMap; +use itertools::Itertools; use p3_field::PrimeField32; use p3_matrix::dense::RowMajorMatrix; use p3_matrix::Matrix; +use p3_maybe_rayon::prelude::{ParallelIterator, ParallelSlice}; use super::{ columns::{ShaCompressCols, NUM_SHA_COMPRESS_COLS}, @@ -10,7 +13,7 @@ use super::{ }; use crate::{ air::{EventLens, MachineAir, WithEvents, Word}, - bytes::event::ByteRecord, + bytes::{event::ByteRecord, ByteLookupEvent}, runtime::{ExecutionRecord, Program}, utils::pad_rows, }; @@ -31,226 +34,16 @@ impl MachineAir for ShaCompressChip { fn generate_trace>( &self, input: &EL, - output: &mut ExecutionRecord, + _: &mut ExecutionRecord, ) -> RowMajorMatrix { - let mut rows = Vec::new(); + let rows = Vec::new(); - let mut new_byte_lookup_events = Vec::new(); + let mut wrapped_rows = Some(rows); for i in 0..input.events().len() { - let mut event = input.events()[i].clone(); - let shard = event.shard; - let channel = event.channel; - - let og_h = event.h; - - let mut octet_num_idx = 0; - - // Load a, b, c, d, e, f, g, h. - for j in 0..8usize { - let mut row = [F::zero(); NUM_SHA_COMPRESS_COLS]; - let cols: &mut ShaCompressCols = row.as_mut_slice().borrow_mut(); - - cols.shard = F::from_canonical_u32(event.shard); - cols.channel = F::from_canonical_u32(event.channel); - cols.clk = F::from_canonical_u32(event.clk); - cols.w_ptr = F::from_canonical_u32(event.w_ptr); - cols.h_ptr = F::from_canonical_u32(event.h_ptr); - - cols.octet[j] = F::one(); - cols.octet_num[octet_num_idx] = F::one(); - cols.is_initialize = F::one(); - - cols.mem.populate_read( - channel, - event.h_read_records[j], - &mut new_byte_lookup_events, - ); - cols.mem_addr = F::from_canonical_u32(event.h_ptr + (j * 4) as u32); - - cols.a = Word::from(event.h_read_records[0].value); - cols.b = Word::from(event.h_read_records[1].value); - cols.c = Word::from(event.h_read_records[2].value); - cols.d = Word::from(event.h_read_records[3].value); - cols.e = Word::from(event.h_read_records[4].value); - cols.f = Word::from(event.h_read_records[5].value); - cols.g = Word::from(event.h_read_records[6].value); - cols.h = Word::from(event.h_read_records[7].value); - - cols.is_real = F::one(); - cols.start = cols.is_real * cols.octet_num[0] * cols.octet[0]; - rows.push(row); - } - - // Performs the compress operation. - for j in 0..64 { - if j % 8 == 0 { - octet_num_idx += 1; - } - let mut row = [F::zero(); NUM_SHA_COMPRESS_COLS]; - let cols: &mut ShaCompressCols = row.as_mut_slice().borrow_mut(); - - cols.k = Word::from(SHA_COMPRESS_K[j]); - cols.is_compression = F::one(); - cols.octet[j % 8] = F::one(); - cols.octet_num[octet_num_idx] = F::one(); - - cols.shard = F::from_canonical_u32(event.shard); - cols.channel = F::from_canonical_u32(event.channel); - cols.clk = F::from_canonical_u32(event.clk); - cols.w_ptr = F::from_canonical_u32(event.w_ptr); - cols.h_ptr = F::from_canonical_u32(event.h_ptr); - cols.mem.populate_read( - channel, - event.w_i_read_records[j], - &mut new_byte_lookup_events, - ); - cols.mem_addr = F::from_canonical_u32(event.w_ptr + (j * 4) as u32); - - let a = event.h[0]; - let b = event.h[1]; - let c = event.h[2]; - let d = event.h[3]; - let e = event.h[4]; - let f = event.h[5]; - let g = event.h[6]; - let h = event.h[7]; - cols.a = Word::from(a); - cols.b = Word::from(b); - cols.c = Word::from(c); - cols.d = Word::from(d); - cols.e = Word::from(e); - cols.f = Word::from(f); - cols.g = Word::from(g); - cols.h = Word::from(h); - - let e_rr_6 = cols.e_rr_6.populate(output, shard, channel, e, 6); - let e_rr_11 = cols.e_rr_11.populate(output, shard, channel, e, 11); - let e_rr_25 = cols.e_rr_25.populate(output, shard, channel, e, 25); - let s1_intermediate = cols - .s1_intermediate - .populate(output, shard, channel, e_rr_6, e_rr_11); - let s1 = cols - .s1 - .populate(output, shard, channel, s1_intermediate, e_rr_25); - - let e_and_f = cols.e_and_f.populate(output, shard, channel, e, f); - let e_not = cols.e_not.populate(output, shard, channel, e); - let e_not_and_g = cols.e_not_and_g.populate(output, shard, channel, e_not, g); - let ch = cols - .ch - .populate(output, shard, channel, e_and_f, e_not_and_g); - - let temp1 = cols.temp1.populate( - output, - shard, - channel, - h, - s1, - ch, - event.w[j], - SHA_COMPRESS_K[j], - ); - - let a_rr_2 = cols.a_rr_2.populate(output, shard, channel, a, 2); - let a_rr_13 = cols.a_rr_13.populate(output, shard, channel, a, 13); - let a_rr_22 = cols.a_rr_22.populate(output, shard, channel, a, 22); - let s0_intermediate = cols - .s0_intermediate - .populate(output, shard, channel, a_rr_2, a_rr_13); - let s0 = cols - .s0 - .populate(output, shard, channel, s0_intermediate, a_rr_22); - - let a_and_b = cols.a_and_b.populate(output, shard, channel, a, b); - let a_and_c = cols.a_and_c.populate(output, shard, channel, a, c); - let b_and_c = cols.b_and_c.populate(output, shard, channel, b, c); - let maj_intermediate = cols - .maj_intermediate - .populate(output, shard, channel, a_and_b, a_and_c); - let maj = cols - .maj - .populate(output, shard, channel, maj_intermediate, b_and_c); - - let temp2 = cols.temp2.populate(output, shard, channel, s0, maj); - - let d_add_temp1 = cols.d_add_temp1.populate(output, shard, channel, d, temp1); - let temp1_add_temp2 = cols - .temp1_add_temp2 - .populate(output, shard, channel, temp1, temp2); - - event.h[7] = g; - event.h[6] = f; - event.h[5] = e; - event.h[4] = d_add_temp1; - event.h[3] = c; - event.h[2] = b; - event.h[1] = a; - event.h[0] = temp1_add_temp2; - - cols.is_real = F::one(); - cols.start = cols.is_real * cols.octet_num[0] * cols.octet[0]; - - rows.push(row); - } - - let mut v: [u32; 8] = [0, 1, 2, 3, 4, 5, 6, 7].map(|i| event.h[i]); - - octet_num_idx += 1; - // Store a, b, c, d, e, f, g, h. - for j in 0..8usize { - let mut row = [F::zero(); NUM_SHA_COMPRESS_COLS]; - let cols: &mut ShaCompressCols = row.as_mut_slice().borrow_mut(); - - cols.shard = F::from_canonical_u32(event.shard); - cols.channel = F::from_canonical_u32(event.channel); - cols.clk = F::from_canonical_u32(event.clk); - cols.w_ptr = F::from_canonical_u32(event.w_ptr); - cols.h_ptr = F::from_canonical_u32(event.h_ptr); - - cols.octet[j] = F::one(); - cols.octet_num[octet_num_idx] = F::one(); - cols.is_finalize = F::one(); - - cols.finalize_add - .populate(output, shard, channel, og_h[j], event.h[j]); - cols.mem.populate_write( - channel, - event.h_write_records[j], - &mut new_byte_lookup_events, - ); - cols.mem_addr = F::from_canonical_u32(event.h_ptr + (j * 4) as u32); - - v[j] = event.h[j]; - cols.a = Word::from(v[0]); - cols.b = Word::from(v[1]); - cols.c = Word::from(v[2]); - cols.d = Word::from(v[3]); - cols.e = Word::from(v[4]); - cols.f = Word::from(v[5]); - cols.g = Word::from(v[6]); - cols.h = Word::from(v[7]); - - match j { - 0 => cols.finalized_operand = cols.a, - 1 => cols.finalized_operand = cols.b, - 2 => cols.finalized_operand = cols.c, - 3 => cols.finalized_operand = cols.d, - 4 => cols.finalized_operand = cols.e, - 5 => cols.finalized_operand = cols.f, - 6 => cols.finalized_operand = cols.g, - 7 => cols.finalized_operand = cols.h, - _ => panic!("unsupported j"), - }; - - cols.is_real = F::one(); - cols.is_last_row = cols.octet[7] * cols.octet_num[9]; - cols.start = cols.is_real * cols.octet_num[0] * cols.octet[0]; - - rows.push(row); - } + let event = input.events()[i].clone(); + self.event_to_rows(&event, &mut wrapped_rows, &mut Vec::new()); } - - output.add_byte_lookup_events(new_byte_lookup_events); + let mut rows = wrapped_rows.unwrap(); let num_real_rows = rows.len(); @@ -296,7 +89,245 @@ impl MachineAir for ShaCompressChip { trace } + fn generate_dependencies>(&self, input: &EL, output: &mut ExecutionRecord) { + let chunk_size = std::cmp::max(input.events().len() / num_cpus::get(), 1); + + let blu_batches = input + .events() + .par_chunks(chunk_size) + .map(|events| { + let mut blu: HashMap> = HashMap::new(); + for event in events.iter() { + self.event_to_rows::(event, &mut None, &mut blu); + } + blu + }) + .collect::>(); + + output.add_sharded_byte_lookup_events(blu_batches.iter().collect_vec()); + } + fn included(&self, shard: &Self::Record) -> bool { !shard.sha_compress_events.is_empty() } } + +impl ShaCompressChip { + fn event_to_rows( + &self, + event: &ShaCompressEvent, + rows: &mut Option>, + blu: &mut impl ByteRecord, + ) { + let shard = event.shard; + let channel = event.channel; + + let og_h = event.h; + + let mut octet_num_idx = 0; + + // Load a, b, c, d, e, f, g, h. + for j in 0..8usize { + let mut row = [F::zero(); NUM_SHA_COMPRESS_COLS]; + let cols: &mut ShaCompressCols = row.as_mut_slice().borrow_mut(); + + cols.shard = F::from_canonical_u32(event.shard); + cols.channel = F::from_canonical_u32(event.channel); + cols.clk = F::from_canonical_u32(event.clk); + cols.w_ptr = F::from_canonical_u32(event.w_ptr); + cols.h_ptr = F::from_canonical_u32(event.h_ptr); + + cols.octet[j] = F::one(); + cols.octet_num[octet_num_idx] = F::one(); + cols.is_initialize = F::one(); + + cols.mem + .populate_read(channel, event.h_read_records[j], blu); + cols.mem_addr = F::from_canonical_u32(event.h_ptr + (j * 4) as u32); + + cols.a = Word::from(event.h_read_records[0].value); + cols.b = Word::from(event.h_read_records[1].value); + cols.c = Word::from(event.h_read_records[2].value); + cols.d = Word::from(event.h_read_records[3].value); + cols.e = Word::from(event.h_read_records[4].value); + cols.f = Word::from(event.h_read_records[5].value); + cols.g = Word::from(event.h_read_records[6].value); + cols.h = Word::from(event.h_read_records[7].value); + + cols.is_real = F::one(); + cols.start = cols.is_real * cols.octet_num[0] * cols.octet[0]; + if rows.as_ref().is_some() { + rows.as_mut().unwrap().push(row); + } + } + + // Performs the compress operation. + let mut h_array = event.h; + for j in 0..64 { + if j % 8 == 0 { + octet_num_idx += 1; + } + let mut row = [F::zero(); NUM_SHA_COMPRESS_COLS]; + let cols: &mut ShaCompressCols = row.as_mut_slice().borrow_mut(); + + cols.k = Word::from(SHA_COMPRESS_K[j]); + cols.is_compression = F::one(); + cols.octet[j % 8] = F::one(); + cols.octet_num[octet_num_idx] = F::one(); + + cols.shard = F::from_canonical_u32(event.shard); + cols.channel = F::from_canonical_u32(event.channel); + cols.clk = F::from_canonical_u32(event.clk); + cols.w_ptr = F::from_canonical_u32(event.w_ptr); + cols.h_ptr = F::from_canonical_u32(event.h_ptr); + cols.mem + .populate_read(channel, event.w_i_read_records[j], blu); + cols.mem_addr = F::from_canonical_u32(event.w_ptr + (j * 4) as u32); + + let a = h_array[0]; + let b = h_array[1]; + let c = h_array[2]; + let d = h_array[3]; + let e = h_array[4]; + let f = h_array[5]; + let g = h_array[6]; + let h = h_array[7]; + cols.a = Word::from(a); + cols.b = Word::from(b); + cols.c = Word::from(c); + cols.d = Word::from(d); + cols.e = Word::from(e); + cols.f = Word::from(f); + cols.g = Word::from(g); + cols.h = Word::from(h); + + let e_rr_6 = cols.e_rr_6.populate(blu, shard, channel, e, 6); + let e_rr_11 = cols.e_rr_11.populate(blu, shard, channel, e, 11); + let e_rr_25 = cols.e_rr_25.populate(blu, shard, channel, e, 25); + let s1_intermediate = cols + .s1_intermediate + .populate(blu, shard, channel, e_rr_6, e_rr_11); + let s1 = cols + .s1 + .populate(blu, shard, channel, s1_intermediate, e_rr_25); + + let e_and_f = cols.e_and_f.populate(blu, shard, channel, e, f); + let e_not = cols.e_not.populate(blu, shard, channel, e); + let e_not_and_g = cols.e_not_and_g.populate(blu, shard, channel, e_not, g); + let ch = cols.ch.populate(blu, shard, channel, e_and_f, e_not_and_g); + + let temp1 = cols.temp1.populate( + blu, + shard, + channel, + h, + s1, + ch, + event.w[j], + SHA_COMPRESS_K[j], + ); + + let a_rr_2 = cols.a_rr_2.populate(blu, shard, channel, a, 2); + let a_rr_13 = cols.a_rr_13.populate(blu, shard, channel, a, 13); + let a_rr_22 = cols.a_rr_22.populate(blu, shard, channel, a, 22); + let s0_intermediate = cols + .s0_intermediate + .populate(blu, shard, channel, a_rr_2, a_rr_13); + let s0 = cols + .s0 + .populate(blu, shard, channel, s0_intermediate, a_rr_22); + + let a_and_b = cols.a_and_b.populate(blu, shard, channel, a, b); + let a_and_c = cols.a_and_c.populate(blu, shard, channel, a, c); + let b_and_c = cols.b_and_c.populate(blu, shard, channel, b, c); + let maj_intermediate = cols + .maj_intermediate + .populate(blu, shard, channel, a_and_b, a_and_c); + let maj = cols + .maj + .populate(blu, shard, channel, maj_intermediate, b_and_c); + + let temp2 = cols.temp2.populate(blu, shard, channel, s0, maj); + + let d_add_temp1 = cols.d_add_temp1.populate(blu, shard, channel, d, temp1); + let temp1_add_temp2 = cols + .temp1_add_temp2 + .populate(blu, shard, channel, temp1, temp2); + + h_array[7] = g; + h_array[6] = f; + h_array[5] = e; + h_array[4] = d_add_temp1; + h_array[3] = c; + h_array[2] = b; + h_array[1] = a; + h_array[0] = temp1_add_temp2; + + cols.is_real = F::one(); + cols.start = cols.is_real * cols.octet_num[0] * cols.octet[0]; + + if rows.as_ref().is_some() { + rows.as_mut().unwrap().push(row); + } + } + + let mut v: [u32; 8] = (0..8) + .map(|i| h_array[i]) + .collect::>() + .try_into() + .unwrap(); + + octet_num_idx += 1; + // Store a, b, c, d, e, f, g, h. + for j in 0..8usize { + let mut row = [F::zero(); NUM_SHA_COMPRESS_COLS]; + let cols: &mut ShaCompressCols = row.as_mut_slice().borrow_mut(); + + cols.shard = F::from_canonical_u32(event.shard); + cols.channel = F::from_canonical_u32(event.channel); + cols.clk = F::from_canonical_u32(event.clk); + cols.w_ptr = F::from_canonical_u32(event.w_ptr); + cols.h_ptr = F::from_canonical_u32(event.h_ptr); + + cols.octet[j] = F::one(); + cols.octet_num[octet_num_idx] = F::one(); + cols.is_finalize = F::one(); + + cols.finalize_add + .populate(blu, shard, channel, og_h[j], h_array[j]); + cols.mem + .populate_write(channel, event.h_write_records[j], blu); + cols.mem_addr = F::from_canonical_u32(event.h_ptr + (j * 4) as u32); + + v[j] = h_array[j]; + cols.a = Word::from(v[0]); + cols.b = Word::from(v[1]); + cols.c = Word::from(v[2]); + cols.d = Word::from(v[3]); + cols.e = Word::from(v[4]); + cols.f = Word::from(v[5]); + cols.g = Word::from(v[6]); + cols.h = Word::from(v[7]); + + match j { + 0 => cols.finalized_operand = cols.a, + 1 => cols.finalized_operand = cols.b, + 2 => cols.finalized_operand = cols.c, + 3 => cols.finalized_operand = cols.d, + 4 => cols.finalized_operand = cols.e, + 5 => cols.finalized_operand = cols.f, + 6 => cols.finalized_operand = cols.g, + 7 => cols.finalized_operand = cols.h, + _ => panic!("unsupported j"), + }; + + cols.is_real = F::one(); + cols.is_last_row = cols.octet[7] * cols.octet_num[9]; + cols.start = cols.is_real * cols.octet_num[0] * cols.octet[0]; + + if rows.as_ref().is_some() { + rows.as_mut().unwrap().push(row); + } + } + } +} diff --git a/core/src/syscall/precompiles/sha256/extend/mod.rs b/core/src/syscall/precompiles/sha256/extend/mod.rs index 66197d1e5..1f8e8f82a 100644 --- a/core/src/syscall/precompiles/sha256/extend/mod.rs +++ b/core/src/syscall/precompiles/sha256/extend/mod.rs @@ -11,7 +11,7 @@ use crate::runtime::{MemoryReadRecord, MemoryWriteRecord}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ShaExtendEvent { - pub lookup_id: usize, + pub lookup_id: u128, pub shard: u32, pub channel: u32, pub clk: u32, @@ -56,6 +56,7 @@ pub mod extend_tests { air::MachineAir, alu::AluEvent, runtime::{ExecutionRecord, Instruction, Opcode, Program, SyscallCode}, + stark::DefaultProver, utils::{ self, run_test, tests::{SHA2_ELF, SHA_EXTEND_ELF}, @@ -101,20 +102,20 @@ pub mod extend_tests { fn test_sha_prove() { utils::setup_logger(); let program = sha_extend_program(); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } #[test] fn test_sha256_program() { utils::setup_logger(); let program = Program::from(SHA2_ELF); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } #[test] fn test_sha_extend_program() { utils::setup_logger(); let program = Program::from(SHA_EXTEND_ELF); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } } diff --git a/core/src/syscall/precompiles/sha256/extend/trace.rs b/core/src/syscall/precompiles/sha256/extend/trace.rs index 387715635..1ea8a67d8 100644 --- a/core/src/syscall/precompiles/sha256/extend/trace.rs +++ b/core/src/syscall/precompiles/sha256/extend/trace.rs @@ -1,12 +1,15 @@ +use hashbrown::HashMap; +use itertools::Itertools; use p3_field::PrimeField32; use p3_matrix::dense::RowMajorMatrix; use p3_matrix::Matrix; +use p3_maybe_rayon::prelude::{ParallelIterator, ParallelSlice}; use std::borrow::BorrowMut; use super::{ShaExtendChip, ShaExtendCols, ShaExtendEvent, NUM_SHA_EXTEND_COLS}; use crate::{ air::{EventLens, MachineAir, WithEvents}, - bytes::event::ByteRecord, + bytes::{event::ByteRecord, ByteLookupEvent}, runtime::{ExecutionRecord, Program}, }; @@ -26,126 +29,21 @@ impl MachineAir for ShaExtendChip { fn generate_trace>( &self, input: &EL, - output: &mut ExecutionRecord, + _: &mut ExecutionRecord, ) -> RowMajorMatrix { - let mut rows = Vec::new(); + let rows = Vec::new(); let mut new_byte_lookup_events = Vec::new(); + let mut wrapped_rows = Some(rows); for i in 0..input.events().len() { - let event = input.events()[i].clone(); - let shard = event.shard; - for j in 0..48usize { - let mut row = [F::zero(); NUM_SHA_EXTEND_COLS]; - let cols: &mut ShaExtendCols = row.as_mut_slice().borrow_mut(); - cols.is_real = F::one(); - cols.populate_flags(j); - cols.shard = F::from_canonical_u32(event.shard); - cols.channel = F::from_canonical_u32(event.channel); - cols.clk = F::from_canonical_u32(event.clk); - cols.w_ptr = F::from_canonical_u32(event.w_ptr); - - cols.w_i_minus_15.populate( - event.channel, - event.w_i_minus_15_reads[j], - &mut new_byte_lookup_events, - ); - cols.w_i_minus_2.populate( - event.channel, - event.w_i_minus_2_reads[j], - &mut new_byte_lookup_events, - ); - cols.w_i_minus_16.populate( - event.channel, - event.w_i_minus_16_reads[j], - &mut new_byte_lookup_events, - ); - cols.w_i_minus_7.populate( - event.channel, - event.w_i_minus_7_reads[j], - &mut new_byte_lookup_events, - ); - - // `s0 := (w[i-15] rightrotate 7) xor (w[i-15] rightrotate 18) xor (w[i-15] rightshift 3)`. - let w_i_minus_15 = event.w_i_minus_15_reads[j].value; - let w_i_minus_15_rr_7 = - cols.w_i_minus_15_rr_7 - .populate(output, shard, event.channel, w_i_minus_15, 7); - let w_i_minus_15_rr_18 = cols.w_i_minus_15_rr_18.populate( - output, - shard, - event.channel, - w_i_minus_15, - 18, - ); - let w_i_minus_15_rs_3 = - cols.w_i_minus_15_rs_3 - .populate(output, shard, event.channel, w_i_minus_15, 3); - let s0_intermediate = cols.s0_intermediate.populate( - output, - shard, - event.channel, - w_i_minus_15_rr_7, - w_i_minus_15_rr_18, - ); - let s0 = cols.s0.populate( - output, - shard, - event.channel, - s0_intermediate, - w_i_minus_15_rs_3, - ); - - // `s1 := (w[i-2] rightrotate 17) xor (w[i-2] rightrotate 19) xor (w[i-2] rightshift 10)`. - let w_i_minus_2 = event.w_i_minus_2_reads[j].value; - let w_i_minus_2_rr_17 = - cols.w_i_minus_2_rr_17 - .populate(output, shard, event.channel, w_i_minus_2, 17); - let w_i_minus_2_rr_19 = - cols.w_i_minus_2_rr_19 - .populate(output, shard, event.channel, w_i_minus_2, 19); - let w_i_minus_2_rs_10 = - cols.w_i_minus_2_rs_10 - .populate(output, shard, event.channel, w_i_minus_2, 10); - let s1_intermediate = cols.s1_intermediate.populate( - output, - shard, - event.channel, - w_i_minus_2_rr_17, - w_i_minus_2_rr_19, - ); - let s1 = cols.s1.populate( - output, - shard, - event.channel, - s1_intermediate, - w_i_minus_2_rs_10, - ); - - // Compute `s2`. - let w_i_minus_7 = event.w_i_minus_7_reads[j].value; - let w_i_minus_16 = event.w_i_minus_16_reads[j].value; - cols.s2.populate( - output, - shard, - event.channel, - w_i_minus_16, - s0, - w_i_minus_7, - s1, - ); - - cols.w_i.populate( - event.channel, - event.w_i_writes[j], - &mut new_byte_lookup_events, - ); - - rows.push(row); - } + self.event_to_rows( + &input.events()[i], + &mut wrapped_rows, + &mut new_byte_lookup_events, + ); } - output.add_byte_lookup_events(new_byte_lookup_events); - + let mut rows = wrapped_rows.unwrap(); let nb_rows = rows.len(); let mut padded_nb_rows = nb_rows.next_power_of_two(); if padded_nb_rows == 2 || padded_nb_rows == 1 { @@ -174,7 +72,119 @@ impl MachineAir for ShaExtendChip { trace } + fn generate_dependencies>(&self, input: &EL, output: &mut ExecutionRecord) { + let chunk_size = std::cmp::max(input.events().len() / num_cpus::get(), 1); + + let blu_batches = input + .events() + .par_chunks(chunk_size) + .map(|events| { + let mut blu: HashMap> = HashMap::new(); + for event in events.iter() { + self.event_to_rows::(event, &mut None, &mut blu); + } + blu + }) + .collect::>(); + + output.add_sharded_byte_lookup_events(blu_batches.iter().collect_vec()); + } + fn included(&self, shard: &Self::Record) -> bool { !shard.sha_extend_events.is_empty() } } + +impl ShaExtendChip { + fn event_to_rows( + &self, + event: &ShaExtendEvent, + rows: &mut Option>, + blu: &mut impl ByteRecord, + ) { + let shard = event.shard; + for j in 0..48usize { + let mut row = [F::zero(); NUM_SHA_EXTEND_COLS]; + let cols: &mut ShaExtendCols = row.as_mut_slice().borrow_mut(); + cols.is_real = F::one(); + cols.populate_flags(j); + cols.shard = F::from_canonical_u32(event.shard); + cols.channel = F::from_canonical_u32(event.channel); + cols.clk = F::from_canonical_u32(event.clk); + cols.w_ptr = F::from_canonical_u32(event.w_ptr); + + cols.w_i_minus_15 + .populate(event.channel, event.w_i_minus_15_reads[j], blu); + cols.w_i_minus_2 + .populate(event.channel, event.w_i_minus_2_reads[j], blu); + cols.w_i_minus_16 + .populate(event.channel, event.w_i_minus_16_reads[j], blu); + cols.w_i_minus_7 + .populate(event.channel, event.w_i_minus_7_reads[j], blu); + + // `s0 := (w[i-15] rightrotate 7) xor (w[i-15] rightrotate 18) xor (w[i-15] rightshift 3)`. + let w_i_minus_15 = event.w_i_minus_15_reads[j].value; + let w_i_minus_15_rr_7 = + cols.w_i_minus_15_rr_7 + .populate(blu, shard, event.channel, w_i_minus_15, 7); + let w_i_minus_15_rr_18 = + cols.w_i_minus_15_rr_18 + .populate(blu, shard, event.channel, w_i_minus_15, 18); + let w_i_minus_15_rs_3 = + cols.w_i_minus_15_rs_3 + .populate(blu, shard, event.channel, w_i_minus_15, 3); + let s0_intermediate = cols.s0_intermediate.populate( + blu, + shard, + event.channel, + w_i_minus_15_rr_7, + w_i_minus_15_rr_18, + ); + let s0 = cols.s0.populate( + blu, + shard, + event.channel, + s0_intermediate, + w_i_minus_15_rs_3, + ); + + // `s1 := (w[i-2] rightrotate 17) xor (w[i-2] rightrotate 19) xor (w[i-2] rightshift 10)`. + let w_i_minus_2 = event.w_i_minus_2_reads[j].value; + let w_i_minus_2_rr_17 = + cols.w_i_minus_2_rr_17 + .populate(blu, shard, event.channel, w_i_minus_2, 17); + let w_i_minus_2_rr_19 = + cols.w_i_minus_2_rr_19 + .populate(blu, shard, event.channel, w_i_minus_2, 19); + let w_i_minus_2_rs_10 = + cols.w_i_minus_2_rs_10 + .populate(blu, shard, event.channel, w_i_minus_2, 10); + let s1_intermediate = cols.s1_intermediate.populate( + blu, + shard, + event.channel, + w_i_minus_2_rr_17, + w_i_minus_2_rr_19, + ); + let s1 = cols.s1.populate( + blu, + shard, + event.channel, + s1_intermediate, + w_i_minus_2_rs_10, + ); + + // Compute `s2`. + let w_i_minus_7 = event.w_i_minus_7_reads[j].value; + let w_i_minus_16 = event.w_i_minus_16_reads[j].value; + cols.s2 + .populate(blu, shard, event.channel, w_i_minus_16, s0, w_i_minus_7, s1); + + cols.w_i.populate(event.channel, event.w_i_writes[j], blu); + + if rows.as_ref().is_some() { + rows.as_mut().unwrap().push(row); + } + } + } +} diff --git a/core/src/syscall/precompiles/uint256/air.rs b/core/src/syscall/precompiles/uint256/air.rs index 8dad96c02..e48cf408f 100644 --- a/core/src/syscall/precompiles/uint256/air.rs +++ b/core/src/syscall/precompiles/uint256/air.rs @@ -34,7 +34,7 @@ const NUM_COLS: usize = size_of::>(); #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Uint256MulEvent { - pub lookup_id: usize, + pub lookup_id: u128, pub shard: u32, pub channel: u32, pub clk: u32, diff --git a/core/src/syscall/precompiles/uint256/mod.rs b/core/src/syscall/precompiles/uint256/mod.rs index aeb42cc60..a05b944f8 100644 --- a/core/src/syscall/precompiles/uint256/mod.rs +++ b/core/src/syscall/precompiles/uint256/mod.rs @@ -6,6 +6,7 @@ pub use air::*; mod tests { use crate::operations::field::params::FieldParameters; + use crate::stark::DefaultProver; use crate::{ io::SphinxStdin, runtime::Program, @@ -21,7 +22,7 @@ mod tests { fn test_uint256_mul() { utils::setup_logger(); let program = Program::from(UINT256_MUL_ELF); - run_test_io(program, SphinxStdin::new()).unwrap(); + run_test_io::>(program, SphinxStdin::new()).unwrap(); } #[test] diff --git a/core/src/syscall/precompiles/weierstrass/weierstrass_add.rs b/core/src/syscall/precompiles/weierstrass/weierstrass_add.rs index a2b92f9b2..6cb14abf6 100644 --- a/core/src/syscall/precompiles/weierstrass/weierstrass_add.rs +++ b/core/src/syscall/precompiles/weierstrass/weierstrass_add.rs @@ -491,11 +491,12 @@ mod tests { use crate::{ runtime::Program, + stark::DefaultProver, utils::{ run_test, setup_logger, tests::{ - BLS12381_G1_ADD_ELF, BLS12381_G1_SCALARMUL_ELF, BN254_ADD_ELF, BN254_MUL_ELF, - SECP256K1_ADD_ELF, SECP256K1_MUL_ELF, + BLS12381_G1_ADD_ELF, BLS12381_G1_DOUBLE_ELF, BLS12381_G1_SCALARMUL_ELF, + BN254_ADD_ELF, BN254_MUL_ELF, SECP256K1_ADD_ELF, SECP256K1_MUL_ELF, }, }, }; @@ -504,41 +505,48 @@ mod tests { fn test_secp256k1_add_simple() { setup_logger(); let program = Program::from(SECP256K1_ADD_ELF); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } #[test] fn test_bn254_add_simple() { setup_logger(); let program = Program::from(BN254_ADD_ELF); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } #[test] fn test_bn254_mul_simple() { setup_logger(); let program = Program::from(BN254_MUL_ELF); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } #[test] fn test_secp256k1_mul_simple() { setup_logger(); let program = Program::from(SECP256K1_MUL_ELF); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } #[test] fn test_bls12381_g1_add_simple() { setup_logger(); let program = Program::from(BLS12381_G1_ADD_ELF); - run_test(program).unwrap(); + run_test::>(program).unwrap(); + } + + #[test] + fn test_bls12381_double_simple() { + setup_logger(); + let program = Program::from(BLS12381_G1_DOUBLE_ELF); + run_test::>(program).unwrap(); } #[test] fn test_bls12381_mul_simple() { setup_logger(); let program = Program::from(BLS12381_G1_SCALARMUL_ELF); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } } diff --git a/core/src/syscall/precompiles/weierstrass/weierstrass_decompress.rs b/core/src/syscall/precompiles/weierstrass/weierstrass_decompress.rs index 3c4c6dc2b..273463d5d 100644 --- a/core/src/syscall/precompiles/weierstrass/weierstrass_decompress.rs +++ b/core/src/syscall/precompiles/weierstrass/weierstrass_decompress.rs @@ -76,8 +76,8 @@ impl Syscall for WeierstrassDecompressChip { fn execute(&self, rt: &mut SyscallContext, arg1: u32, arg2: u32) -> Option { let event = create_ec_decompress_event::(rt, arg1, arg2); match E::CURVE_TYPE { - CurveType::Secp256k1 => rt.record_mut().k256_decompress_events.push(event), - CurveType::Bls12381 => rt.record_mut().bls12381_decompress_events.push(event), + CurveType::Secp256k1 => rt.record_mut().secp256k1_decompress_events.push(event), + CurveType::Bls12381 => rt.record_mut().bls12381_g1_decompress_events.push(event), _ => panic!("Unsupported curve"), } None @@ -155,8 +155,8 @@ impl MachineAir output: &mut ExecutionRecord, ) -> RowMajorMatrix { let events = match E::CURVE_TYPE { - CurveType::Secp256k1 => &input.k256_decompress_events, - CurveType::Bls12381 => &input.bls12381_decompress_events, + CurveType::Secp256k1 => &input.secp256k1_decompress_events, + CurveType::Bls12381 => &input.bls12381_g1_decompress_events, _ => panic!("Unsupported curve"), }; @@ -242,8 +242,8 @@ impl MachineAir fn included(&self, shard: &Self::Record) -> bool { match E::CURVE_TYPE { - CurveType::Secp256k1 => !shard.k256_decompress_events.is_empty(), - CurveType::Bls12381 => !shard.bls12381_decompress_events.is_empty(), + CurveType::Secp256k1 => !shard.secp256k1_decompress_events.is_empty(), + CurveType::Bls12381 => !shard.bls12381_g1_decompress_events.is_empty(), _ => panic!("Unsupported curve"), } } @@ -393,6 +393,7 @@ where #[cfg(test)] mod tests { use crate::io::SphinxStdin; + use crate::stark::DefaultProver; use crate::utils::{self, tests::BLS12381_DECOMPRESS_ELF}; use crate::Program; use amcl::bls381::bls381::basic::key_pair_generate_g2; @@ -416,7 +417,9 @@ mod tests { let (_, compressed) = key_pair_generate_g2(&mut RAND::new()); let stdin = SphinxStdin::from(&compressed); - let mut public_values = run_test_io(Program::from(BLS12381_DECOMPRESS_ELF), stdin).unwrap(); + let mut public_values = + run_test_io::>(Program::from(BLS12381_DECOMPRESS_ELF), stdin) + .unwrap(); let mut result = [0; 96]; public_values.read_slice(&mut result); @@ -446,7 +449,8 @@ mod tests { let inputs = SphinxStdin::from(&compressed); let mut public_values = - run_test_io(Program::from(SECP256K1_DECOMPRESS_ELF), inputs).unwrap(); + run_test_io::>(Program::from(SECP256K1_DECOMPRESS_ELF), inputs) + .unwrap(); let mut result = [0; 65]; public_values.read_slice(&mut result); assert_eq!(result, decompressed); diff --git a/core/src/syscall/precompiles/weierstrass/weierstrass_double.rs b/core/src/syscall/precompiles/weierstrass/weierstrass_double.rs index 9561d9945..4e03677a9 100644 --- a/core/src/syscall/precompiles/weierstrass/weierstrass_double.rs +++ b/core/src/syscall/precompiles/weierstrass/weierstrass_double.rs @@ -528,6 +528,7 @@ pub mod tests { use crate::{ runtime::Program, + stark::DefaultProver, utils::{ run_test, setup_logger, tests::{BLS12381_G1_DOUBLE_ELF, BN254_DOUBLE_ELF, SECP256K1_DOUBLE_ELF}, @@ -538,20 +539,20 @@ pub mod tests { fn test_secp256k1_double_simple() { setup_logger(); let program = Program::from(SECP256K1_DOUBLE_ELF); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } #[test] fn test_bn254_double_simple() { setup_logger(); let program = Program::from(BN254_DOUBLE_ELF); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } #[test] fn test_bls12381_g1_double_simple() { setup_logger(); let program = Program::from(BLS12381_G1_DOUBLE_ELF); - run_test(program).unwrap(); + run_test::>(program).unwrap(); } } diff --git a/core/src/syscall/unconstrained.rs b/core/src/syscall/unconstrained.rs index 22d0a6cc3..9a6b30c3f 100644 --- a/core/src/syscall/unconstrained.rs +++ b/core/src/syscall/unconstrained.rs @@ -1,4 +1,4 @@ -use hashbrown::HashMap; +use std::collections::HashMap; use crate::runtime::{ForkState, Syscall, SyscallContext}; diff --git a/core/src/utils/mod.rs b/core/src/utils/mod.rs index d2d8fbbff..9261050d8 100644 --- a/core/src/utils/mod.rs +++ b/core/src/utils/mod.rs @@ -7,6 +7,7 @@ mod options; #[cfg(any(test, feature = "programs"))] mod programs; mod prove; +mod serde; mod tracer; use std::borrow::Borrow; @@ -16,9 +17,11 @@ pub use config::*; use hybrid_array::{Array, ArraySize}; pub use logger::*; pub use options::*; +use p3_maybe_rayon::prelude::{ParallelBridge as _, ParallelIterator as _}; #[cfg(test)] pub use programs::tests; pub use prove::*; +pub use serde::*; pub use tracer::*; use crate::{ @@ -86,31 +89,34 @@ pub fn pad_rows_fixed( ) { let nb_rows = rows.len(); let dummy_row = row_fn(); - if let Some(size_log2) = size_log2 { - let padded_nb_rows = 1 << size_log2; - if nb_rows * 2 < padded_nb_rows { + rows.resize(next_power_of_two(nb_rows, size_log2), dummy_row); +} + +/// Returns the next power of two that is >= `n` and >= 16. If `fixed_power` is set, it will return +/// `2^fixed_power` after checking that `n <= 2^fixed_power`. +pub fn next_power_of_two(n: usize, fixed_power: Option) -> usize { + if let Some(power) = fixed_power { + let padded_nb_rows = 1 << power; + if n * 2 < padded_nb_rows { tracing::warn!( "fixed log2 rows can be potentially reduced: got {}, expected {}", - nb_rows, + n, padded_nb_rows ); } assert!( - nb_rows <= padded_nb_rows, + n <= padded_nb_rows, "fixed log2 rows is too small: got {}, expected {}", - nb_rows, + n, padded_nb_rows ); - rows.resize(padded_nb_rows, dummy_row); + padded_nb_rows } else { - let mut padded_nb_rows = nb_rows.next_power_of_two(); - if padded_nb_rows < 8 { - padded_nb_rows = 8; - } - if padded_nb_rows == nb_rows { - return; + let mut padded_nb_rows = n.next_power_of_two(); + if padded_nb_rows < 16 { + padded_nb_rows = 16; } - rows.resize(padded_nb_rows, dummy_row); + padded_nb_rows } } @@ -205,3 +211,29 @@ pub fn log2_strict_usize(n: usize) -> usize { assert_eq!(n.wrapping_shr(res), 1, "Not a power of two: {n}"); res as usize } + +pub fn par_for_each_row(vec: &mut [F], num_elements_per_event: usize, processor: P) +where + F: Send, + P: Fn(usize, &mut [F]) + Send + Sync, +{ + // Split the vector into `num_cpus` chunks, but at least `num_cpus` rows per chunk. + assert!(vec.len() % num_elements_per_event == 0); + let len = vec.len() / num_elements_per_event; + let cpus = num_cpus::get(); + let ceil_div = (len + cpus - 1) / cpus; + let chunk_size = std::cmp::max(ceil_div, cpus); + + vec.chunks_mut(chunk_size * num_elements_per_event) + .enumerate() + .par_bridge() + .for_each(|(i, chunk)| { + chunk + .chunks_mut(num_elements_per_event) + .enumerate() + .for_each(|(j, row)| { + assert!(row.len() == num_elements_per_event); + processor(i * chunk_size + j, row); + }); + }); +} diff --git a/core/src/utils/options.rs b/core/src/utils/options.rs index c71b6fcc7..38bb35042 100644 --- a/core/src/utils/options.rs +++ b/core/src/utils/options.rs @@ -1,9 +1,11 @@ use std::env; +use crate::runtime::{SplitOpts, DEFERRED_SPLIT_THRESHOLD}; + const DEFAULT_SHARD_SIZE: usize = 1 << 22; const DEFAULT_SHARD_BATCH_SIZE: usize = 16; -const DEFAULT_SHARD_CHUNKING_MULTIPLIER: usize = 1; -const DEFAULT_RECONSTRUCT_COMMITMENTS: bool = true; +const DEFAULT_COMMIT_STREAM_CAPACITY: usize = 1; +const DEFAULT_PROVE_STREAM_CAPACITY: usize = 1; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct SphinxProverOpts { @@ -24,12 +26,17 @@ impl Default for SphinxProverOpts { pub struct SphinxCoreOpts { pub shard_size: usize, pub shard_batch_size: usize, - pub shard_chunking_multiplier: usize, + pub commit_stream_capacity: usize, + pub prove_stream_capacity: usize, + pub split_opts: SplitOpts, pub reconstruct_commitments: bool, } impl Default for SphinxCoreOpts { fn default() -> Self { + let split_threshold = env::var("SPLIT_THRESHOLD") + .map(|s| s.parse::().unwrap_or(DEFERRED_SPLIT_THRESHOLD)) + .unwrap_or(DEFERRED_SPLIT_THRESHOLD); Self { shard_size: env::var("SHARD_SIZE").map_or_else( |_| DEFAULT_SHARD_SIZE, @@ -39,17 +46,16 @@ impl Default for SphinxCoreOpts { |_| DEFAULT_SHARD_BATCH_SIZE, |s| s.parse::().unwrap_or(DEFAULT_SHARD_BATCH_SIZE), ), - shard_chunking_multiplier: env::var("SHARD_CHUNKING_MULTIPLIER").map_or_else( - |_| DEFAULT_SHARD_CHUNKING_MULTIPLIER, - |s| { - s.parse::() - .unwrap_or(DEFAULT_SHARD_CHUNKING_MULTIPLIER) - }, + commit_stream_capacity: env::var("COMMIT_STREAM_CAPACITY").map_or_else( + |_| DEFAULT_COMMIT_STREAM_CAPACITY, + |s| s.parse::().unwrap_or(DEFAULT_COMMIT_STREAM_CAPACITY), ), - reconstruct_commitments: env::var("RECONSTRUCT_COMMITMENTS").map_or_else( - |_| DEFAULT_RECONSTRUCT_COMMITMENTS, - |s| s.parse::().unwrap_or(DEFAULT_RECONSTRUCT_COMMITMENTS), + prove_stream_capacity: env::var("PROVE_STREAM_CAPACITY").map_or_else( + |_| DEFAULT_PROVE_STREAM_CAPACITY, + |s| s.parse::().unwrap_or(DEFAULT_PROVE_STREAM_CAPACITY), ), + split_opts: SplitOpts::new(split_threshold), + reconstruct_commitments: true, } } } diff --git a/core/src/utils/prove.rs b/core/src/utils/prove.rs index dee783732..4fa9ef22b 100644 --- a/core/src/utils/prove.rs +++ b/core/src/utils/prove.rs @@ -1,37 +1,43 @@ -use hashbrown::HashMap; use nohash_hasher::BuildNoHashHasher; +use std::collections::HashMap; use std::fs::File; -use std::io; -use std::io::{Seek, Write}; +use std::io::Seek; +use std::io::{self}; +use std::sync::mpsc::sync_channel; use std::sync::Arc; use web_time::Instant; -pub use baby_bear_blake3::BabyBearBlake3; -use p3_challenger::CanObserve; -use p3_field::PrimeField32; -use serde::{de::DeserializeOwned, Serialize}; +use p3_maybe_rayon::prelude::*; + +use serde::de::DeserializeOwned; +use serde::Serialize; use size::Size; use thiserror::Error; +pub use baby_bear_blake3::BabyBearBlake3; +use p3_baby_bear::BabyBear; +use p3_field::PrimeField32; + use crate::air::MachineAir; use crate::io::{SphinxPublicValues, SphinxStdin}; use crate::lookup::InteractionBuilder; use crate::runtime::subproof::NoOpSubproofVerifier; use crate::runtime::{ExecutionError, MemoryRecord, SphinxContext}; -use crate::runtime::{ExecutionRecord, ExecutionReport, ShardingConfig}; +use crate::runtime::{ExecutionRecord, ExecutionReport}; use crate::stark::DebugConstraintBuilder; -use crate::stark::Indexed; use crate::stark::MachineProof; +use crate::stark::MachineProver; use crate::stark::ProverConstraintFolder; use crate::stark::StarkVerifyingKey; use crate::stark::Val; use crate::stark::VerifierConstraintFolder; -use crate::stark::{Com, PcsProverData, RiscvAir, ShardProof, StarkProvingKey, UniConfig}; +use crate::stark::{Com, PcsProverData, RiscvAir, StarkProvingKey, UniConfig}; use crate::stark::{MachineRecord, StarkMachine}; use crate::utils::SphinxCoreOpts; use crate::{ runtime::{Program, Runtime}, - stark::{LocalProver, OpeningProof, ShardMainData, StarkGenericConfig}, + stark::StarkGenericConfig, + stark::{DefaultProver, OpeningProof, ShardMainData}, }; const LOG_DEGREE_BOUND: usize = 31; @@ -46,10 +52,10 @@ pub enum SphinxCoreProverError { SerializationError(bincode::Error), } -pub fn prove_simple( +pub fn prove_simple>>( config: SC, - runtime: Runtime<'_>, -) -> Result, SphinxCoreProverError> + mut runtime: Runtime<'_>, +) -> Result<(MachineProof, u64), SphinxCoreProverError> where SC::Challenger: Clone, OpeningProof: Send + Sync, @@ -60,17 +66,29 @@ where { // Setup the machine. let machine = RiscvAir::machine(config); - let (pk, _) = machine.setup(runtime.program.as_ref()); + let prover = P::new(machine); + let (pk, _) = prover.setup(runtime.program.as_ref()); + + // Set the shard numbers. + runtime + .records + .iter_mut() + .enumerate() + .for_each(|(i, shard)| { + shard.public_values.shard = (i + 1) as u32; + }); // Prove the program. - let mut challenger = machine.config().challenger(); + let mut challenger = prover.config().challenger(); let proving_start = Instant::now(); - let proof = machine.prove::>( - &pk, - runtime.record, - &mut challenger, - SphinxCoreOpts::default(), - ); + let proof = prover + .prove( + &pk, + runtime.records, + &mut challenger, + SphinxCoreOpts::default(), + ) + .unwrap(); let proving_duration = proving_start.elapsed().as_millis(); let nb_bytes = bincode::serialize(&proof).unwrap().len(); @@ -83,41 +101,43 @@ where Size::from_bytes(nb_bytes), ); - Ok(proof) + Ok((proof, runtime.state.global_clk)) } -pub fn prove( +pub fn prove>>( program: &Program, stdin: &SphinxStdin, config: SC, opts: SphinxCoreOpts, ) -> Result<(MachineProof, Vec), SphinxCoreProverError> where - SC::Challenger: Clone, - OpeningProof: Send + Sync, + SC::Challenger: 'static + Clone + Send, + ::Val: PrimeField32, + OpeningProof: Send, Com: Send + Sync, PcsProverData: Send + Sync, - ShardMainData: Serialize + DeserializeOwned, - ::Val: PrimeField32, { - prove_with_context(program, stdin, config, opts, Default::default()) + let machine = RiscvAir::machine(config); + let prover = P::new(machine); + prove_with_context::(&prover, program, stdin, opts, Default::default()) + .map(|(pr, pv, _)| (pr, pv)) } -pub fn prove_with_context( +pub fn prove_with_context>>( + prover: &P, program: &Program, stdin: &SphinxStdin, - config: SC, opts: SphinxCoreOpts, context: SphinxContext<'_>, -) -> Result<(MachineProof, Vec), SphinxCoreProverError> +) -> Result<(MachineProof, Vec, u64), SphinxCoreProverError> where - SC::Challenger: Clone, - OpeningProof: Send + Sync, + SC::Val: PrimeField32, + SC::Challenger: 'static + Clone + Send, + OpeningProof: Send, Com: Send + Sync, PcsProverData: Send + Sync, - ShardMainData: Serialize + DeserializeOwned, - ::Val: PrimeField32, { + // Record the start of the process. let proving_start = Instant::now(); // Execute the program. @@ -128,217 +148,327 @@ where } // Setup the machine. - let machine = RiscvAir::machine(config); - let (pk, vk) = machine.setup(runtime.program.as_ref()); - - // If we don't need to batch, we can just run the program normally and prove it. - if opts.shard_batch_size == 0 { - // Execute the runtime and collect all the events.. - runtime - .run() - .map_err(SphinxCoreProverError::ExecutionError)?; - - // If debugging is enabled, we will also debug the constraints. - #[cfg(debug_assertions)] - { - machine.debug_constraints(&pk, runtime.record.clone()); - } - - // Generate the proof and return the proof and public values. - let public_values = std::mem::take(&mut runtime.state.public_values_stream); - let proof = prove_simple(machine.config().clone(), runtime)?; - return Ok((proof, public_values)); - } + let (pk, vk) = prover.setup(runtime.program.as_ref()); // Execute the program, saving checkpoints at the start of every `shard_batch_size` cycle range. + let create_checkpoints_span = tracing::debug_span!("create checkpoints").entered(); let mut checkpoints = Vec::new(); let (public_values_stream, public_values) = loop { // Execute the runtime until we reach a checkpoint. - let (checkpoint, done) = tracing::info_span!("collect_checkpoints") - .in_scope(|| runtime.execute_state()) + let (checkpoint, done) = runtime + .execute_state() .map_err(SphinxCoreProverError::ExecutionError)?; // Save the checkpoint to a temp file. - let mut tempfile = tempfile::tempfile().map_err(SphinxCoreProverError::IoError)?; - let mut writer = io::BufWriter::new(&mut tempfile); - bincode::serialize_into(&mut writer, &checkpoint) - .map_err(SphinxCoreProverError::SerializationError)?; - writer.flush().map_err(SphinxCoreProverError::IoError)?; - drop(writer); - tempfile - .seek(io::SeekFrom::Start(0)) + let mut checkpoint_file = tempfile::tempfile().map_err(SphinxCoreProverError::IoError)?; + checkpoint + .save(&mut checkpoint_file) .map_err(SphinxCoreProverError::IoError)?; - checkpoints.push(tempfile); + checkpoints.push(checkpoint_file); // If we've reached the final checkpoint, break out of the loop. if done { break ( - std::mem::take(&mut runtime.state.public_values_stream), - runtime.record.public_values, + runtime.state.public_values_stream, + runtime + .records + .last() + .expect("at least one record") + .public_values, ); } }; + create_checkpoints_span.exit(); - // For each checkpoint, generate events, shard them, commit shards, and observe in challenger. - let sharding_config = ShardingConfig::default(); - let mut shard_main_datas = Vec::new(); - let mut challenger = machine.config().challenger(); + // Commit to the shards. + #[cfg(debug_assertions)] + let mut debug_records: Vec = Vec::new(); + + let mut deferred = ExecutionRecord::new(program.clone().into()); + let mut state = public_values.reset(); + let nb_checkpoints = checkpoints.len(); + let mut challenger = prover.config().challenger(); vk.observe_into(&mut challenger); - for (num, checkpoint_file) in checkpoints.iter_mut().enumerate() { - let (mut record, _) = tracing::info_span!("commit_checkpoint", num) - .in_scope(|| trace_checkpoint(program, checkpoint_file, opts)); - record.public_values = public_values; - reset_seek(&mut *checkpoint_file); - - // Shard the record into shards. - let checkpoint_shards = - tracing::info_span!("shard").in_scope(|| machine.shard(record, &sharding_config)); - - // Commit to each shard. - let (commitments, commit_data) = tracing::info_span!("commit") - .in_scope(|| LocalProver::commit_shards(&machine, &checkpoint_shards, opts)); - shard_main_datas.push(commit_data); - - // Observe the commitments. - for (commitment, shard) in commitments.into_iter().zip(checkpoint_shards.iter()) { - challenger.observe(commitment); - challenger.observe_slice(&shard.public_values::()[0..machine.num_pv_elts()]); - } - } - // For each checkpoint, generate events and shard again, then prove the shards. - let mut shard_proofs = Vec::>::new(); - let mut report_aggregate = ExecutionReport::default(); - for (num, mut checkpoint_file) in checkpoints.into_iter().enumerate() { - let checkpoint_shards = { - let (mut events, report) = tracing::info_span!("prove_checkpoint", num) - .in_scope(|| trace_checkpoint(program, &checkpoint_file, opts)); - report_aggregate += report; - events.public_values = public_values; - reset_seek(&mut checkpoint_file); - tracing::debug_span!("shard").in_scope(|| machine.shard(events, &sharding_config)) - }; - let mut checkpoint_proofs = checkpoint_shards - .into_iter() - .map(|shard| { - let config = machine.config(); - let shard_data = - LocalProver::commit_main(config, &machine, &shard, shard.index() as usize); - - let chip_ordering = shard_data.chip_ordering.clone(); - let ordered_chips = machine - .shard_chips_ordered(&chip_ordering) - .collect::>() - .clone(); - LocalProver::prove_shard( - config, - &pk, - &ordered_chips, - shard_data, - &mut challenger.clone(), - ) - }) - .collect::>(); - shard_proofs.append(&mut checkpoint_proofs); - } - // Log some of the `ExecutionReport` information. - tracing::info!( - "execution report (totals): total_cycles={}, total_syscall_cycles={}", - report_aggregate.total_instruction_count(), - report_aggregate.total_syscall_count() - ); - // Print the opcode and syscall count tables like `du`: - // sorted by count (descending) and with the count in the first column. - tracing::info!("execution report (opcode counts):"); - for line in ExecutionReport::sorted_table_lines(&report_aggregate.opcode_counts) { - tracing::info!(" {line}"); - } - tracing::info!("execution report (syscall counts):"); - for line in ExecutionReport::sorted_table_lines(&report_aggregate.syscall_counts) { - tracing::info!(" {line}"); - } + let scope_span = tracing::Span::current().clone(); + std::thread::scope(move |s| { + let _span = scope_span.enter(); + + // Spawn a thread for commiting to the shards. + let span = tracing::Span::current().clone(); + let (records_tx, records_rx) = + sync_channel::>(opts.commit_stream_capacity); + let challenger_handle = s.spawn(move || { + let _span = span.enter(); + tracing::debug_span!("phase 1 commiter").in_scope(|| { + for records in records_rx.iter() { + let commitments = tracing::debug_span!("batch").in_scope(|| { + let span = tracing::Span::current().clone(); + records + .par_iter() + .map(|record| { + let _span = span.enter(); + prover.commit(record) + }) + .collect::>() + }); + for (commit, record) in commitments.into_iter().zip(records) { + prover.update( + &mut challenger, + commit, + &record.public_values::()[0..prover.machine().num_pv_elts()], + ); + } + } + }); + + challenger + }); + + tracing::debug_span!("phase 1 record generator").in_scope(|| { + for (checkpoint_idx, checkpoint_file) in checkpoints.iter_mut().enumerate() { + // Trace the checkpoint and reconstruct the execution records. + let (mut records, _) = tracing::debug_span!("trace checkpoint") + .in_scope(|| trace_checkpoint(program, checkpoint_file, opts)); + reset_seek(&mut *checkpoint_file); + + // Update the public values & prover state for the shards which contain "cpu events". + for record in records.iter_mut() { + state.shard += 1; + state.execution_shard = record.public_values.execution_shard; + state.start_pc = record.public_values.start_pc; + state.next_pc = record.public_values.next_pc; + record.public_values = state; + } + + // Generate the dependencies. + tracing::debug_span!("generate dependencies") + .in_scope(|| prover.machine().generate_dependencies(&mut records, &opts)); + + // Defer events that are too expensive to include in every shard. + for record in records.iter_mut() { + deferred.append(&mut record.defer()); + } + + // See if any deferred shards are ready to be commited to. + let is_last_checkpoint = checkpoint_idx == nb_checkpoints - 1; + let mut deferred = deferred.split(is_last_checkpoint, opts.split_opts); + + // Update the public values & prover state for the shards which do not contain "cpu events" + // before committing to them. + if !is_last_checkpoint { + state.execution_shard += 1; + } + for record in deferred.iter_mut() { + state.shard += 1; + state.previous_init_addr_bits = record.public_values.previous_init_addr_bits; + state.last_init_addr_bits = record.public_values.last_init_addr_bits; + state.previous_finalize_addr_bits = + record.public_values.previous_finalize_addr_bits; + state.last_finalize_addr_bits = record.public_values.last_finalize_addr_bits; + state.start_pc = state.next_pc; + record.public_values = state; + } + records.append(&mut deferred); + + #[cfg(debug_assertions)] + { + debug_records.extend(records.clone()); + } + + records_tx.send(records).unwrap(); + } + }); + drop(records_tx); + let challenger = challenger_handle.join().unwrap(); - let proof = MachineProof:: { shard_proofs }; + // Debug the constraints if debug assertions are enabled. + #[cfg(debug_assertions)] + { + let mut challenger = prover.config().challenger(); + prover.debug_constraints(&pk, debug_records, &mut challenger); + } - // Print the summary. - let proving_time = proving_start.elapsed().as_secs_f64(); - tracing::info!( - "summary: cycles={}, e2e={}, khz={:.2}, proofSize={}", - runtime.state.global_clk, - proving_time, - (runtime.state.global_clk as f64 / proving_time), - bincode::serialize(&proof).unwrap().len(), - ); + // Prove the shards. + let mut deferred = ExecutionRecord::new(program.clone().into()); + let mut state = public_values.reset(); + let mut report_aggregate = ExecutionReport::default(); + + // Spawn a thread for proving the shards. + let (records_tx, records_rx) = + sync_channel::>(opts.prove_stream_capacity); + + let commit_and_open = tracing::Span::current().clone(); + let shard_proofs = s.spawn(move || { + let _span = commit_and_open.enter(); + let mut shard_proofs = Vec::new(); + tracing::debug_span!("phase 2 prover").in_scope(|| { + for records in records_rx.iter() { + tracing::debug_span!("batch").in_scope(|| { + let span = tracing::Span::current().clone(); + shard_proofs.par_extend(records.into_par_iter().map(|record| { + let _span = span.enter(); + prover + .commit_and_open(&pk, record, &mut challenger.clone()) + .unwrap() + })); + }); + } + }); + shard_proofs + }); + + tracing::debug_span!("phase 2 record generator").in_scope(|| { + for (checkpoint_idx, mut checkpoint_file) in checkpoints.into_iter().enumerate() { + // Trace the checkpoint and reconstruct the execution records. + let (mut records, report) = tracing::debug_span!("trace checkpoint") + .in_scope(|| trace_checkpoint(program, &checkpoint_file, opts)); + report_aggregate += report; + reset_seek(&mut checkpoint_file); + + // Update the public values & prover state for the shards which contain "cpu events". + for record in records.iter_mut() { + state.shard += 1; + state.execution_shard = record.public_values.execution_shard; + state.start_pc = record.public_values.start_pc; + state.next_pc = record.public_values.next_pc; + record.public_values = state; + } + + // Generate the dependencies. + tracing::debug_span!("generate dependencies") + .in_scope(|| prover.machine().generate_dependencies(&mut records, &opts)); + + // Defer events that are too expensive to include in every shard. + for record in records.iter_mut() { + deferred.append(&mut record.defer()); + } + + // See if any deferred shards are ready to be commited to. + let is_last_checkpoint = checkpoint_idx == nb_checkpoints - 1; + let mut deferred = deferred.split(is_last_checkpoint, opts.split_opts); + + // Update the public values & prover state for the shards which do not contain "cpu events" + // before committing to them. + if !is_last_checkpoint { + state.execution_shard += 1; + } + for record in deferred.iter_mut() { + state.shard += 1; + state.previous_init_addr_bits = record.public_values.previous_init_addr_bits; + state.last_init_addr_bits = record.public_values.last_init_addr_bits; + state.previous_finalize_addr_bits = + record.public_values.previous_finalize_addr_bits; + state.last_finalize_addr_bits = record.public_values.last_finalize_addr_bits; + state.start_pc = state.next_pc; + record.public_values = state; + } + records.append(&mut deferred); + + records_tx.send(records).unwrap(); + } + }); + drop(records_tx); + let shard_proofs = shard_proofs.join().unwrap(); + + // Log some of the `ExecutionReport` information. + tracing::info!( + "execution report (totals): total_cycles={}, total_syscall_cycles={}", + report_aggregate.total_instruction_count(), + report_aggregate.total_syscall_count() + ); + + // Print the opcode and syscall count tables like `du`: sorted by count (descending) and with + // the count in the first column. + tracing::info!("execution report (opcode counts):"); + for line in ExecutionReport::sorted_table_lines(&report_aggregate.opcode_counts) { + tracing::info!(" {line}"); + } + tracing::info!("execution report (syscall counts):"); + for line in ExecutionReport::sorted_table_lines(&report_aggregate.syscall_counts) { + tracing::info!(" {line}"); + } - Ok((proof, public_values_stream)) + let proof = MachineProof:: { shard_proofs }; + let cycles = runtime.state.global_clk; + + // Print the summary. + let proving_time = proving_start.elapsed().as_secs_f64(); + tracing::info!( + "summary: cycles={}, e2e={}s, khz={:.2}, proofSize={}", + cycles, + proving_time, + (runtime.state.global_clk as f64 / (proving_time * 1000.0)), + bincode::serialize(&proof).unwrap().len(), + ); + + Ok((proof, public_values_stream, cycles)) + }) } /// Runs a program and returns the public values stream. -pub fn run_test_io( +pub fn run_test_io>>( program: Program, inputs: &SphinxStdin, ) -> Result> { - let runtime = tracing::info_span!("runtime.run(...)").in_scope(|| { + let runtime = tracing::debug_span!("runtime.run(...)").in_scope(|| { let mut runtime = Runtime::new(program, SphinxCoreOpts::default()); runtime.write_vecs(&inputs.buffer); runtime.run().unwrap(); runtime }); let public_values = SphinxPublicValues::from(&runtime.state.public_values_stream); - let _ = run_test_core(runtime)?; + let _ = run_test_core::

(&runtime, inputs)?; Ok(public_values) } -pub fn run_test_with_memory_inspection( - program: Program, -) -> ( - MachineProof, - HashMap>, -) { - let runtime = tracing::info_span!("runtime.run(...)").in_scope(|| { - let mut runtime = Runtime::new(program, SphinxCoreOpts::default()); - runtime.run().unwrap(); - runtime - }); - - let memory = runtime.state.memory.clone(); - let proof = run_test_core(runtime).unwrap(); - (proof, memory) -} - -pub fn run_test( +pub fn run_test>>( program: Program, ) -> Result< MachineProof, crate::stark::MachineVerificationError, > { - let runtime = tracing::info_span!("runtime.run(...)").in_scope(|| { + let runtime = tracing::debug_span!("runtime.run(...)").in_scope(|| { let mut runtime = Runtime::new(program, SphinxCoreOpts::default()); runtime.run().unwrap(); runtime }); - run_test_core(runtime) + run_test_core::

(&runtime, &SphinxStdin::new()) } #[allow(unused_variables)] -pub fn run_test_core( - runtime: Runtime<'_>, +pub fn run_test_core>>( + runtime: &Runtime<'_>, + inputs: &SphinxStdin, ) -> Result< MachineProof, crate::stark::MachineVerificationError, > { + let config = BabyBearPoseidon2::new(); + let machine = RiscvAir::machine(config); + let prover = P::new(machine); + let (proof, output, _) = prove_with_context( + &prover, + &runtime.program, + inputs, + SphinxCoreOpts::default(), + SphinxContext::default(), + ) + .unwrap(); + let config = BabyBearPoseidon2::new(); let machine = RiscvAir::machine(config); let (pk, vk) = machine.setup(runtime.program.as_ref()); + let mut challenger = machine.config().challenger(); + machine.verify(&vk, &proof, &mut challenger).unwrap(); - let record = runtime.record; - run_test_machine(record, &machine, &pk, &vk) + Ok(proof) } #[allow(unused_variables)] pub fn run_test_machine( - record: A::Record, - machine: &StarkMachine, + records: Vec, + machine: StarkMachine, pk: &StarkProvingKey, vk: &StarkVerifyingKey, ) -> Result, crate::stark::MachineVerificationError> @@ -348,6 +478,7 @@ where + Air>> + for<'a> Air> + for<'a> Air, SC::Challenge>>, + A::Record: MachineRecord, SC: StarkGenericConfig, SC::Val: PrimeField32, SC::Challenger: Clone, @@ -356,49 +487,50 @@ where OpeningProof: Send + Sync, ShardMainData: Serialize + DeserializeOwned, { - #[cfg(debug_assertions)] - { - let record_clone = record.clone(); - machine.debug_constraints(pk, record_clone); - } - let stats = record.stats().clone(); - let cycles = stats.get("cpu_events").unwrap(); - let start = Instant::now(); - let mut challenger = machine.config().challenger(); - - let proof = - machine.prove::>(pk, record, &mut challenger, SphinxCoreOpts::default()); + let prover = DefaultProver::new(machine); + let mut challenger = prover.config().challenger(); + let proof = prover + .prove(pk, records, &mut challenger, SphinxCoreOpts::default()) + .unwrap(); let time = start.elapsed().as_millis(); let nb_bytes = bincode::serialize(&proof).unwrap().len(); - let mut challenger = machine.config().challenger(); - machine.verify(vk, &proof, &mut challenger)?; - - tracing::info!( - "summary: cycles={}, e2e={}, khz={:.2}, proofSize={}", - cycles, - time, - (*cycles as f64 / time as f64), - Size::from_bytes(nb_bytes), - ); + let mut challenger = prover.config().challenger(); + prover.machine().verify(vk, &proof, &mut challenger)?; Ok(proof) } +pub fn run_test_with_memory_inspection>>( + program: Program, +) -> ( + MachineProof, + HashMap>, +) { + let runtime = tracing::info_span!("runtime.run(...)").in_scope(|| { + let mut runtime = Runtime::new(program, SphinxCoreOpts::default()); + runtime.run().unwrap(); + runtime + }); + + let memory = runtime.state.memory.clone(); + let proof = run_test_core::

(&runtime, &SphinxStdin::new()).unwrap(); + (proof, memory) +} + fn trace_checkpoint( program: &Program, file: &File, opts: SphinxCoreOpts, -) -> (ExecutionRecord, ExecutionReport) { +) -> (Vec, ExecutionReport) { let mut reader = io::BufReader::new(file); let state = bincode::deserialize_from(&mut reader).expect("failed to deserialize state"); - let mut runtime = Runtime::recover(program.clone(), state, opts); + let mut runtime = Runtime::recover(program, state, opts); // We already passed the deferred proof verifier when creating checkpoints, so the proofs were // already verified. So here we use a noop verifier to not print any warnings. runtime.subproof_verifier = Arc::new(NoOpSubproofVerifier); - let (events, _) = - tracing::debug_span!("runtime.trace").in_scope(|| runtime.execute_record().unwrap()); + let (events, _) = runtime.execute_record().unwrap(); (events, runtime.report) } diff --git a/core/src/utils/serde.rs b/core/src/utils/serde.rs new file mode 100644 index 000000000..fa7fdcef9 --- /dev/null +++ b/core/src/utils/serde.rs @@ -0,0 +1,18 @@ +use std::collections::HashMap; + +use nohash_hasher::BuildNoHashHasher; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +pub fn serialize_hashmap_as_vec( + map: &HashMap>, + serializer: S, +) -> Result { + Serialize::serialize(&map.iter().collect::>(), serializer) +} + +pub fn deserialize_hashmap_as_vec<'de, V: Deserialize<'de>, D: Deserializer<'de>>( + deserializer: D, +) -> Result>, D::Error> { + let seq: Vec<(u32, V)> = Deserialize::deserialize(deserializer)?; + Ok(seq.into_iter().collect()) +} diff --git a/derive/src/lib.rs b/derive/src/lib.rs index 59efbb6cc..19b7144a1 100644 --- a/derive/src/lib.rs +++ b/derive/src/lib.rs @@ -462,11 +462,11 @@ pub fn cycle_tracker(_attr: TokenStream, item: TokenStream) -> TokenStream { let result = quote! { #visibility fn #name #generics (#inputs) #output #where_clause { - sphinx_zkvm::precompiles::unconstrained! { + sphinx_lib::unconstrained! { println!("cycle-tracker-start: {}", stringify!(#name)); } let result = (|| #block)(); - sphinx_zkvm::precompiles::unconstrained! { + sphinx_lib::unconstrained! { println!("cycle-tracker-end: {}", stringify!(#name)); } result diff --git a/eval/src/main.rs b/eval/src/main.rs index a0a996b34..3d0fe2d9e 100644 --- a/eval/src/main.rs +++ b/eval/src/main.rs @@ -2,6 +2,7 @@ use clap::{command, Parser}; use csv::WriterBuilder; use serde::Serialize; use sphinx_core::runtime::{Program, Runtime}; +use sphinx_core::stark::DefaultProver; use sphinx_core::utils::{ prove_simple, BabyBearBlake3, BabyBearKeccak, BabyBearPoseidon2, SphinxCoreOpts, }; @@ -143,7 +144,7 @@ fn run_evaluation(hashfn: &HashFnId, program: &Program, _elf: &[u8]) -> (f64, f6 let config = BabyBearBlake3::new(); let prove_start = Instant::now(); - let _proof = prove_simple(config.clone(), runtime); + let _proof = prove_simple::<_, DefaultProver<_, _>>(config.clone(), runtime); let prove_duration = prove_start.elapsed().as_secs_f64(); let verify_start = Instant::now(); @@ -161,7 +162,7 @@ fn run_evaluation(hashfn: &HashFnId, program: &Program, _elf: &[u8]) -> (f64, f6 let config = BabyBearPoseidon2::new(); let prove_start = Instant::now(); - let _proof = prove_simple(config.clone(), runtime); + let _proof = prove_simple::<_, DefaultProver<_, _>>(config.clone(), runtime); let prove_duration = prove_start.elapsed().as_secs_f64(); let verify_start = Instant::now(); @@ -179,7 +180,7 @@ fn run_evaluation(hashfn: &HashFnId, program: &Program, _elf: &[u8]) -> (f64, f6 let config = BabyBearKeccak::new(); let prove_start = Instant::now(); - let _proof = prove_simple(config.clone(), runtime); + let _proof = prove_simple::<_, DefaultProver<_, _>>(config.clone(), runtime); let prove_duration = prove_start.elapsed().as_secs_f64(); let verify_start = Instant::now(); diff --git a/examples/aggregation/program/Cargo.lock b/examples/aggregation/program/Cargo.lock index 321ab1a56..21690ad8b 100644 --- a/examples/aggregation/program/Cargo.lock +++ b/examples/aggregation/program/Cargo.lock @@ -23,18 +23,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -44,18 +32,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -65,31 +41,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#0d57d6ac0af6a464c4764809b5bf994d15920762" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -99,18 +56,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -121,16 +66,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -138,23 +73,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", -] - -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", ] [[package]] @@ -163,43 +82,6 @@ version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "gcd" version = "2.3.0" @@ -214,7 +96,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -228,32 +109,12 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - [[package]] name = "hex" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.9" @@ -272,20 +133,6 @@ dependencies = [ "either", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -440,31 +287,12 @@ dependencies = [ "serde", ] -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - [[package]] name = "pin-project-lite" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -489,12 +317,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -525,30 +347,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.204" @@ -580,26 +378,14 @@ dependencies = [ ] [[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -622,34 +408,18 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "p3-baby-bear", "p3-field", "rand", + "serde", "sha2", - "sphinx-precompiles", + "sphinx-lib", "sphinx-primitives", ] -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", -] - -[[package]] -name = "subtle" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d0208408ba0c3df17ed26eb06992cb1a1268d41b2c0e12e65203fbe3972cee5" - [[package]] name = "syn" version = "2.0.68" @@ -661,12 +431,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "tracing" version = "0.1.40" @@ -721,18 +485,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/examples/aggregation/program/elf/riscv32im-succinct-zkvm-elf b/examples/aggregation/program/elf/riscv32im-succinct-zkvm-elf index ab3b57c24..11e165aa3 100755 Binary files a/examples/aggregation/program/elf/riscv32im-succinct-zkvm-elf and b/examples/aggregation/program/elf/riscv32im-succinct-zkvm-elf differ diff --git a/examples/aggregation/program/src/main.rs b/examples/aggregation/program/src/main.rs index e7ccaf1b8..d90d41e3a 100644 --- a/examples/aggregation/program/src/main.rs +++ b/examples/aggregation/program/src/main.rs @@ -56,7 +56,7 @@ pub fn main() { let vkey = &vkeys[i]; let public_values = &public_values[i]; let public_values_digest = Sha256::digest(public_values); - sphinx_zkvm::precompiles::verify::verify_sphinx_proof(vkey, &public_values_digest.into()); + sphinx_zkvm::lib::verify::verify_sphinx_proof(vkey, &public_values_digest.into()); } // TODO: Do something interesting with the proofs here. diff --git a/examples/aggregation/script/Cargo.lock b/examples/aggregation/script/Cargo.lock index fa2802901..591a35d4f 100644 --- a/examples/aggregation/script/Cargo.lock +++ b/examples/aggregation/script/Cargo.lock @@ -2129,7 +2129,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -2522,6 +2522,15 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "ntapi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" +dependencies = [ + "winapi", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -3188,6 +3197,12 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + [[package]] name = "portable-atomic" version = "1.6.0" @@ -4189,6 +4204,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "sphinx-build" +version = "0.1.0" +dependencies = [ + "anyhow", + "cargo_metadata", + "clap", +] + [[package]] name = "sphinx-core" version = "1.0.0" @@ -4231,6 +4255,7 @@ dependencies = [ "p3-symmetric", "p3-uni-stark", "p3-util", + "plain", "rand", "rayon-scan", "rrs-lib", @@ -4265,6 +4290,7 @@ version = "1.0.0" dependencies = [ "cargo_metadata", "chrono", + "sphinx-build", ] [[package]] @@ -4492,6 +4518,7 @@ dependencies = [ "sphinx-prover", "strum", "strum_macros", + "sysinfo", "tempfile", "thiserror", "tokio", @@ -4623,6 +4650,20 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +[[package]] +name = "sysinfo" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b92e0bdf838cbc1c4c9ba14f9c97a7ec6cdcd1ae66b10e1e42775a25553f45d" +dependencies = [ + "core-foundation-sys", + "libc", + "memchr", + "ntapi", + "rayon", + "windows", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -5308,6 +5349,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" +dependencies = [ + "windows-core 0.57.0", + "windows-targets 0.52.5", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -5317,6 +5368,49 @@ dependencies = [ "windows-targets 0.52.5", ] +[[package]] +name = "windows-core" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-implement" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.60", +] + +[[package]] +name = "windows-interface" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.60", +] + +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets 0.52.5", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/examples/bls12381-pairing/script/Cargo.lock b/examples/bls12381-pairing/script/Cargo.lock index d50fa4d14..891bd921f 100644 --- a/examples/bls12381-pairing/script/Cargo.lock +++ b/examples/bls12381-pairing/script/Cargo.lock @@ -2129,7 +2129,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -2528,6 +2528,15 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "ntapi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" +dependencies = [ + "winapi", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -3194,6 +3203,12 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + [[package]] name = "portable-atomic" version = "1.6.0" @@ -4194,6 +4209,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "sphinx-build" +version = "0.1.0" +dependencies = [ + "anyhow", + "cargo_metadata", + "clap", +] + [[package]] name = "sphinx-core" version = "1.0.0" @@ -4236,6 +4260,7 @@ dependencies = [ "p3-symmetric", "p3-uni-stark", "p3-util", + "plain", "rand", "rayon-scan", "rrs-lib", @@ -4270,6 +4295,7 @@ version = "1.0.0" dependencies = [ "cargo_metadata", "chrono", + "sphinx-build", ] [[package]] @@ -4497,6 +4523,7 @@ dependencies = [ "sphinx-prover", "strum", "strum_macros", + "sysinfo", "tempfile", "thiserror", "tokio", @@ -4622,6 +4649,20 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +[[package]] +name = "sysinfo" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b92e0bdf838cbc1c4c9ba14f9c97a7ec6cdcd1ae66b10e1e42775a25553f45d" +dependencies = [ + "core-foundation-sys", + "libc", + "memchr", + "ntapi", + "rayon", + "windows", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -5317,6 +5358,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" +dependencies = [ + "windows-core 0.57.0", + "windows-targets 0.52.5", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -5326,6 +5377,49 @@ dependencies = [ "windows-targets 0.52.5", ] +[[package]] +name = "windows-core" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-implement" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + +[[package]] +name = "windows-interface" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets 0.52.5", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/examples/chess/program/Cargo.lock b/examples/chess/program/Cargo.lock index 55c64b507..ba16d89bd 100644 --- a/examples/chess/program/Cargo.lock +++ b/examples/chess/program/Cargo.lock @@ -44,18 +44,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -65,18 +53,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -86,19 +62,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core 0.6.4", - "subtle", -] - [[package]] name = "cc" version = "1.0.97" @@ -131,12 +94,6 @@ dependencies = [ "sphinx-zkvm", ] -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -146,18 +103,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core 0.6.4", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -168,16 +113,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -185,43 +120,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", -] - -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core 0.6.4", - "sec1", - "subtle", - "tap", - "zeroize", ] [[package]] @@ -246,23 +145,6 @@ dependencies = [ "synstructure", ] -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core 0.6.4", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -271,7 +153,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -291,26 +172,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core 0.6.4", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -320,20 +181,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -388,25 +235,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -431,12 +259,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.7.3" @@ -513,36 +335,12 @@ dependencies = [ "rand_core 0.5.1", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - [[package]] name = "rustc-demangle" version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.204" @@ -575,36 +373,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core 0.6.4", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -615,31 +391,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand 0.8.5", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "1.0.109" @@ -674,12 +434,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -709,18 +463,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/examples/chess/program/elf/riscv32im-succinct-zkvm-elf b/examples/chess/program/elf/riscv32im-succinct-zkvm-elf index 5dbd615c5..c9ccf0887 100755 Binary files a/examples/chess/program/elf/riscv32im-succinct-zkvm-elf and b/examples/chess/program/elf/riscv32im-succinct-zkvm-elf differ diff --git a/examples/chess/script/Cargo.lock b/examples/chess/script/Cargo.lock index eb2e471c7..047564443 100644 --- a/examples/chess/script/Cargo.lock +++ b/examples/chess/script/Cargo.lock @@ -2128,7 +2128,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -2527,6 +2527,15 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "ntapi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" +dependencies = [ + "winapi", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -3193,6 +3202,12 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + [[package]] name = "portable-atomic" version = "1.6.0" @@ -4193,6 +4208,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "sphinx-build" +version = "0.1.0" +dependencies = [ + "anyhow", + "cargo_metadata", + "clap", +] + [[package]] name = "sphinx-core" version = "1.0.0" @@ -4235,6 +4259,7 @@ dependencies = [ "p3-symmetric", "p3-uni-stark", "p3-util", + "plain", "rand", "rayon-scan", "rrs-lib", @@ -4269,6 +4294,7 @@ version = "1.0.0" dependencies = [ "cargo_metadata", "chrono", + "sphinx-build", ] [[package]] @@ -4496,6 +4522,7 @@ dependencies = [ "sphinx-prover", "strum", "strum_macros", + "sysinfo", "tempfile", "thiserror", "tokio", @@ -4621,6 +4648,20 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +[[package]] +name = "sysinfo" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b92e0bdf838cbc1c4c9ba14f9c97a7ec6cdcd1ae66b10e1e42775a25553f45d" +dependencies = [ + "core-foundation-sys", + "libc", + "memchr", + "ntapi", + "rayon", + "windows", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -5316,6 +5357,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" +dependencies = [ + "windows-core 0.57.0", + "windows-targets 0.52.5", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -5325,6 +5376,49 @@ dependencies = [ "windows-targets 0.52.5", ] +[[package]] +name = "windows-core" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-implement" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "windows-interface" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets 0.52.5", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/examples/cycle-tracking/program/Cargo.lock b/examples/cycle-tracking/program/Cargo.lock index 1f1f6c997..7fa668485 100644 --- a/examples/cycle-tracking/program/Cargo.lock +++ b/examples/cycle-tracking/program/Cargo.lock @@ -8,18 +8,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -29,18 +17,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -51,17 +27,10 @@ dependencies = [ ] [[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cfg-if" @@ -69,12 +38,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -84,18 +47,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -111,19 +62,10 @@ name = "cycle-tracking-program" version = "0.1.0" dependencies = [ "sphinx-derive", + "sphinx-lib", "sphinx-zkvm", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -131,62 +73,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", -] - -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", ] -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -195,7 +84,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -209,26 +97,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -238,20 +106,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -277,30 +131,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" +name = "ppv-lite86" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" dependencies = [ - "der", - "spki", + "zerocopy", ] -[[package]] -name = "ppv-lite86" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" - [[package]] name = "proc-macro2" version = "1.0.82" @@ -319,12 +157,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -355,30 +187,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.204" @@ -410,26 +218,6 @@ dependencies = [ "digest", ] -[[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - [[package]] name = "sphinx-derive" version = "1.0.0" @@ -440,16 +228,14 @@ dependencies = [ ] [[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -460,31 +246,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "1.0.109" @@ -507,12 +277,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -527,9 +291,9 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "wasi" @@ -538,16 +302,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] -name = "wyz" -version = "0.5.1" +name = "zerocopy" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ - "tap", + "byteorder", + "zerocopy-derive", ] [[package]] -name = "zeroize" -version = "1.7.0" +name = "zerocopy-derive" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] diff --git a/examples/cycle-tracking/program/Cargo.toml b/examples/cycle-tracking/program/Cargo.toml index f7d994035..bc07d9de4 100644 --- a/examples/cycle-tracking/program/Cargo.toml +++ b/examples/cycle-tracking/program/Cargo.toml @@ -6,4 +6,5 @@ edition = "2021" [dependencies] sphinx-zkvm = { path = "../../../zkvm/entrypoint" } +sphinx-lib = { path = "../../../zkvm/lib" } sphinx-derive = { path = "../../../derive" } diff --git a/examples/cycle-tracking/program/elf/riscv32im-succinct-zkvm-elf b/examples/cycle-tracking/program/elf/riscv32im-succinct-zkvm-elf index eca738e74..dede2cb7f 100755 Binary files a/examples/cycle-tracking/program/elf/riscv32im-succinct-zkvm-elf and b/examples/cycle-tracking/program/elf/riscv32im-succinct-zkvm-elf differ diff --git a/examples/cycle-tracking/script/Cargo.lock b/examples/cycle-tracking/script/Cargo.lock index eee0e1e7b..8002f58f8 100644 --- a/examples/cycle-tracking/script/Cargo.lock +++ b/examples/cycle-tracking/script/Cargo.lock @@ -2128,7 +2128,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -2527,6 +2527,15 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "ntapi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" +dependencies = [ + "winapi", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -3193,6 +3202,12 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + [[package]] name = "portable-atomic" version = "1.6.0" @@ -4193,6 +4208,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "sphinx-build" +version = "0.1.0" +dependencies = [ + "anyhow", + "cargo_metadata", + "clap", +] + [[package]] name = "sphinx-core" version = "1.0.0" @@ -4235,6 +4259,7 @@ dependencies = [ "p3-symmetric", "p3-uni-stark", "p3-util", + "plain", "rand", "rayon-scan", "rrs-lib", @@ -4269,6 +4294,7 @@ version = "1.0.0" dependencies = [ "cargo_metadata", "chrono", + "sphinx-build", ] [[package]] @@ -4496,6 +4522,7 @@ dependencies = [ "sphinx-prover", "strum", "strum_macros", + "sysinfo", "tempfile", "thiserror", "tokio", @@ -4621,6 +4648,20 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +[[package]] +name = "sysinfo" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b92e0bdf838cbc1c4c9ba14f9c97a7ec6cdcd1ae66b10e1e42775a25553f45d" +dependencies = [ + "core-foundation-sys", + "libc", + "memchr", + "ntapi", + "rayon", + "windows", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -5316,6 +5357,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" +dependencies = [ + "windows-core 0.57.0", + "windows-targets 0.52.5", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -5325,6 +5376,49 @@ dependencies = [ "windows-targets 0.52.5", ] +[[package]] +name = "windows-core" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-implement" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "windows-interface" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets 0.52.5", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/examples/fibonacci/program/Cargo.lock b/examples/fibonacci/program/Cargo.lock index cfa9657db..d9940fbae 100644 --- a/examples/fibonacci/program/Cargo.lock +++ b/examples/fibonacci/program/Cargo.lock @@ -8,18 +8,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -29,18 +17,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -50,31 +26,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -84,18 +41,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -106,16 +51,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -123,54 +58,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", -] - -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", ] [[package]] @@ -180,12 +68,6 @@ dependencies = [ "sphinx-zkvm", ] -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -194,7 +76,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -208,26 +89,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -237,20 +98,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -275,25 +122,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -318,12 +146,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -354,30 +176,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.204" @@ -410,36 +208,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -450,31 +226,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.63" @@ -486,12 +246,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -515,18 +269,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/examples/fibonacci/program/elf/riscv32im-succinct-zkvm-elf b/examples/fibonacci/program/elf/riscv32im-succinct-zkvm-elf index ecd7157eb..47bb3bec2 100755 Binary files a/examples/fibonacci/program/elf/riscv32im-succinct-zkvm-elf and b/examples/fibonacci/program/elf/riscv32im-succinct-zkvm-elf differ diff --git a/examples/fibonacci/script/Cargo.lock b/examples/fibonacci/script/Cargo.lock index 17144f2f9..0f46bbbed 100644 --- a/examples/fibonacci/script/Cargo.lock +++ b/examples/fibonacci/script/Cargo.lock @@ -2129,7 +2129,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -2528,6 +2528,15 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "ntapi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" +dependencies = [ + "winapi", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -3194,6 +3203,12 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + [[package]] name = "portable-atomic" version = "1.6.0" @@ -4194,6 +4209,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "sphinx-build" +version = "0.1.0" +dependencies = [ + "anyhow", + "cargo_metadata", + "clap", +] + [[package]] name = "sphinx-core" version = "1.0.0" @@ -4236,6 +4260,7 @@ dependencies = [ "p3-symmetric", "p3-uni-stark", "p3-util", + "plain", "rand", "rayon-scan", "rrs-lib", @@ -4270,6 +4295,7 @@ version = "1.0.0" dependencies = [ "cargo_metadata", "chrono", + "sphinx-build", ] [[package]] @@ -4497,6 +4523,7 @@ dependencies = [ "sphinx-prover", "strum", "strum_macros", + "sysinfo", "tempfile", "thiserror", "tokio", @@ -4622,6 +4649,20 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +[[package]] +name = "sysinfo" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b92e0bdf838cbc1c4c9ba14f9c97a7ec6cdcd1ae66b10e1e42775a25553f45d" +dependencies = [ + "core-foundation-sys", + "libc", + "memchr", + "ntapi", + "rayon", + "windows", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -5317,6 +5358,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" +dependencies = [ + "windows-core 0.57.0", + "windows-targets 0.52.5", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -5326,6 +5377,49 @@ dependencies = [ "windows-targets 0.52.5", ] +[[package]] +name = "windows-core" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-implement" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "windows-interface" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets 0.52.5", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/examples/fibonacci/script/bin/plonk_bn254.rs b/examples/fibonacci/script/bin/plonk_bn254.rs index 72c312e8b..c39851567 100644 --- a/examples/fibonacci/script/bin/plonk_bn254.rs +++ b/examples/fibonacci/script/bin/plonk_bn254.rs @@ -16,16 +16,17 @@ fn main() { // Generate the proof for the given program and input. let client = ProverClient::new(); let (pk, vk) = client.setup(ELF); - let mut proof = client.prove(&pk, stdin).plonk().run().unwrap(); + let proof = client.prove(&pk, stdin).plonk().run().unwrap(); println!("generated proof"); - // Read and verify the output. - let _ = proof.public_values.read::(); - let a = proof.public_values.read::(); - let b = proof.public_values.read::(); - println!("a: {}", a); - println!("b: {}", b); + // Get the public values as bytes. + let public_values = proof.public_values.raw(); + println!("public values: {:?}", public_values); + + // Get the proof as bytes. + let solidity_proof = proof.raw(); + println!("proof: {:?}", solidity_proof); // Verify proof and public values client.verify(&proof, &vk).expect("verification failed"); diff --git a/examples/fibonacci/script/src/main.rs b/examples/fibonacci/script/src/main.rs index 432da8121..90fc65a65 100644 --- a/examples/fibonacci/script/src/main.rs +++ b/examples/fibonacci/script/src/main.rs @@ -8,7 +8,7 @@ fn main() { utils::setup_logger(); // Create an input stream and write '500' to it. - let n = 500u32; + let n = 1u32; let mut stdin = SphinxStdin::new(); stdin.write(&n); diff --git a/examples/io/program/Cargo.lock b/examples/io/program/Cargo.lock index f74802654..23d59f73d 100644 --- a/examples/io/program/Cargo.lock +++ b/examples/io/program/Cargo.lock @@ -8,18 +8,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -29,18 +17,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -50,31 +26,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -84,18 +41,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -106,16 +51,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -123,62 +58,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -187,7 +69,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -201,26 +82,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -238,20 +99,6 @@ dependencies = [ "sphinx-zkvm", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -276,25 +123,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -319,12 +147,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -355,30 +177,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.204" @@ -411,36 +209,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -451,31 +227,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.63" @@ -487,12 +247,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -516,18 +270,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/examples/io/program/elf/riscv32im-succinct-zkvm-elf b/examples/io/program/elf/riscv32im-succinct-zkvm-elf index 390245941..66a61b500 100755 Binary files a/examples/io/program/elf/riscv32im-succinct-zkvm-elf and b/examples/io/program/elf/riscv32im-succinct-zkvm-elf differ diff --git a/examples/io/script/Cargo.lock b/examples/io/script/Cargo.lock index 28487c072..c6efe9ef5 100644 --- a/examples/io/script/Cargo.lock +++ b/examples/io/script/Cargo.lock @@ -2120,7 +2120,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -2528,6 +2528,15 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "ntapi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" +dependencies = [ + "winapi", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -3194,6 +3203,12 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + [[package]] name = "portable-atomic" version = "1.6.0" @@ -4194,6 +4209,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "sphinx-build" +version = "0.1.0" +dependencies = [ + "anyhow", + "cargo_metadata", + "clap", +] + [[package]] name = "sphinx-core" version = "1.0.0" @@ -4236,6 +4260,7 @@ dependencies = [ "p3-symmetric", "p3-uni-stark", "p3-util", + "plain", "rand", "rayon-scan", "rrs-lib", @@ -4270,6 +4295,7 @@ version = "1.0.0" dependencies = [ "cargo_metadata", "chrono", + "sphinx-build", ] [[package]] @@ -4497,6 +4523,7 @@ dependencies = [ "sphinx-prover", "strum", "strum_macros", + "sysinfo", "tempfile", "thiserror", "tokio", @@ -4622,6 +4649,20 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +[[package]] +name = "sysinfo" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b92e0bdf838cbc1c4c9ba14f9c97a7ec6cdcd1ae66b10e1e42775a25553f45d" +dependencies = [ + "core-foundation-sys", + "libc", + "memchr", + "ntapi", + "rayon", + "windows", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -5317,6 +5358,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" +dependencies = [ + "windows-core 0.57.0", + "windows-targets 0.52.5", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -5326,6 +5377,49 @@ dependencies = [ "windows-targets 0.52.5", ] +[[package]] +name = "windows-core" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-implement" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "windows-interface" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets 0.52.5", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/examples/is-prime/script/Cargo.lock b/examples/is-prime/script/Cargo.lock index be397c138..9740801ef 100644 --- a/examples/is-prime/script/Cargo.lock +++ b/examples/is-prime/script/Cargo.lock @@ -2120,7 +2120,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -2526,6 +2526,15 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "ntapi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" +dependencies = [ + "winapi", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -3192,6 +3201,12 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + [[package]] name = "portable-atomic" version = "1.6.0" @@ -4234,6 +4249,7 @@ dependencies = [ "p3-symmetric", "p3-uni-stark", "p3-util", + "plain", "rand", "rayon-scan", "rrs-lib", @@ -4487,6 +4503,7 @@ dependencies = [ "sphinx-prover", "strum", "strum_macros", + "sysinfo", "tempfile", "thiserror", "tokio", @@ -4612,6 +4629,20 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +[[package]] +name = "sysinfo" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b92e0bdf838cbc1c4c9ba14f9c97a7ec6cdcd1ae66b10e1e42775a25553f45d" +dependencies = [ + "core-foundation-sys", + "libc", + "memchr", + "ntapi", + "rayon", + "windows", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -5307,6 +5338,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" +dependencies = [ + "windows-core 0.57.0", + "windows-targets 0.52.5", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -5316,6 +5357,49 @@ dependencies = [ "windows-targets 0.52.5", ] +[[package]] +name = "windows-core" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-implement" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "windows-interface" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets 0.52.5", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/examples/json/program/Cargo.lock b/examples/json/program/Cargo.lock index 446ac505c..5935b1a48 100644 --- a/examples/json/program/Cargo.lock +++ b/examples/json/program/Cargo.lock @@ -8,18 +8,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -29,18 +17,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -50,31 +26,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -84,18 +41,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -106,16 +51,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -123,62 +58,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -187,7 +69,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -201,26 +82,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -246,20 +107,6 @@ dependencies = [ "sphinx-zkvm", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -291,25 +138,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -334,12 +162,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -370,36 +192,12 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - [[package]] name = "ryu" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.204" @@ -443,36 +241,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -483,31 +259,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.63" @@ -519,12 +279,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -548,18 +302,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/examples/json/program/elf/riscv32im-succinct-zkvm-elf b/examples/json/program/elf/riscv32im-succinct-zkvm-elf index cab6ce08b..4243fe7d0 100755 Binary files a/examples/json/program/elf/riscv32im-succinct-zkvm-elf and b/examples/json/program/elf/riscv32im-succinct-zkvm-elf differ diff --git a/examples/json/script/Cargo.lock b/examples/json/script/Cargo.lock index 38cc7729c..8578dd32f 100644 --- a/examples/json/script/Cargo.lock +++ b/examples/json/script/Cargo.lock @@ -2120,7 +2120,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -2537,6 +2537,15 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "ntapi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" +dependencies = [ + "winapi", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -3203,6 +3212,12 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + [[package]] name = "portable-atomic" version = "1.6.0" @@ -4203,6 +4218,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "sphinx-build" +version = "0.1.0" +dependencies = [ + "anyhow", + "cargo_metadata", + "clap", +] + [[package]] name = "sphinx-core" version = "1.0.0" @@ -4245,6 +4269,7 @@ dependencies = [ "p3-symmetric", "p3-uni-stark", "p3-util", + "plain", "rand", "rayon-scan", "rrs-lib", @@ -4279,6 +4304,7 @@ version = "1.0.0" dependencies = [ "cargo_metadata", "chrono", + "sphinx-build", ] [[package]] @@ -4506,6 +4532,7 @@ dependencies = [ "sphinx-prover", "strum", "strum_macros", + "sysinfo", "tempfile", "thiserror", "tokio", @@ -4631,6 +4658,20 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +[[package]] +name = "sysinfo" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b92e0bdf838cbc1c4c9ba14f9c97a7ec6cdcd1ae66b10e1e42775a25553f45d" +dependencies = [ + "core-foundation-sys", + "libc", + "memchr", + "ntapi", + "rayon", + "windows", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -5326,6 +5367,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" +dependencies = [ + "windows-core 0.57.0", + "windows-targets 0.52.5", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -5335,6 +5386,49 @@ dependencies = [ "windows-targets 0.52.5", ] +[[package]] +name = "windows-core" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-implement" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "windows-interface" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets 0.52.5", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/examples/lcs/program/Cargo.lock b/examples/lcs/program/Cargo.lock index 83749d343..53848f488 100644 --- a/examples/lcs/program/Cargo.lock +++ b/examples/lcs/program/Cargo.lock @@ -8,18 +8,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -29,18 +17,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -50,31 +26,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#9334926c03060d5cf4baf3a6c8dee1842fdc1975" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -84,18 +41,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -106,16 +51,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -123,62 +58,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", -] - -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", ] -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -187,7 +69,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -201,26 +82,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.9" @@ -230,20 +91,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -275,25 +122,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -318,12 +146,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -354,30 +176,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.204" @@ -410,36 +208,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -450,31 +226,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" - [[package]] name = "syn" version = "2.0.72" @@ -486,12 +246,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -515,18 +269,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/examples/lcs/program/elf/riscv32im-succinct-zkvm-elf b/examples/lcs/program/elf/riscv32im-succinct-zkvm-elf index 5f01285eb..98a04542d 100755 Binary files a/examples/lcs/program/elf/riscv32im-succinct-zkvm-elf and b/examples/lcs/program/elf/riscv32im-succinct-zkvm-elf differ diff --git a/examples/lcs/script/Cargo.lock b/examples/lcs/script/Cargo.lock index b70086e94..a4ed7afab 100644 --- a/examples/lcs/script/Cargo.lock +++ b/examples/lcs/script/Cargo.lock @@ -2119,7 +2119,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -2528,6 +2528,15 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "ntapi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" +dependencies = [ + "winapi", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -3194,6 +3203,12 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + [[package]] name = "portable-atomic" version = "1.7.0" @@ -4201,6 +4216,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "sphinx-build" +version = "0.1.0" +dependencies = [ + "anyhow", + "cargo_metadata", + "clap", +] + [[package]] name = "sphinx-core" version = "1.0.0" @@ -4243,6 +4267,7 @@ dependencies = [ "p3-symmetric", "p3-uni-stark", "p3-util", + "plain", "rand", "rayon-scan", "rrs-lib", @@ -4277,6 +4302,7 @@ version = "1.0.0" dependencies = [ "cargo_metadata", "chrono", + "sphinx-build", ] [[package]] @@ -4504,6 +4530,7 @@ dependencies = [ "sphinx-prover", "strum", "strum_macros", + "sysinfo", "tempfile", "thiserror", "tokio", @@ -4629,6 +4656,20 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +[[package]] +name = "sysinfo" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b92e0bdf838cbc1c4c9ba14f9c97a7ec6cdcd1ae66b10e1e42775a25553f45d" +dependencies = [ + "core-foundation-sys", + "libc", + "memchr", + "ntapi", + "rayon", + "windows", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -5324,6 +5365,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" +dependencies = [ + "windows-core 0.57.0", + "windows-targets 0.52.6", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -5333,6 +5384,49 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-core" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-implement" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.72", +] + +[[package]] +name = "windows-interface" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.72", +] + +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/examples/lcs2/program/Cargo.lock b/examples/lcs2/program/Cargo.lock index 716d1eb0b..1c7be8622 100644 --- a/examples/lcs2/program/Cargo.lock +++ b/examples/lcs2/program/Cargo.lock @@ -8,18 +8,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -29,18 +17,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -50,31 +26,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#9334926c03060d5cf4baf3a6c8dee1842fdc1975" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -84,18 +41,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -106,16 +51,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -123,62 +58,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", -] - -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", ] -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -187,7 +69,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -201,26 +82,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.9" @@ -230,20 +91,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -275,25 +122,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -318,12 +146,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -354,30 +176,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.204" @@ -410,36 +208,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -450,31 +226,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" - [[package]] name = "syn" version = "2.0.72" @@ -486,12 +246,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -515,18 +269,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/examples/lcs2/program/elf/riscv32im-succinct-zkvm-elf b/examples/lcs2/program/elf/riscv32im-succinct-zkvm-elf index 134a1ce29..b9e66f655 100755 Binary files a/examples/lcs2/program/elf/riscv32im-succinct-zkvm-elf and b/examples/lcs2/program/elf/riscv32im-succinct-zkvm-elf differ diff --git a/examples/lcs2/script/Cargo.lock b/examples/lcs2/script/Cargo.lock index 7e524c852..ebfbee4f6 100644 --- a/examples/lcs2/script/Cargo.lock +++ b/examples/lcs2/script/Cargo.lock @@ -2119,7 +2119,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -2528,6 +2528,15 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "ntapi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" +dependencies = [ + "winapi", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -3194,6 +3203,12 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + [[package]] name = "portable-atomic" version = "1.7.0" @@ -4201,6 +4216,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "sphinx-build" +version = "0.1.0" +dependencies = [ + "anyhow", + "cargo_metadata", + "clap", +] + [[package]] name = "sphinx-core" version = "1.0.0" @@ -4243,6 +4267,7 @@ dependencies = [ "p3-symmetric", "p3-uni-stark", "p3-util", + "plain", "rand", "rayon-scan", "rrs-lib", @@ -4277,6 +4302,7 @@ version = "1.0.0" dependencies = [ "cargo_metadata", "chrono", + "sphinx-build", ] [[package]] @@ -4504,6 +4530,7 @@ dependencies = [ "sphinx-prover", "strum", "strum_macros", + "sysinfo", "tempfile", "thiserror", "tokio", @@ -4629,6 +4656,20 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +[[package]] +name = "sysinfo" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b92e0bdf838cbc1c4c9ba14f9c97a7ec6cdcd1ae66b10e1e42775a25553f45d" +dependencies = [ + "core-foundation-sys", + "libc", + "memchr", + "ntapi", + "rayon", + "windows", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -5324,6 +5365,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" +dependencies = [ + "windows-core 0.57.0", + "windows-targets 0.52.6", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -5333,6 +5384,49 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-core" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-implement" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.72", +] + +[[package]] +name = "windows-interface" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.72", +] + +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/examples/patch-testing/program/Cargo.lock b/examples/patch-testing/program/Cargo.lock index c112df3a4..3a6675b38 100644 --- a/examples/patch-testing/program/Cargo.lock +++ b/examples/patch-testing/program/Cargo.lock @@ -8,18 +8,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -29,18 +17,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.9.0" @@ -59,19 +35,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#9334926c03060d5cf4baf3a6c8dee1842fdc1975" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "byteorder" version = "1.5.0" @@ -84,12 +47,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -105,18 +62,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -139,16 +84,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.9.0" @@ -165,23 +100,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer 0.10.4", - "const-oid", "crypto-common", - "subtle", -] - -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest 0.10.7", - "elliptic-curve", - "rfc6979", - "signature", - "spki", ] [[package]] @@ -198,43 +117,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest 0.10.7", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -243,7 +125,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -257,32 +138,12 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - [[package]] name = "hex" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest 0.10.7", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.9" @@ -292,20 +153,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -336,37 +183,18 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - [[package]] name = "patch-testing-program" version = "0.1.0" dependencies = [ "curve25519-dalek-ng", "ed25519-consensus", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2 0.10.8", "sha2 0.9.8", "sphinx-zkvm", "tiny-keccak", ] -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -391,12 +219,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -427,30 +249,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -495,36 +293,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest 0.10.7", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest 0.10.7", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -535,31 +311,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2 0.10.8", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "subtle-ng" version = "2.5.0" @@ -577,12 +337,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "thiserror" version = "1.0.61" @@ -636,15 +390,6 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - [[package]] name = "zeroize" version = "1.8.1" diff --git a/examples/patch-testing/program/elf/riscv32im-succinct-zkvm-elf b/examples/patch-testing/program/elf/riscv32im-succinct-zkvm-elf index a86d4c345..a3d72df8d 100755 Binary files a/examples/patch-testing/program/elf/riscv32im-succinct-zkvm-elf and b/examples/patch-testing/program/elf/riscv32im-succinct-zkvm-elf differ diff --git a/examples/patch-testing/script/Cargo.lock b/examples/patch-testing/script/Cargo.lock index 1731d242b..790e4077f 100644 --- a/examples/patch-testing/script/Cargo.lock +++ b/examples/patch-testing/script/Cargo.lock @@ -2155,7 +2155,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -2429,7 +2429,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -2548,6 +2548,15 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "ntapi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" +dependencies = [ + "winapi", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -3232,6 +3241,12 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + [[package]] name = "portable-atomic" version = "1.6.0" @@ -4253,6 +4268,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "sphinx-build" +version = "0.1.0" +dependencies = [ + "anyhow", + "cargo_metadata", + "clap", +] + [[package]] name = "sphinx-core" version = "1.0.0" @@ -4295,6 +4319,7 @@ dependencies = [ "p3-symmetric", "p3-uni-stark", "p3-util", + "plain", "rand", "rayon-scan", "rrs-lib", @@ -4329,6 +4354,7 @@ version = "1.0.0" dependencies = [ "cargo_metadata", "chrono", + "sphinx-build", ] [[package]] @@ -4556,6 +4582,7 @@ dependencies = [ "sphinx-prover", "strum", "strum_macros", + "sysinfo", "tempfile", "thiserror", "tokio", @@ -4693,6 +4720,20 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +[[package]] +name = "sysinfo" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b92e0bdf838cbc1c4c9ba14f9c97a7ec6cdcd1ae66b10e1e42775a25553f45d" +dependencies = [ + "core-foundation-sys", + "libc", + "memchr", + "ntapi", + "rayon", + "windows", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -5369,7 +5410,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -5378,6 +5419,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" +dependencies = [ + "windows-core 0.57.0", + "windows-targets 0.52.6", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -5387,6 +5438,49 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-core" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-implement" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.60", +] + +[[package]] +name = "windows-interface" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.60", +] + +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/examples/regex/program/Cargo.lock b/examples/regex/program/Cargo.lock index 10fd84a71..4d42277ca 100644 --- a/examples/regex/program/Cargo.lock +++ b/examples/regex/program/Cargo.lock @@ -17,18 +17,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -38,18 +26,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -59,31 +35,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -93,18 +50,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -115,16 +60,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -132,62 +67,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -196,7 +78,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -210,26 +91,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -239,20 +100,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -283,25 +130,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -326,12 +154,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -399,30 +221,6 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.204" @@ -455,36 +253,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -495,31 +271,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.63" @@ -531,12 +291,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -560,18 +314,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/examples/regex/program/elf/riscv32im-succinct-zkvm-elf b/examples/regex/program/elf/riscv32im-succinct-zkvm-elf index d83a58763..382756aaf 100755 Binary files a/examples/regex/program/elf/riscv32im-succinct-zkvm-elf and b/examples/regex/program/elf/riscv32im-succinct-zkvm-elf differ diff --git a/examples/regex/script/Cargo.lock b/examples/regex/script/Cargo.lock index 2302d6d7f..171d563e4 100644 --- a/examples/regex/script/Cargo.lock +++ b/examples/regex/script/Cargo.lock @@ -2120,7 +2120,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -2519,6 +2519,15 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "ntapi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" +dependencies = [ + "winapi", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -3185,6 +3194,12 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + [[package]] name = "portable-atomic" version = "1.6.0" @@ -4194,6 +4209,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "sphinx-build" +version = "0.1.0" +dependencies = [ + "anyhow", + "cargo_metadata", + "clap", +] + [[package]] name = "sphinx-core" version = "1.0.0" @@ -4236,6 +4260,7 @@ dependencies = [ "p3-symmetric", "p3-uni-stark", "p3-util", + "plain", "rand", "rayon-scan", "rrs-lib", @@ -4270,6 +4295,7 @@ version = "1.0.0" dependencies = [ "cargo_metadata", "chrono", + "sphinx-build", ] [[package]] @@ -4497,6 +4523,7 @@ dependencies = [ "sphinx-prover", "strum", "strum_macros", + "sysinfo", "tempfile", "thiserror", "tokio", @@ -4622,6 +4649,20 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +[[package]] +name = "sysinfo" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b92e0bdf838cbc1c4c9ba14f9c97a7ec6cdcd1ae66b10e1e42775a25553f45d" +dependencies = [ + "core-foundation-sys", + "libc", + "memchr", + "ntapi", + "rayon", + "windows", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -5317,6 +5358,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" +dependencies = [ + "windows-core 0.57.0", + "windows-targets 0.52.5", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -5326,6 +5377,49 @@ dependencies = [ "windows-targets 0.52.5", ] +[[package]] +name = "windows-core" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-implement" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "windows-interface" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets 0.52.5", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/examples/rsa/program/Cargo.lock b/examples/rsa/program/Cargo.lock index b7974d4f4..dd8774af7 100644 --- a/examples/rsa/program/Cargo.lock +++ b/examples/rsa/program/Cargo.lock @@ -14,12 +14,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - [[package]] name = "base64ct" version = "1.6.0" @@ -35,18 +29,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.9.0" @@ -65,19 +47,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "byteorder" version = "1.5.0" @@ -96,12 +65,6 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -121,18 +84,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -149,21 +100,11 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6919815d73839e7ad218de758883aae3a257ba6759ce7a9992501efbb53d705c" dependencies = [ - "const-oid 0.7.1", - "crypto-bigint 0.3.2", + "const-oid", + "crypto-bigint", "pem-rfc7468", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid 0.9.6", - "zeroize", -] - [[package]] name = "digest" version = "0.9.0" @@ -180,62 +121,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer 0.10.4", - "const-oid 0.9.6", "crypto-common", - "subtle", -] - -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der 0.7.9", - "digest 0.10.7", - "elliptic-curve", - "rfc6979", - "signature", - "spki 0.7.3", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint 0.5.5", - "digest 0.10.7", - "ff", - "generic-array", - "group", - "pkcs8 0.10.2", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", ] -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -244,7 +132,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -258,26 +145,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest 0.10.7", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -287,20 +154,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -381,15 +234,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - [[package]] name = "pem-rfc7468" version = "0.3.1" @@ -405,8 +249,8 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a78f66c04ccc83dd4486fd46c33896f4e17b24a7a3a6400dedc48ed0ddd72320" dependencies = [ - "der 0.5.1", - "pkcs8 0.8.0", + "der", + "pkcs8", "zeroize", ] @@ -416,21 +260,11 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7cabda3fb821068a9a4fab19a683eac3af12edf0f34b94a8be53c4972b8149d0" dependencies = [ - "der 0.5.1", - "spki 0.5.4", + "der", + "spki", "zeroize", ] -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der 0.7.9", - "spki 0.7.3", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -455,12 +289,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -491,16 +319,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - [[package]] name = "rsa" version = "0.6.1" @@ -514,7 +332,7 @@ dependencies = [ "num-iter", "num-traits", "pkcs1", - "pkcs8 0.8.0", + "pkcs8", "rand_core", "smallvec", "subtle", @@ -532,20 +350,6 @@ dependencies = [ "sphinx-zkvm", ] -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der 0.7.9", - "generic-array", - "pkcs8 0.10.2", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.204" @@ -589,26 +393,6 @@ dependencies = [ "digest 0.10.7", ] -[[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest 0.10.7", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest 0.10.7", - "rand_core", -] - [[package]] name = "smallvec" version = "1.13.2" @@ -616,16 +400,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -636,13 +418,13 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", + "serde", + "sha2 0.10.8", + "sphinx-lib", ] [[package]] @@ -658,17 +440,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44d01ac02a6ccf3e07db148d2be087da624fea0221a16152ed01f0496a6b0a27" dependencies = [ "base64ct", - "der 0.5.1", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der 0.7.9", + "der", ] [[package]] @@ -688,12 +460,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -718,15 +484,6 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - [[package]] name = "zeroize" version = "1.7.0" diff --git a/examples/rsa/program/elf/riscv32im-succinct-zkvm-elf b/examples/rsa/program/elf/riscv32im-succinct-zkvm-elf index 00aec6e82..fe202851d 100755 Binary files a/examples/rsa/program/elf/riscv32im-succinct-zkvm-elf and b/examples/rsa/program/elf/riscv32im-succinct-zkvm-elf differ diff --git a/examples/rsa/script/Cargo.lock b/examples/rsa/script/Cargo.lock index 9d9a92cd5..e956e00ad 100644 --- a/examples/rsa/script/Cargo.lock +++ b/examples/rsa/script/Cargo.lock @@ -2147,7 +2147,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -2546,6 +2546,15 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "ntapi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" +dependencies = [ + "winapi", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -3260,6 +3269,12 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + [[package]] name = "portable-atomic" version = "1.6.0" @@ -4289,6 +4304,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "sphinx-build" +version = "0.1.0" +dependencies = [ + "anyhow", + "cargo_metadata", + "clap", +] + [[package]] name = "sphinx-core" version = "1.0.0" @@ -4331,6 +4355,7 @@ dependencies = [ "p3-symmetric", "p3-uni-stark", "p3-util", + "plain", "rand", "rayon-scan", "rrs-lib", @@ -4365,6 +4390,7 @@ version = "1.0.0" dependencies = [ "cargo_metadata", "chrono", + "sphinx-build", ] [[package]] @@ -4592,6 +4618,7 @@ dependencies = [ "sphinx-prover", "strum", "strum_macros", + "sysinfo", "tempfile", "thiserror", "tokio", @@ -4727,6 +4754,20 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +[[package]] +name = "sysinfo" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b92e0bdf838cbc1c4c9ba14f9c97a7ec6cdcd1ae66b10e1e42775a25553f45d" +dependencies = [ + "core-foundation-sys", + "libc", + "memchr", + "ntapi", + "rayon", + "windows", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -5422,6 +5463,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" +dependencies = [ + "windows-core 0.57.0", + "windows-targets 0.52.5", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -5431,6 +5482,49 @@ dependencies = [ "windows-targets 0.52.5", ] +[[package]] +name = "windows-core" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-implement" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "windows-interface" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets 0.52.5", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/examples/ssz-withdrawals/program/Cargo.lock b/examples/ssz-withdrawals/program/Cargo.lock index 7113fe49c..749ab5513 100644 --- a/examples/ssz-withdrawals/program/Cargo.lock +++ b/examples/ssz-withdrawals/program/Cargo.lock @@ -280,19 +280,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "bumpalo" version = "3.16.0" @@ -546,7 +533,6 @@ dependencies = [ "rand_core", "sec1", "subtle", - "tap", "zeroize", ] @@ -589,7 +575,6 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" dependencies = [ - "bitvec", "rand_core", "subtle", ] @@ -895,15 +880,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - [[package]] name = "parity-scale-codec" version = "3.6.12" @@ -1344,16 +1320,14 @@ dependencies = [ ] [[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -1364,13 +1338,13 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", + "serde", "sha2 0.10.8", - "sphinx-precompiles", + "sphinx-lib", ] [[package]] diff --git a/examples/ssz-withdrawals/program/elf/riscv32im-succinct-zkvm-elf b/examples/ssz-withdrawals/program/elf/riscv32im-succinct-zkvm-elf index c676bd2c9..e6e3f735a 100755 Binary files a/examples/ssz-withdrawals/program/elf/riscv32im-succinct-zkvm-elf and b/examples/ssz-withdrawals/program/elf/riscv32im-succinct-zkvm-elf differ diff --git a/examples/ssz-withdrawals/script/Cargo.lock b/examples/ssz-withdrawals/script/Cargo.lock index df59923d8..6d53c9c92 100644 --- a/examples/ssz-withdrawals/script/Cargo.lock +++ b/examples/ssz-withdrawals/script/Cargo.lock @@ -2120,7 +2120,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -2519,6 +2519,15 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "ntapi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" +dependencies = [ + "winapi", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -3185,6 +3194,12 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + [[package]] name = "portable-atomic" version = "1.6.0" @@ -4185,6 +4200,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "sphinx-build" +version = "0.1.0" +dependencies = [ + "anyhow", + "cargo_metadata", + "clap", +] + [[package]] name = "sphinx-core" version = "1.0.0" @@ -4227,6 +4251,7 @@ dependencies = [ "p3-symmetric", "p3-uni-stark", "p3-util", + "plain", "rand", "rayon-scan", "rrs-lib", @@ -4261,6 +4286,7 @@ version = "1.0.0" dependencies = [ "cargo_metadata", "chrono", + "sphinx-build", ] [[package]] @@ -4488,6 +4514,7 @@ dependencies = [ "sphinx-prover", "strum", "strum_macros", + "sysinfo", "tempfile", "thiserror", "tokio", @@ -4622,6 +4649,20 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +[[package]] +name = "sysinfo" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b92e0bdf838cbc1c4c9ba14f9c97a7ec6cdcd1ae66b10e1e42775a25553f45d" +dependencies = [ + "core-foundation-sys", + "libc", + "memchr", + "ntapi", + "rayon", + "windows", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -5317,6 +5358,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" +dependencies = [ + "windows-core 0.57.0", + "windows-targets 0.52.5", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -5326,6 +5377,49 @@ dependencies = [ "windows-targets 0.52.5", ] +[[package]] +name = "windows-core" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-implement" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "windows-interface" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets 0.52.5", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/examples/sum/program/Cargo.lock b/examples/sum/program/Cargo.lock index 0ea5146ef..a485aecdb 100644 --- a/examples/sum/program/Cargo.lock +++ b/examples/sum/program/Cargo.lock @@ -8,18 +8,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -29,18 +17,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -50,19 +26,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#9334926c03060d5cf4baf3a6c8dee1842fdc1975" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "byteorder" version = "1.5.0" @@ -75,12 +38,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -90,18 +47,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -112,16 +57,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -129,62 +64,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -193,7 +75,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -207,26 +88,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.9" @@ -236,20 +97,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -274,25 +121,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -320,12 +148,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -356,30 +178,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.204" @@ -412,36 +210,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -452,31 +228,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" - [[package]] name = "sum-program" version = "0.1.0" @@ -495,12 +255,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -525,15 +279,6 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - [[package]] name = "zerocopy" version = "0.7.35" @@ -554,9 +299,3 @@ dependencies = [ "quote", "syn", ] - -[[package]] -name = "zeroize" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/examples/sum/program/elf/riscv32im-succinct-zkvm-elf b/examples/sum/program/elf/riscv32im-succinct-zkvm-elf index d32f42618..2be0afeb4 100755 Binary files a/examples/sum/program/elf/riscv32im-succinct-zkvm-elf and b/examples/sum/program/elf/riscv32im-succinct-zkvm-elf differ diff --git a/examples/sum/script/Cargo.lock b/examples/sum/script/Cargo.lock index 6217a05d9..635924b2a 100644 --- a/examples/sum/script/Cargo.lock +++ b/examples/sum/script/Cargo.lock @@ -2119,7 +2119,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -2518,6 +2518,15 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "ntapi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" +dependencies = [ + "winapi", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -3184,6 +3193,12 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + [[package]] name = "portable-atomic" version = "1.7.0" @@ -4186,6 +4201,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "sphinx-build" +version = "0.1.0" +dependencies = [ + "anyhow", + "cargo_metadata", + "clap", +] + [[package]] name = "sphinx-core" version = "1.0.0" @@ -4228,6 +4252,7 @@ dependencies = [ "p3-symmetric", "p3-uni-stark", "p3-util", + "plain", "rand", "rayon-scan", "rrs-lib", @@ -4262,6 +4287,7 @@ version = "1.0.0" dependencies = [ "cargo_metadata", "chrono", + "sphinx-build", ] [[package]] @@ -4489,6 +4515,7 @@ dependencies = [ "sphinx-prover", "strum", "strum_macros", + "sysinfo", "tempfile", "thiserror", "tokio", @@ -4623,6 +4650,20 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +[[package]] +name = "sysinfo" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b92e0bdf838cbc1c4c9ba14f9c97a7ec6cdcd1ae66b10e1e42775a25553f45d" +dependencies = [ + "core-foundation-sys", + "libc", + "memchr", + "ntapi", + "rayon", + "windows", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -5318,6 +5359,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" +dependencies = [ + "windows-core 0.57.0", + "windows-targets 0.52.6", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -5327,6 +5378,49 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-core" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-implement" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.72", +] + +[[package]] +name = "windows-interface" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.72", +] + +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/examples/tendermint/program/Cargo.lock b/examples/tendermint/program/Cargo.lock index 8ff6cc16d..5db3a00d8 100644 --- a/examples/tendermint/program/Cargo.lock +++ b/examples/tendermint/program/Cargo.lock @@ -14,12 +14,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - [[package]] name = "base64ct" version = "1.6.0" @@ -35,18 +29,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.9.0" @@ -65,19 +47,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "byteorder" version = "1.5.0" @@ -114,18 +83,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -194,23 +151,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer 0.10.4", - "const-oid", "crypto-common", - "subtle", -] - -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest 0.10.7", - "elliptic-curve", - "rfc6979", - "signature", - "spki", ] [[package]] @@ -241,37 +182,6 @@ version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest 0.10.7", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - [[package]] name = "flex-error" version = "0.4.4" @@ -281,12 +191,6 @@ dependencies = [ "paste", ] -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "futures" version = "0.3.30" @@ -356,7 +260,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -370,17 +273,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - [[package]] name = "half" version = "1.8.3" @@ -393,15 +285,6 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest 0.10.7", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -426,20 +309,6 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -496,15 +365,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - [[package]] name = "paste" version = "1.0.15" @@ -595,12 +455,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -631,36 +485,12 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - [[package]] name = "ryu" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.204" @@ -749,22 +579,16 @@ name = "signature" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest 0.10.7", - "rand_core", -] [[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -775,13 +599,13 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", + "serde", "sha2 0.10.8", - "sphinx-precompiles", + "sphinx-lib", ] [[package]] @@ -837,12 +661,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "tendermint" version = "0.35.0" @@ -967,15 +785,6 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - [[package]] name = "zeroize" version = "1.7.0" diff --git a/examples/tendermint/program/elf/riscv32im-succinct-zkvm-elf b/examples/tendermint/program/elf/riscv32im-succinct-zkvm-elf index 3a9a8e199..65779210c 100755 Binary files a/examples/tendermint/program/elf/riscv32im-succinct-zkvm-elf and b/examples/tendermint/program/elf/riscv32im-succinct-zkvm-elf differ diff --git a/examples/tendermint/script/Cargo.lock b/examples/tendermint/script/Cargo.lock index ef2b0a292..ac88ff6cb 100644 --- a/examples/tendermint/script/Cargo.lock +++ b/examples/tendermint/script/Cargo.lock @@ -2222,7 +2222,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -2639,6 +2639,15 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "ntapi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" +dependencies = [ + "winapi", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -3366,6 +3375,12 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + [[package]] name = "portable-atomic" version = "1.6.0" @@ -4499,6 +4514,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "sphinx-build" +version = "0.1.0" +dependencies = [ + "anyhow", + "cargo_metadata", + "clap", +] + [[package]] name = "sphinx-core" version = "1.0.0" @@ -4541,6 +4565,7 @@ dependencies = [ "p3-symmetric", "p3-uni-stark", "p3-util", + "plain", "rand", "rayon-scan", "rrs-lib", @@ -4575,6 +4600,7 @@ version = "1.0.0" dependencies = [ "cargo_metadata", "chrono", + "sphinx-build", ] [[package]] @@ -4802,6 +4828,7 @@ dependencies = [ "sphinx-prover", "strum", "strum_macros", + "sysinfo", "tempfile", "thiserror", "tokio", @@ -4933,6 +4960,20 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +[[package]] +name = "sysinfo" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b92e0bdf838cbc1c4c9ba14f9c97a7ec6cdcd1ae66b10e1e42775a25553f45d" +dependencies = [ + "core-foundation-sys", + "libc", + "memchr", + "ntapi", + "rayon", + "windows", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -5733,6 +5774,16 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" +dependencies = [ + "windows-core 0.57.0", + "windows-targets 0.52.5", +] + [[package]] name = "windows-core" version = "0.52.0" @@ -5742,6 +5793,49 @@ dependencies = [ "windows-targets 0.52.5", ] +[[package]] +name = "windows-core" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-targets 0.52.5", +] + +[[package]] +name = "windows-implement" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "windows-interface" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] + +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets 0.52.5", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/examples/tendermint/script/src/main.rs b/examples/tendermint/script/src/main.rs index 3403db6d0..3f141bc8a 100644 --- a/examples/tendermint/script/src/main.rs +++ b/examples/tendermint/script/src/main.rs @@ -29,10 +29,10 @@ async fn get_light_blocks() -> (LightBlock, LightBlock) { let latest_commit = fetch_latest_commit(&client, &url).await.unwrap(); let block: u64 = latest_commit.result.signed_header.header.height.into(); println!("Latest block: {}", block); - let light_block_1 = fetch_light_block(2029100, peer_id, BASE_URL) + let light_block_1 = fetch_light_block(2279100, peer_id, BASE_URL) .await .expect("Failed to generate light block 1"); - let light_block_2 = fetch_light_block(2029130, peer_id, BASE_URL) + let light_block_2 = fetch_light_block(2279130, peer_id, BASE_URL) .await .expect("Failed to generate light block 2"); (light_block_1, light_block_2) @@ -63,7 +63,7 @@ fn main() { let client = ProverClient::new(); let (pk, vk) = client.setup(TENDERMINT_ELF); - let proof = client.prove(&pk, stdin).run().expect("proving failed"); + let proof = client.prove(&pk, stdin).compressed().run().expect("proving failed"); // Verify proof. client.verify(&proof, &vk).expect("verification failed"); diff --git a/helper/Cargo.toml b/helper/Cargo.toml index 81425dad8..03ed9faf7 100644 --- a/helper/Cargo.toml +++ b/helper/Cargo.toml @@ -8,3 +8,4 @@ license.workspace = true [dependencies] cargo_metadata = { workspace = true } chrono = { workspace = true, features = ["clock"] } +sphinx-build = { path = "../build/"} diff --git a/helper/src/lib.rs b/helper/src/lib.rs index 3dcc62dc6..9289cab78 100644 --- a/helper/src/lib.rs +++ b/helper/src/lib.rs @@ -1,52 +1,56 @@ -use std::{ - io::{BufRead, BufReader}, - process::{Command, Stdio}, - thread, -}; - +use cargo_metadata::Metadata; use chrono::Local; +pub use sphinx_build::BuildArgs; +use std::{path::Path, process::ExitStatus}; fn current_datetime() -> String { let now = Local::now(); now.format("%Y-%m-%d %H:%M:%S").to_string() } -pub fn build_program(path: &str) { - let program_dir = std::path::Path::new(path); - - // Tell cargo to rerun the script only if program/{src, Cargo.toml, Cargo.lock} changes +/// Re-run the cargo command if the Cargo.toml or Cargo.lock file changes. +fn cargo_rerun_if_changed(metadata: &Metadata, program_dir: &Path) { + // Tell cargo to rerun the script only if program/{src, bin, build.rs, Cargo.toml} changes // Ref: https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rerun-if-changed let dirs = vec![ program_dir.join("src"), + program_dir.join("bin"), + program_dir.join("build.rs"), program_dir.join("Cargo.toml"), - program_dir.join("Cargo.lock"), ]; for dir in dirs { - println!("cargo:rerun-if-changed={}", dir.display()); + if dir.exists() { + println!( + "cargo::rerun-if-changed={}", + dir.canonicalize().unwrap().display() + ); + } } - // Print a message so the user knows that their program was built. Cargo caches warnings emitted - // from build scripts, so we'll print the date/time when the program was built. - let metadata_file = program_dir.join("Cargo.toml"); - let mut metadata_cmd = cargo_metadata::MetadataCommand::new(); - let metadata = metadata_cmd.manifest_path(metadata_file).exec().unwrap(); - let root_package = metadata.root_package(); - let root_package_name = root_package.as_ref().map_or("Program", |p| p.name.as_str()); + // Re-run the build script if the workspace root's Cargo.lock changes. If the program is its own + // workspace, this will be the program's Cargo.lock. println!( - "cargo:warning={} built at {}", - root_package_name, - current_datetime() + "cargo:rerun-if-changed={}", + metadata.workspace_root.join("Cargo.lock").as_str() ); - let status = execute_build_cmd(&program_dir) - .unwrap_or_else(|_| panic!("Failed to build `{}`.", root_package_name)); - assert!(status.success(), "Failed to build `{}`.", root_package_name); + // Re-run if any local dependency changes. + for package in &metadata.packages { + for dependency in &package.dependencies { + if let Some(path) = &dependency.path { + println!("cargo:rerun-if-changed={}", path.as_str()); + } + } + } } -/// Executes the `cargo prove build` command in the program directory +/// Executes the `cargo prove build` command in the program directory. If there are any cargo prove +/// build arguments, they are added to the command. +#[allow(clippy::unnecessary_wraps)] fn execute_build_cmd( - program_dir: &impl AsRef, -) -> Result { + program_dir: &impl AsRef, + args: Option, +) -> Result { // Check if RUSTC_WORKSPACE_WRAPPER is set to clippy-driver (i.e. if `cargo clippy` is the current // compiler). If so, don't execute `cargo prove build` because it breaks rust-analyzer's `cargo clippy` feature. let is_clippy_driver = std::env::var("RUSTC_WORKSPACE_WRAPPER") @@ -54,32 +58,86 @@ fn execute_build_cmd( .unwrap_or(false); if is_clippy_driver { println!("cargo:warning=Skipping build due to clippy invocation."); - return Ok(std::process::ExitStatus::default()); + return Ok(ExitStatus::default()); } - let mut cmd = Command::new("cargo"); - cmd.current_dir(program_dir) - .args(["prove", "build"]) - .env("CARGO_MANIFEST_DIR", program_dir.as_ref()) - .env_remove("RUSTC") - .stdout(Stdio::piped()) - .stderr(Stdio::piped()); - let mut child = cmd.spawn()?; + // Build the program with the given arguments. + let path_output = if let Some(args) = args { + sphinx_build::build_program(&args, Some(program_dir.as_ref().to_path_buf())) + } else { + sphinx_build::build_program( + &BuildArgs::default(), + Some(program_dir.as_ref().to_path_buf()), + ) + }; + if let Err(err) = path_output { + panic!("Failed to build SP1 program: {}.", err); + } - let stdout = BufReader::new(child.stdout.take().unwrap()); - let stderr = BufReader::new(child.stderr.take().unwrap()); + Ok(ExitStatus::default()) +} - // Pipe stdout and stderr to the parent process with [sp1] prefix - let stdout_handle = thread::spawn(move || { - stdout.lines().for_each(|line| { - println!("[sp1] {}", line.unwrap()); - }); - }); - stderr.lines().for_each(|line| { - eprintln!("[sp1] {}", line.unwrap()); - }); +/// Builds the program if the program at the specified path, or one of its dependencies, changes. +/// +/// This function monitors the program and its dependencies for changes. If any changes are detected, +/// it triggers a rebuild of the program. +/// +/// # Arguments +/// +/// * `path` - A string slice that holds the path to the program directory. +/// +/// This function is useful for automatically rebuilding the program during development +/// when changes are made to the source code or its dependencies. +/// +/// Set the `SP1_SKIP_PROGRAM_BUILD` environment variable to `true` to skip building the program. +pub fn build_program(path: &str) { + build_program_internal(path, None) +} - stdout_handle.join().unwrap(); +/// Builds the program with the given arguments if the program at path, or one of its dependencies, +/// changes. +/// +/// # Arguments +/// +/// * `path` - A string slice that holds the path to the program directory. +/// * `args` - A [`BuildArgs`] struct that contains various build configuration options. +/// +/// Set the `SP1_SKIP_PROGRAM_BUILD` environment variable to `true` to skip building the program. +pub fn build_program_with_args(path: &str, args: BuildArgs) { + build_program_internal(path, Some(args)) +} - child.wait() +/// Internal helper function to build the program with or without arguments. +fn build_program_internal(path: &str, args: Option) { + // Get the root package name and metadata. + let program_dir = Path::new(path); + let metadata_file = program_dir.join("Cargo.toml"); + let mut metadata_cmd = cargo_metadata::MetadataCommand::new(); + let metadata = metadata_cmd.manifest_path(metadata_file).exec().unwrap(); + let root_package = metadata.root_package(); + let root_package_name = root_package.as_ref().map_or("Program", |p| p.name.as_str()); + + // Skip the program build if the SP1_SKIP_PROGRAM_BUILD environment variable is set to true. + let skip_program_build = std::env::var("SP1_SKIP_PROGRAM_BUILD") + .map(|v| v.eq_ignore_ascii_case("true")) + .unwrap_or(false); + if skip_program_build { + println!( + "cargo:warning=Build skipped for {} at {} due to SP1_SKIP_PROGRAM_BUILD flag", + root_package_name, + current_datetime() + ); + return; + } + + // Activate the build command if the dependencies change. + cargo_rerun_if_changed(&metadata, program_dir); + + let _ = execute_build_cmd(&program_dir, args); + + println!( + "cargo:warning={} built at {}", + root_package_name, + current_datetime() + ); } diff --git a/prover/scripts/e2e.rs b/prover/scripts/e2e.rs index 5d16d7e9c..896cbc1e5 100644 --- a/prover/scripts/e2e.rs +++ b/prover/scripts/e2e.rs @@ -33,7 +33,7 @@ pub fn main() { let elf = include_bytes!("../../tests/fibonacci/elf/riscv32im-succinct-zkvm-elf"); tracing::info!("initializing prover"); - let prover = SphinxProver::new(); + let prover: SphinxProver = SphinxProver::new(); let opts = SphinxProverOpts::default(); let context = SphinxContext::default(); diff --git a/prover/src/build.rs b/prover/src/build.rs index 920b01659..e1ef4699b 100644 --- a/prover/src/build.rs +++ b/prover/src/build.rs @@ -14,29 +14,8 @@ use sphinx_recursion_core::air::RecursionPublicValues; pub use sphinx_recursion_core::stark::utils::sphinx_dev_mode; use sphinx_recursion_gnark_ffi::PlonkBn254Prover; -use crate::install::install_plonk_bn254_artifacts; use crate::utils::{babybear_bytes_to_bn254, babybears_to_bn254, words_to_bytes}; -use crate::{OuterSC, SphinxProver, SPHINX_CIRCUIT_VERSION}; - -/// Tries to install the PLONK artifacts if they are not already installed. -pub fn try_install_plonk_bn254_artifacts(use_aws_cli: bool) -> PathBuf { - let build_dir = plonk_bn254_artifacts_dir(); - - if build_dir.exists() { - println!( - "[sp1] plonk bn254 artifacts already seem to exist at {}. if you want to re-download them, delete the directory", - build_dir.display() - ); - } else { - println!( - "[sp1] plonk bn254 artifacts for version {} do not exist at {}. downloading...", - SPHINX_CIRCUIT_VERSION, - build_dir.display() - ); - install_plonk_bn254_artifacts(&build_dir, use_aws_cli); - } - build_dir -} +use crate::{OuterSC, SphinxProver}; /// Tries to build the PLONK artifacts inside the development directory. pub fn try_build_plonk_bn254_artifacts_dev( @@ -49,16 +28,6 @@ pub fn try_build_plonk_bn254_artifacts_dev( build_dir } -/// Gets the directory where the PLONK artifacts are installed. -fn plonk_bn254_artifacts_dir() -> PathBuf { - home::home_dir() - .unwrap() - .join(".sp1") - .join("circuits") - .join("plonk_bn254") - .join(SPHINX_CIRCUIT_VERSION) -} - /// Gets the directory where the PLONK artifacts are installed in development mode. pub fn plonk_bn254_artifacts_dev_dir() -> PathBuf { home::home_dir() @@ -122,7 +91,7 @@ pub fn dummy_proof() -> (StarkVerifyingKey, ShardProof) { let elf = include_bytes!("../../examples/fibonacci/program/elf/riscv32im-succinct-zkvm-elf"); tracing::info!("initializing prover"); - let prover = SphinxProver::new(); + let prover: SphinxProver = SphinxProver::new(); let opts = SphinxProverOpts::default(); let context = SphinxContext::default(); diff --git a/prover/src/components.rs b/prover/src/components.rs new file mode 100644 index 000000000..d5e09e2d1 --- /dev/null +++ b/prover/src/components.rs @@ -0,0 +1,34 @@ +use sphinx_core::stark::{DefaultProver, MachineProver, RiscvAir, StarkGenericConfig}; + +use crate::{CompressAir, CoreSC, InnerSC, OuterSC, ReduceAir, WrapAir}; + +pub trait SphinxProverComponents: Send + Sync { + /// The prover for making SP1 core proofs. + type CoreProver: MachineProver::Val>> + + Send + + Sync; + + /// The prover for making SP1 recursive proofs. + type CompressProver: MachineProver::Val>> + + Send + + Sync; + + /// The prover for shrinking compressed proofs. + type ShrinkProver: MachineProver::Val>> + + Send + + Sync; + + /// The prover for wrapping compressed proofs into SNARK-friendly field elements. + type WrapProver: MachineProver::Val>> + + Send + + Sync; +} + +pub struct DefaultProverComponents; + +impl SphinxProverComponents for DefaultProverComponents { + type CoreProver = DefaultProver::Val>>; + type CompressProver = DefaultProver::Val>>; + type ShrinkProver = DefaultProver::Val>>; + type WrapProver = DefaultProver::Val>>; +} diff --git a/prover/src/lib.rs b/prover/src/lib.rs index d37110559..5d1c50678 100644 --- a/prover/src/lib.rs +++ b/prover/src/lib.rs @@ -6,9 +6,8 @@ //! 2. Compress shard proofs into a single shard proof. //! 3. Wrap the shard proof into a SNARK-friendly field. //! 4. Wrap the last shard proof, proven over the SNARK-friendly field, into a PLONK proof. - pub mod build; -pub mod install; +pub mod components; pub mod types; pub mod utils; pub mod verify; @@ -17,6 +16,7 @@ use std::borrow::Borrow; use std::path::Path; use std::sync::Arc; +use components::{DefaultProverComponents, SphinxProverComponents}; use p3_baby_bear::BabyBear; use p3_challenger::CanObserve; use p3_field::{AbstractField, PrimeField}; @@ -25,14 +25,13 @@ use rayon::prelude::*; use sphinx_core::air::{PublicValues, Word}; pub use sphinx_core::io::{SphinxPublicValues, SphinxStdin}; use sphinx_core::runtime::{ExecutionError, ExecutionReport, Runtime, SphinxContext}; +use sphinx_core::stark::MachineProver; use sphinx_core::stark::{Challenge, StarkProvingKey}; use sphinx_core::stark::{Challenger, MachineVerificationError}; use sphinx_core::utils::{SphinxCoreOpts, SphinxProverOpts, DIGEST_SIZE}; use sphinx_core::{ runtime::Program, - stark::{ - LocalProver, RiscvAir, ShardProof, StarkGenericConfig, StarkMachine, StarkVerifyingKey, Val, - }, + stark::{RiscvAir, ShardProof, StarkGenericConfig, StarkVerifyingKey, Val}, utils::{BabyBearPoseidon2, SphinxCoreProverError}, }; use sphinx_primitives::hash_deferred_proof; @@ -57,10 +56,7 @@ pub use sphinx_recursion_program::machine::{ SphinxRootMemoryLayout, }; use tracing::instrument; -pub use types::{ - SphinxCoreProof, SphinxCoreProofData, SphinxProvingKey, SphinxRecursionProverError, - SphinxReduceProof, SphinxVerifyingKey, -}; +pub use types::*; use utils::words_to_bytes; pub use sphinx_core::SPHINX_CIRCUIT_VERSION; @@ -83,7 +79,7 @@ pub type CompressAir = RecursionAir; pub type WrapAir = RecursionAir; /// A end-to-end prover implementation for the SP1 RISC-V zkVM. -pub struct SphinxProver { +pub struct SphinxProver { /// The program that can recursively verify a set of proofs into a single proof. pub recursion_program: RecursionProgram, @@ -130,59 +126,64 @@ pub struct SphinxProver { pub wrap_vk: StarkVerifyingKey, /// The machine used for proving the core step. - pub core_machine: StarkMachine::Val>>, + pub core_prover: C::CoreProver, /// The machine used for proving the recursive and reduction steps. - pub compress_machine: StarkMachine::Val>>, + pub compress_prover: C::CompressProver, /// The machine used for proving the shrink step. - pub shrink_machine: StarkMachine::Val>>, + pub shrink_prover: C::ShrinkProver, /// The machine used for proving the wrapping step. - pub wrap_machine: StarkMachine::Val>>, + pub wrap_prover: C::WrapProver, } -impl SphinxProver { +impl SphinxProver { /// Initializes a new [SP1Prover]. #[instrument(name = "initialize prover", level = "debug", skip_all)] pub fn new() -> Self { let core_machine = RiscvAir::machine(CoreSC::default()); + let core_prover = C::CoreProver::new(core_machine); // Get the recursive verifier and setup the proving and verifying keys. - let recursion_program = SphinxRecursiveVerifier::::build(&core_machine); + let recursion_program = + SphinxRecursiveVerifier::::build(core_prover.machine()); let compress_machine = ReduceAir::machine(InnerSC::default()); - let (rec_pk, rec_vk) = compress_machine.setup(&recursion_program); + let compress_prover = C::CompressProver::new(compress_machine); + let (rec_pk, rec_vk) = compress_prover.setup(&recursion_program); // Get the deferred program and keys. let deferred_program = - SphinxDeferredVerifier::::build(&compress_machine); - let (deferred_pk, deferred_vk) = compress_machine.setup(&deferred_program); + SphinxDeferredVerifier::::build(compress_prover.machine()); + let (deferred_pk, deferred_vk) = compress_prover.setup(&deferred_program); // Make the reduce program and keys. let compress_program = SphinxCompressVerifier::::build( - &compress_machine, + compress_prover.machine(), &rec_vk, &deferred_vk, ); - let (compress_pk, compress_vk) = compress_machine.setup(&compress_program); + let (compress_pk, compress_vk) = compress_prover.setup(&compress_program); // Get the compress program, machine, and keys. let shrink_program = SphinxRootVerifier::::build( - &compress_machine, + compress_prover.machine(), &compress_vk, RecursionProgramType::Shrink, ); let shrink_machine = CompressAir::wrap_machine_dyn(InnerSC::compressed()); - let (shrink_pk, shrink_vk) = shrink_machine.setup(&shrink_program); + let shrink_prover = C::ShrinkProver::new(shrink_machine); + let (shrink_pk, shrink_vk) = shrink_prover.setup(&shrink_program); // Get the wrap program, machine, and keys. let wrap_program = SphinxRootVerifier::::build( - &shrink_machine, + shrink_prover.machine(), &shrink_vk, RecursionProgramType::Wrap, ); let wrap_machine = WrapAir::wrap_machine(OuterSC::default()); - let (wrap_pk, wrap_vk) = wrap_machine.setup(&wrap_program); + let wrap_prover = C::WrapProver::new(wrap_machine); + let (wrap_pk, wrap_vk) = wrap_prover.setup(&wrap_program); Self { recursion_program, @@ -200,10 +201,10 @@ impl SphinxProver { wrap_program, wrap_pk, wrap_vk, - core_machine, - compress_machine, - shrink_machine, - wrap_machine, + core_prover, + compress_prover, + shrink_prover, + wrap_prover, } } @@ -211,7 +212,7 @@ impl SphinxProver { #[instrument(name = "setup", level = "debug", skip_all)] pub fn setup(&self, elf: &[u8]) -> (SphinxProvingKey, SphinxVerifyingKey) { let program = Program::from(elf); - let (pk, vk) = self.core_machine.setup(&program); + let (pk, vk) = self.core_prover.setup(&program); let vk = SphinxVerifyingKey { vk }; let pk = SphinxProvingKey { pk, @@ -255,20 +256,21 @@ impl SphinxProver { context .subproof_verifier .get_or_insert_with(|| Arc::new(self)); - let config = CoreSC::default(); let program = Program::from(&pk.elf); - let (proof, public_values_stream) = sphinx_core::utils::prove_with_context( - &program, - stdin, - config, - opts.core_opts, - context, - )?; + let (proof, public_values_stream, cycles) = + sphinx_core::utils::prove_with_context::<_, C::CoreProver>( + &self.core_prover, + &program, + stdin, + opts.core_opts, + context, + )?; let public_values = SphinxPublicValues::from(&public_values_stream); Ok(SphinxCoreProof { proof: SphinxCoreProofData(proof.shard_proofs), stdin: stdin.clone(), public_values, + cycles, }) } @@ -281,7 +283,7 @@ impl SphinxProver { is_complete: bool, ) -> Vec>> { let mut core_inputs = Vec::new(); - let mut reconstruct_challenger = self.core_machine.config().challenger(); + let mut reconstruct_challenger = self.core_prover.config().challenger(); vk.observe_into(&mut reconstruct_challenger); // Prepare the inputs for the recursion programs. @@ -290,18 +292,17 @@ impl SphinxProver { core_inputs.push(SphinxRecursionMemoryLayout { vk, - machine: &self.core_machine, - shard_proofs: proofs, + machine: self.core_prover.machine(), + shard_proofs: proofs.clone(), leaf_challenger, initial_reconstruct_challenger: reconstruct_challenger.clone(), is_complete, - total_core_shards: shard_proofs.len(), }); for proof in batch.iter() { reconstruct_challenger.observe(proof.commitment.main_commit); reconstruct_challenger - .observe_slice(&proof.public_values[0..self.core_machine.num_pv_elts()]); + .observe_slice(&proof.public_values[0..self.core_prover.num_pv_elts()]); } } @@ -328,7 +329,6 @@ impl SphinxProver { last_proof_pv: &PublicValues, BabyBear>, deferred_proofs: &[ShardProof], batch_size: usize, - total_core_shards: usize, ) -> Vec>> { // Prepare the inputs for the deferred proofs recursive verification. let mut deferred_digest = [Val::::zero(); DIGEST_SIZE]; @@ -339,18 +339,20 @@ impl SphinxProver { deferred_inputs.push(SphinxDeferredMemoryLayout { compress_vk: &self.compress_vk, - machine: &self.compress_machine, + machine: self.compress_prover.machine(), proofs, start_reconstruct_deferred_digest: deferred_digest.to_vec(), is_complete: false, sphinx_vk: vk, - sphinx_machine: &self.core_machine, + sphinx_machine: self.core_prover.machine(), end_pc: Val::::zero(), end_shard: last_proof_pv.shard + BabyBear::one(), + end_execution_shard: last_proof_pv.execution_shard, + init_addr_bits: last_proof_pv.last_init_addr_bits, + finalize_addr_bits: last_proof_pv.last_finalize_addr_bits, leaf_challenger: leaf_challenger.clone(), committed_value_digest: last_proof_pv.committed_value_digest.to_vec(), deferred_proofs_digest: last_proof_pv.deferred_proofs_digest.to_vec(), - total_core_shards, }); deferred_digest = Self::hash_deferred_proofs(deferred_digest, batch); @@ -379,14 +381,18 @@ impl SphinxProver { batch_size, is_complete, ); - let last_proof_pv = PublicValues::from_vec(&shard_proofs.last().unwrap().public_values); + let last_proof_pv = shard_proofs + .last() + .unwrap() + .public_values + .as_slice() + .borrow(); let deferred_inputs = self.get_recursion_deferred_inputs( &vk.vk, leaf_challenger, - &last_proof_pv, + last_proof_pv, deferred_proofs, batch_size, - shard_proofs.len(), ); (core_inputs, deferred_inputs) } @@ -404,13 +410,13 @@ impl SphinxProver { let batch_size = 2; let shard_proofs = &proof.proof.0; - let total_core_shards = shard_proofs.len(); + // Get the leaf challenger. - let mut leaf_challenger = self.core_machine.config().challenger(); + let mut leaf_challenger = self.core_prover.config().challenger(); vk.vk.observe_into(&mut leaf_challenger); for proof in shard_proofs.iter() { leaf_challenger.observe(proof.commitment.main_commit); - leaf_challenger.observe_slice(&proof.public_values[0..self.core_machine.num_pv_elts()]); + leaf_challenger.observe_slice(&proof.public_values[0..self.core_prover.num_pv_elts()]); } // Run the recursion and reduce programs. @@ -433,15 +439,10 @@ impl SphinxProver { let proofs = inputs .into_par_iter() .map(|input| { - let proof = self.compress_machine_proof( - input, - &self.recursion_program, - &self.rec_pk, - opts, - ); - (proof, ReduceProgramType::Core) + self.compress_machine_proof(input, &self.recursion_program, &self.rec_pk, opts) + .map(|p| (p, ReduceProgramType::Core)) }) - .collect::>(); + .collect::, _>>()?; reduce_proofs.extend(proofs); } @@ -450,15 +451,15 @@ impl SphinxProver { let proofs = inputs .into_par_iter() .map(|input| { - let proof = self.compress_machine_proof( + self.compress_machine_proof( input, &self.deferred_program, &self.deferred_pk, opts, - ); - (proof, ReduceProgramType::Deferred) + ) + .map(|p| (p, ReduceProgramType::Deferred)) }) - .collect::>(); + .collect::, _>>()?; reduce_proofs.extend(proofs); } @@ -472,7 +473,7 @@ impl SphinxProver { let batched_compress_inputs = compress_inputs.chunks(shard_batch_size).collect::>(); reduce_proofs = batched_compress_inputs - .into_iter() + .into_par_iter() .flat_map(|batches| { batches .par_iter() @@ -482,24 +483,23 @@ impl SphinxProver { let input = SphinxReduceMemoryLayout { compress_vk: &self.compress_vk, - recursive_machine: &self.compress_machine, + recursive_machine: self.compress_prover.machine(), shard_proofs, kinds, is_complete, - total_core_shards, }; - let proof = self.compress_machine_proof( + self.compress_machine_proof( input, &self.compress_program, &self.compress_pk, opts, - ); - (proof, ReduceProgramType::Reduce) + ) + .map(|p| (p, ReduceProgramType::Reduce)) }) .collect::>() }) - .collect::>(); + .collect::, _>>()?; if reduce_proofs.len() == 1 { break; @@ -513,36 +513,43 @@ impl SphinxProver { }) } + /// Generate a proof with the compress machine. pub fn compress_machine_proof( &self, input: impl Hintable, program: &RecursionProgram, pk: &StarkProvingKey, opts: SphinxProverOpts, - ) -> ShardProof { + ) -> Result, SphinxRecursionProverError> { let mut runtime = RecursionRuntime::, Challenge, _>::new( program, - self.compress_machine.config().perm.clone(), + self.compress_prover.config().perm.clone(), ); let mut witness_stream = Vec::new(); witness_stream.extend(input.write()); runtime.witness_stream = witness_stream.into(); - runtime.run(); + runtime + .run() + .map_err(|e| SphinxRecursionProverError::RuntimeError(e.to_string()))?; runtime.print_stats(); - let mut recursive_challenger = self.compress_machine.config().challenger(); - self.compress_machine - .prove::>( + let mut recursive_challenger = self.compress_prover.config().challenger(); + let proof = self + .compress_prover + .prove( pk, - runtime.record, + vec![runtime.record], &mut recursive_challenger, opts.recursion_opts, ) + .unwrap() .shard_proofs .pop() - .unwrap() + .unwrap(); + + Ok(proof) } /// Wrap a reduce proof into a STARK proven over a SNARK-friendly field. @@ -554,7 +561,7 @@ impl SphinxProver { ) -> Result, SphinxRecursionProverError> { // Make the compress proof. let input = SphinxRootMemoryLayout { - machine: &self.compress_machine, + machine: self.compress_prover.machine(), proof: reduced_proof.proof, is_reduce: true, }; @@ -562,25 +569,32 @@ impl SphinxProver { // Run the compress program. let mut runtime = RecursionRuntime::, Challenge, _>::new( &self.shrink_program, - self.shrink_machine.config().perm.clone(), + self.shrink_prover.config().perm.clone(), ); let mut witness_stream = Vec::new(); witness_stream.extend(input.write()); runtime.witness_stream = witness_stream.into(); - runtime.run(); + + runtime + .run() + .map_err(|e| SphinxRecursionProverError::RuntimeError(e.to_string()))?; + runtime.print_stats(); tracing::debug!("Compress program executed successfully"); // Prove the compress program. - let mut compress_challenger = self.shrink_machine.config().challenger(); - let mut compress_proof = self.shrink_machine.prove::>( - &self.shrink_pk, - runtime.record, - &mut compress_challenger, - opts.recursion_opts, - ); + let mut compress_challenger = self.shrink_prover.config().challenger(); + let mut compress_proof = self + .shrink_prover + .prove( + &self.shrink_pk, + vec![runtime.record], + &mut compress_challenger, + opts.recursion_opts, + ) + .unwrap(); Ok(SphinxReduceProof { proof: compress_proof.shard_proofs.pop().unwrap(), @@ -595,7 +609,7 @@ impl SphinxProver { opts: SphinxProverOpts, ) -> Result, SphinxRecursionProverError> { let input = SphinxRootMemoryLayout { - machine: &self.shrink_machine, + machine: self.shrink_prover.machine(), proof: compressed_proof.proof, is_reduce: false, }; @@ -603,32 +617,40 @@ impl SphinxProver { // Run the compress program. let mut runtime = RecursionRuntime::, Challenge, _>::new( &self.wrap_program, - self.shrink_machine.config().perm.clone(), + self.shrink_prover.config().perm.clone(), ); let mut witness_stream = Vec::new(); witness_stream.extend(input.write()); runtime.witness_stream = witness_stream.into(); - runtime.run(); + + runtime + .run() + .map_err(|e| SphinxRecursionProverError::RuntimeError(e.to_string()))?; + runtime.print_stats(); tracing::debug!("Wrap program executed successfully"); // Prove the wrap program. - let mut wrap_challenger = self.wrap_machine.config().challenger(); + let mut wrap_challenger = self.wrap_prover.config().challenger(); let time = std::time::Instant::now(); - let mut wrap_proof = self.wrap_machine.prove::>( - &self.wrap_pk, - runtime.record, - &mut wrap_challenger, - opts.recursion_opts, - ); + let mut wrap_proof = self + .wrap_prover + .prove( + &self.wrap_pk, + vec![runtime.record], + &mut wrap_challenger, + opts.recursion_opts, + ) + .unwrap(); let elapsed = time.elapsed(); tracing::debug!("Wrap proving time: {:?}", elapsed); - let mut wrap_challenger = self.wrap_machine.config().challenger(); - let result = self - .wrap_machine - .verify(&self.wrap_vk, &wrap_proof, &mut wrap_challenger); + let mut wrap_challenger = self.wrap_prover.config().challenger(); + let result = + self.wrap_prover + .machine() + .verify(&self.wrap_vk, &wrap_proof, &mut wrap_challenger); match result { Ok(_) => tracing::info!("Proof verified successfully"), Err(MachineVerificationError::NonZeroCumulativeSum) => { @@ -691,43 +713,40 @@ impl SphinxProver { } } -impl Default for SphinxProver { - fn default() -> Self { - Self::new() - } -} - #[cfg(test)] -mod tests { +pub mod tests { - use std::env; use std::fs::File; use std::io::{Read, Write}; use super::*; - use crate::build::try_install_plonk_bn254_artifacts; use anyhow::Result; use build::try_build_plonk_bn254_artifacts_dev; use p3_field::PrimeField32; - use serial_test::serial; use sphinx_core::io::SphinxStdin; + + #[cfg(test)] + use serial_test::serial; + #[cfg(test)] use sphinx_core::utils::setup_logger; - use types::HashableKey; - fn test_e2e_inner(build_artifacts: bool) -> Result<()> { - setup_logger(); - let elf = include_bytes!("../../tests/fibonacci/elf/riscv32im-succinct-zkvm-elf"); + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + pub enum Test { + Core, + Compress, + Shrink, + Wrap, + Plonk, + } + pub fn test_e2e_prover( + elf: &[u8], + opts: SphinxProverOpts, + test_kind: Test, + ) -> Result<()> { tracing::info!("initializing prover"); - let prover = SphinxProver::new(); - let opts = SphinxProverOpts { - core_opts: SphinxCoreOpts { - shard_size: 1 << 12, - ..Default::default() - }, - recursion_opts: SphinxCoreOpts::default(), - }; + let prover: SphinxProver = SphinxProver::::new(); let context = SphinxContext::default(); tracing::info!("setup elf"); @@ -741,18 +760,30 @@ mod tests { tracing::info!("verify core"); prover.verify(&core_proof.proof, &vk)?; + if test_kind == Test::Core { + return Ok(()); + } + tracing::info!("compress"); let compressed_proof = prover.compress(&vk, core_proof, vec![], opts)?; tracing::info!("verify compressed"); prover.verify_compressed(&compressed_proof, &vk)?; + if test_kind == Test::Compress { + return Ok(()); + } + tracing::info!("shrink"); let shrink_proof = prover.shrink(compressed_proof, opts)?; tracing::info!("verify shrink"); prover.verify_shrink(&shrink_proof, &vk)?; + if test_kind == Test::Shrink { + return Ok(()); + } + tracing::info!("wrap bn254"); let wrapped_bn254_proof = prover.wrap_bn254(shrink_proof, opts)?; let bytes = bincode::serialize(&wrapped_bn254_proof).unwrap(); @@ -771,6 +802,10 @@ mod tests { tracing::info!("verify wrap bn254"); prover.verify_wrap_bn254(&wrapped_bn254_proof, &vk).unwrap(); + if test_kind == Test::Wrap { + return Ok(()); + } + tracing::info!("checking vkey hash babybear"); let vk_digest_babybear = wrapped_bn254_proof.sphinx_vkey_digest_babybear(); assert_eq!(vk_digest_babybear, vk.hash_babybear()); @@ -780,11 +815,8 @@ mod tests { assert_eq!(vk_digest_bn254, vk.hash_bn254()); tracing::info!("generate plonk bn254 proof"); - let artifacts_dir = if build_artifacts { - try_build_plonk_bn254_artifacts_dev(&prover.wrap_vk, &wrapped_bn254_proof.proof) - } else { - try_install_plonk_bn254_artifacts(false) - }; + let artifacts_dir = + try_build_plonk_bn254_artifacts_dev(&prover.wrap_vk, &wrapped_bn254_proof.proof); let plonk_bn254_proof = prover.wrap_plonk_bn254(wrapped_bn254_proof, &artifacts_dir); println!("{:?}", plonk_bn254_proof); @@ -794,34 +826,7 @@ mod tests { Ok(()) } - /// Tests an end-to-end workflow of proving a program across the entire proof generation - /// pipeline. - /// - /// Add `FRI_QUERIES`=1 to your environment for faster execution. Should only take a few minutes - /// on a Mac M2. Note: This test always re-builds the plonk bn254 artifacts, so setting SP1_DEV is - /// not needed. - #[test] - #[serial] - fn test_e2e() -> Result<()> { - test_e2e_inner(true) - } - - /// Tests an end-to-end workflow of proving a program across the entire proof generation - /// pipeline. This test tries to install plonk artifacts, so it is useful to run in in order to check if - /// newly installed parameters work - #[test] - #[ignore] - fn test_e2e_check_parameters() -> Result<()> { - test_e2e_inner(false) - } - - /// Tests an end-to-end workflow of proving a program across the entire proof generation - /// pipeline in addition to verifying deferred proofs. - #[test] - #[serial] - fn test_e2e_with_deferred_proofs() -> Result<()> { - setup_logger(); - + pub fn test_e2e_with_deferred_proofs_prover() -> Result<()> { // Test program which proves the Keccak-256 hash of various inputs. let keccak_elf = include_bytes!("../../tests/keccak256/elf/riscv32im-succinct-zkvm-elf"); @@ -829,7 +834,7 @@ mod tests { let verify_elf = include_bytes!("../../tests/verify-proof/elf/riscv32im-succinct-zkvm-elf"); tracing::info!("initializing prover"); - let prover = SphinxProver::new(); + let prover: SphinxProver = SphinxProver::new(); let opts = SphinxProverOpts::default(); tracing::info!("setup keccak elf"); @@ -904,113 +909,27 @@ mod tests { Ok(()) } + /// Tests an end-to-end workflow of proving a program across the entire proof generation + /// pipeline. + /// + /// Add `FRI_QUERIES`=1 to your environment for faster execution. Should only take a few minutes + /// on a Mac M2. Note: This test always re-builds the plonk bn254 artifacts, so setting SP1_DEV is + /// not needed. #[test] - #[ignore] // ignore for recursion performance reasons - fn test_deferred_proving_with_bls12381_g2_precompiles() { - fn test_inner( - program_elf: &[u8], - deferred_proofs_num: usize, - program_inputs: Vec<&SphinxStdin>, - ) { - assert_eq!(deferred_proofs_num, program_inputs.len()); - - setup_logger(); - env::set_var("RECONSTRUCT_COMMITMENTS", "false"); - env::set_var("FRI_QUERIES", "1"); - - // verify program which verifies proofs of a vkey and a list of committed inputs - let verify_elf = - include_bytes!("../../tests/verify-proof/elf/riscv32im-succinct-zkvm-elf"); - - tracing::info!("initializing prover"); - let prover = SphinxProver::new(); - let opts = SphinxProverOpts::default(); - - tracing::info!("setup elf"); - let (program_pk, program_vk) = prover.setup(program_elf); - let (verify_pk, verify_vk) = prover.setup(verify_elf); - - // Generate deferred proofs - let mut public_values = vec![]; - let mut deferred_compress_proofs = vec![]; - program_inputs - .into_iter() - .enumerate() - .for_each(|(index, input)| { - tracing::info!("prove subproof {}", index); - let deferred_proof = prover - .prove_core(&program_pk, input, opts, Default::default()) - .unwrap(); - let pv = deferred_proof.public_values.to_vec(); - public_values.push(pv); - let deferred_compress = prover - .compress(&program_vk, deferred_proof, vec![], opts) - .unwrap(); - deferred_compress_proofs.push(deferred_compress.proof); - }); - - // Aggregate deferred proofs - let mut stdin = SphinxStdin::new(); - let vkey_digest = program_vk.hash_babybear(); - let vkey_digest: [u32; 8] = vkey_digest - .iter() - .map(|n| n.as_canonical_u32()) - .collect::>() - .try_into() - .unwrap(); - stdin.write(&vkey_digest); - stdin.write(&public_values); - for drp in deferred_compress_proofs.iter() { - stdin.write_proof(drp.clone(), program_vk.vk.clone()); - } - - // Generate aggregated proof - let verify_proof = prover - .prove_core(&verify_pk, &stdin, opts, Default::default()) - .unwrap(); - let verify_compress = prover - .compress( - &verify_vk, - verify_proof.clone(), - deferred_compress_proofs, - opts, - ) - .unwrap(); - - let compress_pv: &RecursionPublicValues<_> = - verify_compress.proof.public_values.as_slice().borrow(); - println!("deferred_hash: {:?}", compress_pv.deferred_proofs_digest); - println!("complete: {:?}", compress_pv.is_complete); - - tracing::info!("verify verify program"); - prover - .verify_compressed(&verify_compress, &verify_vk) - .unwrap(); - } - - // Programs that we will use to produce deferred proofs while testing - let bls12381_g2_add_elf = - include_bytes!("../../tests/bls12381-g2-add/elf/riscv32im-succinct-zkvm-elf"); - let bls12381_g2_double_elf = - include_bytes!("../../tests/bls12381-g2-double/elf/riscv32im-succinct-zkvm-elf"); + #[serial] + fn test_e2e() -> Result<()> { + let elf = include_bytes!("../../tests/fibonacci/elf/riscv32im-succinct-zkvm-elf"); + setup_logger(); + let opts = SphinxProverOpts::default(); + test_e2e_prover::(elf, opts, Test::Plonk) + } - test_inner( - bls12381_g2_add_elf, - 3, - vec![ - &SphinxStdin::new(), - &SphinxStdin::new(), - &SphinxStdin::new(), - ], - ); - test_inner( - bls12381_g2_double_elf, - 3, - vec![ - &SphinxStdin::new(), - &SphinxStdin::new(), - &SphinxStdin::new(), - ], - ); + /// Tests an end-to-end workflow of proving a program across the entire proof generation + /// pipeline in addition to verifying deferred proofs. + #[test] + #[serial] + fn test_e2e_with_deferred_proofs() -> Result<()> { + setup_logger(); + test_e2e_with_deferred_proofs_prover::() } } diff --git a/prover/src/types.rs b/prover/src/types.rs index 7f665aa74..15643890f 100644 --- a/prover/src/types.rs +++ b/prover/src/types.rs @@ -114,6 +114,7 @@ pub struct SphinxProofWithMetadata { pub proof: P, pub stdin: SphinxStdin, pub public_values: SphinxPublicValues, + pub cycles: u64, } impl SphinxProofWithMetadata

{ @@ -198,4 +199,7 @@ pub enum SphinxReduceProofWrapper { } #[derive(Error, Debug)] -pub enum SphinxRecursionProverError {} +pub enum SphinxRecursionProverError { + #[error("Runtime error: {0}")] + RuntimeError(String), +} diff --git a/prover/src/utils.rs b/prover/src/utils.rs index 6053386cf..0a6e53034 100644 --- a/prover/src/utils.rs +++ b/prover/src/utils.rs @@ -3,7 +3,6 @@ use std::{ io::Read, }; -use futures::Future; use p3_baby_bear::BabyBear; use p3_bn254_fr::Bn254Fr; use p3_field::AbstractField; @@ -14,7 +13,6 @@ use sphinx_core::{ runtime::{Program, Runtime}, utils::SphinxCoreOpts, }; -use tokio::{runtime, task::block_in_place}; use crate::SphinxCoreProofData; @@ -85,16 +83,3 @@ pub fn words_to_bytes_be(words: &[u32; 8]) -> [u8; 32] { } bytes } - -/// Utility method for blocking on an async function. If we're already in a tokio runtime, we'll -/// block in place. Otherwise, we'll create a new runtime. -pub fn block_on(fut: impl Future) -> T { - // Handle case if we're already in an tokio runtime. - if let Ok(handle) = runtime::Handle::try_current() { - block_in_place(|| handle.block_on(fut)) - } else { - // Otherwise create a new runtime. - let rt = runtime::Runtime::new().expect("Failed to create a new runtime"); - rt.block_on(fut) - } -} diff --git a/prover/src/verify.rs b/prover/src/verify.rs index 2953283df..de4bb17f3 100644 --- a/prover/src/verify.rs +++ b/prover/src/verify.rs @@ -4,7 +4,9 @@ use anyhow::Result; use num_bigint::BigUint; use p3_baby_bear::BabyBear; use p3_field::{AbstractField, PrimeField}; -use sphinx_core::air::MachineAir; +use sphinx_core::air::{Word, POSEIDON_NUM_WORDS, PV_DIGEST_NUM_WORDS, WORD_SIZE}; +use sphinx_core::cpu::MAX_CPU_LOG_DEGREE; +use sphinx_core::stark::MachineProver; use sphinx_core::{ air::PublicValues, io::SphinxPublicValues, @@ -16,6 +18,7 @@ use sphinx_recursion_core::{air::RecursionPublicValues, stark::config::BabyBearP use sphinx_recursion_gnark_ffi::{PlonkBn254Proof, PlonkBn254Prover}; use thiserror::Error; +use crate::components::SphinxProverComponents; use crate::{ types::HashableKey, CoreSC, OuterSC, SphinxCoreProofData, SphinxProver, SphinxReduceProof, SphinxVerifyingKey, @@ -33,7 +36,7 @@ pub enum PlonkVerificationError { InvalidPublicValues, } -impl SphinxProver { +impl SphinxProver { /// Verify a core proof by verifying the shards, verifying lookup bus, verifying that the /// shards are contiguous and complete. pub fn verify( @@ -41,104 +44,232 @@ impl SphinxProver { proof: &SphinxCoreProofData, vk: &SphinxVerifyingKey, ) -> Result<(), MachineVerificationError> { - let mut challenger = self.core_machine.config().challenger(); - let machine_proof = MachineProof { - shard_proofs: proof.0.clone(), - }; - self.core_machine - .verify(&vk.vk, &machine_proof, &mut challenger)?; - - let num_shards = proof.0.len(); + // First shard has a "CPU" constraint. + // + // Assert that the first shard has a "CPU". + let first_shard = proof.0.first().unwrap(); + if !first_shard.contains_cpu() { + return Err(MachineVerificationError::MissingCpuInFirstShard); + } - // Verify shard transitions. - for (i, shard_proof) in proof.0.iter().enumerate() { - let public_values = PublicValues::from_vec(&shard_proof.public_values); - // Verify shard transitions - if i == 0 { - // If it's the first shard, index should be 1. - if public_values.shard != BabyBear::one() { - return Err(MachineVerificationError::InvalidPublicValues( - "first shard not 1", - )); - } - if public_values.start_pc != vk.vk.pc_start { - return Err(MachineVerificationError::InvalidPublicValues( - "wrong pc_start", - )); - } - } else { - let prev_shard_proof = &proof.0[i - 1]; - let prev_public_values = PublicValues::from_vec(&prev_shard_proof.public_values); - // For non-first shards, the index should be the previous index + 1. - if public_values.shard != prev_public_values.shard + BabyBear::one() { - return Err(MachineVerificationError::InvalidPublicValues( - "non incremental shard index", - )); - } - // Start pc should be what the next pc declared in the previous shard was. - if public_values.start_pc != prev_public_values.next_pc { - return Err(MachineVerificationError::InvalidPublicValues("pc mismatch")); - } - // Digests and exit code should be the same in all shards. - if public_values.committed_value_digest != prev_public_values.committed_value_digest - || public_values.deferred_proofs_digest - != prev_public_values.deferred_proofs_digest - || public_values.exit_code != prev_public_values.exit_code - { - return Err(MachineVerificationError::InvalidPublicValues( - "digest or exit code mismatch", + // CPU log degree bound constraints. + // + // Assert that the CPU log degree does not exceed `MAX_CPU_LOG_DEGREE`. This is to ensure + // that the lookup argument's multiplicities do not overflow. + for shard_proof in proof.0.iter() { + if shard_proof.contains_cpu() { + let log_degree_cpu = shard_proof.log_degree_cpu(); + if log_degree_cpu > MAX_CPU_LOG_DEGREE { + return Err(MachineVerificationError::CpuLogDegreeTooLarge( + log_degree_cpu, )); } - // The last shard should be halted. Halt is signaled with next_pc == 0. - if i == proof.0.len() - 1 && public_values.next_pc != BabyBear::zero() { - return Err(MachineVerificationError::InvalidPublicValues( - "last shard isn't halted", - )); - } - // All non-last shards should not be halted. - if i != proof.0.len() - 1 && public_values.next_pc == BabyBear::zero() { + } + } + + // Shard constraints. + // + // Initialization: + // - Shard should start at one. + // + // Transition: + // - Shard should increment by one for each shard. + let mut current_shard = BabyBear::zero(); + for shard_proof in proof.0.iter() { + let public_values: &PublicValues, _> = + shard_proof.public_values.as_slice().borrow(); + current_shard += BabyBear::one(); + if public_values.shard != current_shard { + return Err(MachineVerificationError::InvalidPublicValues( + "shard index should be the previous shard index + 1 and start at 1", + )); + } + } + + // Execution shard constraints. + // + // Initialization: + // - Execution shard should start at one. + // + // Transition: + // - Execution shard should increment by one for each shard with "CPU". + // - Execution shard should stay the same for non-CPU shards. + // - For the other shards, execution shard does not matter. + let mut current_execution_shard = BabyBear::zero(); + for shard_proof in proof.0.iter() { + let public_values: &PublicValues, _> = + shard_proof.public_values.as_slice().borrow(); + if shard_proof.contains_cpu() { + current_execution_shard += BabyBear::one(); + if public_values.execution_shard != current_execution_shard { return Err(MachineVerificationError::InvalidPublicValues( - "non-last shard is halted", + "execution shard index should be the previous execution shard index + 1 if cpu exists and start at 1", )); } } } - // Verify that the number of shards is not too large. - if proof.0.len() > 1 << 16 { - return Err(MachineVerificationError::TooManyShards); + // Program counter constraints. + // + // Initialization: + // - `start_pc` should start as `vk.start_pc`. + // + // Transition: + // - `next_pc` of the previous shard should equal `start_pc`. + // - If it's not a shard with "CPU", then `start_pc` equals `next_pc`. + // - If it's a shard with "CPU", then `start_pc` should never equal zero. + // + // Finalization: + // - `next_pc` should equal zero. + let mut prev_next_pc = BabyBear::zero(); + for (i, shard_proof) in proof.0.iter().enumerate() { + let public_values: &PublicValues, _> = + shard_proof.public_values.as_slice().borrow(); + if i == 0 && public_values.start_pc != vk.vk.pc_start { + return Err(MachineVerificationError::InvalidPublicValues( + "start_pc != vk.start_pc: program counter should start at vk.start_pc", + )); + } else if i != 0 && public_values.start_pc != prev_next_pc { + return Err(MachineVerificationError::InvalidPublicValues( + "start_pc != next_pc_prev: start_pc should equal next_pc_prev for all shards", + )); + } else if !shard_proof.contains_cpu() && public_values.start_pc != public_values.next_pc + { + return Err(MachineVerificationError::InvalidPublicValues( + "start_pc != next_pc: start_pc should equal next_pc for non-cpu shards", + )); + } else if shard_proof.contains_cpu() && public_values.start_pc == BabyBear::zero() { + return Err(MachineVerificationError::InvalidPublicValues( + "start_pc == 0: execution should never start at halted state", + )); + } else if i == proof.0.len() - 1 && public_values.next_pc != BabyBear::zero() { + return Err(MachineVerificationError::InvalidPublicValues( + "next_pc != 0: execution should have halted", + )); + } + prev_next_pc = public_values.next_pc; } - // Verify that the `MemoryInit` and `MemoryFinalize` chips are the last chips in the proof. - for (i, shard_proof) in proof.0.iter().enumerate() { - let chips = self - .core_machine - .shard_chips_ordered(&shard_proof.chip_ordering) - .collect::>(); - let memory_init_count = chips - .clone() - .into_iter() - .filter(|chip| chip.as_ref().name() == "MemoryInit") - .count(); - let memory_final_count = chips - .into_iter() - .filter(|chip| chip.as_ref().name() == "MemoryFinalize") - .count(); - - // Assert that the `MemoryInit` and `MemoryFinalize` chips only exist in the last shard. - if i != num_shards - 1 && (memory_final_count > 0 || memory_init_count > 0) { - return Err(MachineVerificationError::InvalidChipOccurence( - "memory init and finalize should not exist anywhere but the last chip" - .to_string(), + // Exit code constraints. + // + // - In every shard, the exit code should be zero. + for shard_proof in proof.0.iter() { + let public_values: &PublicValues, _> = + shard_proof.public_values.as_slice().borrow(); + if public_values.exit_code != BabyBear::zero() { + return Err(MachineVerificationError::InvalidPublicValues( + "exit_code != 0: exit code should be zero for all shards", )); } - if i == num_shards - 1 && (memory_init_count != 1 || memory_final_count != 1) { - return Err(MachineVerificationError::InvalidChipOccurence( - "memory init and finalize should exist in the last chip".to_string(), + } + + // Memory initialization & finalization constraints. + // + // Initialization: + // - `previous_init_addr_bits` should be zero. + // - `previous_finalize_addr_bits` should be zero. + // + // Transition: + // - For all shards, `previous_init_addr_bits` should equal `last_init_addr_bits` of the previous shard. + // - For all shards, `previous_finalize_addr_bits` should equal `last_finalize_addr_bits` of the previous shard. + // - For shards without "MemoryInit", `previous_init_addr_bits` should equal `last_init_addr_bits`. + // - For shards without "MemoryFinalize", `previous_finalize_addr_bits` should equal `last_finalize_addr_bits`. + let mut last_init_addr_bits_prev = [BabyBear::zero(); 32]; + let mut last_finalize_addr_bits_prev = [BabyBear::zero(); 32]; + for shard_proof in proof.0.iter() { + let public_values: &PublicValues, _> = + shard_proof.public_values.as_slice().borrow(); + if public_values.previous_init_addr_bits != last_init_addr_bits_prev { + return Err(MachineVerificationError::InvalidPublicValues( + "previous_init_addr_bits != last_init_addr_bits_prev", + )); + } else if public_values.previous_finalize_addr_bits != last_finalize_addr_bits_prev { + return Err(MachineVerificationError::InvalidPublicValues( + "last_init_addr_bits != last_finalize_addr_bits_prev", + )); + } else if !shard_proof.contains_memory_init() + && public_values.previous_init_addr_bits != public_values.last_init_addr_bits + { + return Err(MachineVerificationError::InvalidPublicValues( + "previous_init_addr_bits != last_init_addr_bits", + )); + } else if !shard_proof.contains_memory_finalize() + && public_values.previous_finalize_addr_bits + != public_values.last_finalize_addr_bits + { + return Err(MachineVerificationError::InvalidPublicValues( + "previous_finalize_addr_bits != last_finalize_addr_bits", + )); + } + last_init_addr_bits_prev = public_values.last_init_addr_bits; + last_finalize_addr_bits_prev = public_values.last_finalize_addr_bits; + } + + // Digest constraints. + // + // Initialization: + // - `committed_value_digest` should be zero. + // - `deferred_proofs_digest` should be zero. + // + // Transition: + // - If `commited_value_digest_prev` is not zero, then `committed_value_digest` should equal + // `commited_value_digest_prev`. Otherwise, `committed_value_digest` should equal zero. + // - If `deferred_proofs_digest_prev` is not zero, then `deferred_proofs_digest` should equal + // `deferred_proofs_digest_prev`. Otherwise, `deferred_proofs_digest` should equal zero. + // - If it's not a shard with "CPU", then `commited_value_digest` should not change from the + // previous shard. + // - If it's not a shard with "CPU", then `deferred_proofs_digest` should not change from the + // previous shard. + let zero_commited_value_digest = [Word([BabyBear::zero(); WORD_SIZE]); PV_DIGEST_NUM_WORDS]; + let zero_deferred_proofs_digest = [BabyBear::zero(); POSEIDON_NUM_WORDS]; + let mut commited_value_digest_prev = zero_commited_value_digest; + let mut deferred_proofs_digest_prev = zero_deferred_proofs_digest; + for shard_proof in proof.0.iter() { + let public_values: &PublicValues, _> = + shard_proof.public_values.as_slice().borrow(); + if commited_value_digest_prev != zero_commited_value_digest + && public_values.committed_value_digest != commited_value_digest_prev + { + return Err(MachineVerificationError::InvalidPublicValues( + "committed_value_digest != commited_value_digest_prev", + )); + } else if deferred_proofs_digest_prev != zero_deferred_proofs_digest + && public_values.deferred_proofs_digest != deferred_proofs_digest_prev + { + return Err(MachineVerificationError::InvalidPublicValues( + "deferred_proofs_digest != deferred_proofs_digest_prev", + )); + } else if !shard_proof.contains_cpu() + && public_values.committed_value_digest != commited_value_digest_prev + { + return Err(MachineVerificationError::InvalidPublicValues( + "committed_value_digest != commited_value_digest_prev", + )); + } else if !shard_proof.contains_cpu() + && public_values.deferred_proofs_digest != deferred_proofs_digest_prev + { + return Err(MachineVerificationError::InvalidPublicValues( + "deferred_proofs_digest != deferred_proofs_digest_prev", )); } + commited_value_digest_prev = public_values.committed_value_digest; + deferred_proofs_digest_prev = public_values.deferred_proofs_digest; } + // Verify that the number of shards is not too large. + if proof.0.len() > 1 << 16 { + return Err(MachineVerificationError::TooManyShards); + } + + // Verify the shard proof. + let mut challenger = self.core_prover.config().challenger(); + let machine_proof = MachineProof { + shard_proofs: proof.0.clone(), + }; + self.core_prover + .machine() + .verify(&vk.vk, &machine_proof, &mut challenger)?; + Ok(()) } @@ -148,12 +279,15 @@ impl SphinxProver { proof: &SphinxReduceProof, vk: &SphinxVerifyingKey, ) -> Result<(), MachineVerificationError> { - let mut challenger = self.compress_machine.config().challenger(); + let mut challenger = self.compress_prover.config().challenger(); let machine_proof = MachineProof { shard_proofs: vec![proof.proof.clone()], }; - self.compress_machine - .verify(&self.compress_vk, &machine_proof, &mut challenger)?; + self.compress_prover.machine().verify( + &self.compress_vk, + &machine_proof, + &mut challenger, + )?; // Validate public values let public_values: &RecursionPublicValues<_> = @@ -191,11 +325,12 @@ impl SphinxProver { proof: &SphinxReduceProof, vk: &SphinxVerifyingKey, ) -> Result<(), MachineVerificationError> { - let mut challenger = self.shrink_machine.config().challenger(); + let mut challenger = self.shrink_prover.config().challenger(); let machine_proof = MachineProof { shard_proofs: vec![proof.proof.clone()], }; - self.shrink_machine + self.shrink_prover + .machine() .verify(&self.shrink_vk, &machine_proof, &mut challenger)?; // Validate public values @@ -226,11 +361,12 @@ impl SphinxProver { proof: &SphinxReduceProof, vk: &SphinxVerifyingKey, ) -> Result<(), MachineVerificationError> { - let mut challenger = self.wrap_machine.config().challenger(); + let mut challenger = self.wrap_prover.config().challenger(); let machine_proof = MachineProof { shard_proofs: vec![proof.proof.clone()], }; - self.wrap_machine + self.wrap_prover + .machine() .verify(&self.wrap_vk, &machine_proof, &mut challenger)?; // Validate public values @@ -299,7 +435,7 @@ pub fn verify_plonk_bn254_public_inputs( Ok(()) } -impl SubproofVerifier for &SphinxProver { +impl SubproofVerifier for &SphinxProver { fn verify_deferred_proof( &self, proof: &sphinx_core::stark::ShardProof, diff --git a/recursion/circuit/src/constraints.rs b/recursion/circuit/src/constraints.rs index cfb57f3f6..31559657b 100644 --- a/recursion/circuit/src/constraints.rs +++ b/recursion/circuit/src/constraints.rs @@ -171,8 +171,8 @@ mod tests { use serde::{de::DeserializeOwned, Serialize}; use sphinx_core::{ stark::{ - Chip, Com, Dom, LocalProver, OpeningProof, PcsProverData, ShardCommitment, - ShardMainData, ShardProof, StarkGenericConfig, StarkMachine, + Chip, Com, DefaultProver, Dom, MachineProver, OpeningProof, PcsProverData, + ShardCommitment, ShardMainData, ShardProof, StarkGenericConfig, StarkMachine, }, utils::SphinxCoreOpts, }; @@ -293,22 +293,25 @@ mod tests { let program = basic_program::(); let config = SC::new(); let mut runtime = Runtime::::new_no_perm(&program); - runtime.run(); + runtime.run().unwrap(); let machine = A::machine(config); - let (pk, vk) = machine.setup(&program); - let mut challenger = machine.config().challenger(); - let proof = machine.prove::>( - &pk, - runtime.record, - &mut challenger, - SphinxCoreOpts::recursion(), - ); - - let mut challenger = machine.config().challenger(); + let prover = DefaultProver::new(machine); + let (pk, vk) = prover.setup(&program); + let mut challenger = prover.config().challenger(); + let proof = prover + .prove( + &pk, + vec![runtime.record], + &mut challenger, + SphinxCoreOpts::recursion(), + ) + .unwrap(); + + let mut challenger = prover.config().challenger(); vk.observe_into(&mut challenger); proof.shard_proofs.iter().for_each(|proof| { challenger.observe(proof.commitment.main_commit); - challenger.observe_slice(&proof.public_values[0..machine.num_pv_elts()]); + challenger.observe_slice(&proof.public_values[0..prover.num_pv_elts()]); }); // Run the verify inside the DSL and compare it to the calculated value. @@ -322,7 +325,7 @@ mod tests { permutation_challenges, alpha_val, zeta_val, - ) = get_shard_data(&machine, &proof, &mut challenger); + ) = get_shard_data(prover.machine(), &proof, &mut challenger); for (chip, trace_domain_val, qc_domains_vals, values_vals) in izip!( chips.iter(), diff --git a/recursion/compiler/examples/fibonacci.rs b/recursion/compiler/examples/fibonacci.rs index e2514d0b5..6b2804003 100644 --- a/recursion/compiler/examples/fibonacci.rs +++ b/recursion/compiler/examples/fibonacci.rs @@ -53,7 +53,7 @@ fn main() { let config = SC::new(); let mut runtime = Runtime::::new(&program, config.perm.clone()); - runtime.run(); + runtime.run().unwrap(); // let machine = RecursionAir::machine(config); // let (pk, vk) = machine.setup(&program); diff --git a/recursion/compiler/src/asm/compiler.rs b/recursion/compiler/src/asm/compiler.rs index a72ed5c47..cfc58232a 100644 --- a/recursion/compiler/src/asm/compiler.rs +++ b/recursion/compiler/src/asm/compiler.rs @@ -514,12 +514,12 @@ impl + TwoAdicField> AsmCo _ => unimplemented!(), } } - DslIr::Poseidon2AbsorbBabyBear(p2_hash_num, input) => match input { + DslIr::Poseidon2AbsorbBabyBear(p2_hash_and_absorb_num, input) => match input { Array::Dyn(input, input_size) => { if let Usize::Var(input_size) = input_size { self.push( AsmInstruction::Poseidon2Absorb( - p2_hash_num.fp(), + p2_hash_and_absorb_num.fp(), input.fp(), input_size.fp(), ), diff --git a/recursion/compiler/src/asm/instruction.rs b/recursion/compiler/src/asm/instruction.rs index 5f39a4386..91b99f5cc 100644 --- a/recursion/compiler/src/asm/instruction.rs +++ b/recursion/compiler/src/asm/instruction.rs @@ -843,17 +843,19 @@ impl> AsmInstruction { false, "".to_string(), ), - AsmInstruction::Poseidon2Absorb(hash_num, input_ptr, input_len) => Instruction::new( - Opcode::Poseidon2Absorb, - i32_f(hash_num), - i32_f_arr(input_ptr), - i32_f_arr(input_len), - F::zero(), - F::zero(), - false, - false, - "".to_string(), - ), + AsmInstruction::Poseidon2Absorb(hash_and_absorb_num, input_ptr, input_len) => { + Instruction::new( + Opcode::Poseidon2Absorb, + i32_f(hash_and_absorb_num), + i32_f_arr(input_ptr), + i32_f_arr(input_len), + F::zero(), + F::zero(), + false, + false, + "".to_string(), + ) + } AsmInstruction::Poseidon2Finalize(hash_num, output_ptr) => Instruction::new( Opcode::Poseidon2Finalize, i32_f(hash_num), @@ -1163,15 +1165,15 @@ impl> AsmInstruction { result, src1, src2 ) } - AsmInstruction::Poseidon2Absorb(hash_num, input_ptr, input_len) => { + AsmInstruction::Poseidon2Absorb(hash_and_absorb_num, input_ptr, input_len) => { write!( f, "poseidon2_absorb ({})fp, {})fp, ({})fp", - hash_num, input_ptr, input_len, + hash_and_absorb_num, input_ptr, input_len, ) } AsmInstruction::Poseidon2Finalize(hash_num, output_ptr) => { - write!(f, "poseidon2_finalize ({})fp, {})fp", hash_num, output_ptr,) + write!(f, "poseidon2_finalize ({})fp, ({})fp", hash_num, output_ptr,) } AsmInstruction::Commit(val, index) => { write!(f, "commit ({})fp ({})fp", val, index) diff --git a/recursion/compiler/src/ir/poseidon.rs b/recursion/compiler/src/ir/poseidon.rs index b0e861717..30b201188 100644 --- a/recursion/compiler/src/ir/poseidon.rs +++ b/recursion/compiler/src/ir/poseidon.rs @@ -35,9 +35,15 @@ impl Builder { /// Applies the Poseidon2 absorb function to the given array. /// /// Reference: [p3_symmetric::PaddingFreeSponge] - pub fn poseidon2_absorb(&mut self, p2_hash_num: Var, input: &Array>) { - self.operations - .push(DslIr::Poseidon2AbsorbBabyBear(p2_hash_num, input.clone())); + pub fn poseidon2_absorb( + &mut self, + p2_hash_and_absorb_num: Var, + input: &Array>, + ) { + self.operations.push(DslIr::Poseidon2AbsorbBabyBear( + p2_hash_and_absorb_num, + input.clone(), + )); } /// Applies the Poseidon2 finalize to the given hash number. @@ -128,9 +134,13 @@ impl Builder { self.cycle_tracker("poseidon2-hash"); let p2_hash_num = self.p2_hash_num; + let two_power_12: Var<_> = self.eval(C::N::from_canonical_u32(1 << 12)); + self.range(0, array.len()).for_each(|i, builder| { let subarray = builder.get(array, i); - builder.poseidon2_absorb(p2_hash_num, &subarray); + let p2_hash_and_absorb_num: Var<_> = builder.eval(p2_hash_num * two_power_12 + i); + + builder.poseidon2_absorb(p2_hash_and_absorb_num, &subarray); }); let output: Array> = self.dyn_array(DIGEST_SIZE); diff --git a/recursion/compiler/src/ir/utils.rs b/recursion/compiler/src/ir/utils.rs index 46a8beaef..25a5e6f10 100644 --- a/recursion/compiler/src/ir/utils.rs +++ b/recursion/compiler/src/ir/utils.rs @@ -328,7 +328,7 @@ mod tests { let program = builder.compile_program(); let mut runtime = Runtime::::new(&program, config.perm.clone()); - runtime.run(); + runtime.run().unwrap(); } #[test] @@ -365,6 +365,6 @@ mod tests { let program = builder.compile_program(); let mut runtime = Runtime::::new(&program, config.perm.clone()); - runtime.run(); + runtime.run().unwrap(); } } diff --git a/recursion/compiler/tests/arithmetic.rs b/recursion/compiler/tests/arithmetic.rs index 7398646bb..922f873cd 100644 --- a/recursion/compiler/tests/arithmetic.rs +++ b/recursion/compiler/tests/arithmetic.rs @@ -78,6 +78,6 @@ fn test_compiler_arithmetic() { let config = SC::default(); let mut runtime = Runtime::::new(&program, config.perm.clone()); - runtime.run(); + runtime.run().unwrap(); runtime.print_stats(); } diff --git a/recursion/compiler/tests/array.rs b/recursion/compiler/tests/array.rs index 7908c1a38..691400e49 100644 --- a/recursion/compiler/tests/array.rs +++ b/recursion/compiler/tests/array.rs @@ -114,5 +114,5 @@ fn test_compiler_array() { let config = SC::default(); let mut runtime = Runtime::::new(&program, config.perm.clone()); - runtime.run(); + runtime.run().unwrap(); } diff --git a/recursion/compiler/tests/conditionals.rs b/recursion/compiler/tests/conditionals.rs index f7c9b9179..6ccc3cc3f 100644 --- a/recursion/compiler/tests/conditionals.rs +++ b/recursion/compiler/tests/conditionals.rs @@ -55,7 +55,7 @@ fn test_compiler_conditionals() { let config = SC::default(); let mut runtime = Runtime::::new(&program, config.perm.clone()); - runtime.run(); + runtime.run().unwrap(); } #[test] @@ -91,5 +91,5 @@ fn test_compiler_conditionals_v2() { let config = SC::default(); let mut runtime = Runtime::::new(&program, config.perm.clone()); - runtime.run(); + runtime.run().unwrap(); } diff --git a/recursion/compiler/tests/for_loops.rs b/recursion/compiler/tests/for_loops.rs index c59b431c3..62579069b 100644 --- a/recursion/compiler/tests/for_loops.rs +++ b/recursion/compiler/tests/for_loops.rs @@ -46,7 +46,7 @@ fn test_compiler_for_loops() { let config = SC::default(); let mut runtime = Runtime::::new(&program, config.perm.clone()); - runtime.run(); + runtime.run().unwrap(); } #[test] @@ -84,7 +84,7 @@ fn test_compiler_nested_array_loop() { let config = SC::default(); let mut runtime = Runtime::::new(&program, config.perm.clone()); - runtime.run(); + runtime.run().unwrap(); } #[test] @@ -168,7 +168,7 @@ fn test_compiler_break() { let config = SC::default(); let mut runtime = Runtime::::new(&program, config.perm.clone()); - runtime.run(); + runtime.run().unwrap(); } #[test] @@ -195,7 +195,7 @@ fn test_compiler_step_by() { let config = SC::default(); let mut runtime = Runtime::::new(&program, config.perm.clone()); - runtime.run(); + runtime.run().unwrap(); } #[test] @@ -223,5 +223,5 @@ fn test_compiler_bneinc() { let config = SC::default(); let mut runtime = Runtime::::new(&program, config.perm.clone()); - runtime.run(); + runtime.run().unwrap(); } diff --git a/recursion/compiler/tests/io.rs b/recursion/compiler/tests/io.rs index 2cfe70bc8..c5687d6f6 100644 --- a/recursion/compiler/tests/io.rs +++ b/recursion/compiler/tests/io.rs @@ -38,5 +38,5 @@ fn test_io() { vec![F::one().into(), F::one().into(), F::two().into()], ] .into(); - runtime.run(); + runtime.run().unwrap(); } diff --git a/recursion/compiler/tests/lt.rs b/recursion/compiler/tests/lt.rs index f930c4894..cc0190e74 100644 --- a/recursion/compiler/tests/lt.rs +++ b/recursion/compiler/tests/lt.rs @@ -24,5 +24,5 @@ fn test_compiler_less_than() { let config = SC::default(); let mut runtime = Runtime::::new(&program, config.perm.clone()); - runtime.run(); + runtime.run().unwrap(); } diff --git a/recursion/compiler/tests/poseidon2.rs b/recursion/compiler/tests/poseidon2.rs index 8c6e1938a..5ce76473e 100644 --- a/recursion/compiler/tests/poseidon2.rs +++ b/recursion/compiler/tests/poseidon2.rs @@ -55,7 +55,7 @@ fn test_compiler_poseidon2_permute() { let program = builder.compile_program(); let mut runtime = Runtime::::new(&program, config.perm.clone()); - runtime.run(); + runtime.run().unwrap(); println!( "The program executed successfully, number of cycles: {}", runtime.clk.as_canonical_u32() / 4 @@ -114,7 +114,7 @@ fn test_compiler_poseidon2_hash() { let program = builder.compile_program(); let mut runtime = Runtime::::new(&program, config.perm.clone()); - runtime.run(); + runtime.run().unwrap(); println!( "The program executed successfully, number of cycles: {}", runtime.clk.as_canonical_u32() / 4 @@ -150,7 +150,7 @@ fn test_compiler_poseidon2_hash_v2() { let program = builder.compile_program(); let mut runtime = Runtime::::new(&program, config.perm.clone()); - runtime.run(); + runtime.run().unwrap(); println!( "The program executed successfully, number of cycles: {}", runtime.clk.as_canonical_u32() / 4 diff --git a/recursion/compiler/tests/public_values.rs b/recursion/compiler/tests/public_values.rs index 367c2f39a..7fd06c321 100644 --- a/recursion/compiler/tests/public_values.rs +++ b/recursion/compiler/tests/public_values.rs @@ -25,5 +25,5 @@ fn test_compiler_public_values() { let config = SC::default(); let mut runtime = Runtime::::new(&program, config.perm.clone()); - runtime.run(); + runtime.run().unwrap(); } diff --git a/recursion/core/src/air/multi_builder.rs b/recursion/core/src/air/multi_builder.rs index 1562d3c4a..071be671d 100644 --- a/recursion/core/src/air/multi_builder.rs +++ b/recursion/core/src/air/multi_builder.rs @@ -8,14 +8,28 @@ use sphinx_core::air::MessageBuilder; /// the sub tables in the multi table. pub struct MultiBuilder<'a, AB: AirBuilder> { inner: FilteredAirBuilder<'a, AB>, + + /// These fields are used to determine whether a row is is the first or last row of the subtable, + /// which requires hinting from the parent table. + is_first_row: AB::Expr, + is_last_row: AB::Expr, + next_condition: AB::Expr, } impl<'a, AB: AirBuilder> MultiBuilder<'a, AB> { - pub fn new(builder: &'a mut AB, local_condition: &AB::Expr, next_condition: AB::Expr) -> Self { + pub fn new( + builder: &'a mut AB, + local_condition: &AB::Expr, + is_first_row: AB::Expr, + is_last_row: AB::Expr, + next_condition: AB::Expr, + ) -> Self { let inner = builder.when(local_condition.clone()); Self { inner, + is_first_row, + is_last_row, next_condition, } } @@ -32,11 +46,11 @@ impl<'a, AB: AirBuilder> AirBuilder for MultiBuilder<'a, AB> { } fn is_first_row(&self) -> Self::Expr { - self.inner.is_first_row() + self.is_first_row.clone() } fn is_last_row(&self) -> Self::Expr { - self.inner.is_last_row() + self.is_last_row.clone() } fn is_transition_window(&self, size: usize) -> Self::Expr { diff --git a/recursion/core/src/air/public_values.rs b/recursion/core/src/air/public_values.rs index a14d1550f..571939ffe 100644 --- a/recursion/core/src/air/public_values.rs +++ b/recursion/core/src/air/public_values.rs @@ -81,9 +81,27 @@ pub struct RecursionPublicValues { /// First shard being proven. pub start_shard: T, - /// Next shard that should be proven, if there are more. + /// Next shard that should be proven. pub next_shard: T, + /// First execution shard being proven. + pub start_execution_shard: T, + + /// Next execution shard that should be proven. + pub next_execution_shard: T, + + /// Previous MemoryInit address bits. + pub previous_init_addr_bits: [T; 32], + + /// Last MemoryInit address bits. + pub last_init_addr_bits: [T; 32], + + /// Previous MemoryFinalize address bits. + pub previous_finalize_addr_bits: [T; 32], + + /// Last MemoryFinalize address bits. + pub last_finalize_addr_bits: [T; 32], + /// Start state of reconstruct_challenger. pub start_reconstruct_challenger: ChallengerPublicValues, @@ -111,9 +129,6 @@ pub struct RecursionPublicValues { /// Whether the proof completely proves the program execution. pub is_complete: T, - /// Total number of core shards in the program execution. - pub total_core_shards: T, - /// The digest of all the previous public values elements. pub digest: [T; DIGEST_SIZE], diff --git a/recursion/core/src/cpu/columns/mod.rs b/recursion/core/src/cpu/columns/mod.rs index 9a2a5e244..3914ef74b 100644 --- a/recursion/core/src/cpu/columns/mod.rs +++ b/recursion/core/src/cpu/columns/mod.rs @@ -1,8 +1,7 @@ -use std::mem::{size_of, transmute}; +use std::mem::size_of; use crate::memory::{MemoryReadCols, MemoryReadWriteCols}; use p3_air::BaseAir; -use sphinx_core::utils::indices_arr; use sphinx_derive::AlignedBorrow; mod branch; @@ -23,13 +22,6 @@ use super::CpuChip; pub const NUM_CPU_COLS: usize = size_of::>(); -const fn make_col_map() -> CpuCols { - let indices_arr = indices_arr::(); - unsafe { transmute::<[usize; NUM_CPU_COLS], CpuCols>(indices_arr) } -} - -pub(crate) const CPU_COL_MAP: CpuCols = make_col_map(); - impl BaseAir for CpuChip { fn width(&self) -> usize { NUM_CPU_COLS diff --git a/recursion/core/src/cpu/trace.rs b/recursion/core/src/cpu/trace.rs index 9f3727cf9..0fdbb2d36 100644 --- a/recursion/core/src/cpu/trace.rs +++ b/recursion/core/src/cpu/trace.rs @@ -1,13 +1,5 @@ use std::borrow::BorrowMut; -use p3_field::{extension::BinomiallyExtendable, Field, PrimeField32}; -use p3_matrix::{dense::RowMajorMatrix, Matrix}; -use sphinx_core::{ - air::{BinomialExtension, EventLens, MachineAir, WithEvents}, - utils::pad_rows_fixed, -}; -use tracing::instrument; - use crate::{ air::BinomialExtensionUtils, memory::MemoryCols, @@ -16,8 +8,18 @@ use crate::{ RecursionProgram, D, }, }; +use p3_field::{extension::BinomiallyExtendable, Field, PrimeField32}; +use p3_matrix::dense::RowMajorMatrix; +use p3_maybe_rayon::prelude::IndexedParallelIterator; +use p3_maybe_rayon::prelude::ParallelIterator; +use p3_maybe_rayon::prelude::ParallelSliceMut; +use sphinx_core::{ + air::{BinomialExtension, EventLens, MachineAir, WithEvents}, + utils::{next_power_of_two, par_for_each_row}, +}; +use tracing::instrument; -use super::{CpuChip, CpuCols, CpuEvent, CPU_COL_MAP, NUM_CPU_COLS}; +use super::{CpuChip, CpuCols, CpuEvent, NUM_CPU_COLS}; impl<'a, F: Field, const L: usize> WithEvents<'a> for CpuChip { type Events = &'a [CpuEvent]; @@ -44,116 +46,113 @@ where input: &EL, _: &mut ExecutionRecord, ) -> RowMajorMatrix { - let mut rows = input - .events() - .iter() - .map(|event| { - let mut row = [F::zero(); NUM_CPU_COLS]; - let cols: &mut CpuCols = row.as_mut_slice().borrow_mut(); - - cols.clk = event.clk; - cols.pc = event.pc; - cols.fp = event.fp; - - // Populate the instruction related columns. - cols.selectors.populate(&event.instruction); - cols.instruction.populate(&event.instruction); - - // Populate the register columns. - if let Some(record) = &event.a_record { - cols.a.populate(record); - } - if let Some(record) = &event.b_record { - cols.b.populate(record); - } else { - *cols.b.value_mut() = event.instruction.op_b; - } - if let Some(record) = &event.c_record { - cols.c.populate(record); + let nb_events = input.events().len(); + let padded_nb_rows = next_power_of_two(nb_events, self.fixed_log2_rows); + let mut values = vec![F::zero(); padded_nb_rows * NUM_CPU_COLS]; + + let events = input.events(); + + par_for_each_row(&mut values, NUM_CPU_COLS, |i, row| { + if i >= nb_events { + return; + } + let event = &events[i]; + let cols: &mut CpuCols = row.borrow_mut(); + + cols.clk = event.clk; + cols.pc = event.pc; + cols.fp = event.fp; + + // Populate the instruction related columns. + cols.selectors.populate(&event.instruction); + cols.instruction.populate(&event.instruction); + + // Populate the register columns. + if let Some(record) = &event.a_record { + cols.a.populate(record); + } + if let Some(record) = &event.b_record { + cols.b.populate(record); + } else { + *cols.b.value_mut() = event.instruction.op_b; + } + if let Some(record) = &event.c_record { + cols.c.populate(record); + } else { + *cols.c.value_mut() = event.instruction.op_c; + } + if let Some(record) = &event.memory_record { + let memory_cols = cols.opcode_specific.memory_mut(); + memory_cols.memory.populate(record); + memory_cols.memory_addr = record.addr; + } + + // Populate the heap columns. + if instruction_is_heap_expand(&event.instruction) { + let (u16_range_check, u12_range_check) = + get_heap_size_range_check_events(cols.a.value()[0]); + + let heap_cols = cols.opcode_specific.heap_expand_mut(); + heap_cols.diff_16bit_limb = F::from_canonical_u16(u16_range_check.val); + heap_cols.diff_12bit_limb = F::from_canonical_u16(u12_range_check.val); + } + + // Populate the branch columns. + if matches!( + event.instruction.opcode, + Opcode::BEQ | Opcode::BNE | Opcode::BNEINC + ) { + let branch_cols = cols.opcode_specific.branch_mut(); + let a_ext: BinomialExtension = + BinomialExtensionUtils::from_block(*cols.a.value()); + let b_ext: BinomialExtension = + BinomialExtensionUtils::from_block(*cols.b.value()); + + let (comparison_diff, do_branch) = match event.instruction.opcode { + Opcode::BEQ => (a_ext - b_ext, a_ext == b_ext), + Opcode::BNE | Opcode::BNEINC => (a_ext - b_ext, a_ext != b_ext), + _ => unreachable!(), + }; + + branch_cols + .comparison_diff + .populate((comparison_diff).as_block()); + branch_cols.comparison_diff_val = comparison_diff; + branch_cols.do_branch = F::from_bool(do_branch); + branch_cols.next_pc = if do_branch { + event.pc + event.instruction.op_c[0] } else { - *cols.c.value_mut() = event.instruction.op_c; - } - if let Some(record) = &event.memory_record { - let memory_cols = cols.opcode_specific.memory_mut(); - memory_cols.memory.populate(record); - memory_cols.memory_addr = record.addr; - } - - // Populate the heap columns. - if instruction_is_heap_expand(&event.instruction) { - let (u16_range_check, u12_range_check) = - get_heap_size_range_check_events(cols.a.value()[0]); - - let heap_cols = cols.opcode_specific.heap_expand_mut(); - heap_cols.diff_16bit_limb = F::from_canonical_u16(u16_range_check.val); - heap_cols.diff_12bit_limb = F::from_canonical_u16(u12_range_check.val); - } - - // Populate the branch columns. - if matches!( - event.instruction.opcode, - Opcode::BEQ | Opcode::BNE | Opcode::BNEINC - ) { - let branch_cols = cols.opcode_specific.branch_mut(); - let a_ext: BinomialExtension = - BinomialExtensionUtils::from_block(*cols.a.value()); - let b_ext: BinomialExtension = - BinomialExtensionUtils::from_block(*cols.b.value()); - - let (comparison_diff, do_branch) = match event.instruction.opcode { - Opcode::BEQ => (a_ext - b_ext, a_ext == b_ext), - Opcode::BNE | Opcode::BNEINC => (a_ext - b_ext, a_ext != b_ext), - _ => unreachable!(), - }; - - branch_cols - .comparison_diff - .populate((comparison_diff).as_block()); - branch_cols.comparison_diff_val = comparison_diff; - branch_cols.do_branch = F::from_bool(do_branch); - branch_cols.next_pc = if do_branch { - event.pc + event.instruction.op_c[0] - } else { - event.pc + F::one() - }; - } - - // Populate the public values columns. - if event.instruction.opcode == Opcode::Commit { - let public_values_cols = cols.opcode_specific.public_values_mut(); - let idx = cols.b.prev_value()[0].as_canonical_u32() as usize; - public_values_cols.idx_bitmap[idx] = F::one(); - } - - cols.is_real = F::one(); - row - }) - .collect::>(); - - pad_rows_fixed( - &mut rows, - || { - let mut row = [F::zero(); NUM_CPU_COLS]; - let cols: &mut CpuCols = row.as_mut_slice().borrow_mut(); - cols.selectors.is_noop = F::one(); - cols.instruction.imm_b = F::one(); - cols.instruction.imm_c = F::one(); - row - }, - self.fixed_log2_rows, - ); - - let mut trace = - RowMajorMatrix::new(rows.into_iter().flatten().collect::>(), NUM_CPU_COLS); - - for i in input.events().len()..trace.height() { - trace.values[i * NUM_CPU_COLS + CPU_COL_MAP.clk] = - F::from_canonical_u32(4) * F::from_canonical_usize(i); - trace.values[i * NUM_CPU_COLS + CPU_COL_MAP.instruction.imm_b] = - F::from_canonical_u32(1); - trace.values[i * NUM_CPU_COLS + CPU_COL_MAP.instruction.imm_c] = - F::from_canonical_u32(1); - } + event.pc + F::one() + }; + } + + // Populate the public values columns. + if event.instruction.opcode == Opcode::Commit { + let public_values_cols = cols.opcode_specific.public_values_mut(); + let idx = cols.b.prev_value()[0].as_canonical_u32() as usize; + public_values_cols.idx_bitmap[idx] = F::one(); + } + + cols.is_real = F::one(); + }); + + let mut trace = RowMajorMatrix::new(values, NUM_CPU_COLS); + + // Fill in the dummy values for the padding rows. + let padded_rows = trace + .values + .par_chunks_mut(NUM_CPU_COLS) + .enumerate() + .skip(input.events().len()); + padded_rows.for_each(|(i, row)| { + let cols: &mut CpuCols = row.borrow_mut(); + cols.selectors.is_noop = F::one(); + cols.instruction.imm_b = F::one(); + cols.instruction.imm_c = F::one(); + cols.clk = F::from_canonical_u32(4) * F::from_canonical_usize(i); + cols.instruction.imm_b = F::from_canonical_u32(1); + cols.instruction.imm_c = F::from_canonical_u32(1); + }); trace } diff --git a/recursion/core/src/exp_reverse_bits/mod.rs b/recursion/core/src/exp_reverse_bits/mod.rs index b1be0a9c0..274437bc9 100644 --- a/recursion/core/src/exp_reverse_bits/mod.rs +++ b/recursion/core/src/exp_reverse_bits/mod.rs @@ -1,11 +1,8 @@ -#![allow(clippy::needless_range_loop)] - use crate::air::{Block, IsZeroOperation, RecursionMemoryAirBuilder}; use crate::memory::{MemoryReadSingleCols, MemoryReadWriteSingleCols}; use crate::runtime::Opcode; use core::borrow::Borrow; use core::mem::size_of; -use itertools::Itertools; use p3_air::{Air, AirBuilder, BaseAir}; use p3_field::PrimeField32; use p3_field::{AbstractField, Field}; @@ -15,7 +12,7 @@ use p3_util::reverse_bits_len; use sphinx_core::air::{ BaseAirBuilder, EventLens, ExtensionAirBuilder, MachineAir, SphinxAirBuilder, WithEvents, }; -use sphinx_core::utils::pad_rows_fixed; +use sphinx_core::utils::{next_power_of_two, par_for_each_row}; use sphinx_derive::AlignedBorrow; use std::borrow::BorrowMut; use std::marker::PhantomData; @@ -107,7 +104,7 @@ impl ExpReverseBitsLenEvent { len: new_len, prev_accum, accum, - ptr: F::zero(), + ptr: F::from_canonical_u32(i), base_ptr: F::one(), iteration_num: F::from_canonical_u32(i), }); @@ -196,57 +193,49 @@ impl MachineAir for ExpReverseBitsLenCh input: &EL, _: &mut ExecutionRecord, ) -> RowMajorMatrix { - let mut rows = input - .events() - .iter() - .map(|event| { - let mut row = [F::zero(); NUM_EXP_REVERSE_BITS_LEN_COLS]; - - let cols: &mut ExpReverseBitsLenCols = row.as_mut_slice().borrow_mut(); - - cols.clk = event.clk; - - cols.x.populate(&event.x); - cols.current_bit.populate(&event.current_bit); - cols.len = event.len; - cols.accum = event.accum; - cols.prev_accum_squared = event.prev_accum * event.prev_accum; - cols.is_last.populate(F::one() - event.len); - cols.is_first.populate(event.iteration_num); - cols.is_real = F::one(); - cols.iteration_num = event.iteration_num; - cols.multiplier = if event.current_bit.value - == Block([F::one(), F::zero(), F::zero(), F::zero()]) - { + let nb_events = input.events().len(); + let nb_rows = if self.pad { + next_power_of_two(nb_events, self.fixed_log2_rows) + } else { + nb_events + }; + let mut values = vec![F::zero(); nb_rows * NUM_EXP_REVERSE_BITS_LEN_COLS]; + + let events = input.events(); + par_for_each_row(&mut values, NUM_EXP_REVERSE_BITS_LEN_COLS, |i, row| { + if i >= nb_events { + return; + } + let event = &events[i]; + let cols: &mut ExpReverseBitsLenCols = row.borrow_mut(); + + cols.clk = event.clk; + + cols.x.populate(&event.x); + cols.current_bit.populate(&event.current_bit); + cols.len = event.len; + cols.accum = event.accum; + cols.prev_accum_squared = event.prev_accum * event.prev_accum; + cols.is_last.populate(F::one() - event.len); + cols.is_first.populate(event.iteration_num); + cols.is_real = F::one(); + cols.iteration_num = event.iteration_num; + cols.multiplier = + if event.current_bit.value == Block([F::one(), F::zero(), F::zero(), F::zero()]) { // The event may change the value stored in the x memory access, and we need to // use the previous value. event.x.prev_value[0] } else { F::one() }; - cols.ptr = event.ptr; - cols.base_ptr = event.base_ptr; - cols.x_mem_access_flag = - F::from_bool(cols.len == F::one() || cols.iteration_num == F::zero()); - - row - }) - .collect_vec(); - - // Pad the trace to a power of two. - if self.pad { - pad_rows_fixed( - &mut rows, - || [F::zero(); NUM_EXP_REVERSE_BITS_LEN_COLS], - self.fixed_log2_rows, - ); - } + cols.ptr = event.ptr; + cols.base_ptr = event.base_ptr; + cols.x_mem_access_flag = + F::from_bool(cols.len == F::one() || cols.iteration_num == F::zero()); + }); // Convert the trace to a row major matrix. - let trace = RowMajorMatrix::new( - rows.into_iter().flatten().collect(), - NUM_EXP_REVERSE_BITS_LEN_COLS, - ); + let trace = RowMajorMatrix::new(values, NUM_EXP_REVERSE_BITS_LEN_COLS); #[cfg(debug_assertions)] println!( @@ -297,12 +286,31 @@ impl ExpReverseBitsLenChip { local.is_first.result, ); + // Make sure that local.is_first.result is not on for fake rows, so we don't receive operands + // for a fake row. + builder + .when_not(local.is_real) + .assert_zero(local.is_first.result); + IsZeroOperation::::eval( builder, &(AB::Expr::one() - local.len), local.is_last, &local.is_real.into(), ); + + IsZeroOperation::::eval( + builder, + &local.iteration_num.into(), + local.is_first, + &local.is_real.into(), + ); + + // All real columns need to be in succession. + builder + .when_transition() + .assert_zero((AB::Expr::one() - local.is_real) * next.is_real); + // Assert that the boolean columns are boolean. builder.assert_bool(local.is_real); @@ -327,9 +335,15 @@ impl ExpReverseBitsLenChip { // Assert that the last real row has `is_last` on. builder + .when_transition() .when(local.is_real * (AB::Expr::one() - next.is_real)) .assert_one(local.is_last.result); + builder + .when_last_row() + .when(local.is_real) + .assert_one(local.is_last.result); + // `multiplier` is x if the current bit is 1, and 1 if the current bit is 0. builder .when(current_bit_val) @@ -340,10 +354,9 @@ impl ExpReverseBitsLenChip { .assert_eq(local.multiplier, AB::Expr::one()); // To get `next.accum`, we multiply `local.prev_accum_squared` by `local.multiplier` when not - // `is_last`. + // `is_first`. builder - .when_transition() - .when_not(local.is_last.result) + .when_not(local.is_first.result) .assert_eq(local.accum, local.prev_accum_squared * local.multiplier); // Constrain the accum_squared column. @@ -358,6 +371,14 @@ impl ExpReverseBitsLenChip { .when_not(local.is_last.result) .assert_eq(local.base_ptr, next.base_ptr); + // Constrain the memory address `ptr` to increment by one except when + // `is_last` + builder + .when_transition() + .when(next.is_real) + .when_not(local.is_last.result) + .assert_eq(next.ptr, local.ptr + AB::Expr::one()); + // The `len` counter must decrement when not `is_last`. builder .when_transition() @@ -392,6 +413,11 @@ impl ExpReverseBitsLenChip { - local.is_first.result * local.is_last.result, ); + // Make sure that x is only accessed when `is_real` is 1. + builder + .when_not(local.is_real) + .assert_zero(local.x_mem_access_flag); + // Access the memory for x. // This only needs to be done for the first and last iterations. builder.recursion_eval_memory_access_single( @@ -417,6 +443,13 @@ impl ExpReverseBitsLenChip { // Ensure that the value at the x memory access is unchanged when not `is_last`. builder + .when_transition() + .when(next.is_real) + .when_not(local.is_last.result) + .assert_eq(local.x.access.value, next.x.prev_value); + + builder + .when_transition() .when_not(local.is_last.result) .assert_eq(local.x.access.value, local.x.prev_value); diff --git a/recursion/core/src/fri_fold/mod.rs b/recursion/core/src/fri_fold/mod.rs index 6dba1d946..c9f841c9f 100644 --- a/recursion/core/src/fri_fold/mod.rs +++ b/recursion/core/src/fri_fold/mod.rs @@ -1,17 +1,14 @@ -#![allow(clippy::needless_range_loop)] - use crate::memory::{MemoryReadCols, MemoryReadSingleCols, MemoryReadWriteCols}; use crate::runtime::Opcode; use core::borrow::Borrow; use core::mem::size_of; -use itertools::Itertools; use p3_air::{Air, AirBuilder, BaseAir}; +use p3_field::AbstractField; use p3_field::PrimeField32; -use p3_field::{AbstractField, Field}; use p3_matrix::dense::RowMajorMatrix; use p3_matrix::Matrix; use sphinx_core::air::{BaseAirBuilder, BinomialExtension, EventLens, MachineAir, WithEvents}; -use sphinx_core::utils::pad_rows_fixed; +use sphinx_core::utils::{next_power_of_two, par_for_each_row}; use sphinx_derive::AlignedBorrow; use std::borrow::BorrowMut; use std::marker::PhantomData; @@ -23,11 +20,20 @@ use crate::runtime::{ExecutionRecord, RecursionProgram}; pub const NUM_FRI_FOLD_COLS: usize = size_of::>(); -#[derive(Default)] -pub struct FriFoldChip { +pub struct FriFoldChip { pub fixed_log2_rows: Option, - pub _phantom: PhantomData, pub pad: bool, + pub _phantom: PhantomData, +} + +impl Default for FriFoldChip { + fn default() -> Self { + Self { + fixed_log2_rows: Default::default(), + pad: Default::default(), + _phantom: Default::default(), + } + } } #[derive(Debug, Clone)] @@ -86,13 +92,13 @@ pub struct FriFoldCols { pub is_real: T, } -impl BaseAir for FriFoldChip { +impl BaseAir for FriFoldChip { fn width(&self) -> usize { NUM_FRI_FOLD_COLS } } -impl<'a, F: Field, const DEGREE: usize> WithEvents<'a> for FriFoldChip { +impl<'a, F: 'a, const DEGREE: usize> WithEvents<'a> for FriFoldChip { type Events = &'a [FriFoldEvent]; } @@ -115,51 +121,47 @@ impl MachineAir for FriFoldChip, ) -> RowMajorMatrix { - let mut rows = input - .events() - .iter() - .map(|event| { - let mut row = [F::zero(); NUM_FRI_FOLD_COLS]; - - let cols: &mut FriFoldCols = row.as_mut_slice().borrow_mut(); - - cols.clk = event.clk; - cols.m = event.m; - cols.input_ptr = event.input_ptr; - cols.is_last_iteration = event.is_last_iteration; - cols.is_real = F::one(); - - cols.z.populate(&event.z); - cols.alpha.populate(&event.alpha); - cols.x.populate(&event.x); - cols.log_height.populate(&event.log_height); - cols.mat_opening_ptr.populate(&event.mat_opening_ptr); - cols.ps_at_z_ptr.populate(&event.ps_at_z_ptr); - cols.alpha_pow_ptr.populate(&event.alpha_pow_ptr); - cols.ro_ptr.populate(&event.ro_ptr); - - cols.p_at_x.populate(&event.p_at_x); - cols.p_at_z.populate(&event.p_at_z); - - cols.alpha_pow_at_log_height - .populate(&event.alpha_pow_at_log_height); - cols.ro_at_log_height.populate(&event.ro_at_log_height); - - row - }) - .collect_vec(); - - // Pad the trace to a power of two. - if self.pad { - pad_rows_fixed( - &mut rows, - || [F::zero(); NUM_FRI_FOLD_COLS], - self.fixed_log2_rows, - ); - } + let nb_events = input.events().len(); + let nb_rows = if self.pad { + next_power_of_two(nb_events, self.fixed_log2_rows) + } else { + nb_events + }; + let mut values = vec![F::zero(); nb_rows * NUM_FRI_FOLD_COLS]; + + let events = input.events(); + par_for_each_row(&mut values, NUM_FRI_FOLD_COLS, |i, row| { + if i >= nb_events { + return; + } + let event = &events[i]; + let cols: &mut FriFoldCols = row.borrow_mut(); + + cols.clk = event.clk; + cols.m = event.m; + cols.input_ptr = event.input_ptr; + cols.is_last_iteration = event.is_last_iteration; + cols.is_real = F::one(); + + cols.z.populate(&event.z); + cols.alpha.populate(&event.alpha); + cols.x.populate(&event.x); + cols.log_height.populate(&event.log_height); + cols.mat_opening_ptr.populate(&event.mat_opening_ptr); + cols.ps_at_z_ptr.populate(&event.ps_at_z_ptr); + cols.alpha_pow_ptr.populate(&event.alpha_pow_ptr); + cols.ro_ptr.populate(&event.ro_ptr); + + cols.p_at_x.populate(&event.p_at_x); + cols.p_at_z.populate(&event.p_at_z); + + cols.alpha_pow_at_log_height + .populate(&event.alpha_pow_at_log_height); + cols.ro_at_log_height.populate(&event.ro_at_log_height); + }); // Convert the trace to a row major matrix. - let trace = RowMajorMatrix::new(rows.into_iter().flatten().collect(), NUM_FRI_FOLD_COLS); + let trace = RowMajorMatrix::new(values, NUM_FRI_FOLD_COLS); #[cfg(debug_assertions)] println!( @@ -176,7 +178,7 @@ impl MachineAir for FriFoldChip FriFoldChip { +impl FriFoldChip { pub fn eval_fri_fold( &self, builder: &mut AB, diff --git a/recursion/core/src/memory/air.rs b/recursion/core/src/memory/air.rs index eae7e8250..2ca29f738 100644 --- a/recursion/core/src/memory/air.rs +++ b/recursion/core/src/memory/air.rs @@ -5,22 +5,20 @@ use std::{ }; use p3_air::{Air, AirBuilder, BaseAir}; -use p3_field::AbstractField; -use p3_field::{Field, PrimeField32}; -use p3_matrix::{dense::RowMajorMatrix, Matrix}; -use sphinx_core::{ - air::{AirInteraction, EventLens, MachineAir, WithEvents}, - lookup::InteractionKind, - utils::pad_rows_fixed, -}; +use p3_field::{AbstractField, Field, PrimeField32}; +use p3_matrix::dense::RowMajorMatrix; +use p3_matrix::Matrix; +use sphinx_core::air::MachineAir; +use sphinx_core::air::{AirInteraction, EventLens, WithEvents}; +use sphinx_core::lookup::InteractionKind; +use sphinx_core::utils::next_power_of_two; +use sphinx_core::utils::par_for_each_row; use tracing::instrument; use super::columns::MemoryInitCols; -use crate::{air::Block, memory::MemoryGlobalChip}; -use crate::{ - air::RecursionMemoryAirBuilder, - runtime::{ExecutionRecord, RecursionProgram}, -}; +use crate::air::{Block, RecursionMemoryAirBuilder}; +use crate::memory::MemoryGlobalChip; +use crate::runtime::{ExecutionRecord, RecursionProgram}; pub(crate) const NUM_MEMORY_INIT_COLS: usize = size_of::>(); @@ -61,73 +59,52 @@ impl MachineAir for MemoryGlobalChip { input: &EL, _output: &mut ExecutionRecord, ) -> RowMajorMatrix { - let mut rows = Vec::new(); let (first_memory_events, last_memory_events) = input.events(); - // Fill in the initial memory records. - rows.extend( - first_memory_events - .iter() - .map(|(addr, value)| { - let mut row = [F::zero(); NUM_MEMORY_INIT_COLS]; - let cols: &mut MemoryInitCols = row.as_mut_slice().borrow_mut(); - cols.addr = *addr; - cols.timestamp = F::zero(); - cols.value = *value; - cols.is_initialize = F::one(); - - cols.is_real = F::one(); - - row - }) - .collect::>(), - ); - - let num_mem_final = last_memory_events.len(); - // Fill in the finalize memory records. - rows.extend( - last_memory_events - .iter() - .zip(last_memory_events.iter().skip(1).chain([&( - F::zero(), - F::zero(), - Block::from(F::zero()), - )])) - .enumerate() - .map(|(i, ((addr, timestamp, value), (next_addr, _, _)))| { - let mut row = [F::zero(); NUM_MEMORY_INIT_COLS]; - let cols: &mut MemoryInitCols = row.as_mut_slice().borrow_mut(); - cols.addr = *addr; - cols.timestamp = *timestamp; - cols.value = *value; - cols.is_finalize = F::one(); - (cols.diff_16bit_limb, cols.diff_12bit_limb) = if i != num_mem_final - 1 { - compute_addr_diff(*next_addr, *addr, true) - } else { - (F::zero(), F::zero()) - }; - (cols.addr_16bit_limb, cols.addr_12bit_limb) = - compute_addr_diff(*addr, F::zero(), false); - - cols.is_real = F::one(); - cols.is_range_check = F::from_bool(i != num_mem_final - 1); - - row - }) - .collect::>(), - ); - - // Pad the trace to a power of two. - pad_rows_fixed( - &mut rows, - || [F::zero(); NUM_MEMORY_INIT_COLS], - self.fixed_log2_rows, - ); - - RowMajorMatrix::new( - rows.into_iter().flatten().collect::>(), - NUM_MEMORY_INIT_COLS, - ) + let nb_events = first_memory_events.len() + last_memory_events.len(); + let nb_rows = next_power_of_two(nb_events, self.fixed_log2_rows); + let mut values = vec![F::zero(); nb_rows * NUM_MEMORY_INIT_COLS]; + + par_for_each_row(&mut values, NUM_MEMORY_INIT_COLS, |i, row| { + if i >= nb_events { + return; + } + let cols: &mut MemoryInitCols = row.borrow_mut(); + + if i < first_memory_events.len() { + let (addr, value) = &first_memory_events[i]; + cols.addr = *addr; + cols.timestamp = F::zero(); + cols.value = *value; + cols.is_initialize = F::one(); + + cols.is_real = F::one(); + } else { + let (addr, timestamp, value) = &last_memory_events[i - first_memory_events.len()]; + let last = i == nb_events - 1; + let (next_addr, _, _) = if last { + &(F::zero(), F::zero(), Block::from(F::zero())) + } else { + &last_memory_events[i - first_memory_events.len() + 1] + }; + cols.addr = *addr; + cols.timestamp = *timestamp; + cols.value = *value; + cols.is_finalize = F::one(); + (cols.diff_16bit_limb, cols.diff_12bit_limb) = if !last { + compute_addr_diff(*next_addr, *addr, true) + } else { + (F::zero(), F::zero()) + }; + (cols.addr_16bit_limb, cols.addr_12bit_limb) = + compute_addr_diff(*addr, F::zero(), false); + + cols.is_real = F::one(); + cols.is_range_check = F::from_bool(!last); + } + }); + + RowMajorMatrix::new(values, NUM_MEMORY_INIT_COLS) } fn included(&self, shard: &Self::Record) -> bool { diff --git a/recursion/core/src/multi/mod.rs b/recursion/core/src/multi/mod.rs index 4839e0993..bb058429a 100644 --- a/recursion/core/src/multi/mod.rs +++ b/recursion/core/src/multi/mod.rs @@ -7,7 +7,7 @@ use std::ops::Deref; use core::mem::size_of; use itertools::Itertools; use p3_air::{Air, AirBuilder, BaseAir}; -use p3_field::{Field, PrimeField32}; +use p3_field::{AbstractField, PrimeField32}; use p3_matrix::dense::RowMajorMatrix; use p3_matrix::Matrix; use sphinx_core::air::{BaseAirBuilder, EventLens, MachineAir, Proj, WithEvents}; @@ -40,6 +40,14 @@ pub struct MultiCols { pub is_poseidon2: T, + /// A flag column to indicate whether the row is the first poseidon2 row. + pub poseidon2_first_row: T, + /// A flag column to indicate whether the row is the last poseidon2 row. + pub poseidon2_last_row: T, + + /// Similar for Fri_fold. + pub fri_fold_last_row: T, + /// Rows that needs to receive a poseidon2 syscall. pub poseidon2_receive_table: T, /// Hash/Permute state entries that needs to access memory. This is for the the first half of the permute state. @@ -50,16 +58,16 @@ pub struct MultiCols { pub poseidon2_send_range_check: T, } -impl BaseAir for MultiChip { +impl BaseAir for MultiChip { fn width(&self) -> usize { - let fri_fold_width = Self::fri_fold_width(); - let poseidon2_width = Self::poseidon2_width(); + let fri_fold_width = Self::fri_fold_width::(); + let poseidon2_width = Self::poseidon2_width::(); max(fri_fold_width, poseidon2_width) + NUM_MULTI_COLS } } -impl<'a, F: Field, const DEGREE: usize> WithEvents<'a> for MultiChip { +impl<'a, F: 'a + Sync, const DEGREE: usize> WithEvents<'a> for MultiChip { type Events = ( as WithEvents<'a>>::Events, as WithEvents<'a>>::Events, @@ -108,6 +116,10 @@ impl MachineAir for MultiChip), output); let mut poseidon2_trace = poseidon2.generate_trace(&Proj::new(input, to_poseidon::), output); + + let fri_fold_height = fri_fold_trace.height(); + let poseidon2_height = poseidon2_trace.height(); + let num_columns = as BaseAir>::width(self); let mut rows = fri_fold_trace @@ -131,6 +143,9 @@ impl MachineAir for MultiChip::do_receive_table(fri_fold_cols); multi_cols.fri_fold_memory_access = FriFoldChip::::do_memory_access(fri_fold_cols); + if i == fri_fold_trace.height() - 1 { + multi_cols.fri_fold_last_row = F::one(); + } } else { let multi_cols: &mut MultiCols = row[0..NUM_MULTI_COLS].borrow_mut(); multi_cols.is_poseidon2 = F::one(); @@ -144,6 +159,11 @@ impl MachineAir for MultiChip(&local); - let next_fri_fold_cols = Self::fri_fold::(&next); + let local_fri_fold_cols = Self::fri_fold(&local); + let next_fri_fold_cols = Self::fri_fold(&next); sub_builder.assert_eq( local_multi_cols.is_fri_fold @@ -246,10 +299,12 @@ where let mut sub_builder = MultiBuilder::new( builder, &local_multi_cols.is_poseidon2.into(), + local_multi_cols.poseidon2_first_row.into(), + local_multi_cols.poseidon2_last_row.into(), next_multi_cols.is_poseidon2.into(), ); - let poseidon2_columns = MultiChip::::poseidon2::(local_slice); + let poseidon2_columns = MultiChip::::poseidon2(local_slice); sub_builder.assert_eq( local_multi_cols.is_poseidon2 * poseidon2_columns.control_flow().is_syscall_row, local_multi_cols.poseidon2_receive_table, @@ -279,7 +334,7 @@ where poseidon2_chip.eval_poseidon2( &mut sub_builder, poseidon2_columns.as_ref(), - MultiChip::::poseidon2::(next_slice).as_ref(), + MultiChip::::poseidon2(next_slice).as_ref(), local_multi_cols.poseidon2_receive_table, local_multi_cols.poseidon2_1st_half_memory_access, local_multi_cols.poseidon2_2nd_half_memory_access, @@ -288,35 +343,33 @@ where } } -impl MultiChip { - fn fri_fold_width() -> usize { - as BaseAir>::width(&FriFoldChip::::default()) +impl MultiChip { + fn fri_fold_width() -> usize { + as BaseAir>::width(&FriFoldChip::::default()) } - fn fri_fold>( - row: &dyn Deref, - ) -> FriFoldCols { - let row_slice: &[AB::Var] = row; - let fri_fold_width = Self::fri_fold_width(); - let fri_fold_cols: &FriFoldCols = + fn fri_fold(row: &dyn Deref) -> FriFoldCols { + let row_slice: &[T] = row; + let fri_fold_width = Self::fri_fold_width::(); + let fri_fold_cols: &FriFoldCols = (row_slice[NUM_MULTI_COLS..NUM_MULTI_COLS + fri_fold_width]).borrow(); *fri_fold_cols } - fn poseidon2_width() -> usize { - as BaseAir>::width( - &Poseidon2WideChip::::default(), + fn poseidon2_width() -> usize { + as BaseAir>::width( + &Poseidon2WideChip::::default(), ) } - fn poseidon2<'a, AB: AirBuilder + 'a>( - row: impl Deref, - ) -> Box + 'a> { - let row_slice: &[AB::Var] = &row; - let poseidon2_width = Self::poseidon2_width(); + fn poseidon2<'a, T: 'a + Copy + Sync>( + row: impl Deref, + ) -> Box + 'a> { + let row_slice: &[T] = &row; + let poseidon2_width = Self::poseidon2_width::(); - Poseidon2WideChip::::convert::( + Poseidon2WideChip::::convert::( &row_slice[NUM_MULTI_COLS..NUM_MULTI_COLS + poseidon2_width], ) } diff --git a/recursion/core/src/poseidon2_wide/air/control_flow.rs b/recursion/core/src/poseidon2_wide/air/control_flow.rs index 8a2464035..6529a061c 100644 --- a/recursion/core/src/poseidon2_wide/air/control_flow.rs +++ b/recursion/core/src/poseidon2_wide/air/control_flow.rs @@ -1,5 +1,5 @@ use p3_air::AirBuilder; -use p3_field::{AbstractField, Field}; +use p3_field::AbstractField; use sphinx_core::{air::BaseAirBuilder, operations::IsZeroOperation}; use crate::{ @@ -14,7 +14,7 @@ use crate::{ range_check::RangeCheckOpcode, }; -impl Poseidon2WideChip { +impl Poseidon2WideChip { /// Constraints related to control flow. pub(crate) fn eval_control_flow( &self, @@ -62,6 +62,10 @@ impl Poseidon2WideChip { local_row.syscall_params(), send_range_check, ); + + builder + .when(local_control_flow.is_syscall_row) + .assert_one(local_is_real); } /// This function will verify that all hash rows are before the compress rows and that the first @@ -80,38 +84,56 @@ impl Poseidon2WideChip { local_is_real: &AB::Expr, next_is_real: &AB::Expr, ) { - // We require that the first row is an absorb syscall and that the hash_num == 0. + // We require that the first row is an absorb syscall and that the hash_num == 0 and absorb_num == 0. let mut first_row_builder = builder.when_first_row(); first_row_builder.assert_one(local_control_flow.is_absorb); first_row_builder.assert_one(local_control_flow.is_syscall_row); - first_row_builder.assert_zero(local_syscall_params.absorb().hash_num); + first_row_builder.assert_zero(local_opcode_workspace.absorb().hash_num); + first_row_builder.assert_zero(local_opcode_workspace.absorb().absorb_num); first_row_builder.assert_one(local_opcode_workspace.absorb().is_first_hash_row); - let mut transition_builder = builder.when_transition(); - // For absorb rows, constrain the following: - // 1) next row is either an absorb or syscall finalize. - // 2) when last absorb row, then the next row is a syscall row. - // 2) hash_num == hash_num'. + // 1) when last absorb row, then the next row is a either an absorb or finalize syscall row. + // 2) when last absorb row and the next row is an absorb row, then absorb_num' = absorb_num + 1. + // 3) when not last absorb row, then the next row is an absorb non syscall row. + // 4) when not last absorb row, then absorb_num' = absorb_num. + // 5) hash_num == hash_num'. { - let mut absorb_transition_builder = - transition_builder.when(local_control_flow.is_absorb); - absorb_transition_builder + let mut transition_builder = builder.when_transition(); + + let mut absorb_last_row_builder = + transition_builder.when(local_control_flow.is_absorb_last_row); + absorb_last_row_builder .assert_one(next_control_flow.is_absorb + next_control_flow.is_finalize); - absorb_transition_builder - .when(local_opcode_workspace.absorb().is_last_row::()) - .assert_one(next_control_flow.is_syscall_row); + absorb_last_row_builder.assert_one(next_control_flow.is_syscall_row); + absorb_last_row_builder + .when(next_control_flow.is_absorb) + .assert_eq( + next_opcode_workspace.absorb().absorb_num, + local_opcode_workspace.absorb().absorb_num + AB::Expr::one(), + ); + + let mut absorb_not_last_row_builder = + transition_builder.when(local_control_flow.is_absorb_not_last_row); + absorb_not_last_row_builder.assert_one(next_control_flow.is_absorb); + absorb_not_last_row_builder.assert_zero(next_control_flow.is_syscall_row); + absorb_not_last_row_builder.assert_eq( + local_opcode_workspace.absorb().absorb_num, + next_opcode_workspace.absorb().absorb_num, + ); + let mut absorb_transition_builder = + transition_builder.when(local_control_flow.is_absorb); absorb_transition_builder .when(next_control_flow.is_absorb) .assert_eq( - local_syscall_params.absorb().hash_num, - next_syscall_params.absorb().hash_num, + local_opcode_workspace.absorb().hash_num, + next_opcode_workspace.absorb().hash_num, ); absorb_transition_builder .when(next_control_flow.is_finalize) .assert_eq( - local_syscall_params.absorb().hash_num, + local_opcode_workspace.absorb().hash_num, next_syscall_params.finalize().hash_num, ); } @@ -119,8 +141,10 @@ impl Poseidon2WideChip { // For finalize rows, constrain the following: // 1) next row is syscall compress or syscall absorb. // 2) if next row is absorb -> hash_num + 1 == hash_num' - // 3) if next row is absorb -> is_first_hash' == true + // 3) if next row is absorb -> absorb_num' == 0 + // 4) if next row is absorb -> is_first_hash' == true { + let mut transition_builder = builder.when_transition(); let mut finalize_transition_builder = transition_builder.when(local_control_flow.is_finalize); @@ -132,8 +156,11 @@ impl Poseidon2WideChip { .when(next_control_flow.is_absorb) .assert_eq( local_syscall_params.finalize().hash_num + AB::Expr::one(), - next_syscall_params.absorb().hash_num, + next_opcode_workspace.absorb().hash_num, ); + finalize_transition_builder + .when(next_control_flow.is_absorb) + .assert_zero(next_opcode_workspace.absorb().absorb_num); finalize_transition_builder .when(next_control_flow.is_absorb) .assert_one(next_opcode_workspace.absorb().is_first_hash_row); @@ -143,26 +170,33 @@ impl Poseidon2WideChip { // 1) if compress syscall -> next row is a compress output // 2) if compress output -> next row is a compress syscall or not real { + builder.assert_eq( + local_control_flow.is_compress_output, + local_control_flow.is_compress + * (AB::Expr::one() - local_control_flow.is_syscall_row), + ); + + let mut transition_builder = builder.when_transition(); + transition_builder .when(local_control_flow.is_compress) .when(local_control_flow.is_syscall_row) .assert_one(next_control_flow.is_compress_output); + // When we are at a compress output row, then ensure next row is either not real or is a compress syscall row. transition_builder .when(local_control_flow.is_compress_output) .assert_one( - next_control_flow.is_compress + (AB::Expr::one() - next_is_real.clone()), + (AB::Expr::one() - next_is_real.clone()) + + next_control_flow.is_compress * next_control_flow.is_syscall_row, ); - - transition_builder - .when(local_control_flow.is_compress_output) - .when(next_control_flow.is_compress) - .assert_one(next_control_flow.is_syscall_row); } // Constrain that there is only one is_real -> not is real transition. Also contrain that // the last real row is a compress output row. { + let mut transition_builder = builder.when_transition(); + transition_builder .when_not(local_is_real.clone()) .assert_zero(next_is_real.clone()); @@ -194,6 +228,29 @@ impl Poseidon2WideChip { let last_row_ending_cursor_is_seven = local_hash_workspace.last_row_ending_cursor_is_seven.result; + // Verify that the hash_num and absorb_num are correctly decomposed from the syscall + // hash_and_absorb_num param. + // Also range check that both hash_num is within [0, 2^16 - 1] and absorb_num is within [0, 2^12 - 1]; + { + let mut absorb_builder = builder.when(local_control_flow.is_absorb); + + absorb_builder.assert_eq( + local_hash_workspace.hash_num * AB::Expr::from_canonical_u32(1 << 12) + + local_hash_workspace.absorb_num, + local_syscall_params.absorb().hash_and_absorb_num, + ); + builder.send_range_check( + AB::Expr::from_canonical_u8(RangeCheckOpcode::U16 as u8), + local_hash_workspace.hash_num, + send_range_check, + ); + builder.send_range_check( + AB::Expr::from_canonical_u8(RangeCheckOpcode::U12 as u8), + local_hash_workspace.absorb_num, + send_range_check, + ); + } + // Constrain the materialized control flow flags. { let mut absorb_builder = builder.when(local_control_flow.is_absorb); @@ -232,12 +289,16 @@ impl Poseidon2WideChip { local_control_flow.is_absorb * (AB::Expr::one() - local_hash_workspace.is_last_row::()), ); + builder.assert_eq( + local_control_flow.is_absorb_last_row, + local_control_flow.is_absorb * local_hash_workspace.is_last_row::(), + ); builder.assert_eq( local_control_flow.is_absorb_no_perm, local_control_flow.is_absorb * (AB::Expr::one() - local_hash_workspace.do_perm::()), - ) + ); } // For the absorb syscall row, ensure correct value of num_remaining_rows, last_row_num_consumed, @@ -274,7 +335,16 @@ impl Poseidon2WideChip { expected_last_row_ending_cursor, ); - // Range check that num_remaining_rows is between [0, 2^18-1]. + // Range check that input_len < 2^16. This check is only needed for absorb syscall rows, + // but we send it for all absorb rows, since the `is_real` parameter must be an expression + // with at most degree 1. + builder.send_range_check( + AB::Expr::from_canonical_u8(RangeCheckOpcode::U16 as u8), + local_syscall_params.absorb().input_len, + send_range_check, + ); + + // Range check that num_remaining_rows is between [0, 2^16-1]. builder.send_range_check( AB::Expr::from_canonical_u8(RangeCheckOpcode::U16 as u8), local_hash_workspace.num_remaining_rows, diff --git a/recursion/core/src/poseidon2_wide/air/memory.rs b/recursion/core/src/poseidon2_wide/air/memory.rs index 50080229c..7c06739a4 100644 --- a/recursion/core/src/poseidon2_wide/air/memory.rs +++ b/recursion/core/src/poseidon2_wide/air/memory.rs @@ -1,5 +1,5 @@ use p3_air::AirBuilder; -use p3_field::{AbstractField, Field}; +use p3_field::AbstractField; use sphinx_core::air::BaseAirBuilder; use crate::{ @@ -14,7 +14,7 @@ use crate::{ }, }; -impl Poseidon2WideChip { +impl Poseidon2WideChip { /// Eval the memory related columns. #[allow(clippy::too_many_arguments)] pub(crate) fn eval_mem( @@ -84,6 +84,7 @@ impl Poseidon2WideChip { // Contrain memory access for the first half of the memory accesses. { let mut addr: AB::Expr = local_memory.start_addr.into(); + #[allow(clippy::needless_range_loop)] for i in 0..WIDTH / 2 { builder.recursion_eval_memory_access_single( clk + control_flow.is_compress_output, @@ -185,12 +186,21 @@ impl Poseidon2WideChip { } // Verify that all elements of start_mem_idx_bitmap and end_mem_idx_bitmap are bool. + // Also verify that exactly one of the bits in start_mem_idx_bitmap and end_mem_idx_bitmap + // is one. + let mut start_mem_idx_bitmap_sum = AB::Expr::zero(); for bit in start_mem_idx_bitmap.iter() { absorb_builder.assert_bool(*bit); + start_mem_idx_bitmap_sum += (*bit).into(); } + absorb_builder.assert_one(start_mem_idx_bitmap_sum); + + let mut end_mem_idx_bitmap_sum = AB::Expr::zero(); for bit in end_mem_idx_bitmap.iter() { absorb_builder.assert_bool(*bit); + end_mem_idx_bitmap_sum += (*bit).into(); } + absorb_builder.assert_one(end_mem_idx_bitmap_sum); // Verify correct value of start_mem_idx_bitmap and end_mem_idx_bitmap. let start_mem_idx: AB::Expr = start_mem_idx_bitmap @@ -209,7 +219,7 @@ impl Poseidon2WideChip { // When we are not in the last row, end_mem_idx should be zero. absorb_builder .when_not(opcode_workspace.absorb().is_last_row::()) - .assert_zero(end_mem_idx.clone()); + .assert_zero(end_mem_idx.clone() - AB::Expr::from_canonical_usize(7)); // When we are in the last row, end_mem_idx bitmap should equal last_row_ending_cursor. absorb_builder diff --git a/recursion/core/src/poseidon2_wide/air/mod.rs b/recursion/core/src/poseidon2_wide/air/mod.rs index 5ef8acd9b..440eebdbc 100644 --- a/recursion/core/src/poseidon2_wide/air/mod.rs +++ b/recursion/core/src/poseidon2_wide/air/mod.rs @@ -4,7 +4,7 @@ //! # Layout of the poseidon2 chip: //! //! All the hash related rows should be in the first part of the chip and all the compress -//! related rows in the second part. E.g. the chip should has this format: +//! related rows in the second part. E.g. the chip should have this format: //! //! absorb row (for hash num 1) //! absorb row (for hash num 1) @@ -34,7 +34,7 @@ //! last_row_ending_cursor will be copied down to all of the rows. Also, for the next absorb/finalize //! syscall, its state_cursor is set to (last_row_ending_cursor + 1) % RATE. //! -//! From num_remaining_rows and syscall column, we know the absorb 's first row and last row. +//! From num_remaining_rows and syscall column, we know the absorb's first row and last row. //! From that fact, we can then enforce the following state writes. //! //! 1. is_first_row && is_last_row -> state writes are [state_cursor..state_cursor + last_row_ending_cursor] @@ -73,7 +73,6 @@ //! into the next row. That row should then verify the correct memory write accesses. use p3_air::{Air, BaseAir}; -use p3_field::Field; use p3_matrix::Matrix; use crate::air::SphinxRecursionAirBuilder; @@ -89,7 +88,7 @@ use super::{ Poseidon2WideChip, WIDTH, }; -impl BaseAir for Poseidon2WideChip { +impl BaseAir for Poseidon2WideChip { fn width(&self) -> usize { if DEGREE == 3 { NUM_POSEIDON2_DEGREE3_COLS @@ -132,7 +131,7 @@ where } } -impl Poseidon2WideChip { +impl Poseidon2WideChip { pub(crate) fn eval_poseidon2( &self, builder: &mut AB, diff --git a/recursion/core/src/poseidon2_wide/air/permutation.rs b/recursion/core/src/poseidon2_wide/air/permutation.rs index 24b5d3ad6..5b93538c3 100644 --- a/recursion/core/src/poseidon2_wide/air/permutation.rs +++ b/recursion/core/src/poseidon2_wide/air/permutation.rs @@ -1,6 +1,6 @@ use std::array; -use p3_field::{AbstractField, Field}; +use p3_field::AbstractField; use sphinx_primitives::RC_16_30_U32; use crate::{ @@ -16,7 +16,7 @@ use crate::{ }, }; -impl Poseidon2WideChip { +impl Poseidon2WideChip { pub(crate) fn eval_perm( &self, builder: &mut AB, diff --git a/recursion/core/src/poseidon2_wide/air/state_transition.rs b/recursion/core/src/poseidon2_wide/air/state_transition.rs index 3c4b85994..e5c0f1792 100644 --- a/recursion/core/src/poseidon2_wide/air/state_transition.rs +++ b/recursion/core/src/poseidon2_wide/air/state_transition.rs @@ -1,7 +1,6 @@ use std::array; use p3_air::AirBuilder; -use p3_field::Field; use sphinx_core::{air::BaseAirBuilder, utils::DIGEST_SIZE}; use crate::{ @@ -16,7 +15,7 @@ use crate::{ }, }; -impl Poseidon2WideChip { +impl Poseidon2WideChip { #[allow(clippy::too_many_arguments)] pub(crate) fn eval_state_transition( &self, diff --git a/recursion/core/src/poseidon2_wide/air/syscall_params.rs b/recursion/core/src/poseidon2_wide/air/syscall_params.rs index eec046c65..dc968498b 100644 --- a/recursion/core/src/poseidon2_wide/air/syscall_params.rs +++ b/recursion/core/src/poseidon2_wide/air/syscall_params.rs @@ -1,5 +1,4 @@ use p3_air::AirBuilder; -use p3_field::Field; use sphinx_core::air::BaseAirBuilder; use crate::{ @@ -11,7 +10,7 @@ use crate::{ runtime::Opcode, }; -impl Poseidon2WideChip { +impl Poseidon2WideChip { /// Eval the syscall parameters. pub(crate) fn eval_syscall_params( &self, @@ -74,8 +73,10 @@ impl Poseidon2WideChip { let next_syscall_params = next_syscall.absorb(); absorb_syscall_builder.assert_eq(local_syscall_params.clk, next_syscall_params.clk); - absorb_syscall_builder - .assert_eq(local_syscall_params.hash_num, next_syscall_params.hash_num); + absorb_syscall_builder.assert_eq( + local_syscall_params.hash_and_absorb_num, + next_syscall_params.hash_and_absorb_num, + ); absorb_syscall_builder.assert_eq( local_syscall_params.input_ptr, next_syscall_params.input_ptr, diff --git a/recursion/core/src/poseidon2_wide/columns/control_flow.rs b/recursion/core/src/poseidon2_wide/columns/control_flow.rs index 298850c7f..a308a505c 100644 --- a/recursion/core/src/poseidon2_wide/columns/control_flow.rs +++ b/recursion/core/src/poseidon2_wide/columns/control_flow.rs @@ -15,6 +15,8 @@ pub struct ControlFlow { pub is_absorb_no_perm: T, /// Specifies if this row is for an absorb that is not the last row. pub is_absorb_not_last_row: T, + /// Specifies if this row is for an absorb that is the last row. + pub is_absorb_last_row: T, /// Specifies if this row is for finalize. pub is_finalize: T, diff --git a/recursion/core/src/poseidon2_wide/columns/opcode_workspace.rs b/recursion/core/src/poseidon2_wide/columns/opcode_workspace.rs index 2f24cadb7..af6c56a4f 100644 --- a/recursion/core/src/poseidon2_wide/columns/opcode_workspace.rs +++ b/recursion/core/src/poseidon2_wide/columns/opcode_workspace.rs @@ -88,6 +88,10 @@ pub struct AbsorbWorkspace { pub is_last_row_ending_cursor_is_seven: T, /// Is the last of an absorb and the state is not filled up (e.g. it's ending cursor is not 7). pub is_last_row_ending_cursor_not_seven: T, + + /// Used for control flow as well. + pub hash_num: T, + pub absorb_num: T, } /// Methods that are "virtual" columns (e.g. will return expressions). diff --git a/recursion/core/src/poseidon2_wide/columns/syscall_params.rs b/recursion/core/src/poseidon2_wide/columns/syscall_params.rs index 5c7f3438e..63f40e5c0 100644 --- a/recursion/core/src/poseidon2_wide/columns/syscall_params.rs +++ b/recursion/core/src/poseidon2_wide/columns/syscall_params.rs @@ -67,7 +67,7 @@ pub struct CompressParams { #[repr(C)] pub struct AbsorbParams { pub clk: T, - pub hash_num: T, + pub hash_and_absorb_num: T, pub input_ptr: T, pub input_len: T, } diff --git a/recursion/core/src/poseidon2_wide/events.rs b/recursion/core/src/poseidon2_wide/events.rs index 5d17d27fa..83e22415b 100644 --- a/recursion/core/src/poseidon2_wide/events.rs +++ b/recursion/core/src/poseidon2_wide/events.rs @@ -28,29 +28,32 @@ pub struct Poseidon2CompressEvent { #[derive(Debug, Clone)] pub struct Poseidon2AbsorbEvent { pub clk: F, - pub hash_num: F, // from a_val - pub input_addr: F, // from b_val - pub input_len: F, // from c_val + pub hash_and_absorb_num: F, // from a_val + pub input_addr: F, // from b_val + pub input_len: F, // from c_val + pub hash_num: F, + pub absorb_num: F, pub iterations: Vec>, - pub is_first_aborb: bool, } impl Poseidon2AbsorbEvent { pub(crate) fn new( clk: F, - hash_num: F, + hash_and_absorb_num: F, input_addr: F, input_len: F, - is_first_absorb: bool, + hash_num: F, + absorb_num: F, ) -> Self { Self { clk, - hash_num, + hash_and_absorb_num, input_addr, input_len, + hash_num, + absorb_num, iterations: Vec::new(), - is_first_aborb: is_first_absorb, } } } diff --git a/recursion/core/src/poseidon2_wide/mod.rs b/recursion/core/src/poseidon2_wide/mod.rs index a17db24aa..3eea1fc04 100644 --- a/recursion/core/src/poseidon2_wide/mod.rs +++ b/recursion/core/src/poseidon2_wide/mod.rs @@ -1,5 +1,3 @@ -#![allow(clippy::needless_range_loop)] - use std::borrow::Borrow; use std::borrow::BorrowMut; use std::marker::PhantomData; @@ -7,7 +5,6 @@ use std::ops::Deref; use p3_baby_bear::{MONTY_INVERSE, POSEIDON2_INTERNAL_MATRIX_DIAG_16_BABYBEAR_MONTY}; use p3_field::AbstractField; -use p3_field::Field; use p3_field::PrimeField32; pub mod air; @@ -31,14 +28,23 @@ pub const NUM_INTERNAL_ROUNDS: usize = 13; pub const NUM_ROUNDS: usize = NUM_EXTERNAL_ROUNDS + NUM_INTERNAL_ROUNDS; /// A chip that implements addition for the opcode ADD. -#[derive(Default)] -pub struct Poseidon2WideChip { +pub struct Poseidon2WideChip { pub fixed_log2_rows: Option, pub pad: bool, pub _phantom: PhantomData, } -impl<'a, F: Field, const DEGREE: usize> Poseidon2WideChip { +impl Default for Poseidon2WideChip { + fn default() -> Self { + Self { + fixed_log2_rows: Default::default(), + pad: Default::default(), + _phantom: Default::default(), + } + } +} + +impl<'a, F: Sync, const DEGREE: usize> Poseidon2WideChip { /// Transmute a row it to an immutable Poseidon2 instance. pub(crate) fn convert(row: impl Deref) -> Box + 'a> where @@ -54,17 +60,19 @@ impl<'a, F: Field, const DEGREE: usize> Poseidon2WideChip { panic!("Unsupported degree"); } } +} +impl<'a, F: Sync + Copy, const DEGREE: usize> Poseidon2WideChip { /// Transmute a row it to a mutable Poseidon2 instance. pub(crate) fn convert_mut<'b: 'a>( &self, - row: &'b mut Vec, + row: &'b mut [F], ) -> Box + 'a> { if DEGREE == 3 { - let convert: &mut Poseidon2Degree3 = row.as_mut_slice().borrow_mut(); + let convert: &mut Poseidon2Degree3 = row.borrow_mut(); Box::new(convert) } else if DEGREE == 9 || DEGREE == 17 { - let convert: &mut Poseidon2Degree9 = row.as_mut_slice().borrow_mut(); + let convert: &mut Poseidon2Degree9 = row.borrow_mut(); Box::new(convert) } else { panic!("Unsupported degree"); @@ -211,12 +219,21 @@ pub(crate) mod tests { let prev_ts = BabyBear::from_canonical_usize(i); let absorb_ts = BabyBear::from_canonical_usize(i + 1); let finalize_ts = BabyBear::from_canonical_usize(i + 2); - let hash_num = BabyBear::from_canonical_usize(i); + let hash_num = i as u32; + let absorb_num = 0_u32; + let hash_and_absorb_num = + BabyBear::from_canonical_u32(hash_num * (1 << 12) + absorb_num); let start_addr = BabyBear::from_canonical_usize(i + 1); let input_len = BabyBear::from_canonical_usize(*input_size); - let mut absorb_event = - Poseidon2AbsorbEvent::new(absorb_ts, hash_num, start_addr, input_len, true); + let mut absorb_event = Poseidon2AbsorbEvent::new( + absorb_ts, + hash_and_absorb_num, + start_addr, + input_len, + BabyBear::from_canonical_u32(hash_num), + BabyBear::from_canonical_u32(absorb_num), + ); let mut hash_state = [BabyBear::zero(); WIDTH]; let mut hash_state_cursor = 0; @@ -245,7 +262,7 @@ pub(crate) mod tests { .poseidon2_hash_events .push(Poseidon2HashEvent::Finalize(Poseidon2FinalizeEvent { clk: finalize_ts, - hash_num, + hash_num: BabyBear::from_canonical_u32(hash_num), output_ptr: start_addr, output_records: dummy_memory_access_records( state.as_slice(), diff --git a/recursion/core/src/poseidon2_wide/trace.rs b/recursion/core/src/poseidon2_wide/trace.rs index bb4f3a87d..ad6ae949c 100644 --- a/recursion/core/src/poseidon2_wide/trace.rs +++ b/recursion/core/src/poseidon2_wide/trace.rs @@ -1,11 +1,16 @@ use std::borrow::Borrow; use p3_air::BaseAir; -use p3_field::{Field, PrimeField32}; -#[allow(unused_imports)] -use p3_matrix::{dense::RowMajorMatrix, Matrix}; -use sphinx_core::air::{EventLens, WithEvents}; -use sphinx_core::{air::MachineAir, utils::pad_rows_fixed}; +use p3_field::PrimeField32; +use p3_matrix::dense::RowMajorMatrix; +use p3_maybe_rayon::prelude::IndexedParallelIterator; +use p3_maybe_rayon::prelude::ParallelIterator; +use p3_maybe_rayon::prelude::ParallelSliceMut; +use sphinx_core::air::EventLens; +use sphinx_core::air::MachineAir; +use sphinx_core::air::WithEvents; +use sphinx_core::utils::next_power_of_two; +use sphinx_core::utils::par_for_each_row; use sphinx_primitives::RC_16_30_U32; use tracing::instrument; @@ -21,7 +26,7 @@ use super::events::{Poseidon2AbsorbEvent, Poseidon2CompressEvent, Poseidon2Final use super::RATE; use super::{internal_linear_layer, Poseidon2WideChip, NUM_INTERNAL_ROUNDS}; -impl<'a, F: Field, const DEGREE: usize> WithEvents<'a> for Poseidon2WideChip { +impl<'a, F: 'a + Sync, const DEGREE: usize> WithEvents<'a> for Poseidon2WideChip { type Events = (&'a [Poseidon2HashEvent], &'a [Poseidon2CompressEvent]); } @@ -40,53 +45,69 @@ impl MachineAir for Poseidon2WideChip, ) -> RowMajorMatrix { - let mut rows = Vec::new(); + let (hash_events, compress_events) = input.events(); + // Calculate the number of rows in the trace. + let mut nb_rows = 0; + for event in hash_events.iter() { + match event { + Poseidon2HashEvent::Absorb(absorb_event) => { + nb_rows += absorb_event.iterations.len(); + } + Poseidon2HashEvent::Finalize(_) => { + nb_rows += 1; + } + } + } + nb_rows += compress_events.len() * 2; + + let nb_padded_rows = if self.pad { + next_power_of_two(nb_rows, self.fixed_log2_rows) + } else { + nb_rows + }; let num_columns = as BaseAir>::width(self); - let (hash_events, compress_events) = input.events(); + let mut rows = vec![F::zero(); nb_padded_rows * num_columns]; - // Populate the hash events. + // Populate the hash events. We do this serially, since each absorb event could populate a different + // number of rows. Also, most of the rows are populated by the compress events. + let mut row_cursor = 0; for event in hash_events { match event { Poseidon2HashEvent::Absorb(absorb_event) => { - rows.extend(self.populate_absorb_event(absorb_event, num_columns, output)); + let num_absorb_elements = absorb_event.iterations.len() * num_columns; + let absorb_rows = &mut rows[row_cursor..row_cursor + num_absorb_elements]; + self.populate_absorb_event(absorb_rows, absorb_event, num_columns, output); + row_cursor += num_absorb_elements; } Poseidon2HashEvent::Finalize(finalize_event) => { - rows.push(self.populate_finalize_event(finalize_event, num_columns)); + let finalize_row = &mut rows[row_cursor..row_cursor + num_columns]; + self.populate_finalize_event(finalize_row, finalize_event); + row_cursor += num_columns; } } } // Populate the compress events. - for event in compress_events { - rows.extend(self.populate_compress_event(event, num_columns)); - } + let compress_rows = &mut rows[row_cursor..nb_rows * num_columns]; + par_for_each_row(compress_rows, num_columns * 2, |i, rows| { + self.populate_compress_event(rows, &compress_events[i], num_columns); + }); + + // Convert the trace to a row major matrix. + let mut trace = RowMajorMatrix::new(rows, num_columns); + + let padded_rows = trace.values.par_chunks_mut(num_columns).skip(nb_rows); if self.pad { - // Pad the trace to a power of two. - pad_rows_fixed( - &mut rows, - || { - let mut padded_row = vec![F::zero(); num_columns]; - self.populate_permutation([F::zero(); WIDTH], None, &mut padded_row); - padded_row - }, - self.fixed_log2_rows, - ); + let mut dummy_row = vec![F::zero(); num_columns]; + self.populate_permutation([F::zero(); WIDTH], None, &mut dummy_row); + padded_rows.for_each(|padded_row| { + padded_row.copy_from_slice(&dummy_row); + }); } - // Convert the trace to a row major matrix. - let trace = - RowMajorMatrix::new(rows.into_iter().flatten().collect::>(), num_columns); - - #[cfg(debug_assertions)] - println!( - "poseidon2 wide trace dims is width: {:?}, height: {:?}", - trace.width(), - trace.height() - ); - trace } @@ -98,15 +119,14 @@ impl MachineAir for Poseidon2WideChip Poseidon2WideChip { pub fn populate_compress_event( &self, + rows: &mut [F], compress_event: &Poseidon2CompressEvent, num_columns: usize, - ) -> Vec> { - let mut compress_rows = Vec::new(); - - let mut input_row = vec![F::zero(); num_columns]; + ) { + let input_row = &mut rows[0..num_columns]; // Populate the control flow fields. { - let mut cols = self.convert_mut(&mut input_row); + let mut cols = self.convert_mut(input_row); let control_flow = cols.control_flow_mut(); control_flow.is_compress = F::one(); @@ -115,7 +135,7 @@ impl Poseidon2WideChip { // Populate the syscall params fields. { - let mut cols = self.convert_mut(&mut input_row); + let mut cols = self.convert_mut(input_row); let syscall_params = cols.syscall_params_mut().compress_mut(); syscall_params.clk = compress_event.clk; @@ -126,7 +146,7 @@ impl Poseidon2WideChip { // Populate the memory fields. { - let mut cols = self.convert_mut(&mut input_row); + let mut cols = self.convert_mut(input_row); let memory = cols.memory_mut(); memory.start_addr = compress_event.left; @@ -139,7 +159,7 @@ impl Poseidon2WideChip { // Populate the opcode workspace fields. { - let mut cols = self.convert_mut(&mut input_row); + let mut cols = self.convert_mut(input_row); let compress_cols = cols.opcode_workspace_mut().compress_mut(); compress_cols.start_addr = compress_event.right; @@ -154,14 +174,12 @@ impl Poseidon2WideChip { self.populate_permutation( compress_event.input, Some(compress_event.result_array), - &mut input_row, + input_row, ); - compress_rows.push(input_row); - - let mut output_row = vec![F::zero(); num_columns]; + let output_row = &mut rows[num_columns..]; { - let mut cols = self.convert_mut(&mut output_row); + let mut cols = self.convert_mut(output_row); let control_flow = cols.control_flow_mut(); control_flow.is_compress = F::one(); @@ -169,7 +187,7 @@ impl Poseidon2WideChip { } { - let mut cols = self.convert_mut(&mut output_row); + let mut cols = self.convert_mut(output_row); let syscall_cols = cols.syscall_params_mut().compress_mut(); syscall_cols.clk = compress_event.clk; @@ -179,7 +197,7 @@ impl Poseidon2WideChip { } { - let mut cols = self.convert_mut(&mut output_row); + let mut cols = self.convert_mut(output_row); let memory = cols.memory_mut(); memory.start_addr = compress_event.dst; @@ -191,7 +209,7 @@ impl Poseidon2WideChip { } { - let mut cols = self.convert_mut(&mut output_row); + let mut cols = self.convert_mut(output_row); let compress_cols = cols.opcode_workspace_mut().compress_mut(); compress_cols.start_addr = compress_event.dst + F::from_canonical_usize(WIDTH / 2); @@ -201,20 +219,16 @@ impl Poseidon2WideChip { } } - self.populate_permutation(compress_event.result_array, None, &mut output_row); - - compress_rows.push(output_row); - compress_rows + self.populate_permutation(compress_event.result_array, None, output_row); } pub fn populate_absorb_event( &self, + rows: &mut [F], absorb_event: &Poseidon2AbsorbEvent, num_columns: usize, output: &mut ExecutionRecord, - ) -> Vec> { - let mut absorb_rows = Vec::new(); - + ) { // We currently don't support an input_len of 0, since it will need special logic in the AIR. assert!(absorb_event.input_len > F::zero()); @@ -222,35 +236,41 @@ impl Poseidon2WideChip { let num_absorb_rows = absorb_event.iterations.len(); for (iter_num, absorb_iter) in absorb_event.iterations.iter().enumerate() { - let mut absorb_row = vec![F::zero(); num_columns]; + let absorb_row = &mut rows[iter_num * num_columns..(iter_num + 1) * num_columns]; let is_syscall_row = iter_num == 0; let is_last_row = iter_num == num_absorb_rows - 1; // Populate the control flow fields. { - let mut cols = self.convert_mut(&mut absorb_row); + let mut cols = self.convert_mut(absorb_row); let control_flow = cols.control_flow_mut(); control_flow.is_absorb = F::one(); control_flow.is_syscall_row = F::from_bool(is_syscall_row); control_flow.is_absorb_no_perm = F::from_bool(!absorb_iter.do_perm); control_flow.is_absorb_not_last_row = F::from_bool(!is_last_row); + control_flow.is_absorb_last_row = F::from_bool(is_last_row); } // Populate the syscall params fields. { - let mut cols = self.convert_mut(&mut absorb_row); + let mut cols = self.convert_mut(absorb_row); let syscall_params = cols.syscall_params_mut().absorb_mut(); syscall_params.clk = absorb_event.clk; - syscall_params.hash_num = absorb_event.hash_num; + syscall_params.hash_and_absorb_num = absorb_event.hash_and_absorb_num; syscall_params.input_ptr = absorb_event.input_addr; syscall_params.input_len = absorb_event.input_len; + + output.add_range_check_events(&[RangeCheckEvent::new( + RangeCheckOpcode::U16, + absorb_event.input_len.as_canonical_u32() as u16, + )]); } // Populate the memory fields. { - let mut cols = self.convert_mut(&mut absorb_row); + let mut cols = self.convert_mut(absorb_row); let memory = cols.memory_mut(); memory.start_addr = absorb_iter.start_addr; @@ -262,9 +282,20 @@ impl Poseidon2WideChip { // Populate the opcode workspace fields. { - let mut cols = self.convert_mut(&mut absorb_row); + let mut cols = self.convert_mut(absorb_row); let absorb_workspace = cols.opcode_workspace_mut().absorb_mut(); + absorb_workspace.hash_num = absorb_event.hash_num; + output.add_range_check_events(&[RangeCheckEvent::new( + RangeCheckOpcode::U16, + absorb_event.hash_num.as_canonical_u32() as u16, + )]); + absorb_workspace.absorb_num = absorb_event.absorb_num; + output.add_range_check_events(&[RangeCheckEvent::new( + RangeCheckOpcode::U12, + absorb_event.absorb_num.as_canonical_u32() as u16, + )]); + let num_remaining_rows = num_absorb_rows - 1 - iter_num; absorb_workspace.num_remaining_rows = F::from_canonical_usize(num_remaining_rows); output.add_range_check_events(&[RangeCheckEvent::new( @@ -319,11 +350,13 @@ impl Poseidon2WideChip { absorb_workspace.previous_state = absorb_iter.previous_state; absorb_workspace.state_cursor = F::from_canonical_usize(absorb_iter.state_cursor); absorb_workspace.is_first_hash_row = - F::from_bool(iter_num == 0 && absorb_event.is_first_aborb); + F::from_bool(iter_num == 0 && absorb_event.absorb_num.is_zero()); absorb_workspace.start_mem_idx_bitmap[absorb_iter.state_cursor] = F::one(); if is_last_row { absorb_workspace.end_mem_idx_bitmap[last_row_ending_cursor] = F::one(); + } else { + absorb_workspace.end_mem_idx_bitmap[7] = F::one(); } } @@ -335,25 +368,19 @@ impl Poseidon2WideChip { } else { None }, - &mut absorb_row, + absorb_row, ); - - absorb_rows.push(absorb_row); } - - absorb_rows } pub fn populate_finalize_event( &self, + row: &mut [F], finalize_event: &Poseidon2FinalizeEvent, - num_columns: usize, - ) -> Vec { - let mut finalize_row = vec![F::zero(); num_columns]; - + ) { // Populate the control flow fields. { - let mut cols = self.convert_mut(&mut finalize_row); + let mut cols = self.convert_mut(row); let control_flow = cols.control_flow_mut(); control_flow.is_finalize = F::one(); control_flow.is_syscall_row = F::one(); @@ -361,7 +388,7 @@ impl Poseidon2WideChip { // Populate the syscall params fields. { - let mut cols = self.convert_mut(&mut finalize_row); + let mut cols = self.convert_mut(row); let syscall_params = cols.syscall_params_mut().finalize_mut(); syscall_params.clk = finalize_event.clk; @@ -371,7 +398,7 @@ impl Poseidon2WideChip { // Populate the memory fields. { - let mut cols = self.convert_mut(&mut finalize_row); + let mut cols = self.convert_mut(row); let memory = cols.memory_mut(); memory.start_addr = finalize_event.output_ptr; @@ -383,7 +410,7 @@ impl Poseidon2WideChip { // Populate the opcode workspace fields. { - let mut cols = self.convert_mut(&mut finalize_row); + let mut cols = self.convert_mut(row); let finalize_workspace = cols.opcode_workspace_mut().finalize_mut(); finalize_workspace.previous_state = finalize_event.previous_state; @@ -402,10 +429,8 @@ impl Poseidon2WideChip { } else { None }, - &mut finalize_row, + row, ); - - finalize_row } pub fn populate_permutation( @@ -482,6 +507,7 @@ impl Poseidon2WideChip { r + NUM_INTERNAL_ROUNDS }; let mut add_rc = *round_state; + #[allow(clippy::needless_range_loop)] for i in 0..WIDTH { add_rc[i] += F::from_wrapped_u32(RC_16_30_U32[round][i]); } diff --git a/recursion/core/src/runtime/mod.rs b/recursion/core/src/runtime/mod.rs index 59b5792ac..03ecc9ba6 100644 --- a/recursion/core/src/runtime/mod.rs +++ b/recursion/core/src/runtime/mod.rs @@ -4,9 +4,8 @@ mod program; mod record; mod utils; -use std::array; use std::collections::VecDeque; -use std::process::exit; +use std::{array, fmt}; use std::{marker::PhantomData, sync::Arc}; use hashbrown::HashMap; @@ -141,6 +140,21 @@ pub struct Runtime, Diffusion> { _marker: PhantomData, } +#[derive(Debug)] +pub enum RuntimeError { + Trap(String), +} + +impl fmt::Display for RuntimeError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + RuntimeError::Trap(msg) => write!(f, "TRAP encountered: {}", msg), + } + } +} + +impl std::error::Error for RuntimeError {} + impl, Diffusion> Runtime where Poseidon2< @@ -431,7 +445,7 @@ where (a_val, b_val, c_val) } - pub fn run(&mut self) { + pub fn run(&mut self) -> Result<(), RuntimeError> { let early_exit_ts = std::env::var("RECURSION_EARLY_EXIT_TS") .map_or(usize::MAX, |ts: String| ts.parse().unwrap()); while self.pc < F::from_canonical_u32(self.program.instructions.len() as u32) { @@ -620,20 +634,19 @@ where let trace = self.program.traces[trap_pc].clone(); if let Some(mut trace) = trace { trace.resolve(); - panic!("TRAP encountered. Backtrace:\n{:?}", trace); + return Err(RuntimeError::Trap(format!("Backtrace:\n{:?}", trace))); } else { for nearby_pc in (0..trap_pc).rev() { let trace = self.program.traces[nearby_pc].clone(); if let Some(mut trace) = trace { trace.resolve(); - eprintln!( + return Err(RuntimeError::Trap(format!( "TRAP encountered at pc={}. Nearest trace at pc={}: {:?}", trap_pc, nearby_pc, trace - ); - exit(1); + ))); } } - panic!("TRAP encountered. No backtrace available"); + return Err(RuntimeError::Trap("No backtrace available".to_string())); } } Opcode::HALT => { @@ -722,23 +735,32 @@ where self.nb_poseidons += 1; let (a_val, b_val, c_val) = self.all_rr(&instruction); - let hash_num = a_val[0]; + let hash_and_absorb_num = a_val[0]; let start_addr = b_val[0]; let input_len = c_val[0]; let timestamp = self.clk; + let two_pow_12 = 1 << 12; + + let hash_and_absorb_num_u32 = hash_and_absorb_num.as_canonical_u32(); + let hash_num = F::from_canonical_u32(hash_and_absorb_num_u32 / two_pow_12); + let absorb_num = F::from_canonical_u32(hash_and_absorb_num_u32 % two_pow_12); + + // Double check that hash_num is [0, 2^16 - 1] and absorb_num is [0, 2^12 - 1] since + // that is what the AIR will enforce. + assert!(hash_num.as_canonical_u32() < 1 << 16); + assert!(absorb_num.as_canonical_u32() < 1 << 12); + // We currently don't support an input_len of 0, since it will need special logic in the AIR. assert!(input_len > F::zero()); - let is_first_absorb = self.p2_current_hash_num.is_none() - || self.p2_current_hash_num.unwrap() != hash_num; - let mut absorb_event = Poseidon2AbsorbEvent::new( timestamp, - hash_num, + hash_and_absorb_num, start_addr, input_len, - is_first_absorb, + hash_num, + absorb_num, ); let memory_records: Vec> = (0..input_len.as_canonical_u32()) @@ -1079,6 +1101,8 @@ where self.record.last_memory_record.last().unwrap().0, false, ); + + Ok(()) } } @@ -1090,7 +1114,7 @@ mod tests { utils::BabyBearPoseidon2, }; - use super::{Instruction, Opcode, RecursionProgram, Runtime}; + use super::{Instruction, Opcode, RecursionProgram, Runtime, RuntimeError}; type SC = BabyBearPoseidon2; type F = ::Val; @@ -1098,7 +1122,7 @@ mod tests { type A = RiscvAir; #[test] - fn test_witness() { + fn test_witness_success() { let zero = F::zero(); let zero_block = [F::zero(); 4]; let program = RecursionProgram { @@ -1132,6 +1156,41 @@ mod tests { let mut runtime = Runtime::::new(&program, machine.config().perm.clone()); runtime.witness_stream = vec![vec![F::two().into(), F::two().into(), F::two().into()]].into(); - runtime.run(); + + let result = runtime.run(); + assert!(result.is_ok(), "Expected run to complete successfully"); + } + + #[test] + fn test_witness_trap_error() { + let zero = F::zero(); + let zero_block = [F::zero(); 4]; + let trap_program = RecursionProgram { + traces: vec![None], // None trace for the TRAP instruction + instructions: vec![Instruction::new( + Opcode::TRAP, + zero, + zero_block, + zero_block, + zero, + zero, + false, + false, + "".to_string(), + )], + }; + let machine = A::machine(SC::default()); + let mut trap_runtime = + Runtime::::new(&trap_program, machine.config().perm.clone()); + + let trap_result = trap_runtime.run(); + assert!( + trap_result.is_err(), + "Expected run to return an error due to TRAP instruction" + ); + + if let Err(RuntimeError::Trap(msg)) = trap_result { + println!("Caught expected trap error: {}", msg); + } } } diff --git a/recursion/core/src/runtime/record.rs b/recursion/core/src/runtime/record.rs index 5a1cbf113..4d2755871 100644 --- a/recursion/core/src/runtime/record.rs +++ b/recursion/core/src/runtime/record.rs @@ -1,10 +1,12 @@ use hashbrown::HashMap; -use sphinx_core::air::EventLens; +use sphinx_core::air::{EventLens, PublicValues, Word}; +use sphinx_core::utils::SphinxCoreOpts; use std::array; +use std::borrow::Borrow; use std::sync::Arc; use p3_field::{AbstractField, PrimeField32}; -use sphinx_core::stark::{Indexed, MachineRecord, PROOF_MAX_NUM_PVS}; +use sphinx_core::stark::{MachineRecord, PublicValued, PROOF_MAX_NUM_PVS}; use super::RecursionProgram; use crate::air::Block; @@ -45,26 +47,26 @@ impl ExecutionRecord { } } -impl Indexed for ExecutionRecord { - fn index(&self) -> u32 { - 0 +impl PublicValued for ExecutionRecord { + fn public_values(&self) -> PublicValues, F> { + let pvs: Vec = MachineRecord::public_values::(self); + let pv: &PublicValues, F> = Borrow::borrow(&pvs[..]); + pv.clone() } } impl MachineRecord for ExecutionRecord { - type Config = (); - - fn set_index(&mut self, _: u32) {} + type Config = SphinxCoreOpts; fn stats(&self) -> HashMap { let mut stats = HashMap::new(); stats.insert("cpu_events".to_string(), self.cpu_events.len()); stats.insert( - "poseidon2_events".to_string(), + "poseidon2_compress_events".to_string(), self.poseidon2_compress_events.len(), ); stats.insert( - "poseidon2_events".to_string(), + "poseidon2_hash_events".to_string(), self.poseidon2_hash_events.len(), ); stats.insert("fri_fold_events".to_string(), self.fri_fold_events.len()); @@ -96,10 +98,6 @@ impl MachineRecord for ExecutionRecord { } } - fn shard(self, _: &Self::Config) -> Vec { - vec![self] - } - fn public_values(&self) -> Vec { let ret: [T; PROOF_MAX_NUM_PVS] = array::from_fn(|i| { if i < self.public_values.len() { diff --git a/recursion/core/src/stark/mod.rs b/recursion/core/src/stark/mod.rs index 32db6eb32..7f777fdbb 100644 --- a/recursion/core/src/stark/mod.rs +++ b/recursion/core/src/stark/mod.rs @@ -131,7 +131,7 @@ impl, const DEGREE: usize> RecursionAi _phantom: PhantomData, }))) .chain(once(RecursionAir::MemoryGlobal(MemoryGlobalChip { - fixed_log2_rows: Some(20), + fixed_log2_rows: Some(21), _phantom: PhantomData, }))) .chain(once(RecursionAir::Multi(MultiChip { diff --git a/recursion/core/src/stark/utils.rs b/recursion/core/src/stark/utils.rs index cbd36a5eb..810b58556 100644 --- a/recursion/core/src/stark/utils.rs +++ b/recursion/core/src/stark/utils.rs @@ -6,7 +6,7 @@ use sphinx_core::utils::BabyBearPoseidon2; use crate::air::Block; use crate::runtime::RecursionProgram; use crate::runtime::Runtime; -use crate::stark::RecursionAir; +use crate::stark::RecursionAirWideDeg3; use crate::stark::RecursionAirWideDeg9; use p3_field::PrimeField32; use sphinx_core::utils::run_test_machine; @@ -37,17 +37,26 @@ pub fn run_test_recursion( if witness.is_some() { runtime.witness_stream = witness.unwrap(); } - runtime.run(); - println!( - "The program executed successfully, number of cycles: {}", - runtime.clk.as_canonical_u32() / 4 - ); + + match runtime.run() { + Ok(_) => { + println!( + "The program executed successfully, number of cycles: {}", + runtime.clk.as_canonical_u32() / 4 + ); + } + Err(e) => { + eprintln!("Runtime error: {:?}", e); + return; + } + } + + let records = vec![runtime.record]; if test_config == TestConfig::All || test_config == TestConfig::WideDeg3 { - let machine = RecursionAir::<_, 3>::machine(BabyBearPoseidon2::default()); + let machine = RecursionAirWideDeg3::machine(BabyBearPoseidon2::default()); let (pk, vk) = machine.setup(program); - let record = runtime.record.clone(); - let result = run_test_machine(record, &machine, &pk, &vk); + let result = run_test_machine(records.clone(), machine, &pk, &vk); if let Err(e) = result { panic!("Verification failed: {:?}", e); } @@ -56,8 +65,7 @@ pub fn run_test_recursion( if test_config == TestConfig::All || test_config == TestConfig::SkinnyDeg7 { let machine = RecursionAirWideDeg9::machine(BabyBearPoseidon2::compressed()); let (pk, vk) = machine.setup(program); - let record = runtime.record.clone(); - let result = run_test_machine(record, &machine, &pk, &vk); + let result = run_test_machine(records.clone(), machine, &pk, &vk); if let Err(e) = result { panic!("Verification failed: {:?}", e); } @@ -66,8 +74,7 @@ pub fn run_test_recursion( if test_config == TestConfig::All || test_config == TestConfig::WideDeg17Wrap { let machine = RecursionAirWideDeg9::wrap_machine(BabyBearPoseidon2::compressed()); let (pk, vk) = machine.setup(program); - let record = runtime.record.clone(); - let result = run_test_machine(record, &machine, &pk, &vk); + let result = run_test_machine(records.clone(), machine, &pk, &vk); if let Err(e) = result { panic!("Verification failed: {:?}", e); } diff --git a/recursion/gnark-cli/Cargo.toml b/recursion/gnark-cli/Cargo.toml index cd6fe2647..62a9bed02 100644 --- a/recursion/gnark-cli/Cargo.toml +++ b/recursion/gnark-cli/Cargo.toml @@ -1,10 +1,10 @@ [workspace] [package] -name = "sp1-recursion-gnark-cli" +name = "sphinx-recursion-gnark-cli" version = "0.1.0" edition = "2021" [dependencies] -sp1-recursion-gnark-ffi = { path = "../gnark-ffi", features = ["native"] } +sphinx-recursion-gnark-ffi = { path = "../gnark-ffi", features = ["native"] } clap = { version = "4.3.8", features = ["derive"] } bincode = "1.3.3" diff --git a/recursion/gnark-ffi/assets/ISphinxVerifier.txt b/recursion/gnark-ffi/assets/ISphinxVerifier.txt deleted file mode 100644 index bb1f4daec..000000000 --- a/recursion/gnark-ffi/assets/ISphinxVerifier.txt +++ /dev/null @@ -1,29 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; - -/// @title Sphinx Verifier Interface -/// @author Lurk & Succinct Labs -/// @notice This contract is the interface for the Sphinx Verifier. -interface ISphinxVerifier { - /// @notice Returns the version of Sphinx this verifier corresponds to. - function VERSION() external pure returns (string memory); - - /// @notice Returns the hash of the verification key. - function VKEY_HASH() external pure returns (bytes32); - - /// @notice Verifies a proof with given public values and vkey. - /// @param vkey The verification key for the RISC-V program. - /// @param publicValues The public values encoded as bytes. - /// @param proofBytes The proof of the program execution the Sphinx zkVM encoded as bytes. - function verifyProof( - bytes32 vkey, - bytes calldata publicValues, - bytes calldata proofBytes - ) external view; -} - -interface ISphinxVerifierWithHash is ISphinxVerifier { - /// @notice Returns the SHA-256 hash of the verifier. - /// @dev This is automatically generated by taking hash of the VKey file. - function VERIFIER_HASH() external pure returns (bytes32); -} \ No newline at end of file diff --git a/recursion/gnark-ffi/assets/SphinxMockVerifier.txt b/recursion/gnark-ffi/assets/SphinxMockVerifier.txt deleted file mode 100644 index bf4fc98d8..000000000 --- a/recursion/gnark-ffi/assets/SphinxMockVerifier.txt +++ /dev/null @@ -1,26 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.19; - -import {ISphinxVerifier} from "./ISphinxVerifier.sol"; - -/// @title Sphinx Mock Verifier -/// @notice This contracts implements a Mock solidity verifier for Sphinx. -contract SphinxMockVerifier is ISphinxVerifier { - function VERSION() external pure returns (string memory) { - return "{SPHINX_CIRCUIT_VERSION}"; - } - - function VKEY_HASH() external pure returns (bytes32) { - return bytes32(0); - } - - /// @notice Verifies a mock proof with given public values and vkey. - /// @param proofBytes The proof of the program execution the Sphinx zkVM encoded as bytes. - function verifyProof( - bytes32, - bytes memory, - bytes memory proofBytes - ) external pure { - assert(proofBytes.length == 0); - } -} diff --git a/recursion/gnark-ffi/build.rs b/recursion/gnark-ffi/build.rs index 15d1598b9..93d54d8cf 100644 --- a/recursion/gnark-ffi/build.rs +++ b/recursion/gnark-ffi/build.rs @@ -27,10 +27,20 @@ fn main() { return; } + // Detect current OS and set GOOS accordingly + let goos = match env::consts::OS { + "macos" => "darwin", + "linux" => "linux", + "windows" => "windows", + _ => panic!("Unsupported OS"), + }; + + // Run the go build command let status = Command::new("go") .current_dir("go") .env("CGO_ENABLED", "1") + .env("GOOS", goos) // Set GOOS based on the current OS .args([ "build", "-o", diff --git a/recursion/gnark-ffi/go/sp1/babybear/babybear.go b/recursion/gnark-ffi/go/sp1/babybear/babybear.go index 74219c428..066edd265 100644 --- a/recursion/gnark-ffi/go/sp1/babybear/babybear.go +++ b/recursion/gnark-ffi/go/sp1/babybear/babybear.go @@ -16,9 +16,10 @@ import ( var modulus = new(big.Int).SetUint64(2013265921) func init() { - solver.RegisterHint(invFHint) - solver.RegisterHint(invEHint) - solver.RegisterHint(reduceHint) + // These functions must be public so Gnark's hint system can access them. + solver.RegisterHint(InvFHint) + solver.RegisterHint(InvEHint) + solver.RegisterHint(ReduceHint) } type Variable struct { @@ -103,7 +104,7 @@ func (c *Chip) negF(a Variable) Variable { func (c *Chip) invF(in Variable) Variable { in = c.ReduceSlow(in) - result, err := c.api.Compiler().NewHint(invFHint, 1, in.Value) + result, err := c.api.Compiler().NewHint(InvFHint, 1, in.Value) if err != nil { panic(err) } @@ -215,7 +216,7 @@ func (c *Chip) InvE(in ExtensionVariable) ExtensionVariable { in.Value[1] = c.ReduceSlow(in.Value[1]) in.Value[2] = c.ReduceSlow(in.Value[2]) in.Value[3] = c.ReduceSlow(in.Value[3]) - result, err := c.api.Compiler().NewHint(invEHint, 4, in.Value[0].Value, in.Value[1].Value, in.Value[2].Value, in.Value[3].Value) + result, err := c.api.Compiler().NewHint(InvEHint, 4, in.Value[0].Value, in.Value[1].Value, in.Value[2].Value, in.Value[3].Value) if err != nil { panic(err) } @@ -274,7 +275,7 @@ func (p *Chip) ReduceSlow(x Variable) Variable { } func (p *Chip) reduceWithMaxBits(x frontend.Variable, maxNbBits uint64) frontend.Variable { - result, err := p.api.Compiler().NewHint(reduceHint, 2, x) + result, err := p.api.Compiler().NewHint(ReduceHint, 2, x) if err != nil { panic(err) } @@ -291,7 +292,7 @@ func (p *Chip) reduceWithMaxBits(x frontend.Variable, maxNbBits uint64) frontend } // The hint used to compute Reduce. -func reduceHint(_ *big.Int, inputs []*big.Int, results []*big.Int) error { +func ReduceHint(_ *big.Int, inputs []*big.Int, results []*big.Int) error { if len(inputs) != 1 { panic("reduceHint expects 1 input operand") } @@ -303,14 +304,14 @@ func reduceHint(_ *big.Int, inputs []*big.Int, results []*big.Int) error { return nil } -func invFHint(_ *big.Int, inputs []*big.Int, results []*big.Int) error { +func InvFHint(_ *big.Int, inputs []*big.Int, results []*big.Int) error { a := C.uint(inputs[0].Uint64()) ainv := C.babybearinv(a) results[0].SetUint64(uint64(ainv)) return nil } -func invEHint(_ *big.Int, inputs []*big.Int, results []*big.Int) error { +func InvEHint(_ *big.Int, inputs []*big.Int, results []*big.Int) error { a := C.uint(inputs[0].Uint64()) b := C.uint(inputs[1].Uint64()) c := C.uint(inputs[2].Uint64()) diff --git a/recursion/gnark-ffi/go/sp1/build.go b/recursion/gnark-ffi/go/sp1/build.go index 5531b7ebb..9beb8ef29 100644 --- a/recursion/gnark-ffi/go/sp1/build.go +++ b/recursion/gnark-ffi/go/sp1/build.go @@ -149,14 +149,20 @@ func Build(dataDir string) { } // Create the build directory. - os.MkdirAll(dataDir, 0755) + err = os.MkdirAll(dataDir, 0755) + if err != nil { + panic(err) + } // Write the solidity verifier. solidityVerifierFile, err := os.Create(dataDir + "/" + verifierContractPath) if err != nil { panic(err) } - vk.ExportSolidity(solidityVerifierFile) + err = vk.ExportSolidity(solidityVerifierFile) + if err != nil { + panic(err) + } defer solidityVerifierFile.Close() // Write the R1CS. diff --git a/recursion/gnark-ffi/go/sp1/prove.go b/recursion/gnark-ffi/go/sp1/prove.go index 7260f99ff..332d73e76 100644 --- a/recursion/gnark-ffi/go/sp1/prove.go +++ b/recursion/gnark-ffi/go/sp1/prove.go @@ -23,7 +23,9 @@ func Prove(dataDir string, witnessPath string) Proof { panic(err) } scs := plonk.NewCS(ecc.BN254) - scs.ReadFrom(scsFile) + if _, err := scs.ReadFrom(scsFile); err != nil { + panic(err) + } defer scsFile.Close() // Read the proving key. @@ -33,7 +35,10 @@ func Prove(dataDir string, witnessPath string) Proof { } pk := plonk.NewProvingKey(ecc.BN254) bufReader := bufio.NewReaderSize(pkFile, 1024*1024) - pk.UnsafeReadFrom(bufReader) + _, err = pk.UnsafeReadFrom(bufReader) + if err != nil { + panic(err) + } defer pkFile.Close() // Read the verifier key. @@ -42,7 +47,9 @@ func Prove(dataDir string, witnessPath string) Proof { panic(err) } vk := plonk.NewVerifyingKey(ecc.BN254) - vk.ReadFrom(vkFile) + if _, err := vk.ReadFrom(vkFile); err != nil { + panic(err) + } defer vkFile.Close() // Read the file. diff --git a/recursion/gnark-ffi/go/sp1/trusted_setup/trusted_setup.go b/recursion/gnark-ffi/go/sp1/trusted_setup/trusted_setup.go index fcafee173..ff9088980 100644 --- a/recursion/gnark-ffi/go/sp1/trusted_setup/trusted_setup.go +++ b/recursion/gnark-ffi/go/sp1/trusted_setup/trusted_setup.go @@ -17,7 +17,10 @@ import ( func sanityCheck(srs *kzg_bn254.SRS) { // we can now use the SRS to verify a proof // create a polynomial - f := randomPolynomial(60) + f, err := randomPolynomial(60) + if err != nil { + log.Fatal(err) + } // commit the polynomial digest, err := kzg_bn254.Commit(f, srs.Pk) @@ -27,7 +30,9 @@ func sanityCheck(srs *kzg_bn254.SRS) { // compute opening proof at a random point var point fr.Element - point.SetString("4321") + if _, err := point.SetString("4321"); err != nil { + log.Fatal(err) + } proof, err := kzg_bn254.Open(f, point, srs.Pk) if err != nil { log.Fatal(err) @@ -46,12 +51,14 @@ func sanityCheck(srs *kzg_bn254.SRS) { } } -func randomPolynomial(size int) []fr.Element { +func randomPolynomial(size int) ([]fr.Element, error) { f := make([]fr.Element, size) for i := 0; i < size; i++ { - f[i].SetRandom() + if _, err := f[i].SetRandom(); err != nil { + return nil, err + } } - return f + return f, nil } // eval returns p(point) where p is interpreted as a polynomial diff --git a/recursion/gnark-ffi/go/sp1/verify.go b/recursion/gnark-ffi/go/sp1/verify.go index 27c459c99..4620ad52f 100644 --- a/recursion/gnark-ffi/go/sp1/verify.go +++ b/recursion/gnark-ffi/go/sp1/verify.go @@ -33,7 +33,9 @@ func Verify(verifyCmdDataDir string, verifyCmdProof string, verifyCmdVkeyHash st panic(err) } vk := plonk.NewVerifyingKey(ecc.BN254) - vk.ReadFrom(vkFile) + if _, err := vk.ReadFrom(vkFile); err != nil { + panic(err) + } // Compute the public witness. circuit := Circuit{ diff --git a/recursion/gnark-ffi/src/plonk_bn254.rs b/recursion/gnark-ffi/src/plonk_bn254.rs index 4bc85af5e..5c794585b 100644 --- a/recursion/gnark-ffi/src/plonk_bn254.rs +++ b/recursion/gnark-ffi/src/plonk_bn254.rs @@ -77,34 +77,18 @@ impl PlonkBn254Prover { build_plonk_bn254(build_dir.to_str().unwrap()); // Write the corresponding asset files to the build dir. - let sphinx_mock_verifier_path = build_dir.join("SphinxMockVerifier.sol"); - let sphinx_mock_verifier_str = include_str!("../assets/SphinxMockVerifier.txt") - .replace("{SPHINX_CIRCUIT_VERSION}", SPHINX_CIRCUIT_VERSION); - let mut mock_verifier_file = File::create(sphinx_mock_verifier_path).unwrap(); - mock_verifier_file - .write_all(sphinx_mock_verifier_str.as_bytes()) - .unwrap(); - let sphinx_verifier_path = build_dir.join("SphinxVerifier.sol"); let vkey_hash = Self::get_vkey_hash(build_dir); let sphinx_verifier_str = include_str!("../assets/SphinxVerifier.txt") .replace("{SPHINX_CIRCUIT_VERSION}", SPHINX_CIRCUIT_VERSION) .replace( - "{VKEY_HASH}", + "{VERIFIER_HASH}", format!("0x{}", hex::encode(vkey_hash)).as_str(), ); let mut sphinx_verifier_file = File::create(sphinx_verifier_path).unwrap(); sphinx_verifier_file .write_all(sphinx_verifier_str.as_bytes()) .unwrap(); - - let interface_sphinx_verifier_path = build_dir.join("ISphinxVerifier.sol"); - let interface_sphinx_verifier_str = include_str!("../assets/ISphinxVerifier.txt"); - let mut interface_sphinx_verifier_file = - File::create(interface_sphinx_verifier_path).unwrap(); - interface_sphinx_verifier_file - .write_all(interface_sphinx_verifier_str.as_bytes()) - .unwrap(); } /// Generates a PLONK proof given a witness. diff --git a/recursion/program/Cargo.toml b/recursion/program/Cargo.toml index a3f38f1d3..87a9addaf 100644 --- a/recursion/program/Cargo.toml +++ b/recursion/program/Cargo.toml @@ -23,6 +23,7 @@ sphinx-primitives = { path = "../../primitives" } sphinx-recursion-core = { path = "../core" } sphinx-recursion-compiler = { path = "../compiler" } sphinx-core = { path = "../../core" } +stacker = { workspace = true } itertools = { workspace = true } serde = { workspace = true, features = ["derive"] } rand = { workspace = true } diff --git a/recursion/program/src/constraints.rs b/recursion/program/src/constraints.rs index 5554fd496..e4df25f89 100644 --- a/recursion/program/src/constraints.rs +++ b/recursion/program/src/constraints.rs @@ -161,6 +161,7 @@ mod tests { use p3_field::PrimeField32; use rand::{thread_rng, Rng}; use serde::{de::DeserializeOwned, Serialize}; + use sphinx_core::stark::DefaultProver; use sphinx_core::{ io::SphinxStdin, runtime::Program, @@ -170,6 +171,7 @@ mod tests { }, utils::{BabyBearPoseidon2, SphinxCoreOpts}, }; + use sphinx_recursion_core::stark::utils::{run_test_recursion, TestConfig}; use sphinx_recursion_compiler::{asm::AsmBuilder, ir::Felt, prelude::ExtConst}; @@ -279,7 +281,7 @@ mod tests { let machine = A::machine(SC::default()); let (_, vk) = machine.setup(&Program::from(elf)); let mut challenger = machine.config().challenger(); - let (proof, _) = sphinx_core::utils::prove( + let (proof, _) = sphinx_core::utils::prove::<_, DefaultProver<_, _>>( &Program::from(elf), &SphinxStdin::new(), SC::default(), diff --git a/recursion/program/src/fri/two_adic_pcs.rs b/recursion/program/src/fri/two_adic_pcs.rs index 046cca785..b653b3efa 100644 --- a/recursion/program/src/fri/two_adic_pcs.rs +++ b/recursion/program/src/fri/two_adic_pcs.rs @@ -32,7 +32,7 @@ pub fn verify_two_adic_pcs( let g = builder.generator(); let log_blowup = config.log_blowup; - let blowup = config.log_blowup; + let blowup = config.blowup; let alpha = challenger.sample_ext(builder); builder.cycle_tracker("stage-d-1-verify-shape-and-sample-challenges"); diff --git a/recursion/program/src/hints.rs b/recursion/program/src/hints.rs index 4dad66cdf..d068157a4 100644 --- a/recursion/program/src/hints.rs +++ b/recursion/program/src/hints.rs @@ -517,7 +517,6 @@ impl<'a, A: MachineAir> Hintable let initial_reconstruct_challenger = DuplexChallenger::::read(builder); let is_complete = builder.hint_var(); - let total_core_shards = builder.hint_var(); SphinxRecursionMemoryLayoutVariable { vk, @@ -525,7 +524,6 @@ impl<'a, A: MachineAir> Hintable leaf_challenger, initial_reconstruct_challenger, is_complete, - total_core_shards, } } @@ -545,7 +543,6 @@ impl<'a, A: MachineAir> Hintable stream.extend(self.leaf_challenger.write()); stream.extend(self.initial_reconstruct_challenger.write()); stream.extend(usize::from(self.is_complete).write()); - stream.extend(self.total_core_shards.write()); stream } @@ -561,14 +558,12 @@ impl<'a, A: MachineAir> Hintable let shard_proofs = Vec::>::read(builder); let kinds = Vec::::read(builder); let is_complete = builder.hint_var(); - let total_core_shards = builder.hint_var(); SphinxReduceMemoryLayoutVariable { compress_vk, shard_proofs, kinds, is_complete, - total_core_shards, } } @@ -592,7 +587,6 @@ impl<'a, A: MachineAir> Hintable stream.extend(proof_hints.write()); stream.extend(kinds.write()); stream.extend(usize::from(self.is_complete).write()); - stream.extend(self.total_core_shards.write()); stream } @@ -637,7 +631,9 @@ impl<'a, A: MachineAir> Hintable let leaf_challenger = DuplexChallenger::::read(builder); let end_pc = InnerVal::read(builder); let end_shard = InnerVal::read(builder); - let total_core_shards = builder.hint_var(); + let end_execution_shard = InnerVal::read(builder); + let init_addr_bits = Vec::::read(builder); + let finalize_addr_bits = Vec::::read(builder); SphinxDeferredMemoryLayoutVariable { compress_vk, @@ -650,7 +646,9 @@ impl<'a, A: MachineAir> Hintable leaf_challenger, end_pc, end_shard, - total_core_shards, + end_execution_shard, + init_addr_bits, + finalize_addr_bits, } } @@ -686,7 +684,9 @@ impl<'a, A: MachineAir> Hintable stream.extend(self.leaf_challenger.write()); stream.extend(self.end_pc.write()); stream.extend(self.end_shard.write()); - stream.extend(self.total_core_shards.write()); + stream.extend(self.end_execution_shard.write()); + stream.extend(self.init_addr_bits.to_vec().write()); + stream.extend(self.finalize_addr_bits.to_vec().write()); stream } diff --git a/recursion/program/src/machine/compress.rs b/recursion/program/src/machine/compress.rs index b284d7190..a5c8a121b 100644 --- a/recursion/program/src/machine/compress.rs +++ b/recursion/program/src/machine/compress.rs @@ -9,7 +9,7 @@ use p3_baby_bear::BabyBear; use p3_commit::TwoAdicMultiplicativeCoset; use p3_field::{AbstractField, PrimeField32, TwoAdicField}; use serde::{Deserialize, Serialize}; -use sphinx_core::air::MachineAir; +use sphinx_core::air::{MachineAir, WORD_SIZE}; use sphinx_core::air::{Word, POSEIDON_NUM_WORDS, PV_DIGEST_NUM_WORDS}; use sphinx_core::stark::StarkMachine; use sphinx_core::stark::{Com, ShardProof, StarkGenericConfig, StarkVerifyingKey}; @@ -30,8 +30,8 @@ use crate::stark::{RecursiveVerifierConstraintFolder, StarkVerifier}; use crate::types::ShardProofVariable; use crate::types::VerifyingKeyVariable; use crate::utils::{ - assert_challenger_eq_pv, assign_challenger_from_pv, const_fri_config, - get_challenger_public_values, hash_vkey, var2felt, + assert_challenger_eq_pv, assign_challenger_from_pv, const_fri_config, felt2var, + get_challenger_public_values, hash_vkey, }; use super::utils::{commit_public_values, proof_data_from_vk, verify_public_values_hash}; @@ -60,7 +60,6 @@ pub struct SphinxReduceMemoryLayout<'a, SC: StarkGenericConfig, A: MachineAir>, pub is_complete: bool, pub kinds: Vec, - pub total_core_shards: usize, } #[derive(DslVariable, Clone)] @@ -69,7 +68,6 @@ pub struct SphinxReduceMemoryLayoutVariable { pub shard_proofs: Array>, pub kinds: Array>, pub is_complete: Var, - pub total_core_shards: Var, } impl SphinxCompressVerifier @@ -141,16 +139,13 @@ where shard_proofs, kinds, is_complete, - total_core_shards, } = input; - let total_core_shards_felt = var2felt(builder, total_core_shards); // Initialize the values for the aggregated public output. let mut reduce_public_values_stream: Vec> = (0..RECURSIVE_PROOF_NUM_PV_ELTS) .map(|_| builder.uninit()) .collect(); - let reduce_public_values: &mut RecursionPublicValues<_> = reduce_public_values_stream.as_mut_slice().borrow_mut(); @@ -162,6 +157,7 @@ where // Assert that there is at least one proof. builder.assert_usize_ne(shard_proofs.len(), 0); + // Assert that the number of proofs is equal to the number of kinds. builder.assert_usize_eq(shard_proofs.len(), kinds.len()); @@ -169,6 +165,7 @@ where let sphinx_vk_digest: [Felt<_>; DIGEST_SIZE] = array::from_fn(|_| builder.uninit()); let pc: Felt<_> = builder.uninit(); let shard: Felt<_> = builder.uninit(); + let execution_shard: Felt<_> = builder.uninit(); let mut initial_reconstruct_challenger = DuplexChallengerVariable::new(builder); let mut reconstruct_challenger = DuplexChallengerVariable::new(builder); let mut leaf_challenger = DuplexChallengerVariable::new(builder); @@ -179,6 +176,8 @@ where let reconstruct_deferred_digest: [Felt<_>; POSEIDON_NUM_WORDS] = array::from_fn(|_| builder.uninit()); let cumulative_sum: [Felt<_>; D] = array::from_fn(|_| builder.eval(C::F::zero())); + let init_addr_bits: [Felt<_>; 32] = array::from_fn(|_| builder.uninit()); + let finalize_addr_bits: [Felt<_>; 32] = array::from_fn(|_| builder.uninit()); // Collect verifying keys for each kind of program. let recursive_vk_variable = proof_data_from_vk(builder, recursive_vk, machine); @@ -193,6 +192,7 @@ where builder.range(0, shard_proofs.len()).for_each(|i, builder| { // Load the proof. let proof = builder.get(&shard_proofs, i); + // Get the kind of proof we are verifying. let kind = builder.get(&kinds, i); @@ -200,6 +200,7 @@ where // Initialize values for verifying key and proof data. let vk: VerifyingKeyVariable<_> = builder.uninit(); + // Set the correct value given the value of kind, and assert it must be one of the // valid values. We can do that by nested `if-else` statements. builder.if_eq(kind, core_kind).then_or_else( @@ -217,8 +218,7 @@ where builder.assign(&vk, compress_vk.clone()); }, |builder| { - // If the kind is not one of the valid values, raise - // an error. + // If the kind is not one of the valid values, raise an error. builder.error(); }, ); @@ -231,17 +231,19 @@ where // Prepare a challenger. let mut challenger = DuplexChallengerVariable::new(builder); + // Observe the vk and start pc. challenger.observe(builder, vk.commitment.clone()); challenger.observe(builder, vk.pc_start); + // Observe the main commitment and public values. challenger.observe(builder, proof.commitment.main_commit.clone()); for j in 0..machine.num_pv_elts() { let element = builder.get(&proof.public_values, j); challenger.observe(builder, element); } - // verify proof. - let one_var = builder.eval(C::N::one()); + + // Verify proof. StarkVerifier::::verify_shard( builder, &vk, @@ -249,7 +251,7 @@ where machine, &mut challenger, &proof, - one_var, + true, ); // Load the public values from the proof. @@ -303,12 +305,45 @@ where current_public_values.start_shard, ); + // Initialize start execution shard. + builder.assign( + &execution_shard, + current_public_values.start_execution_shard, + ); + builder.assign( + &reduce_public_values.start_execution_shard, + current_public_values.start_execution_shard, + ); + + // Initialize the MemoryInitialize address bits. + for (bit, (first_bit, current_bit)) in init_addr_bits.iter().zip( + reduce_public_values + .previous_init_addr_bits + .iter() + .zip(current_public_values.previous_init_addr_bits.iter()), + ) { + builder.assign(bit, *current_bit); + builder.assign(first_bit, *current_bit); + } + + // Initialize the MemoryFinalize address bits. + for (bit, (first_bit, current_bit)) in finalize_addr_bits.iter().zip( + reduce_public_values + .previous_finalize_addr_bits + .iter() + .zip(current_public_values.previous_finalize_addr_bits.iter()), + ) { + builder.assign(bit, *current_bit); + builder.assign(first_bit, *current_bit); + } + // Initialize the leaf challenger. assign_challenger_from_pv( builder, &mut leaf_challenger, current_public_values.leaf_challenger, ); + // Initialize the reconstruct challenger. assign_challenger_from_pv( builder, @@ -337,20 +372,6 @@ where { builder.assign(digest, *current_digest); } - - // Initialize the start reconstruct deferred digest. - for (digest, first_digest, global_digest) in izip!( - reconstruct_deferred_digest.iter(), - current_public_values - .start_reconstruct_deferred_digest - .iter(), - reduce_public_values - .start_reconstruct_deferred_digest - .iter() - ) { - builder.assign(digest, *first_digest); - builder.assign(global_digest, *first_digest); - } }); // Assert that the current values match the accumulated values. @@ -364,7 +385,7 @@ where builder.assert_felt_eq(*digest, *current_digest); } - // consistency checks for all accumulated values. + // Consistency checks for all accumulated values. // Assert that the sp1_vk digest is always the same. for (digest, current) in sphinx_vk_digest @@ -376,10 +397,31 @@ where // Assert that the start pc is equal to the current pc. builder.assert_felt_eq(pc, current_public_values.start_pc); - // Verfiy that the shard is equal to the current shard. + + // Verify that the shard is equal to the current shard. builder.assert_felt_eq(shard, current_public_values.start_shard); + + // Verfiy that the exeuction shard is equal to the current execution shard. + builder.assert_felt_eq(execution_shard, current_public_values.start_execution_shard); + // Assert that the leaf challenger is always the same. + // Assert that the MemoryInitialize address bits are the same. + for (bit, current_bit) in init_addr_bits + .iter() + .zip(current_public_values.previous_init_addr_bits.iter()) + { + builder.assert_felt_eq(*bit, *current_bit); + } + + // Assert that the MemoryFinalize address bits are the same. + for (bit, current_bit) in finalize_addr_bits + .iter() + .zip(current_public_values.previous_finalize_addr_bits.iter()) + { + builder.assert_felt_eq(*bit, *current_bit); + } + assert_challenger_eq_pv( builder, &leaf_challenger, @@ -392,32 +434,73 @@ where current_public_values.start_reconstruct_challenger, ); - // Assert that the commited digests are the same. - for (word, current_word) in committed_value_digest - .iter() - .zip_eq(current_public_values.committed_value_digest.iter()) + // Digest constraints. { - for (byte, current_byte) in word.0.iter().zip_eq(current_word.0.iter()) { - builder.assert_felt_eq(*byte, *current_byte); + // If `commited_value_digest` is not zero, then `public_values.commited_value_digest + // should be the current value. + let is_zero: Var<_> = builder.eval(C::N::one()); + #[allow(clippy::needless_range_loop)] + for i in 0..committed_value_digest.len() { + for j in 0..WORD_SIZE { + let d = felt2var(builder, committed_value_digest[i][j]); + builder.if_ne(d, C::N::zero()).then(|builder| { + builder.assign(&is_zero, C::N::zero()); + }); + } + } + builder.if_eq(is_zero, C::N::zero()).then(|builder| { + #[allow(clippy::needless_range_loop)] + for i in 0..committed_value_digest.len() { + for j in 0..WORD_SIZE { + builder.assert_felt_eq( + committed_value_digest[i][j], + current_public_values.committed_value_digest[i][j], + ); + } + } + }); + + // Update the committed value digest. + #[allow(clippy::needless_range_loop)] + for i in 0..committed_value_digest.len() { + for j in 0..WORD_SIZE { + builder.assign( + &committed_value_digest[i][j], + current_public_values.committed_value_digest[i][j], + ); + } } - } - // Assert that the deferred proof digests are the same. - for (digest, current_digest) in deferred_proofs_digest - .iter() - .zip_eq(current_public_values.deferred_proofs_digest.iter()) - { - builder.assert_felt_eq(*digest, *current_digest); + // If `deferred_proofs_digest` is not zero, then `public_values.deferred_proofs_digest + // should be the current value. + let is_zero: Var<_> = builder.eval(C::N::one()); + #[allow(clippy::needless_range_loop)] + for i in 0..deferred_proofs_digest.len() { + let d = felt2var(builder, deferred_proofs_digest[i]); + builder.if_ne(d, C::N::zero()).then(|builder| { + builder.assign(&is_zero, C::N::zero()); + }); + } + builder.if_eq(is_zero, C::N::zero()).then(|builder| { + #[allow(clippy::needless_range_loop)] + for i in 0..deferred_proofs_digest.len() { + builder.assert_felt_eq( + deferred_proofs_digest[i], + current_public_values.deferred_proofs_digest[i], + ); + } + }); + + // Update the deferred proofs digest. + #[allow(clippy::needless_range_loop)] + for i in 0..deferred_proofs_digest.len() { + builder.assign( + &deferred_proofs_digest[i], + current_public_values.deferred_proofs_digest[i], + ); + } } - // Assert that total_core_shards is the same. - builder.assert_felt_eq( - total_core_shards_felt, - current_public_values.total_core_shards, - ); - - // Update the accumulated values. - // Update the deferred proof digest. for (digest, current_digest) in reconstruct_deferred_digest .iter() @@ -429,8 +512,29 @@ where // Update the accumulated values. // Update pc to be the next pc. builder.assign(&pc, current_public_values.next_pc); + // Update the shard to be the next shard. builder.assign(&shard, current_public_values.next_shard); + + // Update the execution shard to be the next execution shard. + builder.assign(&execution_shard, current_public_values.next_execution_shard); + + // Update the MemoryInitialize address bits. + for (bit, next_bit) in init_addr_bits + .iter() + .zip(current_public_values.last_init_addr_bits.iter()) + { + builder.assign(bit, *next_bit); + } + + // Update the MemoryFinalize address bits. + for (bit, next_bit) in finalize_addr_bits + .iter() + .zip(current_public_values.last_finalize_addr_bits.iter()) + { + builder.assign(bit, *next_bit); + } + // Update the reconstruct challenger. assign_challenger_from_pv( builder, @@ -452,8 +556,14 @@ where reduce_public_values.sphinx_vk_digest = sphinx_vk_digest; // Set next_pc to be the last pc (which is the same as accumulated pc) reduce_public_values.next_pc = pc; - // Set next shard to be the last shard (which is the same as accumulated shard) + // Set next shard to be the last shard reduce_public_values.next_shard = shard; + // Set next execution shard to be the last execution shard + reduce_public_values.next_execution_shard = execution_shard; + // Set the MemoryInitialize address bits to be the last MemoryInitialize address bits. + reduce_public_values.last_init_addr_bits = init_addr_bits; + // Set the MemoryFinalize address bits to be the last MemoryFinalize address bits. + reduce_public_values.last_finalize_addr_bits = finalize_addr_bits; // Set the leaf challenger to it's value. let values = get_challenger_public_values(builder, &leaf_challenger); reduce_public_values.leaf_challenger = values; @@ -465,15 +575,12 @@ where reduce_public_values.end_reconstruct_challenger = values; // Set the start reconstruct deferred digest to be the last reconstruct deferred digest. reduce_public_values.end_reconstruct_deferred_digest = reconstruct_deferred_digest; - - // Assign the deffered proof digests. + // Assign the deferred proof digests. reduce_public_values.deferred_proofs_digest = deferred_proofs_digest; // Assign the committed value digests. reduce_public_values.committed_value_digest = committed_value_digest; // Assign the cumulative sum. reduce_public_values.cumulative_sum = cumulative_sum; - // Assign the total number of shards. - reduce_public_values.total_core_shards = total_core_shards_felt; // If the proof is complete, make completeness assertions and set the flag. Otherwise, check // the flag is zero and set the public value to zero. diff --git a/recursion/program/src/machine/core.rs b/recursion/program/src/machine/core.rs index 78ee07c30..9406f8a52 100644 --- a/recursion/program/src/machine/core.rs +++ b/recursion/program/src/machine/core.rs @@ -1,13 +1,14 @@ use std::array; -use std::borrow::BorrowMut; +use std::borrow::{Borrow, BorrowMut}; use std::marker::PhantomData; use itertools::Itertools; use p3_baby_bear::BabyBear; use p3_commit::TwoAdicMultiplicativeCoset; use p3_field::{AbstractField, PrimeField32, TwoAdicField}; -use sphinx_core::air::{MachineAir, PublicValues}; +use sphinx_core::air::{MachineAir, PublicValues, WORD_SIZE}; use sphinx_core::air::{Word, POSEIDON_NUM_WORDS, PV_DIGEST_NUM_WORDS}; +use sphinx_core::cpu::MAX_CPU_LOG_DEGREE; use sphinx_core::stark::StarkMachine; use sphinx_core::stark::{Com, RiscvAir, ShardProof, StarkGenericConfig, StarkVerifyingKey}; use sphinx_core::utils::BabyBearPoseidon2; @@ -15,15 +16,14 @@ use sphinx_primitives::types::RecursionProgramType; use sphinx_recursion_compiler::config::InnerConfig; use sphinx_recursion_compiler::ir::{Array, Builder, Config, Ext, ExtConst, Felt, Var}; use sphinx_recursion_compiler::prelude::DslVariable; +use sphinx_recursion_compiler::prelude::*; use sphinx_recursion_core::air::{RecursionPublicValues, RECURSIVE_PROOF_NUM_PV_ELTS}; use sphinx_recursion_core::runtime::{RecursionProgram, DIGEST_SIZE}; -use sphinx_recursion_compiler::prelude::*; - use crate::challenger::{CanObserveVariable, DuplexChallengerVariable}; use crate::fri::TwoAdicFriPcsVariable; use crate::hints::Hintable; -use crate::stark::StarkVerifier; +use crate::stark::{StarkVerifier, EMPTY}; use crate::types::ShardProofVariable; use crate::types::VerifyingKeyVariable; use crate::utils::{const_fri_config, felt2var, get_challenger_public_values, hash_vkey, var2felt}; @@ -43,21 +43,15 @@ pub struct SphinxRecursionMemoryLayout<'a, SC: StarkGenericConfig, A: MachineAir pub leaf_challenger: &'a SC::Challenger, pub initial_reconstruct_challenger: SC::Challenger, pub is_complete: bool, - pub total_core_shards: usize, } #[derive(DslVariable, Clone)] pub struct SphinxRecursionMemoryLayoutVariable { pub vk: VerifyingKeyVariable, - pub shard_proofs: Array>, - pub leaf_challenger: DuplexChallengerVariable, pub initial_reconstruct_challenger: DuplexChallengerVariable, - pub is_complete: Var, - - pub total_core_shards: Var, } impl SphinxRecursiveVerifier { @@ -108,14 +102,9 @@ where /// of verifying the FRI proof for openings and verifying the constraints. /// /// ## Aggregating the shard public values. - /// /// See [SP1Prover::verify] for the verification algorithm of a complete SP1 proof. In this /// function, we are aggregating several shard proofs and attesting to an aggregated state which - /// represents all the shards. The consistency conditions of the aggregated state are - /// asserted in the following way: - /// - /// - Start pc for every shard should be what the next pc declared in the previous shard was. - /// - Public input, deferred proof digests, and exit code should be the same in all shards. + /// represents all the shards. /// /// ## The leaf challenger. /// A key difference between the recursive tree verification and the complete one in @@ -138,57 +127,80 @@ where leaf_challenger, initial_reconstruct_challenger, is_complete, - total_core_shards, } = input; - // Initialize values we will commit to public outputs. + // Initialize shard variables. + let initial_shard = builder.uninit(); + let current_shard: Felt<_> = builder.uninit(); + + // Initialize execution shard variables. + let initial_execution_shard: Felt<_> = builder.uninit(); + let current_execution_shard: Felt<_> = builder.uninit(); - // Start and end of program counters. + // Initialize program counter variables. let start_pc: Felt<_> = builder.uninit(); + let current_pc: Felt<_> = builder.uninit(); + + // Initialize memory initialization and finalization variables. + let initial_previous_init_addr_bits: [Felt<_>; 32] = array::from_fn(|_| builder.uninit()); + let initial_previous_finalize_addr_bits: [Felt<_>; 32] = + array::from_fn(|_| builder.uninit()); + let current_init_addr_bits: [Felt<_>; 32] = array::from_fn(|_| builder.uninit()); + let current_finalize_addr_bits: [Felt<_>; 32] = array::from_fn(|_| builder.uninit()); - // Start and end shard indices. - let initial_shard: Felt<_> = builder.uninit(); + // Initialize the exit code variable. + let exit_code: Felt<_> = builder.uninit(); - // The commited values digest and deferred proof digest. These will be checked to be the - // same for all proofs. + // Initialize the public values digest. let committed_value_digest: [Word>; PV_DIGEST_NUM_WORDS] = array::from_fn(|_| Word(array::from_fn(|_| builder.uninit()))); + + // Initialize the deferred proofs digest. let deferred_proofs_digest: [Felt<_>; POSEIDON_NUM_WORDS] = array::from_fn(|_| builder.uninit()); - // Assert that the number of proofs is not zero. - builder.assert_usize_ne(shard_proofs.len(), 0); - + // Initialize the challenger variables. let leaf_challenger_public_values = get_challenger_public_values(builder, &leaf_challenger); - - // Initialize loop variables. - let current_shard: Felt<_> = builder.uninit(); let mut reconstruct_challenger: DuplexChallengerVariable<_> = initial_reconstruct_challenger.copy(builder); + + // Initialize the cumulative sum. let cumulative_sum: Ext<_, _> = builder.eval(C::EF::zero().cons()); - let current_pc: Felt<_> = builder.uninit(); - let exit_code: Felt<_> = builder.uninit(); - // Range check that the number of proofs is sufficiently small. - let num_shard_proofs: Var<_> = shard_proofs.len().materialize(builder); - builder.range_check_v(num_shard_proofs, 16); + // Assert that the number of proofs is not zero. + builder.assert_usize_ne(shard_proofs.len(), 0); // Verify proofs, validate transitions, and update accumulation variables. builder.range(0, shard_proofs.len()).for_each(|i, builder| { // Load the proof. let proof = builder.get(&shard_proofs, i); - // Verify the shard proof. - let mut challenger = leaf_challenger.copy(builder); - StarkVerifier::::verify_shard( - builder, - &vk, - pcs, - machine, - &mut challenger, - &proof, - total_core_shards, - ); + // Compute some flags about which chips exist in the shard. + let contains_cpu: Var<_> = builder.eval(C::N::zero()); + let contains_memory_init: Var<_> = builder.eval(C::N::zero()); + let contains_memory_finalize: Var<_> = builder.eval(C::N::zero()); + for (i, chip) in machine.chips().iter().enumerate() { + let index = builder.get(&proof.sorted_idxs, i); + if chip.as_ref().name() == "CPU" { + builder + .if_ne(index, C::N::from_canonical_usize(EMPTY)) + .then(|builder| { + builder.assign(&contains_cpu, C::N::one()); + }); + } else if chip.as_ref().name() == "MemoryInit" { + builder + .if_ne(index, C::N::from_canonical_usize(EMPTY)) + .then(|builder| { + builder.assign(&contains_memory_init, C::N::one()); + }); + } else if chip.as_ref().name() == "MemoryFinalize" { + builder + .if_ne(index, C::N::from_canonical_usize(EMPTY)) + .then(|builder| { + builder.assign(&contains_memory_finalize, C::N::one()); + }); + } + } // Extract public values. let mut pv_elements = Vec::new(); @@ -196,20 +208,44 @@ where let element = builder.get(&proof.public_values, i); pv_elements.push(element); } - let public_values = PublicValues::>, Felt<_>>::from_vec(&pv_elements); + let public_values: &PublicValues>, Felt<_>> = + pv_elements.as_slice().borrow(); - // If this is the first proof in the batch, verify the initial conditions. + // If this is the first proof in the batch, initialize the variables. builder.if_eq(i, C::N::zero()).then(|builder| { - // Initialize the values of accumulated variables. - // Shard. builder.assign(&initial_shard, public_values.shard); builder.assign(¤t_shard, public_values.shard); + // Execution shard. + builder.assign(&initial_execution_shard, public_values.execution_shard); + builder.assign(¤t_execution_shard, public_values.execution_shard); + // Program counter. builder.assign(&start_pc, public_values.start_pc); builder.assign(¤t_pc, public_values.start_pc); + // Memory initialization & finalization. + for ((bit, pub_bit), first_bit) in current_init_addr_bits + .iter() + .zip(public_values.previous_init_addr_bits.iter()) + .zip(initial_previous_init_addr_bits.iter()) + { + builder.assign(bit, *pub_bit); + builder.assign(first_bit, *pub_bit); + } + for ((bit, pub_bit), first_bit) in current_finalize_addr_bits + .iter() + .zip(public_values.previous_finalize_addr_bits.iter()) + .zip(initial_previous_finalize_addr_bits.iter()) + { + builder.assign(bit, *pub_bit); + builder.assign(first_bit, *pub_bit); + } + + // Exit code. + builder.assign(&exit_code, public_values.exit_code); + // Commited public values digests. for (word, first_word) in committed_value_digest .iter() @@ -227,86 +263,294 @@ where { builder.assign(digest, *first_digest); } - - // Exit code. - builder.assign(&exit_code, public_values.exit_code); }); - // If shard is one, verify the global initial conditions hold on challenger and pc. + // If the shard is the first shard, assert that the initial challenger is equal to a + // fresh challenger observing the verifier key and the initial pc. let shard = felt2var(builder, public_values.shard); builder.if_eq(shard, C::N::one()).then(|builder| { - // This should be the 0th proof in this batch. - builder.assert_var_eq(i, C::N::zero()); - - // Start pc should be vk.pc_start - builder.assert_felt_eq(public_values.start_pc, vk.pc_start); - - // Assert that the initial challenger is equal to a fresh challenger observing the - // verifier key and the initial pc. let mut first_initial_challenger = DuplexChallengerVariable::new(builder); - first_initial_challenger.observe(builder, vk.commitment.clone()); first_initial_challenger.observe(builder, vk.pc_start); - - // Make sure the start reconstruct challenger is correct, since we will - // commit to it in public values. initial_reconstruct_challenger.assert_eq(builder, &first_initial_challenger); }); - // Assert compatibility of the shard values. + // Verify the shard. + // + // Do not verify the cumulative sum here, since the permutation challenge is shared + // between all shards. + let mut challenger = leaf_challenger.copy(builder); + StarkVerifier::::verify_shard( + builder, + &vk, + pcs, + machine, + &mut challenger, + &proof, + false, + ); - // Assert that the committed value digests are all the same. - for (word, current_word) in committed_value_digest - .iter() - .zip_eq(public_values.committed_value_digest.iter()) + // First shard has a "CPU" constraint. { - for (byte, current_byte) in word.0.iter().zip_eq(current_word.0.iter()) { - builder.assert_felt_eq(*byte, *current_byte); + builder.if_eq(shard, C::N::one()).then(|builder| { + builder.assert_var_eq(contains_cpu, C::N::one()); + }); + } + + // CPU log degree bound check constraints. + { + for (i, chip) in machine.chips().iter().enumerate() { + if chip.as_ref().name() == "CPU" { + builder.if_eq(contains_cpu, C::N::one()).then(|builder| { + let index = builder.get(&proof.sorted_idxs, i); + let cpu_log_degree = + builder.get(&proof.opened_values.chips, index).log_degree; + let cpu_log_degree_lt_max: Var<_> = builder.eval(C::N::zero()); + builder + .range(0, MAX_CPU_LOG_DEGREE + 1) + .for_each(|j, builder| { + builder.if_eq(j, cpu_log_degree).then(|builder| { + builder.assign(&cpu_log_degree_lt_max, C::N::one()); + }); + }); + builder.assert_var_eq(cpu_log_degree_lt_max, C::N::one()); + }); + } } } - // Assert that the start_pc of the proof is equal to the current pc. - builder.assert_felt_eq(current_pc, public_values.start_pc); - // Assert that the start_pc is not zero (this means program has halted in a non-last - // shard). - builder.assert_felt_ne(public_values.start_pc, C::F::zero()); + // Shard constraints. + { + // Assert that the shard of the proof is equal to the current shard. + builder.assert_felt_eq(current_shard, public_values.shard); - // Assert that the shard of the proof is equal to the current shard. - builder.assert_felt_eq(current_shard, public_values.shard); + // Increment the current shard by one. + builder.assign(¤t_shard, current_shard + C::F::one()); + } - // Assert that exit code is the same for all proofs. - builder.assert_felt_eq(exit_code, public_values.exit_code); + // Execution shard constraints. + let execution_shard = felt2var(builder, public_values.execution_shard); + { + // Assert that the shard of the proof is equal to the current shard. + builder.if_eq(contains_cpu, C::N::one()).then(|builder| { + builder.assert_felt_eq(current_execution_shard, public_values.execution_shard); + }); - // Assert that the exit code is zero (success) for all proofs. - builder.assert_felt_eq(exit_code, C::F::zero()); + // If the shard has a "CPU" chip, then the execution shard should be incremented by 1. + builder.if_eq(contains_cpu, C::N::one()).then(|builder| { + builder.assign( + ¤t_execution_shard, + current_execution_shard + C::F::one(), + ); + }); + } - // Assert that the deferred proof digest is the same for all proofs. - for (digest, current_digest) in deferred_proofs_digest - .iter() - .zip_eq(public_values.deferred_proofs_digest.iter()) + // Program counter constraints. { - builder.assert_felt_eq(*digest, *current_digest); + // If it's the first shard (which is the first execution shard), then the start_pc + // should be vk.pc_start. + builder.if_eq(shard, C::N::one()).then(|builder| { + builder.assert_felt_eq(public_values.start_pc, vk.pc_start); + }); + + // Assert that the start_pc of the proof is equal to the current pc. + builder.assert_felt_eq(current_pc, public_values.start_pc); + + // If it's not a shard with "CPU", then assert that the start_pc equals the next_pc. + builder.if_ne(contains_cpu, C::N::one()).then(|builder| { + builder.assert_felt_eq(public_values.start_pc, public_values.next_pc); + }); + + // If it's a shard with "CPU", then assert that the start_pc is not zero. + builder.if_eq(contains_cpu, C::N::one()).then(|builder| { + builder.assert_felt_ne(public_values.start_pc, C::F::zero()); + }); + + // Update current_pc to be the end_pc of the current proof. + builder.assign(¤t_pc, public_values.next_pc); + } + + // Exit code constraints. + { + // Assert that the exit code is zero (success) for all proofs. + builder.assert_felt_eq(exit_code, C::F::zero()); + } + + // Memory initialization & finalization constraints. + { + // Assert that `init_addr_bits` and `finalize_addr_bits` are zero for the first execution shard. + builder.if_eq(execution_shard, C::N::one()).then(|builder| { + // Assert that the MemoryInitialize address bits are zero. + for bit in current_init_addr_bits.iter() { + builder.assert_felt_eq(*bit, C::F::zero()); + } + + // Assert that the MemoryFinalize address bits are zero. + for bit in current_finalize_addr_bits.iter() { + builder.assert_felt_eq(*bit, C::F::zero()); + } + }); + + // Assert that the MemoryInitialize address bits match the current loop variable. + for (bit, current_bit) in current_init_addr_bits + .iter() + .zip_eq(public_values.previous_init_addr_bits.iter()) + { + builder.assert_felt_eq(*bit, *current_bit); + } + + // Assert that the MemoryFinalize address bits match the current loop variable. + for (bit, current_bit) in current_finalize_addr_bits + .iter() + .zip_eq(public_values.previous_finalize_addr_bits.iter()) + { + builder.assert_felt_eq(*bit, *current_bit); + } + + // Assert that if MemoryInit is not present, then the address bits are the same. + builder + .if_ne(contains_memory_init, C::N::one()) + .then(|builder| { + for (prev_bit, last_bit) in public_values + .previous_init_addr_bits + .iter() + .zip_eq(public_values.last_init_addr_bits.iter()) + { + builder.assert_felt_eq(*prev_bit, *last_bit); + } + }); + + // Assert that if MemoryFinalize is not present, then the address bits are the same. + builder + .if_ne(contains_memory_finalize, C::N::one()) + .then(|builder| { + for (prev_bit, last_bit) in public_values + .previous_finalize_addr_bits + .iter() + .zip_eq(public_values.last_finalize_addr_bits.iter()) + { + builder.assert_felt_eq(*prev_bit, *last_bit); + } + }); + + // Update the MemoryInitialize address bits. + for (bit, pub_bit) in current_init_addr_bits + .iter() + .zip(public_values.last_init_addr_bits.iter()) + { + builder.assign(bit, *pub_bit); + } + + // Update the MemoryFinalize address bits. + for (bit, pub_bit) in current_finalize_addr_bits + .iter() + .zip(public_values.last_finalize_addr_bits.iter()) + { + builder.assign(bit, *pub_bit); + } } - // Range check the shard count to be less than 1<<16. - builder.range_check_f(current_shard, 16); + // Digest constraints. + { + // If `commited_value_digest` is not zero, then `public_values.commited_value_digest + // should be the current value. + let is_zero: Var<_> = builder.eval(C::N::one()); + #[allow(clippy::needless_range_loop)] + for i in 0..committed_value_digest.len() { + for j in 0..WORD_SIZE { + let d = felt2var(builder, committed_value_digest[i][j]); + builder.if_ne(d, C::N::zero()).then(|builder| { + builder.assign(&is_zero, C::N::zero()); + }); + } + } + builder.if_eq(is_zero, C::N::zero()).then(|builder| { + #[allow(clippy::needless_range_loop)] + for i in 0..committed_value_digest.len() { + for j in 0..WORD_SIZE { + builder.assert_felt_eq( + committed_value_digest[i][j], + public_values.committed_value_digest[i][j], + ); + } + } + }); - // Update the loop variables: the reconstruct challenger, cumulative sum, shard number, - // and program counter. + // If it's not a shard with "CPU", then the committed value digest should not change. + builder.if_ne(contains_cpu, C::N::one()).then(|builder| { + #[allow(clippy::needless_range_loop)] + for i in 0..committed_value_digest.len() { + for j in 0..WORD_SIZE { + builder.assert_felt_eq( + committed_value_digest[i][j], + public_values.committed_value_digest[i][j], + ); + } + } + }); - // Increment the shard index by one. - builder.assign(¤t_shard, current_shard + C::F::one()); + // Update the committed value digest. + #[allow(clippy::needless_range_loop)] + for i in 0..committed_value_digest.len() { + for j in 0..WORD_SIZE { + builder.assign( + &committed_value_digest[i][j], + public_values.committed_value_digest[i][j], + ); + } + } + + // If `deferred_proofs_digest` is not zero, then `public_values.deferred_proofs_digest + // should be the current value. + let is_zero: Var<_> = builder.eval(C::N::one()); + #[allow(clippy::needless_range_loop)] + for i in 0..deferred_proofs_digest.len() { + let d = felt2var(builder, deferred_proofs_digest[i]); + builder.if_ne(d, C::N::zero()).then(|builder| { + builder.assign(&is_zero, C::N::zero()); + }); + } + builder.if_eq(is_zero, C::N::zero()).then(|builder| { + #[allow(clippy::needless_range_loop)] + for i in 0..deferred_proofs_digest.len() { + builder.assert_felt_eq( + deferred_proofs_digest[i], + public_values.deferred_proofs_digest[i], + ); + } + }); + + // If it's not a shard with "CPU", then the deferred proofs digest should not change. + builder.if_ne(contains_cpu, C::N::one()).then(|builder| { + #[allow(clippy::needless_range_loop)] + for i in 0..deferred_proofs_digest.len() { + builder.assert_felt_eq( + deferred_proofs_digest[i], + public_values.deferred_proofs_digest[i], + ); + } + }); + + // Update the deferred proofs digest. + #[allow(clippy::needless_range_loop)] + for i in 0..deferred_proofs_digest.len() { + builder.assign( + &deferred_proofs_digest[i], + public_values.deferred_proofs_digest[i], + ); + } + } + + // Verify that the number of shards is not too large. + builder.range_check_f(public_values.shard, 16); // Update the reconstruct challenger. - reconstruct_challenger.observe(builder, proof.commitment.main_commit); + reconstruct_challenger.observe(builder, proof.commitment.main_commit.clone()); for j in 0..machine.num_pv_elts() { let element = builder.get(&proof.public_values, j); reconstruct_challenger.observe(builder, element); } - // Update current_pc to be the end_pc of the current proof. - builder.assign(¤t_pc, public_values.next_pc); - // Cumulative sum is updated by sums of all chips. let opened_values = proof.opened_values.chips; builder @@ -319,59 +563,66 @@ where }); // Write all values to the public values struct and commit to them. + { + // Compute the vk digest. + let vk_digest = hash_vkey(builder, &vk); + let vk_digest: [Felt<_>; DIGEST_SIZE] = array::from_fn(|i| builder.get(&vk_digest, i)); + + // Collect the public values for challengers. + let initial_challenger_public_values = + get_challenger_public_values(builder, &initial_reconstruct_challenger); + let final_challenger_public_values = + get_challenger_public_values(builder, &reconstruct_challenger); + + // Collect the cumulative sum. + let cumulative_sum_array = builder.ext2felt(cumulative_sum); + let cumulative_sum_array = array::from_fn(|i| builder.get(&cumulative_sum_array, i)); + + // Collect the deferred proof digests. + let zero: Felt<_> = builder.eval(C::F::zero()); + let start_deferred_digest = [zero; POSEIDON_NUM_WORDS]; + let end_deferred_digest = [zero; POSEIDON_NUM_WORDS]; + + // Collect the is_complete flag. + let is_complete_felt = var2felt(builder, is_complete); + + // Initialize the public values we will commit to. + let mut recursion_public_values_stream = [zero; RECURSIVE_PROOF_NUM_PV_ELTS]; + let recursion_public_values: &mut RecursionPublicValues<_> = + recursion_public_values_stream.as_mut_slice().borrow_mut(); + recursion_public_values.committed_value_digest = committed_value_digest; + recursion_public_values.deferred_proofs_digest = deferred_proofs_digest; + recursion_public_values.start_pc = start_pc; + recursion_public_values.next_pc = current_pc; + recursion_public_values.start_shard = initial_shard; + recursion_public_values.next_shard = current_shard; + recursion_public_values.start_execution_shard = initial_execution_shard; + recursion_public_values.next_execution_shard = current_execution_shard; + recursion_public_values.previous_init_addr_bits = initial_previous_init_addr_bits; + recursion_public_values.last_init_addr_bits = current_init_addr_bits; + recursion_public_values.previous_finalize_addr_bits = + initial_previous_finalize_addr_bits; + recursion_public_values.last_finalize_addr_bits = current_finalize_addr_bits; + recursion_public_values.sphinx_vk_digest = vk_digest; + recursion_public_values.leaf_challenger = leaf_challenger_public_values; + recursion_public_values.start_reconstruct_challenger = initial_challenger_public_values; + recursion_public_values.end_reconstruct_challenger = final_challenger_public_values; + recursion_public_values.cumulative_sum = cumulative_sum_array; + recursion_public_values.start_reconstruct_deferred_digest = start_deferred_digest; + recursion_public_values.end_reconstruct_deferred_digest = end_deferred_digest; + recursion_public_values.exit_code = exit_code; + recursion_public_values.is_complete = is_complete_felt; + + // If the proof represents a complete proof, make completeness assertions. + // + // *Remark*: In this program, this only happends if there is one shard and the program has + // no deferred proofs to verify. However, the completeness check is independent of these + // facts. + builder.if_eq(is_complete, C::N::one()).then(|builder| { + assert_complete(builder, recursion_public_values, &reconstruct_challenger) + }); - // Compute vk digest. - let vk_digest = hash_vkey(builder, &vk); - let vk_digest: [Felt<_>; DIGEST_SIZE] = array::from_fn(|i| builder.get(&vk_digest, i)); - - // Collect values for challenges. - let initial_challenger_public_values = - get_challenger_public_values(builder, &initial_reconstruct_challenger); - let final_challenger_public_values = - get_challenger_public_values(builder, &reconstruct_challenger); - - let cumulative_sum_arrray = builder.ext2felt(cumulative_sum); - let cumulative_sum_arrray = array::from_fn(|i| builder.get(&cumulative_sum_arrray, i)); - - let zero: Felt<_> = builder.eval(C::F::zero()); - - // Initialize the public values we will commit to. - let mut recursion_public_values_stream = [zero; RECURSIVE_PROOF_NUM_PV_ELTS]; - - let recursion_public_values: &mut RecursionPublicValues<_> = - recursion_public_values_stream.as_mut_slice().borrow_mut(); - - let start_deferred_digest = [zero; POSEIDON_NUM_WORDS]; - let end_deferred_digest = [zero; POSEIDON_NUM_WORDS]; - - let is_complete_felt = var2felt(builder, is_complete); - let total_core_shards_felt = var2felt(builder, total_core_shards); - - recursion_public_values.committed_value_digest = committed_value_digest; - recursion_public_values.deferred_proofs_digest = deferred_proofs_digest; - recursion_public_values.start_pc = start_pc; - recursion_public_values.next_pc = current_pc; - recursion_public_values.start_shard = initial_shard; - recursion_public_values.next_shard = current_shard; - recursion_public_values.sphinx_vk_digest = vk_digest; - recursion_public_values.leaf_challenger = leaf_challenger_public_values; - recursion_public_values.start_reconstruct_challenger = initial_challenger_public_values; - recursion_public_values.end_reconstruct_challenger = final_challenger_public_values; - recursion_public_values.cumulative_sum = cumulative_sum_arrray; - recursion_public_values.start_reconstruct_deferred_digest = start_deferred_digest; - recursion_public_values.end_reconstruct_deferred_digest = end_deferred_digest; - recursion_public_values.is_complete = is_complete_felt; - recursion_public_values.total_core_shards = total_core_shards_felt; - - // If the proof represents a complete proof, make completeness assertions. - // - // *Remark*: In this program, this only happends if there is one shard and the program has - // no deferred proofs to verify. However, the completeness check is independent of these - // facts. - builder.if_eq(is_complete, C::N::one()).then(|builder| { - assert_complete(builder, recursion_public_values, &reconstruct_challenger) - }); - - commit_public_values(builder, recursion_public_values); + commit_public_values(builder, recursion_public_values); + } } } diff --git a/recursion/program/src/machine/deferred.rs b/recursion/program/src/machine/deferred.rs index fd6bc787d..23399927c 100644 --- a/recursion/program/src/machine/deferred.rs +++ b/recursion/program/src/machine/deferred.rs @@ -55,7 +55,9 @@ where pub leaf_challenger: SC::Challenger, pub end_pc: SC::Val, pub end_shard: SC::Val, - pub total_core_shards: usize, + pub end_execution_shard: SC::Val, + pub init_addr_bits: [SC::Val; 32], + pub finalize_addr_bits: [SC::Val; 32], } /// A variable version of the [SP1DeferredMemoryLayout] struct. @@ -75,7 +77,9 @@ pub struct SphinxDeferredMemoryLayoutVariable { pub leaf_challenger: DuplexChallengerVariable, pub end_pc: Felt, pub end_shard: Felt, - pub total_core_shards: Var, + pub end_execution_shard: Felt, + pub init_addr_bits: Array>, + pub finalize_addr_bits: Array>, } impl SphinxDeferredVerifier @@ -132,13 +136,15 @@ where proofs, start_reconstruct_deferred_digest, is_complete, - total_core_shards, sphinx_vk, committed_value_digest, deferred_proofs_digest, leaf_challenger, end_pc, end_shard, + end_execution_shard, + init_addr_bits, + finalize_addr_bits, } = input; // Initialize the values for the aggregated public output as all zeros. @@ -192,7 +198,6 @@ where } // Verify the proof. - let one_var = builder.constant(C::N::one()); StarkVerifier::::verify_shard( builder, &compress_vk, @@ -200,7 +205,7 @@ where machine, &mut challenger, &proof, - one_var, + true, ); // Load the public values from the proof. @@ -264,6 +269,15 @@ where deferred_public_values.next_pc = end_pc; deferred_public_values.start_shard = end_shard; deferred_public_values.next_shard = end_shard; + deferred_public_values.start_execution_shard = end_execution_shard; + deferred_public_values.next_execution_shard = end_execution_shard; + // Set the init and finalize address bits to be the hintred values. + let init_addr_bits = array::from_fn(|i| builder.get(&init_addr_bits, i)); + deferred_public_values.previous_init_addr_bits = init_addr_bits; + deferred_public_values.last_init_addr_bits = init_addr_bits; + let finalize_addr_bits = array::from_fn(|i| builder.get(&finalize_addr_bits, i)); + deferred_public_values.previous_finalize_addr_bits = finalize_addr_bits; + deferred_public_values.last_finalize_addr_bits = finalize_addr_bits; // Set the sp1_vk_digest to be the hitned value. let sphinx_vk_digest = hash_vkey(builder, &sphinx_vk); @@ -296,7 +310,6 @@ where // Set the is_complete flag. deferred_public_values.is_complete = var2felt(builder, is_complete); - deferred_public_values.total_core_shards = var2felt(builder, total_core_shards); commit_public_values(builder, deferred_public_values); } diff --git a/recursion/program/src/machine/mod.rs b/recursion/program/src/machine/mod.rs index 8115c9c2a..38e17690f 100644 --- a/recursion/program/src/machine/mod.rs +++ b/recursion/program/src/machine/mod.rs @@ -9,439 +9,3 @@ pub use core::*; pub use deferred::*; pub use root::*; pub use utils::*; - -#[cfg(test)] -mod tests { - - use p3_baby_bear::BabyBear; - use p3_challenger::CanObserve; - use p3_maybe_rayon::prelude::*; - use sphinx_core::stark::{MachineVerificationError, RiscvAir, StarkGenericConfig}; - use sphinx_core::utils::{BabyBearPoseidon2, SphinxCoreOpts}; - use sphinx_core::{ - io::SphinxStdin, - runtime::Program, - stark::{Challenge, LocalProver}, - }; - use sphinx_primitives::types::RecursionProgramType; - use sphinx_recursion_compiler::config::InnerConfig; - use sphinx_recursion_core::{ - runtime::Runtime, - stark::{config::BabyBearPoseidon2Outer, RecursionAir}, - }; - - use crate::hints::Hintable; - - use super::*; - - #[derive(Clone, Copy)] - enum Test { - Recursion, - Reduce, - Compress, - Wrap, - } - - fn test_sphinx_recursive_machine_verify(program: &Program, batch_size: usize, test: Test) { - type SC = BabyBearPoseidon2; - type F = BabyBear; - type EF = Challenge; - - sphinx_core::utils::setup_logger(); - - let machine = RiscvAir::machine(SC::default()); - let (_, vk) = machine.setup(program); - - // Make the recursion program. - let recursive_program = SphinxRecursiveVerifier::::build(&machine); - let recursive_config = SC::default(); - type A = RecursionAir; - let recursive_machine = A::machine(recursive_config.clone()); - let (rec_pk, rec_vk) = recursive_machine.setup(&recursive_program); - - // Make the deferred program. - let deferred_program = - SphinxDeferredVerifier::::build(&recursive_machine); - let (_, deferred_vk) = recursive_machine.setup(&deferred_program); - - // Make the compress program. - let reduce_program = SphinxCompressVerifier::::build( - &recursive_machine, - &rec_vk, - &deferred_vk, - ); - - let (reduce_pk, compress_vk) = recursive_machine.setup(&reduce_program); - - // Make the compress program. - let compress_machine = RecursionAir::<_, 9>::machine(SC::compressed()); - let compress_program = SphinxRootVerifier::::build( - &recursive_machine, - &compress_vk, - RecursionProgramType::Shrink, - ); - let (compress_pk, compress_vk) = compress_machine.setup(&compress_program); - - // Make the wrap program. - let wrap_machine = RecursionAir::<_, 17>::wrap_machine(BabyBearPoseidon2Outer::default()); - let wrap_program = SphinxRootVerifier::::build( - &compress_machine, - &compress_vk, - RecursionProgramType::Wrap, - ); - - let mut challenger = machine.config().challenger(); - let time = std::time::Instant::now(); - let (proof, _) = sphinx_core::utils::prove( - program, - &SphinxStdin::new(), - SC::default(), - SphinxCoreOpts::default(), - ) - .unwrap(); - machine.verify(&vk, &proof, &mut challenger).unwrap(); - let total_core_shards = proof.shard_proofs.len(); - tracing::info!("Proof generated successfully"); - let elapsed = time.elapsed(); - tracing::info!("Execution proof time: {:?}", elapsed); - - // Get the and leaf challenger. - let mut leaf_challenger = machine.config().challenger(); - vk.observe_into(&mut leaf_challenger); - proof.shard_proofs.iter().for_each(|proof| { - leaf_challenger.observe(proof.commitment.main_commit); - leaf_challenger.observe_slice(&proof.public_values[0..machine.num_pv_elts()]); - }); - // Make sure leaf challenger is not mutable anymore. - let leaf_challenger = leaf_challenger; - - let mut layouts = Vec::new(); - - let mut reconstruct_challenger = machine.config().challenger(); - vk.observe_into(&mut reconstruct_challenger); - - let is_complete = proof.shard_proofs.len() == 1; - for batch in proof.shard_proofs.chunks(batch_size) { - let proofs = batch.to_vec(); - - layouts.push(SphinxRecursionMemoryLayout { - vk: &vk, - machine: &machine, - shard_proofs: proofs, - leaf_challenger: &leaf_challenger, - initial_reconstruct_challenger: reconstruct_challenger.clone(), - is_complete, - total_core_shards, - }); - - for proof in batch.iter() { - reconstruct_challenger.observe(proof.commitment.main_commit); - reconstruct_challenger - .observe_slice(&proof.public_values[0..machine.num_pv_elts()]); - } - } - - assert_eq!( - reconstruct_challenger.sponge_state, - leaf_challenger.sponge_state - ); - assert_eq!( - reconstruct_challenger.input_buffer, - leaf_challenger.input_buffer - ); - assert_eq!( - reconstruct_challenger.output_buffer, - leaf_challenger.output_buffer - ); - - // Run the recursion programs. - let mut records = Vec::new(); - - for layout in layouts { - let mut runtime = - Runtime::::new(&recursive_program, machine.config().perm.clone()); - - let mut witness_stream = Vec::new(); - witness_stream.extend(layout.write()); - - runtime.witness_stream = witness_stream.into(); - runtime.run(); - runtime.print_stats(); - - records.push(runtime.record); - } - - // Prove all recursion programs and verify the recursive proofs. - - // Make the recursive proofs. - let time = std::time::Instant::now(); - let recursive_proofs = records - .into_par_iter() - .map(|record| { - let mut recursive_challenger = recursive_machine.config().challenger(); - recursive_machine.prove::>( - &rec_pk, - record, - &mut recursive_challenger, - SphinxCoreOpts::recursion(), - ) - }) - .collect::>(); - let elapsed = time.elapsed(); - tracing::info!("Recursive first layer proving time: {:?}", elapsed); - - // Verify the recursive proofs. - for rec_proof in recursive_proofs.iter() { - let mut recursive_challenger = recursive_machine.config().challenger(); - let result = recursive_machine.verify(&rec_vk, rec_proof, &mut recursive_challenger); - - match result { - Ok(_) => tracing::info!("Proof verified successfully"), - Err(MachineVerificationError::NonZeroCumulativeSum) => { - tracing::info!("Proof verification failed: NonZeroCumulativeSum") - } - e => panic!("Proof verification failed: {:?}", e), - } - } - if let Test::Recursion = test { - return; - } - - tracing::info!("Recursive proofs verified successfully"); - - // Chain all the individual shard proofs. - let mut recursive_proofs = recursive_proofs - .into_iter() - .flat_map(|proof| proof.shard_proofs) - .collect::>(); - - // Iterate over the recursive proof batches until there is one proof remaining. - let mut is_first_layer = true; - let mut is_complete; - let time = std::time::Instant::now(); - loop { - tracing::info!("Recursive proofs: {}", recursive_proofs.len()); - is_complete = recursive_proofs.len() <= batch_size; - recursive_proofs = recursive_proofs - .par_chunks(batch_size) - .map(|batch| { - let kind = if is_first_layer { - ReduceProgramType::Core - } else { - ReduceProgramType::Reduce - }; - let kinds = batch.iter().map(|_| kind).collect::>(); - let input = SphinxReduceMemoryLayout { - compress_vk: &compress_vk, - recursive_machine: &recursive_machine, - shard_proofs: batch.to_vec(), - kinds, - is_complete, - total_core_shards, - }; - - let mut runtime = Runtime::::new( - &reduce_program, - recursive_machine.config().perm.clone(), - ); - - let mut witness_stream = Vec::new(); - witness_stream.extend(input.write()); - - runtime.witness_stream = witness_stream.into(); - runtime.run(); - runtime.print_stats(); - - let mut recursive_challenger = recursive_machine.config().challenger(); - let mut proof = recursive_machine.prove::>( - &reduce_pk, - runtime.record, - &mut recursive_challenger, - SphinxCoreOpts::recursion(), - ); - let mut recursive_challenger = recursive_machine.config().challenger(); - let result = - recursive_machine.verify(&compress_vk, &proof, &mut recursive_challenger); - - match result { - Ok(_) => tracing::info!("Proof verified successfully"), - Err(MachineVerificationError::NonZeroCumulativeSum) => { - tracing::info!("Proof verification failed: NonZeroCumulativeSum") - } - e => panic!("Proof verification failed: {:?}", e), - } - - assert_eq!(proof.shard_proofs.len(), 1); - proof.shard_proofs.pop().unwrap() - }) - .collect(); - is_first_layer = false; - - if recursive_proofs.len() == 1 { - break; - } - } - let elapsed = time.elapsed(); - tracing::info!("Reduction successful, time: {:?}", elapsed); - if let Test::Reduce = test { - return; - } - - assert_eq!(recursive_proofs.len(), 1); - let reduce_proof = recursive_proofs.pop().unwrap(); - - // Make the compress proof. - let input = SphinxRootMemoryLayout { - machine: &recursive_machine, - proof: reduce_proof, - is_reduce: true, - }; - - // Run the compress program. - let mut runtime = - Runtime::::new(&compress_program, compress_machine.config().perm.clone()); - - let mut witness_stream = Vec::new(); - witness_stream.extend(input.write()); - - runtime.witness_stream = witness_stream.into(); - runtime.run(); - runtime.print_stats(); - tracing::info!("Compress program executed successfully"); - - // Prove the compress program. - let mut compress_challenger = compress_machine.config().challenger(); - - let time = std::time::Instant::now(); - let mut compress_proof = compress_machine.prove::>( - &compress_pk, - runtime.record, - &mut compress_challenger, - SphinxCoreOpts::default(), - ); - let elapsed = time.elapsed(); - tracing::info!("Compress proving time: {:?}", elapsed); - let mut compress_challenger = compress_machine.config().challenger(); - let result = - compress_machine.verify(&compress_vk, &compress_proof, &mut compress_challenger); - match result { - Ok(_) => tracing::info!("Proof verified successfully"), - Err(MachineVerificationError::NonZeroCumulativeSum) => { - tracing::info!("Proof verification failed: NonZeroCumulativeSum") - } - e => panic!("Proof verification failed: {:?}", e), - } - - if let Test::Compress = test { - return; - } - - // Run and prove the wrap program. - - let (wrap_pk, wrap_vk) = wrap_machine.setup(&wrap_program); - - let compress_proof = compress_proof.shard_proofs.pop().unwrap(); - let input = SphinxRootMemoryLayout { - machine: &compress_machine, - proof: compress_proof, - is_reduce: false, - }; - - // Run the compress program. - let mut runtime = - Runtime::::new(&wrap_program, compress_machine.config().perm.clone()); - - let mut witness_stream = Vec::new(); - witness_stream.extend(input.write()); - - runtime.witness_stream = witness_stream.into(); - runtime.run(); - runtime.print_stats(); - tracing::info!("Wrap program executed successfully"); - - // Prove the wrap program. - let mut wrap_challenger = wrap_machine.config().challenger(); - let time = std::time::Instant::now(); - let wrap_proof = wrap_machine.prove::>( - &wrap_pk, - runtime.record, - &mut wrap_challenger, - SphinxCoreOpts::recursion(), - ); - let elapsed = time.elapsed(); - tracing::info!("Wrap proving time: {:?}", elapsed); - let mut wrap_challenger = wrap_machine.config().challenger(); - let result = wrap_machine.verify(&wrap_vk, &wrap_proof, &mut wrap_challenger); - match result { - Ok(_) => tracing::info!("Proof verified successfully"), - Err(MachineVerificationError::NonZeroCumulativeSum) => { - tracing::info!("Proof verification failed: NonZeroCumulativeSum") - } - e => panic!("Proof verification failed: {:?}", e), - } - tracing::info!("Wrapping successful"); - } - - #[test] - fn test_sphinx_recursive_machine_verify_fibonacci() { - let elf = include_bytes!("../../../../tests/fibonacci/elf/riscv32im-succinct-zkvm-elf"); - test_sphinx_recursive_machine_verify(&Program::from(elf), 1, Test::Recursion) - } - - #[test] - #[ignore] - fn test_sphinx_reduce_machine_verify_fibonacci() { - let elf = include_bytes!("../../../../tests/fibonacci/elf/riscv32im-succinct-zkvm-elf"); - test_sphinx_recursive_machine_verify(&Program::from(elf), 1, Test::Reduce) - } - - #[test] - #[ignore] - fn test_sphinx_compress_machine_verify_fibonacci() { - let elf = include_bytes!("../../../../tests/fibonacci/elf/riscv32im-succinct-zkvm-elf"); - test_sphinx_recursive_machine_verify(&Program::from(elf), 1, Test::Compress) - } - - #[test] - #[ignore] - fn test_sphinx_wrap_machine_verify_fibonacci() { - let elf = include_bytes!("../../../../tests/fibonacci/elf/riscv32im-succinct-zkvm-elf"); - test_sphinx_recursive_machine_verify(&Program::from(elf), 1, Test::Wrap) - } - - #[test] - #[ignore] - fn test_sphinx_reduce_machine_verify_tendermint() { - let elf = include_bytes!( - "../../../../tests/tendermint-benchmark/elf/riscv32im-succinct-zkvm-elf" - ); - test_sphinx_recursive_machine_verify(&Program::from(elf), 2, Test::Reduce) - } - - #[test] - #[ignore] - fn test_sphinx_recursive_machine_verify_tendermint() { - let elf = include_bytes!( - "../../../../tests/tendermint-benchmark/elf/riscv32im-succinct-zkvm-elf" - ); - test_sphinx_recursive_machine_verify(&Program::from(elf), 2, Test::Recursion) - } - - #[test] - #[ignore] - fn test_sphinx_compress_machine_verify_tendermint() { - let elf = include_bytes!( - "../../../../tests/tendermint-benchmark/elf/riscv32im-succinct-zkvm-elf" - ); - test_sphinx_recursive_machine_verify(&Program::from(elf), 2, Test::Compress) - } - - #[test] - #[ignore] - fn test_sphinx_wrap_machine_verify_tendermint() { - let elf = include_bytes!( - "../../../../tests/tendermint-benchmark/elf/riscv32im-succinct-zkvm-elf" - ); - test_sphinx_recursive_machine_verify(&Program::from(elf), 2, Test::Wrap) - } -} diff --git a/recursion/program/src/machine/root.rs b/recursion/program/src/machine/root.rs index cf6116f0e..fc6c96e1e 100644 --- a/recursion/program/src/machine/root.rs +++ b/recursion/program/src/machine/root.rs @@ -113,7 +113,6 @@ where challenger.observe(builder, element); } // verify proof. - let one = builder.constant(C::N::one()); StarkVerifier::::verify_shard( builder, &vk, @@ -121,7 +120,7 @@ where machine, &mut challenger, proof, - one, + true, ); // Get the public inputs from the proof. diff --git a/recursion/program/src/machine/utils.rs b/recursion/program/src/machine/utils.rs index 0a40b6a0d..236ef4106 100644 --- a/recursion/program/src/machine/utils.rs +++ b/recursion/program/src/machine/utils.rs @@ -34,40 +34,40 @@ pub(crate) fn assert_complete( next_pc, start_shard, next_shard, + start_execution_shard, + next_execution_shard, cumulative_sum, start_reconstruct_deferred_digest, end_reconstruct_deferred_digest, leaf_challenger, - total_core_shards, .. } = public_values; - // Assert that `end_pc` is equal to zero (so program execution has completed) + // Assert that `next_pc` is equal to zero (so program execution has completed) builder.assert_felt_eq(*next_pc, C::F::zero()); - // Assert that the start shard is equal to 1. + // Assert that start shard is equal to 1. builder.assert_felt_eq(*start_shard, C::F::one()); - // Assert that total_core_shards is correct by ensuring it equals next_shard - 1. - builder.assert_felt_eq(*total_core_shards, *next_shard - C::F::one()); + // Assert that the next shard is not equal to one. This guarantees that there is at least one shard. + builder.assert_felt_ne(*next_shard, C::F::one()); - // The challenger has been fully verified. + // Assert that the start execution shard is equal to 1. + builder.assert_felt_eq(*start_execution_shard, C::F::one()); - // The start_reconstruct_challenger should be the same as an empty challenger observing the - // verifier key and the start pc. This was already verified when verifying the leaf proofs so - // there is no need to assert it here. + // Assert that next shard is not equal to one. This guarantees that there is at least one shard + // with CPU. + builder.assert_felt_ne(*next_execution_shard, C::F::one()); // Assert that the end reconstruct challenger is equal to the leaf challenger. assert_challenger_eq_pv(builder, end_reconstruct_challenger, *leaf_challenger); - // The deferred digest has been fully reconstructed. - - // The start reconstruct digest should be zero. + // The start reconstruct deffered digest should be zero. for start_digest_word in start_reconstruct_deferred_digest { builder.assert_felt_eq(*start_digest_word, C::F::zero()); } - // The end reconstruct digest should be equal to the deferred proofs digest. + // The end reconstruct deffered digest should be equal to the deferred proofs digest. for (end_digest_word, deferred_digest_word) in end_reconstruct_deferred_digest .iter() .zip_eq(deferred_proofs_digest.iter()) diff --git a/recursion/program/src/stark.rs b/recursion/program/src/stark.rs index 445a8f08f..67916265c 100644 --- a/recursion/program/src/stark.rs +++ b/recursion/program/src/stark.rs @@ -3,8 +3,6 @@ use p3_commit::TwoAdicMultiplicativeCoset; use p3_field::AbstractField; use p3_field::TwoAdicField; use sphinx_core::air::MachineAir; -use sphinx_core::air::PublicValues; -use sphinx_core::air::Word; use sphinx_core::stark::Com; use sphinx_core::stark::GenericVerifierConstraintFolder; use sphinx_core::stark::ShardProof; @@ -14,6 +12,7 @@ use sphinx_core::stark::StarkMachine; use sphinx_core::stark::StarkVerifyingKey; use sphinx_recursion_compiler::ir::Array; use sphinx_recursion_compiler::ir::Ext; +use sphinx_recursion_compiler::ir::ExtConst; use sphinx_recursion_compiler::ir::SymbolicExt; use sphinx_recursion_compiler::ir::SymbolicVar; use sphinx_recursion_compiler::ir::Var; @@ -120,7 +119,7 @@ where machine: &StarkMachine, challenger: &mut DuplexChallengerVariable, proof: &ShardProofVariable, - total_shards: Var, + check_cumulative_sum: bool, ) where A: MachineAir + for<'a> Air>, C::F: TwoAdicField, @@ -135,14 +134,6 @@ where .. } = proof; - // Extract public values. - let mut pv_elements = Vec::new(); - for i in 0..machine.num_pv_elts() { - let element = builder.get(&proof.public_values, i); - pv_elements.push(element); - } - let public_values = PublicValues::>, Felt<_>>::from_vec(&pv_elements); - let ShardCommitmentVariable { main_commit, permutation_commit, @@ -155,7 +146,6 @@ where challenger.observe(builder, permutation_commit.clone()); - #[allow(unused_variables)] let alpha = challenger.sample_ext(builder); challenger.observe(builder, quotient_commit.clone()); @@ -233,7 +223,6 @@ where builder.set_value(&mut quotient_domains, i, "ient_domain); // Get trace_opening_points. - let mut trace_points = builder.dyn_array::>(2); let zeta_next = domain.next_point(builder, zeta); builder.set_value(&mut trace_points, 0, &zeta); @@ -262,7 +251,6 @@ where builder.set_value(&mut perm_mats, i, &perm_mat); // Get the quotient matrices and values. - let qc_domains = quotient_domain.split_domains(builder, log_quotient_degree, quotient_size); @@ -313,42 +301,15 @@ where builder.cycle_tracker("stage-e-verify-constraints"); - let shard_bits = builder.num2bits_f(public_values.shard); - let shard = builder.bits2num_v(&shard_bits); + let num_shard_chips_enabled: Var<_> = builder.eval(C::N::zero()); for (i, chip) in machine.chips().iter().enumerate() { tracing::debug!("verifying constraints for chip: {}", chip.as_ref().name()); let index = builder.get(&proof.sorted_idxs, i); - if chip.as_ref().name() == "CPU" { - builder.assert_var_ne(index, C::N::from_canonical_usize(EMPTY)); - } - if chip.as_ref().preprocessed_width() > 0 { builder.assert_var_ne(index, C::N::from_canonical_usize(EMPTY)); } - if chip.as_ref().name() == "MemoryInit" { - builder.if_eq(shard, total_shards).then_or_else( - |builder| { - builder.assert_var_ne(index, C::N::from_canonical_usize(EMPTY)); - }, - |builder| { - builder.assert_var_eq(index, C::N::from_canonical_usize(EMPTY)); - }, - ); - } - - if chip.as_ref().name() == "MemoryFinalize" { - builder.if_eq(shard, total_shards).then_or_else( - |builder| { - builder.assert_var_ne(index, C::N::from_canonical_usize(EMPTY)); - }, - |builder| { - builder.assert_var_eq(index, C::N::from_canonical_usize(EMPTY)); - }, - ); - } - builder .if_ne(index, C::N::from_canonical_usize(EMPTY)) .then(|builder| { @@ -372,19 +333,44 @@ where let qc_domains = quotient_domain.split_domains_const(builder, log_quotient_degree); - Self::verify_constraints( - builder, - chip, - &values, - &proof.public_values, - &trace_domain, - &qc_domains, - zeta, - alpha, - &permutation_challenges, + // Verify the constraints. + stacker::maybe_grow(16 * 1024 * 1024, 16 * 1024 * 1024, || { + Self::verify_constraints( + builder, + chip, + &values, + &proof.public_values, + &trace_domain, + &qc_domains, + zeta, + alpha, + &permutation_challenges, + ); + }); + + // Increment the number of shard chips that are enabled. + builder.assign( + &num_shard_chips_enabled, + num_shard_chips_enabled + C::N::one(), ); }); } + + // Assert that the number of chips in `opened_values` matches the number of shard chips enabled. + builder.assert_var_eq(num_shard_chips_enabled, num_shard_chips); + + // If we're checking the cumulative sum, assert that the sum of the cumulative sums is zero. + if check_cumulative_sum { + let sum: Ext<_, _> = builder.eval(C::EF::zero().cons()); + builder + .range(0, proof.opened_values.chips.len()) + .for_each(|i, builder| { + let cumulative_sum = builder.get(&proof.opened_values.chips, i).cumulative_sum; + builder.assign(&sum, sum + cumulative_sum); + }); + builder.assert_ext_eq(sum, C::EF::zero().cons()); + } + builder.cycle_tracker("stage-e-verify-constraints"); } } @@ -408,7 +394,8 @@ pub(crate) mod tests { use sphinx_core::air::POSEIDON_NUM_WORDS; use sphinx_core::io::SphinxStdin; use sphinx_core::runtime::Program; - use sphinx_core::stark::LocalProver; + use sphinx_core::stark::DefaultProver; + use sphinx_core::stark::MachineProver; use sphinx_core::utils::setup_logger; use sphinx_core::utils::InnerChallenge; use sphinx_core::utils::InnerVal; @@ -454,7 +441,7 @@ pub(crate) mod tests { let machine = A::machine(SC::default()); let (_, vk) = machine.setup(&Program::from(elf)); let mut challenger_val = machine.config().challenger(); - let (proof, _) = sphinx_core::utils::prove( + let (proof, _) = sphinx_core::utils::prove::<_, DefaultProver<_, _>>( &Program::from(elf), &SphinxStdin::new(), SC::default(), @@ -536,7 +523,7 @@ pub(crate) mod tests { public_values.sphinx_vk_digest = [builder.constant(::F::zero()); DIGEST_SIZE]; public_values.next_pc = builder.constant(::F::one()); - public_values.next_shard = builder.constant(::F::two()); + public_values.next_execution_shard = builder.constant(::F::two()); public_values.end_reconstruct_deferred_digest = [builder.constant(::F::from_canonical_usize(3)); POSEIDON_NUM_WORDS]; @@ -559,22 +546,25 @@ pub(crate) mod tests { let config = SC::default(); let mut runtime = Runtime::::new(&program, config.perm.clone()); - runtime.run(); + runtime.run().unwrap(); let machine = RecursionAir::<_, 3>::machine(SC::default()); - let (pk, vk) = machine.setup(&program); + let prover = DefaultProver::new(machine); + let (pk, vk) = prover.setup(&program); let record = runtime.record.clone(); - let mut challenger = machine.config().challenger(); - let mut proof = machine.prove::>>( - &pk, - record, - &mut challenger, - SphinxCoreOpts::recursion(), - ); - - let mut challenger = machine.config().challenger(); - let verification_result = machine.verify(&vk, &proof, &mut challenger); + let mut challenger = prover.config().challenger(); + let mut proof = prover + .prove( + &pk, + vec![record], + &mut challenger, + SphinxCoreOpts::recursion(), + ) + .unwrap(); + + let mut challenger = prover.config().challenger(); + let verification_result = prover.machine().verify(&vk, &proof, &mut challenger); assert!( verification_result.is_ok(), "Proof should verify successfully" @@ -583,11 +573,11 @@ pub(crate) mod tests { // Corrupt the public values. proof.shard_proofs[0].public_values[RECURSION_PUBLIC_VALUES_COL_MAP.digest[0]] = InnerVal::zero(); - let verification_result = machine.verify(&vk, &proof, &mut challenger); + let verification_result = prover.machine().verify(&vk, &proof, &mut challenger); assert!( verification_result.is_err(), "Proof should not verify successfully" - ); + ) } #[test] diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index a81eb80b3..0a76232a2 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -40,6 +40,7 @@ strum_macros = { workspace = true } strum = { workspace = true } thiserror = { workspace = true } hashbrown = { workspace = true } +sysinfo = { workspace = true } [features] default = ["network"] diff --git a/sdk/src/action.rs b/sdk/src/action.rs index 477664726..aad6afbaf 100644 --- a/sdk/src/action.rs +++ b/sdk/src/action.rs @@ -2,7 +2,10 @@ use sphinx_core::{ runtime::{ExecutionReport, HookEnv, SphinxContextBuilder}, utils::{SphinxCoreOpts, SphinxProverOpts}, }; -use sphinx_prover::{SphinxProver, SphinxProvingKey, SphinxPublicValues, SphinxStdin}; +use sphinx_prover::{ + components::DefaultProverComponents, SphinxProver, SphinxProvingKey, SphinxPublicValues, + SphinxStdin, +}; use anyhow::{Ok, Result}; @@ -38,7 +41,9 @@ impl<'a> Execute<'a> { mut context_builder, } = self; let context = context_builder.build(); - Ok(SphinxProver::execute(elf, &stdin, context)?) + Ok(SphinxProver::::execute( + elf, &stdin, context, + )?) } /// Add a runtime [Hook](super::Hook) into the context. @@ -63,12 +68,20 @@ impl<'a> Execute<'a> { self.context_builder.without_default_hooks(); self } + + /// Set the maximum number of cpu cycles to use for execution. + /// + /// If the cycle limit is exceeded, execution will return [sp1_core::runtime::ExecutionError::ExceededCycleLimit]. + pub fn max_cycles(mut self, max_cycles: u64) -> Self { + self.context_builder.max_cycles(max_cycles); + self + } } /// Builder to prepare and configure proving execution of a program on an input. /// May be run with [Self::run]. pub struct Prove<'a> { - prover: &'a dyn Prover, + prover: &'a dyn Prover, kind: SphinxProofKind, context_builder: SphinxContextBuilder<'a>, pk: &'a SphinxProvingKey, @@ -81,7 +94,11 @@ impl<'a> Prove<'a> { /// /// Prefer using [ProverClient::prove](super::ProverClient::prove). /// See there for more documentation. - pub fn new(prover: &'a dyn Prover, pk: &'a SphinxProvingKey, stdin: SphinxStdin) -> Self { + pub fn new( + prover: &'a dyn Prover, + pk: &'a SphinxProvingKey, + stdin: SphinxStdin, + ) -> Self { Self { prover, kind: Default::default(), @@ -164,9 +181,15 @@ impl<'a> Prove<'a> { self } - /// Set the chunking multiplier for proving. - pub fn shard_chunking_multiplier(mut self, value: usize) -> Self { - self.opts.shard_chunking_multiplier = value; + /// Set the commit stream capacity for proving. + pub fn commit_stream_capacity(mut self, value: usize) -> Self { + self.opts.commit_stream_capacity = value; + self + } + + /// Set the prove stream capacity for proving. + pub fn prove_stream_capacity(mut self, value: usize) -> Self { + self.opts.prove_stream_capacity = value; self } @@ -175,4 +198,12 @@ impl<'a> Prove<'a> { self.opts.reconstruct_commitments = value; self } + + /// Set the maximum number of cpu cycles to use for execution. + /// + /// If the cycle limit is exceeded, execution will return [sp1_core::runtime::ExecutionError::ExceededCycleLimit]. + pub fn cycle_limit(mut self, cycle_limit: u64) -> Self { + self.context_builder.max_cycles(cycle_limit); + self + } } diff --git a/sdk/src/artifacts.rs b/sdk/src/artifacts.rs index 9e5475570..ae835eefb 100644 --- a/sdk/src/artifacts.rs +++ b/sdk/src/artifacts.rs @@ -4,9 +4,9 @@ use anyhow::{Context, Result}; use futures::StreamExt; use indicatif::{ProgressBar, ProgressStyle}; use reqwest::Client; -pub use sphinx_prover::build::{ - build_plonk_bn254_artifacts_with_dummy, try_install_plonk_bn254_artifacts, -}; +pub use sphinx_prover::build::build_plonk_bn254_artifacts_with_dummy; + +use crate::install::try_install_plonk_bn254_artifacts; /// Exports the solidity verifier for PLONK proofs to the specified output directory. /// @@ -16,7 +16,7 @@ pub fn export_solidity_plonk_bn254_verifier(output_dir: impl Into) -> R let artifacts_dir = if sphinx_prover::build::sphinx_dev_mode() { sphinx_prover::build::plonk_bn254_artifacts_dev_dir() } else { - try_install_plonk_bn254_artifacts(false) + try_install_plonk_bn254_artifacts() }; let verifier_path = artifacts_dir.join("SphinxVerifier.sol"); diff --git a/prover/src/install.rs b/sdk/src/install.rs similarity index 60% rename from prover/src/install.rs rename to sdk/src/install.rs index c898c0b39..6b4a90a58 100644 --- a/prover/src/install.rs +++ b/sdk/src/install.rs @@ -5,20 +5,51 @@ use std::{ process::Command, }; -use futures::StreamExt; +use futures::{Future, StreamExt}; use indicatif::{ProgressBar, ProgressStyle}; use reqwest::Client; +use tokio::{runtime, task::block_in_place}; -use crate::{utils::block_on, SPHINX_CIRCUIT_VERSION}; +use crate::SPHINX_CIRCUIT_VERSION; /// The base URL for the S3 bucket containing the plonk bn254 artifacts. pub const PLONK_BN254_ARTIFACTS_URL_BASE: &str = "https://sphinx-plonk-params.s3.amazonaws.com"; +/// Gets the directory where the PLONK artifacts are installed. +fn plonk_bn254_artifacts_dir() -> PathBuf { + home::home_dir() + .unwrap() + .join(".sp1") + .join("circuits") + .join("plonk_bn254") + .join(SPHINX_CIRCUIT_VERSION) +} + +/// Tries to install the PLONK artifacts if they are not already installed. +pub fn try_install_plonk_bn254_artifacts() -> PathBuf { + let build_dir = plonk_bn254_artifacts_dir(); + + if build_dir.exists() { + println!( + "[sp1] plonk bn254 artifacts already seem to exist at {}. if you want to re-download them, delete the directory", + build_dir.display() + ); + } else { + println!( + "[sp1] plonk bn254 artifacts for version {} do not exist at {}. downloading...", + SPHINX_CIRCUIT_VERSION, + build_dir.display() + ); + install_plonk_bn254_artifacts(&build_dir.clone()); + } + build_dir +} + /// Install the latest plonk bn254 artifacts. /// /// This function will download the latest plonk bn254 artifacts from the S3 bucket and extract them to /// the directory specified by [plonk_bn254_artifacts_dir()]. -pub fn install_plonk_bn254_artifacts(build_dir: &Path, use_aws_cli: bool) { +pub fn install_plonk_bn254_artifacts(build_dir: &Path) { // Create the build directory. std::fs::create_dir_all(build_dir).expect("failed to create build directory"); @@ -29,21 +60,15 @@ pub fn install_plonk_bn254_artifacts(build_dir: &Path, use_aws_cli: bool) { ); let mut artifacts_tar_gz_file = tempfile::NamedTempFile::new().expect("failed to create tempfile"); - - if use_aws_cli { - block_on(download_file_aws(&download_url, &mut artifacts_tar_gz_file)) - .expect("failed to download file [aws]"); - } else { - let client = Client::builder() - .build() - .expect("failed to create reqwest client"); - block_on(download_file( - &client, - &download_url, - &mut artifacts_tar_gz_file, - )) - .expect("failed to download file"); - } + let client = Client::builder() + .build() + .expect("failed to create reqwest client"); + block_on(download_file( + &client, + &download_url, + &mut artifacts_tar_gz_file, + )) + .expect("failed to download file"); // Extract the tarball to the build directory. let mut res = Command::new("tar") @@ -110,16 +135,15 @@ pub async fn download_file( Ok(()) } -/// Download the file using the AWS cli -pub async fn download_file_aws( - url: &str, - file: &mut tempfile::NamedTempFile, -) -> Result<(), String> { - let mut res = Command::new("aws") - .args(["s3", "cp", url, file.path().to_str().unwrap()]) - .spawn() - .expect("couldn't run `aws` command. Probably it is not installed / configured"); - res.wait().unwrap(); - - Ok(()) +/// Utility method for blocking on an async function. If we're already in a tokio runtime, we'll +/// block in place. Otherwise, we'll create a new runtime. +pub fn block_on(fut: impl Future) -> T { + // Handle case if we're already in an tokio runtime. + if let Ok(handle) = runtime::Handle::try_current() { + block_in_place(|| handle.block_on(fut)) + } else { + // Otherwise create a new runtime. + let rt = runtime::Runtime::new().expect("Failed to create a new runtime"); + rt.block_on(fut) + } } diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index f694e6241..c83622e73 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -11,6 +11,7 @@ pub mod proto { } pub mod action; pub mod artifacts; +pub mod install; #[cfg(feature = "network")] pub mod network; #[cfg(feature = "network")] @@ -25,21 +26,24 @@ pub mod utils { use cfg_if::cfg_if; pub use proof::*; pub use provers::SphinxVerificationError; +use sphinx_prover::components::DefaultProverComponents; use std::env; pub use provers::{LocalProver, MockProver, Prover}; -pub use sphinx_core::runtime::{Hook, HookEnv, SphinxContext, SphinxContextBuilder}; +pub use sphinx_core::runtime::{ + ExecutionReport, Hook, HookEnv, SphinxContext, SphinxContextBuilder, +}; use sphinx_core::SPHINX_CIRCUIT_VERSION; pub use sphinx_prover::{ - types::HashableKey, CoreSC, InnerSC, OuterSC, PlonkBn254Proof, SphinxProver, SphinxProvingKey, + CoreSC, HashableKey, InnerSC, OuterSC, PlonkBn254Proof, SphinxProver, SphinxProvingKey, SphinxPublicValues, SphinxStdin, SphinxVerifyingKey, }; /// A client for interacting with Sphinx. pub struct ProverClient { /// The underlying prover implementation. - pub prover: Box, + pub prover: Box>, } impl ProverClient { @@ -335,6 +339,17 @@ mod tests { client.execute(elf, stdin).run().unwrap(); } + #[should_panic] + #[test] + fn test_cycle_limit_fail() { + utils::setup_logger(); + let client = ProverClient::local(); + let elf = include_bytes!("../../tests/panic/elf/riscv32im-succinct-zkvm-elf"); + let mut stdin = SphinxStdin::new(); + stdin.write(&10usize); + client.execute(elf, stdin).max_cycles(1).run().unwrap(); + } + #[test] fn test_e2e_prove_plonk() { utils::setup_logger(); diff --git a/sdk/src/network/prover.rs b/sdk/src/network/prover.rs index 4633bc130..6b2dd4c71 100644 --- a/sdk/src/network/prover.rs +++ b/sdk/src/network/prover.rs @@ -1,5 +1,6 @@ use std::{env, time::Duration}; +use crate::install::block_on; use crate::proto::network::ProofMode; use crate::{ network::client::{NetworkClient, DEFAULT_PROVER_NETWORK_RPC}, @@ -13,7 +14,7 @@ use crate::{ use anyhow::Result; use serde::de::DeserializeOwned; use sphinx_core::utils::SphinxProverOpts; -use sphinx_prover::utils::block_on; +use sphinx_prover::components::DefaultProverComponents; use sphinx_prover::{SphinxProver, SphinxStdin, SPHINX_CIRCUIT_VERSION}; use tokio::time::sleep; @@ -22,7 +23,7 @@ use crate::provers::{LocalProver, ProverType}; /// An implementation of [crate::ProverClient] that can generate proofs on a remote RPC server. pub struct NetworkProver { client: NetworkClient, - local_prover: LocalProver, + local_prover: LocalProver, } impl NetworkProver { @@ -59,7 +60,8 @@ impl NetworkProver { .unwrap_or(false); if !skip_simulation { - let (_, report) = SphinxProver::execute(elf, &stdin, Default::default())?; + let (_, report) = + SphinxProver::::execute(elf, &stdin, Default::default())?; log::info!( "Simulation complete, cycles: {}", report.total_instruction_count() @@ -122,7 +124,7 @@ impl NetworkProver { } } -impl Prover for NetworkProver { +impl Prover for NetworkProver { fn id(&self) -> ProverType { ProverType::Network } @@ -165,6 +167,7 @@ fn warn_if_not_default(opts: &SphinxProverOpts, context: &SphinxContext<'_>) { let SphinxContext { hook_registry, subproof_verifier, + .. } = context; if hook_registry.is_some() { tracing::warn!( diff --git a/sdk/src/proof.rs b/sdk/src/proof.rs index 5b2cf3a37..a1525e2c4 100644 --- a/sdk/src/proof.rs +++ b/sdk/src/proof.rs @@ -39,6 +39,30 @@ impl SphinxProofWithPublicValues { bincode::deserialize_from(File::open(path).expect("failed to open file")) .map_err(Into::into) } + + /// Returns the raw proof as a string. + pub fn raw(&self) -> String { + match &self.proof { + SphinxProof::Plonk(plonk) => plonk.raw_proof.clone(), + _ => unimplemented!(), + } + } + + /// For Plonk proofs, returns the proof in a byte encoding the onchain verifier accepts. + /// The bytes consist of the first four bytes of Plonk vkey hash followed by the encoded proof. + pub fn bytes(&self) -> Vec { + match &self.proof { + SphinxProof::Plonk(plonk_proof) => { + let mut bytes = Vec::with_capacity(4 + plonk_proof.encoded_proof.len()); + bytes.extend_from_slice(&plonk_proof.plonk_vkey_hash[..4]); + bytes.extend_from_slice( + &hex::decode(&plonk_proof.encoded_proof).expect("Invalid Plonk proof"), + ); + bytes + } + _ => unimplemented!("only Plonk proofs are verifiable onchain"), + } + } } pub type SphinxCoreProofVerificationError = MachineVerificationError; diff --git a/sdk/src/provers/local.rs b/sdk/src/provers/local.rs index 2f2c39c8b..f210ca7be 100644 --- a/sdk/src/provers/local.rs +++ b/sdk/src/provers/local.rs @@ -1,28 +1,34 @@ use anyhow::Result; use sphinx_core::{runtime::SphinxContext, utils::SphinxProverOpts}; -use sphinx_prover::{SphinxProver, SphinxStdin}; +use sphinx_prover::{components::SphinxProverComponents, SphinxProver, SphinxStdin}; +use sysinfo::System; use crate::{ - Prover, SphinxProof, SphinxProofKind, SphinxProofWithPublicValues, SphinxProvingKey, - SphinxVerifyingKey, + install::try_install_plonk_bn254_artifacts, Prover, SphinxProof, SphinxProofKind, + SphinxProofWithPublicValues, SphinxProvingKey, SphinxVerifyingKey, }; use super::ProverType; /// An implementation of [crate::ProverClient] that can generate end-to-end proofs locally. -pub struct LocalProver { - prover: SphinxProver, +pub struct LocalProver { + prover: SphinxProver, } -impl LocalProver { +impl LocalProver { /// Creates a new [LocalProver]. pub fn new() -> Self { let prover = SphinxProver::new(); Self { prover } } + + /// Creates a new [LocalProver] from an existing [SP1Prover]. + pub fn from_prover(prover: SphinxProver) -> Self { + Self { prover } + } } -impl Prover for LocalProver { +impl Prover for LocalProver { fn id(&self) -> ProverType { ProverType::Local } @@ -31,7 +37,7 @@ impl Prover for LocalProver { self.prover.setup(elf) } - fn sphinx_prover(&self) -> &SphinxProver { + fn sphinx_prover(&self) -> &SphinxProver { &self.prover } @@ -43,6 +49,13 @@ impl Prover for LocalProver { context: SphinxContext<'a>, kind: SphinxProofKind, ) -> Result { + let total_ram_gb = System::new_all().total_memory() / 1_000_000_000; + if kind == SphinxProofKind::Plonk && total_ram_gb <= 120 { + return Err(anyhow::anyhow!( + "not enough memory to generate plonk proof. at least 128GB is required." + )); + } + let proof = self.prover.prove_core(pk, &stdin, opts, context)?; if kind == SphinxProofKind::Core { return Ok(SphinxProofWithPublicValues { @@ -72,7 +85,7 @@ impl Prover for LocalProver { &outer_proof.proof, ) } else { - sphinx_prover::build::try_install_plonk_bn254_artifacts(false) + try_install_plonk_bn254_artifacts() }; let proof = self .prover @@ -89,7 +102,7 @@ impl Prover for LocalProver { } } -impl Default for LocalProver { +impl Default for LocalProver { fn default() -> Self { Self::new() } diff --git a/sdk/src/provers/mock.rs b/sdk/src/provers/mock.rs index 8dc6dc193..0e4584dcd 100644 --- a/sdk/src/provers/mock.rs +++ b/sdk/src/provers/mock.rs @@ -1,9 +1,11 @@ +#![allow(unused_variables)] +use hashbrown::HashMap; + use crate::{ Prover, SphinxProof, SphinxProofKind, SphinxProofWithPublicValues, SphinxProvingKey, SphinxVerificationError, SphinxVerifyingKey, }; use anyhow::Result; -use hashbrown::HashMap; use p3_baby_bear::BabyBear; use p3_field::{AbstractField, PrimeField}; use p3_fri::{FriProof, TwoAdicFriPcsProof}; @@ -13,8 +15,8 @@ use sphinx_core::{ utils::SphinxProverOpts, }; use sphinx_prover::{ - types::HashableKey, verify::verify_plonk_bn254_public_inputs, PlonkBn254Proof, SphinxProver, - SphinxStdin, + components::DefaultProverComponents, types::HashableKey as _, + verify::verify_plonk_bn254_public_inputs, PlonkBn254Proof, SphinxProver, SphinxStdin, }; use super::ProverType; @@ -32,7 +34,7 @@ impl MockProver { } } -impl Prover for MockProver { +impl Prover for MockProver { fn id(&self) -> ProverType { ProverType::Mock } @@ -55,7 +57,8 @@ impl Prover for MockProver { ) -> Result { match kind { SphinxProofKind::Core => { - let (public_values, _) = SphinxProver::execute(&pk.elf, &stdin, context)?; + let (public_values, _) = + SphinxProver::::execute(&pk.elf, &stdin, context)?; Ok(SphinxProofWithPublicValues { proof: SphinxProof::Core(vec![]), stdin, @@ -64,7 +67,8 @@ impl Prover for MockProver { }) } SphinxProofKind::Compressed => { - let (public_values, _) = SphinxProver::execute(&pk.elf, &stdin, context)?; + let (public_values, _) = + SphinxProver::::execute(&pk.elf, &stdin, context)?; Ok(SphinxProofWithPublicValues { proof: SphinxProof::Compressed(ShardProof { commitment: ShardCommitment { @@ -91,7 +95,8 @@ impl Prover for MockProver { }) } SphinxProofKind::Plonk => { - let (public_values, _) = SphinxProver::execute(&pk.elf, &stdin, context)?; + let (public_values, _) = + SphinxProver::::execute(&pk.elf, &stdin, context)?; Ok(SphinxProofWithPublicValues { proof: SphinxProof::Plonk(PlonkBn254Proof { public_inputs: [ diff --git a/sdk/src/provers/mod.rs b/sdk/src/provers/mod.rs index e81f5847d..42d23bd42 100644 --- a/sdk/src/provers/mod.rs +++ b/sdk/src/provers/mod.rs @@ -8,6 +8,7 @@ use sphinx_core::runtime::SphinxContext; use sphinx_core::stark::MachineVerificationError; use sphinx_core::utils::SphinxProverOpts; use sphinx_core::SPHINX_CIRCUIT_VERSION; +use sphinx_prover::components::SphinxProverComponents; use sphinx_prover::CoreSC; use sphinx_prover::InnerSC; use sphinx_prover::SphinxCoreProofData; @@ -17,6 +18,7 @@ use sphinx_prover::{SphinxProvingKey, SphinxStdin, SphinxVerifyingKey}; use strum_macros::EnumString; use thiserror::Error; +use crate::install::try_install_plonk_bn254_artifacts; use crate::SphinxProof; use crate::SphinxProofKind; use crate::SphinxProofWithPublicValues; @@ -42,10 +44,10 @@ pub enum SphinxVerificationError { } /// An implementation of [crate::ProverClient]. -pub trait Prover: Send + Sync { +pub trait Prover: Send + Sync { fn id(&self) -> ProverType; - fn sphinx_prover(&self) -> &SphinxProver; + fn sphinx_prover(&self) -> &SphinxProver; fn version(&self) -> &str { SPHINX_CIRCUIT_VERSION @@ -94,7 +96,7 @@ pub trait Prover: Send + Sync { &if sphinx_prover::build::sphinx_dev_mode() { sphinx_prover::build::plonk_bn254_artifacts_dev_dir() } else { - sphinx_prover::build::try_install_plonk_bn254_artifacts(false) + try_install_plonk_bn254_artifacts() }, ) .map_err(SphinxVerificationError::Plonk), diff --git a/sp1up/install b/sp1up/install index 6e0ce40a5..39dd6b941 100644 --- a/sp1up/install +++ b/sp1up/install @@ -6,7 +6,7 @@ set -e echo Installing sp1up... -BASE_DIR=${XDG_CONFIG_HOME:-$HOME} +BASE_DIR=$HOME SP1_DIR=${SP1_DIR-"$BASE_DIR/.sp1"} SP1_BIN_DIR="$SP1_DIR/bin" diff --git a/sp1up/sp1up b/sp1up/sp1up index 5524462ba..6ad15dfd1 100644 --- a/sp1up/sp1up +++ b/sp1up/sp1up @@ -4,7 +4,7 @@ set -eo pipefail -BASE_DIR=${XDG_CONFIG_HOME:-$HOME} +BASE_DIR=$HOME SP1_DIR=${SP1_DIR:-"$BASE_DIR/.sp1"} SP1_BIN_DIR="$SP1_DIR/bin" mkdir -p $SP1_BIN_DIR @@ -29,6 +29,7 @@ main() { -C|--commit) shift; SP1UP_COMMIT=$1;; --arch) shift; SP1UP_ARCH=$1;; --platform) shift; SP1UP_PLATFORM=$1;; + -t|--token) shift; GITHUB_TOKEN=$1;; -h|--help) usage exit 0 diff --git a/tests/bls12381-fp-add/Cargo.lock b/tests/bls12381-fp-add/Cargo.lock index ca15e236d..416073e05 100644 --- a/tests/bls12381-fp-add/Cargo.lock +++ b/tests/bls12381-fp-add/Cargo.lock @@ -14,18 +14,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -35,18 +23,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -65,31 +41,12 @@ dependencies = [ "sphinx-zkvm", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -99,18 +56,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -121,16 +66,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -138,62 +73,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -202,7 +84,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -216,55 +97,21 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - [[package]] name = "hex-literal" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" -version = "0.2.0-rc.8" +version = "0.2.0-rc.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53668f5da5a41d9eaf4bf7064be46d1ebe6a4e1ceed817f387587b18f2b51047" +checksum = "4d306b679262030ad8813a82d4915fc04efff97776e4db7f8eb5137039d56400" dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -350,25 +197,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -393,12 +221,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -429,30 +251,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -485,36 +283,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -525,31 +301,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.63" @@ -561,12 +321,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -590,18 +344,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/tests/bls12381-fp-add/elf/riscv32im-succinct-zkvm-elf b/tests/bls12381-fp-add/elf/riscv32im-succinct-zkvm-elf index 6699ef10f..e4eb305cc 100755 Binary files a/tests/bls12381-fp-add/elf/riscv32im-succinct-zkvm-elf and b/tests/bls12381-fp-add/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/bls12381-fp-mul/Cargo.lock b/tests/bls12381-fp-mul/Cargo.lock index 3feb0bb9d..704e87804 100644 --- a/tests/bls12381-fp-mul/Cargo.lock +++ b/tests/bls12381-fp-mul/Cargo.lock @@ -14,18 +14,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -35,18 +23,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -65,31 +41,12 @@ dependencies = [ "sphinx-zkvm", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -99,18 +56,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -121,16 +66,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -138,62 +73,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -202,7 +84,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -216,32 +97,12 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - [[package]] name = "hex-literal" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -251,20 +112,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -350,25 +197,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -393,12 +221,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -429,30 +251,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -485,36 +283,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -525,31 +301,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.63" @@ -561,12 +321,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -590,18 +344,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/tests/bls12381-fp-mul/elf/riscv32im-succinct-zkvm-elf b/tests/bls12381-fp-mul/elf/riscv32im-succinct-zkvm-elf index 76de64137..fdf5ba46e 100755 Binary files a/tests/bls12381-fp-mul/elf/riscv32im-succinct-zkvm-elf and b/tests/bls12381-fp-mul/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/bls12381-fp-sub/Cargo.lock b/tests/bls12381-fp-sub/Cargo.lock index 92c3824e0..7efb43521 100644 --- a/tests/bls12381-fp-sub/Cargo.lock +++ b/tests/bls12381-fp-sub/Cargo.lock @@ -14,18 +14,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -35,18 +23,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -65,31 +41,12 @@ dependencies = [ "sphinx-zkvm", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -99,18 +56,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -121,16 +66,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -138,62 +73,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -202,7 +84,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -216,32 +97,12 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - [[package]] name = "hex-literal" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -251,20 +112,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -350,25 +197,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -393,12 +221,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -429,30 +251,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -485,36 +283,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -525,31 +301,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.63" @@ -561,12 +321,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -590,18 +344,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/tests/bls12381-fp-sub/elf/riscv32im-succinct-zkvm-elf b/tests/bls12381-fp-sub/elf/riscv32im-succinct-zkvm-elf index aca4eeddb..b1ad822e6 100755 Binary files a/tests/bls12381-fp-sub/elf/riscv32im-succinct-zkvm-elf and b/tests/bls12381-fp-sub/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/bls12381-fp2-add/Cargo.lock b/tests/bls12381-fp2-add/Cargo.lock index c6f171b2a..7abfdd246 100644 --- a/tests/bls12381-fp2-add/Cargo.lock +++ b/tests/bls12381-fp2-add/Cargo.lock @@ -14,18 +14,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -35,18 +23,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -65,31 +41,12 @@ dependencies = [ "sphinx-zkvm", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#0d57d6ac0af6a464c4764809b5bf994d15920762" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -99,18 +56,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -121,16 +66,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -138,62 +73,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -202,7 +84,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -216,32 +97,12 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - [[package]] name = "hex-literal" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.9" @@ -251,20 +112,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -350,25 +197,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -393,12 +221,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -429,30 +251,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.204" @@ -485,36 +283,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -525,31 +301,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" - [[package]] name = "syn" version = "2.0.72" @@ -561,12 +321,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -590,18 +344,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/tests/bls12381-fp2-add/elf/riscv32im-succinct-zkvm-elf b/tests/bls12381-fp2-add/elf/riscv32im-succinct-zkvm-elf index 84638bbdd..51835eb26 100755 Binary files a/tests/bls12381-fp2-add/elf/riscv32im-succinct-zkvm-elf and b/tests/bls12381-fp2-add/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/bls12381-fp2-mul/Cargo.lock b/tests/bls12381-fp2-mul/Cargo.lock index cdefb7b54..f815a4c9d 100644 --- a/tests/bls12381-fp2-mul/Cargo.lock +++ b/tests/bls12381-fp2-mul/Cargo.lock @@ -14,18 +14,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -35,18 +23,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -65,31 +41,12 @@ dependencies = [ "sphinx-zkvm", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -99,18 +56,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -121,16 +66,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -138,62 +73,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -202,7 +84,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -216,32 +97,12 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - [[package]] name = "hex-literal" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -251,20 +112,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -350,25 +197,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -393,12 +221,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -429,30 +251,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -485,36 +283,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -525,31 +301,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.63" @@ -561,12 +321,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -590,18 +344,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/tests/bls12381-fp2-mul/elf/riscv32im-succinct-zkvm-elf b/tests/bls12381-fp2-mul/elf/riscv32im-succinct-zkvm-elf index d3fcb7e17..91cb1ac55 100755 Binary files a/tests/bls12381-fp2-mul/elf/riscv32im-succinct-zkvm-elf and b/tests/bls12381-fp2-mul/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/bls12381-fp2-sub/Cargo.lock b/tests/bls12381-fp2-sub/Cargo.lock index e9c54baaa..b8caaf3fa 100644 --- a/tests/bls12381-fp2-sub/Cargo.lock +++ b/tests/bls12381-fp2-sub/Cargo.lock @@ -14,18 +14,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -35,18 +23,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -65,31 +41,12 @@ dependencies = [ "sphinx-zkvm", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#0d57d6ac0af6a464c4764809b5bf994d15920762" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -99,18 +56,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -121,16 +66,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -138,62 +73,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -202,7 +84,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -216,32 +97,12 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - [[package]] name = "hex-literal" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.9" @@ -251,20 +112,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -350,25 +197,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -393,12 +221,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -429,30 +251,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.204" @@ -485,36 +283,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -525,31 +301,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" - [[package]] name = "syn" version = "2.0.72" @@ -561,12 +321,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -590,18 +344,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/tests/bls12381-fp2-sub/elf/riscv32im-succinct-zkvm-elf b/tests/bls12381-fp2-sub/elf/riscv32im-succinct-zkvm-elf index 9605feaae..8294346f3 100755 Binary files a/tests/bls12381-fp2-sub/elf/riscv32im-succinct-zkvm-elf and b/tests/bls12381-fp2-sub/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/bls12381-g1-add/Cargo.lock b/tests/bls12381-g1-add/Cargo.lock index 92f6c8239..b282259b4 100644 --- a/tests/bls12381-g1-add/Cargo.lock +++ b/tests/bls12381-g1-add/Cargo.lock @@ -14,18 +14,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -35,18 +23,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -64,31 +40,12 @@ dependencies = [ "sphinx-zkvm", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -98,18 +55,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -120,16 +65,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -137,62 +72,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -201,7 +83,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -215,26 +96,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -244,20 +105,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -343,25 +190,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -386,12 +214,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -422,30 +244,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -478,36 +276,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -518,31 +294,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.63" @@ -554,12 +314,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -583,18 +337,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/tests/bls12381-g1-add/elf/riscv32im-succinct-zkvm-elf b/tests/bls12381-g1-add/elf/riscv32im-succinct-zkvm-elf index 01bd31e2b..2663584f9 100755 Binary files a/tests/bls12381-g1-add/elf/riscv32im-succinct-zkvm-elf and b/tests/bls12381-g1-add/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/bls12381-g1-add/src/main.rs b/tests/bls12381-g1-add/src/main.rs index 3c7673bb5..cfac7fa82 100644 --- a/tests/bls12381-g1-add/src/main.rs +++ b/tests/bls12381-g1-add/src/main.rs @@ -1,9 +1,8 @@ #![no_main] -sphinx_zkvm::entrypoint!(main); -extern "C" { - fn syscall_bls12381_g1_add(p: *mut u32, q: *const u32); -} +use sphinx_zkvm::syscalls::syscall_bls12381_g1_add; + +sphinx_zkvm::entrypoint!(main); pub fn main() { for _ in 0..4 { @@ -31,9 +30,7 @@ pub fn main() { 22, ]; - unsafe { - syscall_bls12381_g1_add(a.as_mut_ptr() as *mut u32, b.as_ptr() as *const u32); - } + syscall_bls12381_g1_add(a.as_mut_ptr() as *mut u32, b.as_ptr() as *const u32); // 3 * generator. // 1527649530533633684281386512094328299672026648504329745640827351945739272160755686119065091946435084697047221031460 diff --git a/tests/bls12381-g1-decompress/Cargo.lock b/tests/bls12381-g1-decompress/Cargo.lock index 8a02584f5..e12891fa1 100644 --- a/tests/bls12381-g1-decompress/Cargo.lock +++ b/tests/bls12381-g1-decompress/Cargo.lock @@ -8,18 +8,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -29,18 +17,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -57,31 +33,12 @@ dependencies = [ "sphinx-zkvm", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -91,18 +48,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -113,16 +58,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -130,62 +65,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -194,7 +76,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -208,26 +89,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -237,20 +98,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -275,25 +122,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -318,12 +146,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -354,30 +176,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -410,36 +208,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -450,31 +226,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.63" @@ -486,12 +246,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -515,18 +269,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/tests/bls12381-g1-decompress/elf/riscv32im-succinct-zkvm-elf b/tests/bls12381-g1-decompress/elf/riscv32im-succinct-zkvm-elf index c3d101746..1d25cf64d 100755 Binary files a/tests/bls12381-g1-decompress/elf/riscv32im-succinct-zkvm-elf and b/tests/bls12381-g1-decompress/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/bls12381-g1-double/Cargo.lock b/tests/bls12381-g1-double/Cargo.lock index 5446bd317..7782a19d2 100644 --- a/tests/bls12381-g1-double/Cargo.lock +++ b/tests/bls12381-g1-double/Cargo.lock @@ -14,18 +14,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -35,18 +23,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -64,31 +40,12 @@ dependencies = [ "sphinx-zkvm", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -98,18 +55,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -120,16 +65,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -137,62 +72,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -201,7 +83,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -215,26 +96,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -244,20 +105,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -343,25 +190,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -386,12 +214,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -422,30 +244,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -478,36 +276,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -518,31 +294,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.63" @@ -554,12 +314,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -583,18 +337,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/tests/bls12381-g1-double/elf/riscv32im-succinct-zkvm-elf b/tests/bls12381-g1-double/elf/riscv32im-succinct-zkvm-elf index 50d5bbb81..07227dcf6 100755 Binary files a/tests/bls12381-g1-double/elf/riscv32im-succinct-zkvm-elf and b/tests/bls12381-g1-double/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/bls12381-g1-double/src/main.rs b/tests/bls12381-g1-double/src/main.rs index 993b2e312..51091e420 100644 --- a/tests/bls12381-g1-double/src/main.rs +++ b/tests/bls12381-g1-double/src/main.rs @@ -1,9 +1,8 @@ #![no_main] -sphinx_zkvm::entrypoint!(main); -extern "C" { - fn syscall_bls12381_g1_double(p: *mut u32); -} +use sphinx_zkvm::syscalls::syscall_bls12381_g1_double; + +sphinx_zkvm::entrypoint!(main); pub fn main() { for _ in 0..10i64.pow(3) { @@ -19,9 +18,7 @@ pub fn main() { 179, 8, ]; - unsafe { - syscall_bls12381_g1_double(a.as_mut_ptr() as *mut u32); - } + syscall_bls12381_g1_double(a.as_mut_ptr() as *mut u32); // 2 * generator. // 838589206289216005799424730305866328161735431124665289961769162861615689790485775997575391185127590486775437397838 diff --git a/tests/bls12381-g1-scalarmul/Cargo.lock b/tests/bls12381-g1-scalarmul/Cargo.lock index a39885bc4..1ec246975 100644 --- a/tests/bls12381-g1-scalarmul/Cargo.lock +++ b/tests/bls12381-g1-scalarmul/Cargo.lock @@ -8,18 +8,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -56,13 +44,14 @@ version = "0.1.0" dependencies = [ "hybrid-array", "sphinx-derive", + "sphinx-lib", "sphinx-zkvm", ] [[package]] name = "bls12_381" version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" +source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#8b816fe5e9f0701305288f86fdfe45ed21dcf416" dependencies = [ "cfg-if", "ff", @@ -78,12 +67,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -93,18 +76,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -115,16 +86,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -132,43 +93,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", -] - -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", ] [[package]] @@ -196,7 +121,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -221,15 +145,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -239,20 +154,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -286,16 +187,6 @@ dependencies = [ "group", ] -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -356,30 +247,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -411,26 +278,6 @@ dependencies = [ "digest", ] -[[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - [[package]] name = "sphinx-derive" version = "1.0.0" @@ -441,7 +288,7 @@ dependencies = [ ] [[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", @@ -450,7 +297,6 @@ dependencies = [ "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -461,23 +307,13 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] [[package]] @@ -546,9 +382,3 @@ checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" dependencies = [ "tap", ] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/tests/bls12381-g1-scalarmul/Cargo.toml b/tests/bls12381-g1-scalarmul/Cargo.toml index 2b61cc321..8a152dfd9 100644 --- a/tests/bls12381-g1-scalarmul/Cargo.toml +++ b/tests/bls12381-g1-scalarmul/Cargo.toml @@ -6,5 +6,6 @@ edition = "2021" [dependencies] sphinx-zkvm = { path = "../../zkvm/entrypoint" } +sphinx-lib = { path = "../../zkvm/lib" } sphinx-derive = { path = "../../derive" } -hybrid-array = "0.2.0-rc" \ No newline at end of file +hybrid-array = "0.2.0-rc" diff --git a/tests/bls12381-g1-scalarmul/elf/riscv32im-succinct-zkvm-elf b/tests/bls12381-g1-scalarmul/elf/riscv32im-succinct-zkvm-elf index dfeaceb87..eef719ccf 100755 Binary files a/tests/bls12381-g1-scalarmul/elf/riscv32im-succinct-zkvm-elf and b/tests/bls12381-g1-scalarmul/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/bls12381-g1-scalarmul/src/main.rs b/tests/bls12381-g1-scalarmul/src/main.rs index 1c043431e..8b3414b83 100644 --- a/tests/bls12381-g1-scalarmul/src/main.rs +++ b/tests/bls12381-g1-scalarmul/src/main.rs @@ -1,9 +1,9 @@ #![no_main] sphinx_zkvm::entrypoint!(main); +use sphinx_lib::bls12_381::Bls12381; +use sphinx_lib::utils::AffinePoint; use hybrid_array::typenum::U24; -use sphinx_zkvm::precompiles::bls12_381::Bls12381; -use sphinx_zkvm::precompiles::utils::AffinePoint; #[sphinx_derive::cycle_tracker] pub fn main() { diff --git a/tests/bls12381-g2-add/Cargo.lock b/tests/bls12381-g2-add/Cargo.lock index 86d6c1b1a..7fb08733f 100644 --- a/tests/bls12381-g2-add/Cargo.lock +++ b/tests/bls12381-g2-add/Cargo.lock @@ -8,18 +8,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -29,18 +17,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -57,31 +33,12 @@ dependencies = [ "sphinx-zkvm", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -91,18 +48,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -113,16 +58,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -130,62 +65,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -194,7 +76,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -208,26 +89,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -237,20 +98,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -275,25 +122,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -318,12 +146,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -354,30 +176,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -410,36 +208,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -450,31 +226,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.63" @@ -486,12 +246,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -515,18 +269,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/tests/bls12381-g2-add/elf/riscv32im-succinct-zkvm-elf b/tests/bls12381-g2-add/elf/riscv32im-succinct-zkvm-elf index 6999293d9..921d9988f 100755 Binary files a/tests/bls12381-g2-add/elf/riscv32im-succinct-zkvm-elf and b/tests/bls12381-g2-add/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/bls12381-g2-double/Cargo.lock b/tests/bls12381-g2-double/Cargo.lock index 0072ed9d7..96e21acb9 100644 --- a/tests/bls12381-g2-double/Cargo.lock +++ b/tests/bls12381-g2-double/Cargo.lock @@ -8,18 +8,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -29,18 +17,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -57,31 +33,12 @@ dependencies = [ "sphinx-zkvm", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#0d57d6ac0af6a464c4764809b5bf994d15920762" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -91,18 +48,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -113,16 +58,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -130,62 +65,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -194,7 +76,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -208,26 +89,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -237,20 +98,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -275,25 +122,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -318,12 +146,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -354,30 +176,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -410,36 +208,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -450,31 +226,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.66" @@ -486,12 +246,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -515,18 +269,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/tests/bls12381-g2-double/elf/riscv32im-succinct-zkvm-elf b/tests/bls12381-g2-double/elf/riscv32im-succinct-zkvm-elf index 3ae24aa14..979885bde 100755 Binary files a/tests/bls12381-g2-double/elf/riscv32im-succinct-zkvm-elf and b/tests/bls12381-g2-double/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/bn254-add/Cargo.lock b/tests/bn254-add/Cargo.lock index 6234a8706..a8cadcab5 100644 --- a/tests/bn254-add/Cargo.lock +++ b/tests/bn254-add/Cargo.lock @@ -14,18 +14,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -35,18 +23,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -56,19 +32,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "bn254-add-test" version = "0.1.0" @@ -83,12 +46,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -98,18 +55,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -120,16 +65,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -137,62 +72,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -201,7 +83,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -215,26 +96,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -244,20 +105,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -343,25 +190,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -386,12 +214,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -422,30 +244,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -478,36 +276,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -518,31 +294,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.63" @@ -554,12 +314,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -583,18 +337,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/tests/bn254-add/elf/riscv32im-succinct-zkvm-elf b/tests/bn254-add/elf/riscv32im-succinct-zkvm-elf index b9b8439c2..17d13ba6a 100755 Binary files a/tests/bn254-add/elf/riscv32im-succinct-zkvm-elf and b/tests/bn254-add/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/bn254-add/src/main.rs b/tests/bn254-add/src/main.rs index 2fe8f2672..28de6f0ef 100644 --- a/tests/bn254-add/src/main.rs +++ b/tests/bn254-add/src/main.rs @@ -1,9 +1,8 @@ #![no_main] -sphinx_zkvm::entrypoint!(main); -extern "C" { - fn syscall_bn254_add(p: *mut u32, q: *const u32); -} +use sphinx_zkvm::syscalls::syscall_bn254_add; + +sphinx_zkvm::entrypoint!(main); pub fn main() { for _ in 0..4 { @@ -26,9 +25,7 @@ pub fn main() { 124, 10, 14, 140, 115, 237, 21, ]; - unsafe { - syscall_bn254_add(a.as_mut_ptr() as *mut u32, b.as_ptr() as *const u32); - } + syscall_bn254_add(a.as_mut_ptr() as *mut u32, b.as_ptr() as *const u32); // 3 * generator. // 3353031288059533942658390886683067124040920775575537747144343083137631628272 diff --git a/tests/bn254-double/Cargo.lock b/tests/bn254-double/Cargo.lock index 934c67ae3..544ca717b 100644 --- a/tests/bn254-double/Cargo.lock +++ b/tests/bn254-double/Cargo.lock @@ -14,18 +14,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -35,18 +23,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -56,19 +32,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "bn254-double-test" version = "0.1.0" @@ -84,12 +47,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -99,18 +56,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -121,16 +66,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -138,62 +73,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -202,7 +84,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -216,32 +97,12 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - [[package]] name = "hex-literal" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -251,20 +112,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -350,25 +197,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -393,12 +221,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -429,30 +251,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -485,36 +283,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -525,31 +301,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.63" @@ -561,12 +321,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -590,18 +344,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/tests/bn254-double/elf/riscv32im-succinct-zkvm-elf b/tests/bn254-double/elf/riscv32im-succinct-zkvm-elf index 141ffa1d7..011143bed 100755 Binary files a/tests/bn254-double/elf/riscv32im-succinct-zkvm-elf and b/tests/bn254-double/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/bn254-double/src/main.rs b/tests/bn254-double/src/main.rs index b560de643..8ddc05666 100644 --- a/tests/bn254-double/src/main.rs +++ b/tests/bn254-double/src/main.rs @@ -1,9 +1,8 @@ #![no_main] -sphinx_zkvm::entrypoint!(main); -extern "C" { - fn syscall_bn254_double(p: *mut u32); -} +use sphinx_zkvm::syscalls::syscall_bn254_double; + +sphinx_zkvm::entrypoint!(main); pub fn main() { for _ in 0..10i64.pow(3) { @@ -16,9 +15,7 @@ pub fn main() { 0, 0, 0, 0, 0, 0, ]; - unsafe { - syscall_bn254_double(a.as_mut_ptr() as *mut u32); - } + syscall_bn254_double(a.as_mut_ptr() as *mut u32); // 2 * generator. // 1368015179489954701390400359078579693043519447331113978918064868415326638035 diff --git a/tests/bn254-mul/Cargo.lock b/tests/bn254-mul/Cargo.lock index dff2ef2d3..b40c49a07 100644 --- a/tests/bn254-mul/Cargo.lock +++ b/tests/bn254-mul/Cargo.lock @@ -8,18 +8,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -29,18 +17,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -50,61 +26,37 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "bn254-mul-test" version = "0.1.0" dependencies = [ "hybrid-array", "sphinx-derive", + "sphinx-lib", "sphinx-zkvm", ] [[package]] -name = "cfg-if" -version = "1.0.0" +name = "byteorder" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] -name = "const-oid" -version = "0.9.6" +name = "cfg-if" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cpufeatures" -version = "0.2.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +checksum = "51e852e6dc9a5bed1fae92dd2375037bf2b768725bf3be87811edee3249d09ad" dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -115,16 +67,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -132,62 +74,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", -] - -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", ] -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -196,7 +85,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -210,26 +98,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -239,20 +107,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -278,30 +132,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" +name = "ppv-lite86" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" dependencies = [ - "der", - "spki", + "zerocopy", ] -[[package]] -name = "ppv-lite86" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" - [[package]] name = "proc-macro2" version = "1.0.82" @@ -320,12 +158,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -356,30 +188,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -411,26 +219,6 @@ dependencies = [ "digest", ] -[[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - [[package]] name = "sphinx-derive" version = "1.0.0" @@ -441,16 +229,14 @@ dependencies = [ ] [[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -461,31 +247,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "1.0.109" @@ -508,12 +278,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -528,9 +292,9 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "wasi" @@ -539,16 +303,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] -name = "wyz" -version = "0.5.1" +name = "zerocopy" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ - "tap", + "byteorder", + "zerocopy-derive", ] [[package]] -name = "zeroize" -version = "1.7.0" +name = "zerocopy-derive" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.63", +] diff --git a/tests/bn254-mul/Cargo.toml b/tests/bn254-mul/Cargo.toml index fe87d69be..4cc9e41b8 100644 --- a/tests/bn254-mul/Cargo.toml +++ b/tests/bn254-mul/Cargo.toml @@ -6,5 +6,6 @@ edition = "2021" [dependencies] sphinx-zkvm = { path = "../../zkvm/entrypoint" } +sphinx-lib = { path = "../../zkvm/lib", features = ["bn254"] } sphinx-derive = { path = "../../derive" } hybrid-array = "0.2.0-rc" diff --git a/tests/bn254-mul/elf/riscv32im-succinct-zkvm-elf b/tests/bn254-mul/elf/riscv32im-succinct-zkvm-elf index b5563e800..46f2dda12 100755 Binary files a/tests/bn254-mul/elf/riscv32im-succinct-zkvm-elf and b/tests/bn254-mul/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/bn254-mul/src/main.rs b/tests/bn254-mul/src/main.rs index be4be4bd3..55a5becd5 100644 --- a/tests/bn254-mul/src/main.rs +++ b/tests/bn254-mul/src/main.rs @@ -1,9 +1,9 @@ #![no_main] sphinx_zkvm::entrypoint!(main); +use sphinx_lib::bn254::Bn254; +use sphinx_lib::utils::AffinePoint; use hybrid_array::typenum::U16; -use sphinx_zkvm::precompiles::bn254::Bn254; -use sphinx_zkvm::precompiles::utils::AffinePoint; #[sphinx_derive::cycle_tracker] pub fn main() { diff --git a/tests/cycle-tracker/Cargo.lock b/tests/cycle-tracker/Cargo.lock index d04bb15dc..db6f66eaa 100644 --- a/tests/cycle-tracker/Cargo.lock +++ b/tests/cycle-tracker/Cargo.lock @@ -8,18 +8,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -29,18 +17,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -50,31 +26,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -84,18 +41,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -111,19 +56,10 @@ name = "cycle-tracker-test" version = "0.1.0" dependencies = [ "sphinx-derive", + "sphinx-lib", "sphinx-zkvm", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -131,62 +67,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -195,7 +78,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -209,26 +91,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -238,20 +100,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -276,25 +124,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -319,12 +148,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -355,30 +178,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -410,26 +209,6 @@ dependencies = [ "digest", ] -[[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - [[package]] name = "sphinx-derive" version = "1.0.0" @@ -440,16 +219,14 @@ dependencies = [ ] [[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -460,31 +237,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "1.0.109" @@ -507,12 +268,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -536,18 +291,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/tests/cycle-tracker/Cargo.toml b/tests/cycle-tracker/Cargo.toml index 243a838ef..c08817dbe 100644 --- a/tests/cycle-tracker/Cargo.toml +++ b/tests/cycle-tracker/Cargo.toml @@ -7,3 +7,5 @@ edition = "2021" [dependencies] sphinx-zkvm = { path = "../../zkvm/entrypoint" } sphinx-derive = { path = "../../derive" } +sphinx-lib = { path = "../../zkvm/lib" } + diff --git a/tests/cycle-tracker/elf/riscv32im-succinct-zkvm-elf b/tests/cycle-tracker/elf/riscv32im-succinct-zkvm-elf index 31445db9f..14960a622 100755 Binary files a/tests/cycle-tracker/elf/riscv32im-succinct-zkvm-elf and b/tests/cycle-tracker/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/ecrecover/Cargo.lock b/tests/ecrecover/Cargo.lock index 922349158..c2443ebe8 100644 --- a/tests/ecrecover/Cargo.lock +++ b/tests/ecrecover/Cargo.lock @@ -56,19 +56,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" @@ -155,6 +142,7 @@ dependencies = [ "hex-literal", "k256", "num", + "sphinx-lib", "sphinx-zkvm", ] @@ -262,7 +250,7 @@ dependencies = [ "ecdsa", "elliptic-curve", "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2", "signature", ] @@ -351,15 +339,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - [[package]] name = "pkcs8" version = "0.10.2" @@ -485,16 +464,6 @@ dependencies = [ "digest", ] -[[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - [[package]] name = "signature" version = "2.2.0" @@ -506,12 +475,11 @@ dependencies = [ ] [[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", @@ -526,13 +494,13 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", + "serde", + "sha2", + "sphinx-lib", ] [[package]] diff --git a/tests/ecrecover/Cargo.toml b/tests/ecrecover/Cargo.toml index fa0318531..bb230a3ec 100644 --- a/tests/ecrecover/Cargo.toml +++ b/tests/ecrecover/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] sphinx-zkvm = { path = "../../zkvm/entrypoint" } +sphinx-lib = { path = "../../zkvm/lib", features = ["secp256k1"] } hex-literal = "0.4.1" num = { version = "0.4.1", default-features = false } k256 = { version = "0.13.3", features = ["ecdsa"] } diff --git a/tests/ecrecover/elf/riscv32im-succinct-zkvm-elf b/tests/ecrecover/elf/riscv32im-succinct-zkvm-elf index 00e023b42..6b1d8b409 100755 Binary files a/tests/ecrecover/elf/riscv32im-succinct-zkvm-elf and b/tests/ecrecover/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/ecrecover/src/main.rs b/tests/ecrecover/src/main.rs index 511eb0d2b..1b116ffba 100644 --- a/tests/ecrecover/src/main.rs +++ b/tests/ecrecover/src/main.rs @@ -2,8 +2,8 @@ sphinx_zkvm::entrypoint!(main); use hex_literal::hex; -use sphinx_zkvm::precompiles::io; -use sphinx_zkvm::precompiles::secp256k1::ecrecover; +use sphinx_lib::io; +use sphinx_lib::secp256k1::ecrecover; pub fn main() { // recovery param: 1 @@ -12,7 +12,9 @@ pub fn main() { // pubkey: 044a071e8a6e10aada2b8cf39fa3b5fb3400b04e99ea8ae64ceea1a977dbeaf5d5f8c8fbd10b71ab14cd561f7df8eb6da50f8a8d81ba564342244d26d1d4211595 let msg_hash = hex!("5ae8317d34d1e595e3fa7247db80c0af4320cce1116de187f8f7e2e099c0d8d0"); - let sig = hex!("45c0b7f8c09a9e1f1cea0c25785594427b6bf8f9f878a8af0b1abbb48e16d0920d8becd0c220f67c51217eecfd7184ef0732481c843857e6bc7fc095c4f6b78801"); + let sig = hex!( + "45c0b7f8c09a9e1f1cea0c25785594427b6bf8f9f878a8af0b1abbb48e16d0920d8becd0c220f67c51217eecfd7184ef0732481c843857e6bc7fc095c4f6b78801" + ); let pubkey = ecrecover(&sig, &msg_hash).unwrap(); io::commit_slice(&pubkey); diff --git a/tests/ed-add/Cargo.lock b/tests/ed-add/Cargo.lock index d3cdfd18d..798f5f2df 100644 --- a/tests/ed-add/Cargo.lock +++ b/tests/ed-add/Cargo.lock @@ -14,18 +14,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -35,18 +23,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -56,31 +32,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -90,18 +47,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -112,16 +57,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -129,23 +64,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", -] - -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", ] [[package]] @@ -157,43 +76,6 @@ dependencies = [ "sphinx-zkvm", ] -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -202,7 +84,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -216,32 +97,12 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - [[package]] name = "hex-literal" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -251,20 +112,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -350,25 +197,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -393,12 +221,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -429,30 +251,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -485,36 +283,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -525,31 +301,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.63" @@ -561,12 +321,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -590,18 +344,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/tests/ed-add/elf/riscv32im-succinct-zkvm-elf b/tests/ed-add/elf/riscv32im-succinct-zkvm-elf index 4ebfbac27..e7be682aa 100755 Binary files a/tests/ed-add/elf/riscv32im-succinct-zkvm-elf and b/tests/ed-add/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/ed-add/src/main.rs b/tests/ed-add/src/main.rs index 1c9783602..868db2a9d 100644 --- a/tests/ed-add/src/main.rs +++ b/tests/ed-add/src/main.rs @@ -1,9 +1,8 @@ #![no_main] -sphinx_zkvm::entrypoint!(main); -extern "C" { - fn syscall_ed_add(p: *mut u32, q: *const u32); -} +use sphinx_zkvm::syscalls::syscall_ed_add; + +sphinx_zkvm::entrypoint!(main); pub fn main() { for _ in 0..4 { @@ -25,9 +24,7 @@ pub fn main() { 167, 131, 199, 47, 82, 134, 53, 62, ]; - unsafe { - syscall_ed_add(a.as_mut_ptr() as *mut u32, b.as_ptr() as *const u32); - } + syscall_ed_add(a.as_mut_ptr() as *mut u32, b.as_ptr() as *mut u32); // 36213413123116753589144482590359479011148956763279542162278577842046663495729 // 17093345531692682197799066694073110060588941459686871373458223451938707761683 diff --git a/tests/ed-decompress/Cargo.lock b/tests/ed-decompress/Cargo.lock index bd87cff2d..321e05dfe 100644 --- a/tests/ed-decompress/Cargo.lock +++ b/tests/ed-decompress/Cargo.lock @@ -8,18 +8,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -29,18 +17,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -50,31 +26,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#0d57d6ac0af6a464c4764809b5bf994d15920762" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -84,18 +41,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -106,16 +51,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -123,23 +58,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", -] - -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", ] [[package]] @@ -150,43 +69,6 @@ dependencies = [ "sphinx-zkvm", ] -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -195,7 +77,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -209,32 +90,12 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - [[package]] name = "hex-literal" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -244,20 +105,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -282,25 +129,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -325,12 +153,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -361,30 +183,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -417,36 +215,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -457,31 +233,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.66" @@ -493,12 +253,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -522,18 +276,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/tests/ed-decompress/elf/riscv32im-succinct-zkvm-elf b/tests/ed-decompress/elf/riscv32im-succinct-zkvm-elf index 6d62d826b..35c24faee 100755 Binary files a/tests/ed-decompress/elf/riscv32im-succinct-zkvm-elf and b/tests/ed-decompress/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/ed-decompress/src/main.rs b/tests/ed-decompress/src/main.rs index c1e0e5af9..5920ea906 100644 --- a/tests/ed-decompress/src/main.rs +++ b/tests/ed-decompress/src/main.rs @@ -1,11 +1,9 @@ #![no_main] -sphinx_zkvm::entrypoint!(main); use hex_literal::hex; +use sphinx_zkvm::syscalls::syscall_ed_decompress; -extern "C" { - fn syscall_ed_decompress(p: *mut u8); -} +sphinx_zkvm::entrypoint!(main); pub fn main() { for _ in 0..4 { @@ -16,9 +14,7 @@ pub fn main() { println!("before: {:?}", decompressed); - unsafe { - syscall_ed_decompress(decompressed.as_mut_ptr()); - } + syscall_ed_decompress(&mut decompressed); let expected: [u8; 64] = [ 47, 252, 114, 91, 153, 234, 110, 201, 201, 153, 152, 14, 68, 231, 90, 221, 137, 110, diff --git a/tests/ed25519/Cargo.lock b/tests/ed25519/Cargo.lock index 316c5fcb6..d343dfcda 100644 --- a/tests/ed25519/Cargo.lock +++ b/tests/ed25519/Cargo.lock @@ -8,12 +8,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - [[package]] name = "base64ct" version = "1.6.0" @@ -29,18 +23,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -50,19 +32,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#0d57d6ac0af6a464c4764809b5bf994d15920762" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "byteorder" version = "1.5.0" @@ -90,18 +59,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -157,23 +114,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", -] - -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", ] [[package]] @@ -194,7 +135,7 @@ dependencies = [ "curve25519-dalek", "ed25519", "serde", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2", "subtle", "zeroize", ] @@ -208,49 +149,12 @@ dependencies = [ "sphinx-zkvm", ] -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - [[package]] name = "fiat-crypto" version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -259,7 +163,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -273,32 +176,12 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - [[package]] name = "hex-literal" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.9" @@ -308,20 +191,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -346,15 +215,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - [[package]] name = "pkcs8" version = "0.10.2" @@ -398,12 +258,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -434,16 +288,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - [[package]] name = "rustc_version" version = "0.4.0" @@ -453,20 +297,6 @@ dependencies = [ "semver", ] -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "semver" version = "1.0.23" @@ -504,23 +334,12 @@ dependencies = [ "digest", ] -[[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - [[package]] name = "signature" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" dependencies = [ - "digest", "rand_core", ] @@ -536,16 +355,14 @@ dependencies = [ ] [[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -556,13 +373,13 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", + "serde", + "sha2", + "sphinx-lib", ] [[package]] @@ -592,12 +409,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -622,15 +433,6 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - [[package]] name = "zerocopy" version = "0.6.6" diff --git a/tests/ed25519/elf/riscv32im-succinct-zkvm-elf b/tests/ed25519/elf/riscv32im-succinct-zkvm-elf index f235f8adb..028fa98d9 100755 Binary files a/tests/ed25519/elf/riscv32im-succinct-zkvm-elf and b/tests/ed25519/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/fibonacci/Cargo.lock b/tests/fibonacci/Cargo.lock index cf5cd5b4a..93fa955c4 100644 --- a/tests/fibonacci/Cargo.lock +++ b/tests/fibonacci/Cargo.lock @@ -8,18 +8,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -29,18 +17,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -50,31 +26,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#0d57d6ac0af6a464c4764809b5bf994d15920762" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -84,18 +41,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -106,16 +51,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -123,54 +58,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", -] - -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", ] [[package]] @@ -180,12 +68,6 @@ dependencies = [ "sphinx-zkvm", ] -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -194,7 +76,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -208,26 +89,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -237,20 +98,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -275,25 +122,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -318,12 +146,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -354,30 +176,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -410,36 +208,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -450,31 +226,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.66" @@ -486,12 +246,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -515,18 +269,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/tests/fibonacci/elf/riscv32im-succinct-zkvm-elf b/tests/fibonacci/elf/riscv32im-succinct-zkvm-elf index 840beb6ba..7cb9f50f2 100755 Binary files a/tests/fibonacci/elf/riscv32im-succinct-zkvm-elf and b/tests/fibonacci/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/hint-io/Cargo.lock b/tests/hint-io/Cargo.lock index cfdb7b465..f8c5f1c41 100644 --- a/tests/hint-io/Cargo.lock +++ b/tests/hint-io/Cargo.lock @@ -8,18 +8,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -29,18 +17,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -50,31 +26,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -84,18 +41,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -106,16 +51,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -123,62 +58,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -187,7 +69,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -201,17 +82,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - [[package]] name = "hint-io-test" version = "0.1.0" @@ -219,15 +89,6 @@ dependencies = [ "sphinx-zkvm", ] -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -237,20 +98,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -275,25 +122,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -318,12 +146,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -354,30 +176,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -410,36 +208,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -450,31 +226,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.63" @@ -486,12 +246,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -515,18 +269,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/tests/hint-io/elf/riscv32im-succinct-zkvm-elf b/tests/hint-io/elf/riscv32im-succinct-zkvm-elf index 36e018b20..bd63b2e06 100755 Binary files a/tests/hint-io/elf/riscv32im-succinct-zkvm-elf and b/tests/hint-io/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/keccak-permute/Cargo.lock b/tests/keccak-permute/Cargo.lock index b321d11b6..42a86f78a 100644 --- a/tests/keccak-permute/Cargo.lock +++ b/tests/keccak-permute/Cargo.lock @@ -8,18 +8,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -29,18 +17,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -50,31 +26,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -84,18 +41,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -106,16 +51,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -123,62 +58,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -187,7 +69,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -201,49 +82,15 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" -version = "0.2.0-rc.8" +version = "0.2.0-rc.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53668f5da5a41d9eaf4bf7064be46d1ebe6a4e1ceed817f387587b18f2b51047" +checksum = "4d306b679262030ad8813a82d4915fc04efff97776e4db7f8eb5137039d56400" dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "keccak-permute-test" version = "0.1.0" @@ -275,25 +122,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -318,12 +146,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -354,30 +176,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -410,36 +208,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -450,48 +226,26 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" -version = "2.0.63" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -515,18 +269,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/tests/keccak-permute/elf/riscv32im-succinct-zkvm-elf b/tests/keccak-permute/elf/riscv32im-succinct-zkvm-elf index f96bc2809..cade30453 100755 Binary files a/tests/keccak-permute/elf/riscv32im-succinct-zkvm-elf and b/tests/keccak-permute/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/keccak256/Cargo.lock b/tests/keccak256/Cargo.lock index 105a4e386..d6d5ed711 100644 --- a/tests/keccak256/Cargo.lock +++ b/tests/keccak256/Cargo.lock @@ -8,18 +8,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -29,18 +17,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -50,31 +26,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -90,18 +47,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -112,16 +57,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -129,62 +64,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -193,7 +75,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -207,49 +88,15 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" -version = "0.2.0-rc.8" +version = "0.2.0-rc.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53668f5da5a41d9eaf4bf7064be46d1ebe6a4e1ceed817f387587b18f2b51047" +checksum = "4d306b679262030ad8813a82d4915fc04efff97776e4db7f8eb5137039d56400" dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "keccak256-test" version = "0.1.0" @@ -282,25 +129,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -325,12 +153,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -361,30 +183,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -417,36 +215,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -457,48 +233,26 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" -version = "2.0.63" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "tiny-keccak" version = "2.0.2" @@ -531,18 +285,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/tests/keccak256/elf/riscv32im-succinct-zkvm-elf b/tests/keccak256/elf/riscv32im-succinct-zkvm-elf index 8b70eabd3..89e484845 100755 Binary files a/tests/keccak256/elf/riscv32im-succinct-zkvm-elf and b/tests/keccak256/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/panic/Cargo.lock b/tests/panic/Cargo.lock index 8cf6d9060..c9ff1ff9a 100644 --- a/tests/panic/Cargo.lock +++ b/tests/panic/Cargo.lock @@ -8,18 +8,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -29,18 +17,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -50,31 +26,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#0d57d6ac0af6a464c4764809b5bf994d15920762" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -84,18 +41,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -106,16 +51,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -123,62 +58,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -187,7 +69,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -201,26 +82,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -230,20 +91,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -268,15 +115,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - [[package]] name = "panic-test" version = "0.1.0" @@ -285,16 +123,6 @@ dependencies = [ "sphinx-zkvm", ] -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -319,12 +147,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -355,30 +177,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -410,26 +208,6 @@ dependencies = [ "digest", ] -[[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - [[package]] name = "sphinx-derive" version = "1.0.0" @@ -440,16 +218,14 @@ dependencies = [ ] [[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -460,31 +236,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "1.0.109" @@ -507,12 +267,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -536,18 +290,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/tests/panic/elf/riscv32im-succinct-zkvm-elf b/tests/panic/elf/riscv32im-succinct-zkvm-elf index 518fc9a50..eaee81283 100755 Binary files a/tests/panic/elf/riscv32im-succinct-zkvm-elf and b/tests/panic/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/rand/Cargo.lock b/tests/rand/Cargo.lock index f1a28c95f..f1c6ff070 100644 --- a/tests/rand/Cargo.lock +++ b/tests/rand/Cargo.lock @@ -8,18 +8,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -29,18 +17,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -50,31 +26,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#0d57d6ac0af6a464c4764809b5bf994d15920762" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -84,18 +41,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -106,16 +51,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -123,62 +58,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -187,7 +69,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -201,26 +82,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.9" @@ -230,20 +91,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -268,25 +115,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -311,12 +139,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -356,30 +178,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.204" @@ -411,26 +209,6 @@ dependencies = [ "digest", ] -[[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - [[package]] name = "sphinx-derive" version = "1.0.0" @@ -441,16 +219,14 @@ dependencies = [ ] [[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -461,31 +237,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" - [[package]] name = "syn" version = "1.0.109" @@ -508,12 +268,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -537,18 +291,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/tests/rand/elf/riscv32im-succinct-zkvm-elf b/tests/rand/elf/riscv32im-succinct-zkvm-elf index f54e85df8..437becb4f 100755 Binary files a/tests/rand/elf/riscv32im-succinct-zkvm-elf and b/tests/rand/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/secp256k1-add/Cargo.lock b/tests/secp256k1-add/Cargo.lock index da09d15d3..5b68fa7b5 100644 --- a/tests/secp256k1-add/Cargo.lock +++ b/tests/secp256k1-add/Cargo.lock @@ -14,18 +14,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -35,18 +23,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -56,31 +32,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -90,18 +47,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -112,16 +57,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -129,62 +64,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -193,7 +75,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -207,32 +88,12 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - [[package]] name = "hex-literal" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -242,20 +103,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -341,25 +188,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -384,12 +212,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -420,30 +242,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "secp256k1-add-test" version = "0.1.0" @@ -485,36 +283,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -525,31 +301,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.63" @@ -561,12 +321,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -590,18 +344,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/tests/secp256k1-add/elf/riscv32im-succinct-zkvm-elf b/tests/secp256k1-add/elf/riscv32im-succinct-zkvm-elf index 5029c92fd..9f74d6e4b 100755 Binary files a/tests/secp256k1-add/elf/riscv32im-succinct-zkvm-elf and b/tests/secp256k1-add/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/secp256k1-add/src/main.rs b/tests/secp256k1-add/src/main.rs index aee720507..a7790f6ac 100644 --- a/tests/secp256k1-add/src/main.rs +++ b/tests/secp256k1-add/src/main.rs @@ -1,9 +1,8 @@ #![no_main] -sphinx_zkvm::entrypoint!(main); -extern "C" { - fn syscall_secp256k1_add(p: *mut u32, q: *const u32); -} +use sphinx_zkvm::syscalls::syscall_secp256k1_add; + +sphinx_zkvm::entrypoint!(main); pub fn main() { for _ in 0..4 { @@ -27,9 +26,7 @@ pub fn main() { 163, 57, 195, 61, 166, 254, 104, 225, 26, ]; - unsafe { - syscall_secp256k1_add(a.as_mut_ptr() as *mut u32, b.as_ptr() as *const u32); - } + syscall_secp256k1_add(a.as_mut_ptr() as *mut u32, b.as_ptr() as *mut u32); // 3 * generator. // 112711660439710606056748659173929673102114977341539408544630613555209775888121 diff --git a/tests/secp256k1-decompress/Cargo.lock b/tests/secp256k1-decompress/Cargo.lock index 43dc7f1ac..69c3e847c 100644 --- a/tests/secp256k1-decompress/Cargo.lock +++ b/tests/secp256k1-decompress/Cargo.lock @@ -8,18 +8,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -29,18 +17,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -50,31 +26,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -84,18 +41,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -106,16 +51,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -123,62 +58,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -187,7 +69,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -201,26 +82,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -230,20 +91,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -268,25 +115,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -311,12 +139,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -347,30 +169,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "secp256k1-decompress-test" version = "0.1.0" @@ -410,36 +208,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -450,31 +226,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.63" @@ -486,12 +246,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -515,18 +269,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/tests/secp256k1-decompress/elf/riscv32im-succinct-zkvm-elf b/tests/secp256k1-decompress/elf/riscv32im-succinct-zkvm-elf index 39ad9cb48..928d41774 100755 Binary files a/tests/secp256k1-decompress/elf/riscv32im-succinct-zkvm-elf and b/tests/secp256k1-decompress/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/secp256k1-decompress/src/main.rs b/tests/secp256k1-decompress/src/main.rs index 244ca59aa..356a47f35 100644 --- a/tests/secp256k1-decompress/src/main.rs +++ b/tests/secp256k1-decompress/src/main.rs @@ -1,9 +1,8 @@ #![no_main] -sphinx_zkvm::entrypoint!(main); -extern "C" { - fn syscall_secp256k1_decompress(compressed_key: &mut [u8; 64], is_odd: bool); -} +use sphinx_zkvm::syscalls::syscall_secp256k1_decompress; + +sphinx_zkvm::entrypoint!(main); pub fn main() { let compressed_key: [u8; 33] = sphinx_zkvm::io::read_vec().try_into().unwrap(); @@ -16,9 +15,7 @@ pub fn main() { 3 => true, _ => panic!("Invalid compressed key"), }; - unsafe { - syscall_secp256k1_decompress(&mut decompressed_key, is_odd); - } + syscall_secp256k1_decompress(&mut decompressed_key, is_odd); let mut result: [u8; 65] = [0; 65]; result[0] = 4; diff --git a/tests/secp256k1-double/Cargo.lock b/tests/secp256k1-double/Cargo.lock index 308e5e305..3be9b59e5 100644 --- a/tests/secp256k1-double/Cargo.lock +++ b/tests/secp256k1-double/Cargo.lock @@ -14,18 +14,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -35,18 +23,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -56,31 +32,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -90,18 +47,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -112,16 +57,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -129,62 +64,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -193,7 +75,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -207,32 +88,12 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - [[package]] name = "hex-literal" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -242,20 +103,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -341,25 +188,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -384,12 +212,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -420,30 +242,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "secp256k1-double-test" version = "0.1.0" @@ -485,36 +283,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -525,31 +301,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.63" @@ -561,12 +321,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -590,18 +344,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/tests/secp256k1-double/elf/riscv32im-succinct-zkvm-elf b/tests/secp256k1-double/elf/riscv32im-succinct-zkvm-elf index cd4b4c96e..ba523ce1a 100755 Binary files a/tests/secp256k1-double/elf/riscv32im-succinct-zkvm-elf and b/tests/secp256k1-double/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/secp256k1-double/src/main.rs b/tests/secp256k1-double/src/main.rs index 67ea831af..6ffa99ce8 100644 --- a/tests/secp256k1-double/src/main.rs +++ b/tests/secp256k1-double/src/main.rs @@ -1,9 +1,7 @@ #![no_main] -sphinx_zkvm::entrypoint!(main); +use sphinx_zkvm::syscalls::syscall_secp256k1_double; -extern "C" { - fn syscall_secp256k1_double(p: *mut u32); -} +sphinx_zkvm::entrypoint!(main); pub fn main() { for _ in 0..10i64.pow(3) { @@ -17,9 +15,7 @@ pub fn main() { 101, 196, 163, 38, 119, 218, 58, 72, ]; - unsafe { - syscall_secp256k1_double(a.as_mut_ptr() as *mut u32); - } + syscall_secp256k1_double(a.as_mut_ptr() as *mut u32); // 2 * generator. // 89565891926547004231252920425935692360644145829622209833684329913297188986597 diff --git a/tests/secp256k1-mul/Cargo.lock b/tests/secp256k1-mul/Cargo.lock index f00ddbd54..64e329309 100644 --- a/tests/secp256k1-mul/Cargo.lock +++ b/tests/secp256k1-mul/Cargo.lock @@ -50,19 +50,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" @@ -240,7 +227,7 @@ dependencies = [ "ecdsa", "elliptic-curve", "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2", "signature", ] @@ -268,15 +255,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - [[package]] name = "pkcs8" version = "0.10.2" @@ -377,6 +355,7 @@ version = "0.1.0" dependencies = [ "hybrid-array", "sphinx-derive", + "sphinx-lib", "sphinx-zkvm", ] @@ -411,16 +390,6 @@ dependencies = [ "digest", ] -[[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - [[package]] name = "signature" version = "2.2.0" @@ -441,12 +410,11 @@ dependencies = [ ] [[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", @@ -461,13 +429,13 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", + "serde", + "sha2", + "sphinx-lib", ] [[package]] diff --git a/tests/secp256k1-mul/Cargo.toml b/tests/secp256k1-mul/Cargo.toml index 734e8f969..62c079d29 100644 --- a/tests/secp256k1-mul/Cargo.toml +++ b/tests/secp256k1-mul/Cargo.toml @@ -6,5 +6,6 @@ edition = "2021" [dependencies] sphinx-zkvm = { path = "../../zkvm/entrypoint" } +sphinx-lib = { path = "../../zkvm/lib", features = ["secp256k1"] } sphinx-derive = { path = "../../derive" } hybrid-array = "0.2.0-rc" diff --git a/tests/secp256k1-mul/elf/riscv32im-succinct-zkvm-elf b/tests/secp256k1-mul/elf/riscv32im-succinct-zkvm-elf index 68efa53f6..431189ad8 100755 Binary files a/tests/secp256k1-mul/elf/riscv32im-succinct-zkvm-elf and b/tests/secp256k1-mul/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/secp256k1-mul/src/main.rs b/tests/secp256k1-mul/src/main.rs index 93d2d4baa..3fc2c6bf4 100644 --- a/tests/secp256k1-mul/src/main.rs +++ b/tests/secp256k1-mul/src/main.rs @@ -1,9 +1,9 @@ #![no_main] sphinx_zkvm::entrypoint!(main); +use sphinx_lib::secp256k1::Secp256k1Operations; +use sphinx_lib::utils::AffinePoint; use hybrid_array::typenum::U16; -use sphinx_zkvm::precompiles::secp256k1::Secp256k1Operations; -use sphinx_zkvm::precompiles::utils::AffinePoint; #[sphinx_derive::cycle_tracker] pub fn main() { diff --git a/tests/sha-compress/Cargo.lock b/tests/sha-compress/Cargo.lock index 96848dc64..d1927a05a 100644 --- a/tests/sha-compress/Cargo.lock +++ b/tests/sha-compress/Cargo.lock @@ -8,18 +8,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -29,18 +17,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -50,31 +26,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -84,18 +41,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -106,16 +51,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -123,62 +58,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -187,7 +69,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -201,26 +82,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -230,20 +91,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -268,25 +115,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -311,12 +139,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -347,30 +169,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -410,36 +208,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -450,31 +226,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.63" @@ -486,12 +246,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -515,18 +269,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/tests/sha-compress/elf/riscv32im-succinct-zkvm-elf b/tests/sha-compress/elf/riscv32im-succinct-zkvm-elf index ffa7ed1a1..be5db5164 100755 Binary files a/tests/sha-compress/elf/riscv32im-succinct-zkvm-elf and b/tests/sha-compress/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/sha-extend/Cargo.lock b/tests/sha-extend/Cargo.lock index 24f835e43..6872f6508 100644 --- a/tests/sha-extend/Cargo.lock +++ b/tests/sha-extend/Cargo.lock @@ -8,18 +8,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -29,18 +17,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -50,31 +26,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -84,18 +41,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -106,16 +51,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -123,62 +58,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -187,7 +69,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -201,26 +82,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -230,20 +91,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -268,25 +115,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -311,12 +139,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -347,30 +169,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -410,36 +208,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -450,31 +226,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.63" @@ -486,12 +246,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -515,18 +269,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/tests/sha-extend/elf/riscv32im-succinct-zkvm-elf b/tests/sha-extend/elf/riscv32im-succinct-zkvm-elf index fe278cb53..ffa09779c 100755 Binary files a/tests/sha-extend/elf/riscv32im-succinct-zkvm-elf and b/tests/sha-extend/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/sha2/Cargo.lock b/tests/sha2/Cargo.lock index d027817e5..b5c555052 100644 --- a/tests/sha2/Cargo.lock +++ b/tests/sha2/Cargo.lock @@ -8,18 +8,6 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -29,18 +17,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -50,31 +26,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#811d00a5b776b606cbcc091e82e7828bd5b5372c" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -84,18 +41,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -106,16 +51,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -123,62 +58,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", -] - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "generic-array" version = "0.14.7" @@ -187,7 +69,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -201,17 +82,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - [[package]] name = "hex" version = "0.4.3" @@ -224,15 +94,6 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -242,20 +103,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -280,25 +127,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -323,12 +151,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -359,30 +181,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -424,16 +222,6 @@ dependencies = [ "digest", ] -[[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - [[package]] name = "sha2-test" version = "0.1.0" @@ -445,26 +233,14 @@ dependencies = [ ] [[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -475,31 +251,15 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", + "serde", + "sha2 0.10.8", + "sphinx-lib", ] -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" version = "2.0.63" @@ -511,12 +271,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "typenum" version = "1.17.0" @@ -540,18 +294,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/tests/sha2/elf/riscv32im-succinct-zkvm-elf b/tests/sha2/elf/riscv32im-succinct-zkvm-elf index 5965b34ce..110f6ace7 100755 Binary files a/tests/sha2/elf/riscv32im-succinct-zkvm-elf and b/tests/sha2/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/tendermint-benchmark/Cargo.lock b/tests/tendermint-benchmark/Cargo.lock index ebb51e843..673162436 100644 --- a/tests/tendermint-benchmark/Cargo.lock +++ b/tests/tendermint-benchmark/Cargo.lock @@ -14,12 +14,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - [[package]] name = "base64ct" version = "1.6.0" @@ -35,18 +29,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.9.0" @@ -65,19 +47,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#0d57d6ac0af6a464c4764809b5bf994d15920762" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "byteorder" version = "1.5.0" @@ -114,18 +83,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -197,23 +154,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer 0.10.4", - "const-oid", "crypto-common", - "subtle", -] - -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest 0.10.7", - "elliptic-curve", - "rfc6979", - "signature", - "spki", ] [[package]] @@ -244,37 +185,6 @@ version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest 0.10.7", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - [[package]] name = "flex-error" version = "0.4.4" @@ -284,12 +194,6 @@ dependencies = [ "paste", ] -[[package]] -name = "funty" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" - [[package]] name = "futures" version = "0.3.30" @@ -359,7 +263,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -373,32 +276,12 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - [[package]] name = "hex" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest 0.10.7", -] - [[package]] name = "hybrid-array" version = "0.2.0-rc.8" @@ -423,20 +306,6 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -493,15 +362,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - [[package]] name = "paste" version = "1.0.15" @@ -592,12 +452,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -628,36 +482,12 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - [[package]] name = "ryu" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -732,25 +562,11 @@ dependencies = [ "digest 0.10.7", ] -[[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest 0.10.7", -] - [[package]] name = "signature" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest 0.10.7", - "rand_core", -] [[package]] name = "sp1-lib" @@ -765,16 +581,14 @@ dependencies = [ ] [[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -785,13 +599,13 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", + "serde", + "sha2 0.10.8", + "sphinx-lib", ] [[package]] @@ -847,12 +661,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "tendermint" version = "0.34.1" @@ -873,7 +681,7 @@ dependencies = [ "serde_bytes", "serde_json", "serde_repr", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2 0.10.8", "signature", "subtle", "subtle-encoding", @@ -977,15 +785,6 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - [[package]] name = "zeroize" version = "1.8.1" diff --git a/tests/tendermint-benchmark/elf/riscv32im-succinct-zkvm-elf b/tests/tendermint-benchmark/elf/riscv32im-succinct-zkvm-elf index 8738c9a74..98b78d1f6 100755 Binary files a/tests/tendermint-benchmark/elf/riscv32im-succinct-zkvm-elf and b/tests/tendermint-benchmark/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/verify-proof/Cargo.lock b/tests/verify-proof/Cargo.lock index c3cf0765d..1bd77b40a 100644 --- a/tests/verify-proof/Cargo.lock +++ b/tests/verify-proof/Cargo.lock @@ -14,18 +14,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" -[[package]] -name = "base16ct" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bincode" version = "1.3.3" @@ -35,18 +23,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitvec" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" -dependencies = [ - "funty", - "radium", - "tap", - "wyz", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -56,31 +32,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bls12_381" -version = "0.8.0" -source = "git+https://github.com/argumentcomputer/bls12_381.git?branch=zkvm#0d57d6ac0af6a464c4764809b5bf994d15920762" -dependencies = [ - "cfg-if", - "ff", - "group", - "pairing", - "rand_core", - "subtle", -] - [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "cpufeatures" version = "0.2.12" @@ -90,18 +47,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crypto-bigint" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" -dependencies = [ - "generic-array", - "rand_core", - "subtle", - "zeroize", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -112,16 +57,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "digest" version = "0.10.7" @@ -129,67 +64,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", -] - -[[package]] -name = "ecdsa" -version = "0.16.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" -dependencies = [ - "der", - "digest", - "elliptic-curve", - "rfc6979", - "signature", - "spki", ] [[package]] name = "either" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" - -[[package]] -name = "elliptic-curve" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" -dependencies = [ - "base16ct", - "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core", - "sec1", - "subtle", - "tap", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "bitvec", - "rand_core", - "subtle", -] - -[[package]] -name = "funty" -version = "2.0.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "gcd" @@ -205,7 +87,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -219,17 +100,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core", - "subtle", -] - [[package]] name = "hex" version = "0.4.3" @@ -242,20 +112,11 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - [[package]] name = "hybrid-array" -version = "0.2.0-rc.8" +version = "0.2.0-rc.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53668f5da5a41d9eaf4bf7064be46d1ebe6a4e1ceed817f387587b18f2b51047" +checksum = "4d306b679262030ad8813a82d4915fc04efff97776e4db7f8eb5137039d56400" dependencies = [ "typenum", ] @@ -269,20 +130,6 @@ dependencies = [ "either", ] -[[package]] -name = "k256" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" -dependencies = [ - "cfg-if", - "ecdsa", - "elliptic-curve", - "once_cell", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", - "signature", -] - [[package]] name = "lazy_static" version = "1.5.0" @@ -303,9 +150,9 @@ checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] name = "num-bigint" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" dependencies = [ "num-integer", "num-traits", @@ -338,7 +185,7 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "p3-baby-bear" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#c5ee5502813e9621641407b3d2e22afee057321a" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" dependencies = [ "num-bigint", "p3-field", @@ -352,7 +199,7 @@ dependencies = [ [[package]] name = "p3-dft" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#c5ee5502813e9621641407b3d2e22afee057321a" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" dependencies = [ "p3-field", "p3-matrix", @@ -364,7 +211,7 @@ dependencies = [ [[package]] name = "p3-field" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#c5ee5502813e9621641407b3d2e22afee057321a" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" dependencies = [ "itertools", "num-bigint", @@ -377,7 +224,7 @@ dependencies = [ [[package]] name = "p3-matrix" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#c5ee5502813e9621641407b3d2e22afee057321a" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" dependencies = [ "itertools", "p3-field", @@ -391,12 +238,12 @@ dependencies = [ [[package]] name = "p3-maybe-rayon" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#c5ee5502813e9621641407b3d2e22afee057321a" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" [[package]] name = "p3-mds" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#c5ee5502813e9621641407b3d2e22afee057321a" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" dependencies = [ "itertools", "p3-dft", @@ -410,7 +257,7 @@ dependencies = [ [[package]] name = "p3-poseidon2" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#c5ee5502813e9621641407b3d2e22afee057321a" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" dependencies = [ "gcd", "p3-field", @@ -422,7 +269,7 @@ dependencies = [ [[package]] name = "p3-symmetric" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#c5ee5502813e9621641407b3d2e22afee057321a" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" dependencies = [ "itertools", "p3-field", @@ -432,36 +279,17 @@ dependencies = [ [[package]] name = "p3-util" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#c5ee5502813e9621641407b3d2e22afee057321a" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1#b75d346d549d47ad91afcb6bb18ef757850c13c7" dependencies = [ "serde", ] -[[package]] -name = "pairing" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" -dependencies = [ - "group", -] - [[package]] name = "pin-project-lite" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -486,12 +314,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "radium" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" - [[package]] name = "rand" version = "0.8.5" @@ -522,30 +344,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rfc6979" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" -dependencies = [ - "hmac", - "subtle", -] - -[[package]] -name = "sec1" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" -dependencies = [ - "base16ct", - "der", - "generic-array", - "pkcs8", - "subtle", - "zeroize", -] - [[package]] name = "serde" version = "1.0.205" @@ -578,36 +376,14 @@ dependencies = [ ] [[package]] -name = "sha2" -version = "0.10.8" -source = "git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8#1f224388fdede7cef649bce0d63876d1a9e3f515" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - -[[package]] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" dependencies = [ "anyhow", "bincode", - "bls12_381", "cfg-if", "getrandom", "hybrid-array", - "k256", "serde", ] @@ -630,51 +406,29 @@ dependencies = [ "bincode", "cfg-if", "getrandom", - "k256", "lazy_static", "libm", "once_cell", "p3-baby-bear", "p3-field", "rand", - "sha2 0.10.8 (git+https://github.com/sp1-patches/RustCrypto-hashes?branch=patch-v0.10.8)", - "sphinx-precompiles", + "serde", + "sha2", + "sphinx-lib", "sphinx-primitives", ] -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", -] - -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "syn" -version = "2.0.66" +version = "2.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] -[[package]] -name = "tap" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" - [[package]] name = "tracing" version = "0.1.40" @@ -724,7 +478,8 @@ version = "0.1.0" dependencies = [ "hex", "hex-literal", - "sha2 0.10.8 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2", + "sphinx-lib", "sphinx-zkvm", ] @@ -739,18 +494,3 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wyz" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" -dependencies = [ - "tap", -] - -[[package]] -name = "zeroize" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/tests/verify-proof/Cargo.toml b/tests/verify-proof/Cargo.toml index ea9d7e245..c4d0afa5f 100644 --- a/tests/verify-proof/Cargo.toml +++ b/tests/verify-proof/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] sphinx-zkvm = { path = "../../zkvm/entrypoint", features = ["verify"] } +sphinx-lib = { path = "../../zkvm/lib", features = ["verify"] } hex-literal = "0.4.1" hex = "0.4.3" sha2 = "0.10.8" diff --git a/tests/verify-proof/elf/riscv32im-succinct-zkvm-elf b/tests/verify-proof/elf/riscv32im-succinct-zkvm-elf index d32876321..58f214cce 100755 Binary files a/tests/verify-proof/elf/riscv32im-succinct-zkvm-elf and b/tests/verify-proof/elf/riscv32im-succinct-zkvm-elf differ diff --git a/tests/verify-proof/src/main.rs b/tests/verify-proof/src/main.rs index 345ad0020..3afc71ee4 100644 --- a/tests/verify-proof/src/main.rs +++ b/tests/verify-proof/src/main.rs @@ -1,11 +1,10 @@ //! This is a test program that takes in a sp1_core vkey and a list of inputs, and then verifies the -//! SP1 proof for each input. - +//! Sphinx proof for each input. #![no_main] sphinx_zkvm::entrypoint!(main); use sha2::{Digest, Sha256}; -use sphinx_zkvm::precompiles::verify::verify_sphinx_proof; +use sphinx_lib::verify::verify_sphinx_proof; fn words_to_bytes(words: &[u32; 8]) -> [u8; 32] { let mut bytes = [0u8; 32]; diff --git a/zkvm/entrypoint/Cargo.toml b/zkvm/entrypoint/Cargo.toml index dfeb4f613..5456ba3d2 100644 --- a/zkvm/entrypoint/Cargo.toml +++ b/zkvm/entrypoint/Cargo.toml @@ -6,31 +6,30 @@ repository.workspace = true license.workspace = true [dependencies] -sphinx-precompiles = { path = "../precompiles" } -sphinx-primitives = { path = "../../primitives", optional = true } -p3-baby-bear = { workspace = true, optional = true } -p3-field = { workspace = true, optional = true } bincode = { workspace = true } cfg-if = { workspace = true } -getrandom = { workspace = true, features = ["custom"] } -libm = { workspace = true, optional = true } -k256 = { workspace = true, features = ["ecdsa", "std", "bits"] } -lazy_static = { workspace = true } +getrandom = { version = "0.2.14", features = ["custom"] } once_cell = { workspace = true } rand = { workspace = true } -# Not using the workspace dependency or a patch here to ensure that downstream users always use the patched crate -sha2 = { version = "0.10.8", git = "https://github.com/sp1-patches/RustCrypto-hashes", branch = "patch-v0.10.8" } +serde = { workspace = true, features = ["derive"] } +libm = { workspace = true, optional = true } +sha2 = { workspace = true } +lazy_static = { workspace = true } + +# optional +sphinx-lib = { path = "../lib", optional = true } +sphinx-primitives = { path = "../../primitives", optional = true } +p3-baby-bear = { workspace = true, optional = true } +p3-field = { workspace = true, optional = true } [features] -default = ["libm"] +default = ["libm", "lib"] libm = ["dep:libm"] -verify = ["dep:sphinx-primitives", "dep:p3-baby-bear", "dep:p3-field", "sphinx-precompiles/verify"] - - -[package.metadata.cargo-udeps.ignore] # used w/ verify feature & some examples -normal = [ - "p3-baby-bear", - "p3-field", - "sphinx-primitives", - "rand" +lib = ["dep:sphinx-lib"] +verify = [ + "dep:sphinx-primitives", + "dep:p3-baby-bear", + "dep:p3-field", + "sphinx-lib/verify", ] + diff --git a/zkvm/entrypoint/src/lib.rs b/zkvm/entrypoint/src/lib.rs index a2e59309a..a78bd0d97 100644 --- a/zkvm/entrypoint/src/lib.rs +++ b/zkvm/entrypoint/src/lib.rs @@ -1,15 +1,15 @@ pub mod heap; pub mod syscalls; + +#[cfg(feature = "lib")] pub mod io { - pub use sphinx_precompiles::io::*; + pub use sphinx_lib::io::*; } -pub mod precompiles { - pub use sphinx_precompiles::*; +#[cfg(feature = "lib")] +pub mod lib { + pub use sphinx_lib::*; } -#[allow(unused_extern_crates)] -extern crate alloc; - #[macro_export] macro_rules! entrypoint { ($path:path) => { diff --git a/zkvm/entrypoint/src/memory.rs b/zkvm/entrypoint/src/memory.rs deleted file mode 100644 index b4c967ea1..000000000 --- a/zkvm/entrypoint/src/memory.rs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2023 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. - -const SYSTEM_START: usize = 0x0C00_0000; - -#[allow(clippy::missing_safety_doc)] -#[no_mangle] -pub unsafe extern "C" fn sys_alloc_aligned(bytes: usize, align: usize) -> *mut u8 { - extern "C" { - // https://lld.llvm.org/ELF/linker_script.html#sections-command - static _end: u8; - } - - // Pointer to next heap address to use, or 0 if the heap has not yet been - // initialized. - static mut HEAP_POS: usize = 0; - - // SAFETY: Single threaded, so nothing else can touch this while we're working. - let mut heap_pos = unsafe { HEAP_POS }; - - if heap_pos == 0 { - heap_pos = unsafe { (&_end) as *const u8 as usize }; - } - - let offset = heap_pos & (align - 1); - if offset != 0 { - heap_pos += align - offset; - } - - let ptr = heap_pos as *mut u8; - heap_pos += bytes; - - // Check to make sure heap doesn't collide with SYSTEM memory. - if SYSTEM_START < heap_pos { - panic!(); - } - - unsafe { HEAP_POS = heap_pos }; - ptr -} diff --git a/zkvm/entrypoint/src/syscalls/bigint.rs b/zkvm/entrypoint/src/syscalls/bigint.rs index 81b20ef4d..0f9799aa2 100644 --- a/zkvm/entrypoint/src/syscalls/bigint.rs +++ b/zkvm/entrypoint/src/syscalls/bigint.rs @@ -2,6 +2,8 @@ use sphinx_precompiles::BIGINT_WIDTH_WORDS; use super::syscall_uint256_mulmod; +pub const BIGINT_WIDTH_WORDS: usize = 8; + /// Sets result to be (x op y) % modulus. Currently only multiplication is supported. If modulus is /// zero, the modulus applied is 2^256. #[allow(unused_variables)] diff --git a/zkvm/entrypoint/src/syscalls/halt.rs b/zkvm/entrypoint/src/syscalls/halt.rs index caaf55d9a..76867a975 100644 --- a/zkvm/entrypoint/src/syscalls/halt.rs +++ b/zkvm/entrypoint/src/syscalls/halt.rs @@ -22,37 +22,27 @@ pub extern "C" fn syscall_halt(exit_code: u8) -> ! { unsafe { // When we halt, we retrieve the public values finalized digest. This is the hash of all // the bytes written to the public values fd. + #[allow(static_mut_refs)] // TODO: fix this with a OnceCell let pv_digest_bytes = core::mem::take(&mut zkvm::PUBLIC_VALUES_HASHER) .unwrap() .finalize(); - // Convert the digest bytes into words, since we will be calling COMMIT ecall with - // the words as a parameter. - let pv_digest_words: [u32; PV_DIGEST_NUM_WORDS] = pv_digest_bytes - .as_slice() - .chunks_exact(4) - .map(|chunk| u32::from_le_bytes(chunk.try_into().unwrap())) - .collect::>() - .try_into() - .unwrap(); - // For each digest word, call COMMIT ecall. In the runtime, this will store the digest words // into the runtime's execution record's public values digest. In the AIR, it will be used // to verify that the provided public values digest matches the one computed by the program. for i in 0..PV_DIGEST_NUM_WORDS { - asm!("ecall", in("t0") crate::syscalls::COMMIT, in("a0") i, in("a1") pv_digest_words[i]); + // Convert the digest bytes into words, since we will call COMMIT one word at a time. + let word = u32::from_le_bytes(pv_digest_bytes[i * 4..(i + 1) * 4].try_into().unwrap()); + asm!("ecall", in("t0") crate::syscalls::COMMIT, in("a0") i, in("a1") word); } cfg_if! { if #[cfg(feature = "verify")] { let deferred_proofs_digest = zkvm::DEFERRED_PROOFS_DIGEST.as_mut().unwrap(); - let deferred_proofs_digest_words = deferred_proofs_digest - .iter() - .map(|baby_bear| baby_bear.as_canonical_u32()) - .collect::>(); for i in 0..POSEIDON_NUM_WORDS { - asm!("ecall", in("t0") crate::syscalls::COMMIT_DEFERRED_PROOFS, in("a0") i, in("a1") deferred_proofs_digest_words[i]); + let word = deferred_proofs_digest[i].as_canonical_u32(); + asm!("ecall", in("t0") crate::syscalls::COMMIT_DEFERRED_PROOFS, in("a0") i, in("a1") word); } } else { for i in 0..POSEIDON_NUM_WORDS { diff --git a/zkvm/entrypoint/src/syscalls/io.rs b/zkvm/entrypoint/src/syscalls/io.rs index 4ef5875df..6ba7c62dd 100644 --- a/zkvm/entrypoint/src/syscalls/io.rs +++ b/zkvm/entrypoint/src/syscalls/io.rs @@ -3,7 +3,6 @@ cfg_if::cfg_if! { use core::arch::asm; use crate::zkvm; use sha2::digest::Update; - use sphinx_precompiles::io::FD_PUBLIC_VALUES; } } @@ -13,6 +12,7 @@ cfg_if::cfg_if! { pub extern "C" fn syscall_write(fd: u32, write_buf: *const u8, nbytes: usize) { cfg_if::cfg_if! { if #[cfg(target_os = "zkvm")] { + const FD_PUBLIC_VALUES: u32 = 3; unsafe { asm!( "ecall", diff --git a/zkvm/entrypoint/src/syscalls/memory.rs b/zkvm/entrypoint/src/syscalls/memory.rs index d78196948..fdf470904 100644 --- a/zkvm/entrypoint/src/syscalls/memory.rs +++ b/zkvm/entrypoint/src/syscalls/memory.rs @@ -12,7 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -const SYSTEM_START: usize = 0x0C00_0000; +// Memory addresses must be lower than BabyBear prime. +const MAX_MEMORY: usize = 0x78000000; #[allow(clippy::missing_safety_doc)] #[no_mangle] @@ -39,10 +40,12 @@ pub unsafe extern "C" fn sys_alloc_aligned(bytes: usize, align: usize) -> *mut u } let ptr = heap_pos as *mut u8; - heap_pos += bytes; + let (heap_pos, overflowed) = heap_pos.overflowing_add(bytes); - // Check to make sure heap doesn't collide with SYSTEM memory. - assert!(SYSTEM_START >= heap_pos); + assert!( + !(overflowed || MAX_MEMORY < heap_pos), + "Memory limit exceeded (0x78000000)" + ); unsafe { HEAP_POS = heap_pos }; ptr diff --git a/zkvm/precompiles/Cargo.toml b/zkvm/lib/Cargo.toml similarity index 71% rename from zkvm/precompiles/Cargo.toml rename to zkvm/lib/Cargo.toml index 6a0d4ddd1..8ec50732d 100644 --- a/zkvm/precompiles/Cargo.toml +++ b/zkvm/lib/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "sphinx-precompiles" +name = "sphinx-lib" version = "1.0.0" edition.workspace = true repository.workspace = true @@ -11,8 +11,11 @@ bincode = { workspace = true } cfg-if = { workspace = true } getrandom = { workspace = true, features = ["custom"] } hybrid-array = { workspace = true } -k256 = { workspace = true, features = ["ecdsa", "std", "bits"] } +k256 = { workspace = true, features = ["ecdsa", "std", "bits"], optional = true } serde = { workspace = true, features = ["derive"] } [features] +default = [] verify = [] +bn254 = [] +secp256k1 = ["dep:k256"] \ No newline at end of file diff --git a/zkvm/precompiles/src/bls12_381.rs b/zkvm/lib/src/bls12_381.rs similarity index 100% rename from zkvm/precompiles/src/bls12_381.rs rename to zkvm/lib/src/bls12_381.rs diff --git a/zkvm/precompiles/src/bn254.rs b/zkvm/lib/src/bn254.rs similarity index 100% rename from zkvm/precompiles/src/bn254.rs rename to zkvm/lib/src/bn254.rs diff --git a/zkvm/precompiles/src/io.rs b/zkvm/lib/src/io.rs similarity index 54% rename from zkvm/precompiles/src/io.rs rename to zkvm/lib/src/io.rs index b98da2b08..1582ef40b 100644 --- a/zkvm/precompiles/src/io.rs +++ b/zkvm/lib/src/io.rs @@ -1,22 +1,26 @@ #![allow(unused_unsafe)] -use std::{alloc::Layout, io::Write}; - use serde::{de::DeserializeOwned, Serialize}; +use std::io::Result; +use std::{alloc::Layout, io::Write}; use crate::{syscall_hint_len, syscall_hint_read, syscall_write}; -const FD_HINT: u32 = 4; +/// The file descriptor for public values. pub const FD_PUBLIC_VALUES: u32 = 3; -// Runtime hook file descriptors. Make sure these match the FDs in the HookRegistry. -// The default hooks can be found in `core/src/runtime/hooks.rs`. + +/// The file descriptor for hints. +pub const FD_HINT: u32 = 4; + +/// The file descriptor for the `ecreover` hook. pub const FD_ECRECOVER_HOOK: u32 = 5; -pub struct SyscallWriter { +/// A writer that writes to a file descriptor inside the zkVM. +struct SyscallWriter { fd: u32, } impl Write for SyscallWriter { - fn write(&mut self, buf: &[u8]) -> std::io::Result { + fn write(&mut self, buf: &[u8]) -> Result { let nbytes = buf.len(); let write_buf = buf.as_ptr(); unsafe { @@ -25,19 +29,26 @@ impl Write for SyscallWriter { Ok(nbytes) } - fn flush(&mut self) -> std::io::Result<()> { + fn flush(&mut self) -> Result<()> { Ok(()) } } +/// Read a buffer from the input stream. +/// +/// ### Examples +/// ```ignore +/// let data: Vec = sp1_zkvm::io::read_vec(); +/// ``` pub fn read_vec() -> Vec { - let len = unsafe { syscall_hint_len() }; // Round up to the nearest multiple of 4 so that the memory allocated is in whole words + let len = unsafe { syscall_hint_len() }; let capacity = (len + 3) / 4 * 4; // Allocate a buffer of the required length that is 4 byte aligned let layout = Layout::from_size_align(capacity, 4).expect("vec is too large"); let ptr = unsafe { std::alloc::alloc(layout) }; + // SAFETY: // 1. `ptr` was allocated using alloc // 2. We assuume that the VM global allocator doesn't dealloc @@ -45,6 +56,7 @@ pub fn read_vec() -> Vec { // 4/5. Length is 0 // 7. Layout::from_size_align already checks this let mut vec = unsafe { Vec::from_raw_parts(ptr, 0, capacity) }; + // Read the vec into uninitialized memory. The syscall assumes the memory is uninitialized, // which should be true because the allocator does not dealloc, so a new alloc should be fresh. unsafe { @@ -54,11 +66,43 @@ pub fn read_vec() -> Vec { vec } +/// Read a deserializable object from the input stream. +/// +/// ### Examples +/// ```ignore +/// use serde::{Deserialize, Serialize}; +/// +/// #[derive(Serialize, Deserialize)] +/// struct MyStruct { +/// a: u32, +/// b: u32, +/// } +/// +/// let data: MyStruct = sp1_zkvm::io::read(); +/// ``` pub fn read() -> T { let vec = read_vec(); bincode::deserialize(&vec).expect("deserialization failed") } +/// Commit a serializable object to the public values stream. +/// +/// ### Examples +/// ```ignore +/// use serde::{Deserialize, Serialize}; +/// +/// #[derive(Serialize, Deserialize)] +/// struct MyStruct { +/// a: u32, +/// b: u32, +/// } +/// +/// let data = MyStruct { +/// a: 1, +/// b: 2, +/// }; +/// sp1_zkvm::io::commit(&data); +/// ``` pub fn commit(value: &T) { let writer = SyscallWriter { fd: FD_PUBLIC_VALUES, @@ -66,6 +110,13 @@ pub fn commit(value: &T) { bincode::serialize_into(writer, value).expect("serialization failed"); } +/// Commit bytes to the public values stream. +/// +/// ### Examples +/// ```ignore +/// let data = vec![1, 2, 3, 4]; +/// sp1_zkvm::io::commit_slice(&data); +/// ``` pub fn commit_slice(buf: &[u8]) { let mut my_writer = SyscallWriter { fd: FD_PUBLIC_VALUES, @@ -73,17 +124,48 @@ pub fn commit_slice(buf: &[u8]) { my_writer.write_all(buf).unwrap(); } +/// Hint a serializable object to the hint stream. +/// +/// ### Examples +/// ```ignore +/// use serde::{Deserialize, Serialize}; +/// +/// #[derive(Serialize, Deserialize)] +/// struct MyStruct { +/// a: u32, +/// b: u32, +/// } +/// +/// let data = MyStruct { +/// a: 1, +/// b: 2, +/// }; +/// sp1_zkvm::io::hint(&data); +/// ``` pub fn hint(value: &T) { let writer = SyscallWriter { fd: FD_HINT }; bincode::serialize_into(writer, value).expect("serialization failed"); } +/// Hint bytes to the hint stream. +/// +/// ### Examples +/// ```ignore +/// let data = vec![1, 2, 3, 4]; +/// sp1_zkvm::io::hint_slice(&data); +/// ``` pub fn hint_slice(buf: &[u8]) { let mut my_reader = SyscallWriter { fd: FD_HINT }; my_reader.write_all(buf).unwrap(); } -/// Write the data `buf` to the file descriptor `fd` using `Write::write_all` . +/// Write the data `buf` to the file descriptor `fd`. +/// +/// ### Examples +/// ```ignore +/// let data = vec![1, 2, 3, 4]; +/// sp1_zkvm::io::write(3, &data); +/// ``` pub fn write(fd: u32, buf: &[u8]) { SyscallWriter { fd }.write_all(buf).unwrap(); } diff --git a/zkvm/precompiles/src/lib.rs b/zkvm/lib/src/lib.rs similarity index 64% rename from zkvm/precompiles/src/lib.rs rename to zkvm/lib/src/lib.rs index 4dd6257e4..a36aa74eb 100644 --- a/zkvm/precompiles/src/lib.rs +++ b/zkvm/lib/src/lib.rs @@ -1,33 +1,49 @@ -//! Precompiles for SP1 zkVM. -//! -//! Specifically, this crate contains user-friendly functions that call SP1 syscalls. Syscalls are -//! also declared here for convenience. In order to avoid duplicate symbol errors, the syscall -//! function impls must live in sp1-zkvm, which is only imported into the end user program crate. -//! In contrast, sp1-precompiles can be imported into any crate in the dependency tree. - +//! System calls for the SP1 zkVM. pub mod bls12_381; pub mod bn254; pub mod io; +#[cfg(feature = "secp256k1")] pub mod secp256k1; pub mod unconstrained; pub mod utils; #[cfg(feature = "verify")] pub mod verify; -pub const BIGINT_WIDTH_WORDS: usize = 8; - extern "C" { + /// Halts the program with the given exit code. pub fn syscall_halt(exit_code: u8) -> !; + + /// Writes the bytes in the given buffer to the given file descriptor. pub fn syscall_write(fd: u32, write_buf: *const u8, nbytes: usize); + + /// Reads the bytes from the given file descriptor into the given buffer. pub fn syscall_read(fd: u32, read_buf: *mut u8, nbytes: usize); + + /// Executes the SHA-256 extend operation on the given word array. pub fn syscall_sha256_extend(w: *mut u32); + + /// Executes the SHA-256 compress operation on the given word array and a given state. pub fn syscall_sha256_compress(w: *mut u32, state: *mut u32); + + /// Executes an Ed25519 curve addition on the given points. pub fn syscall_ed_add(p: *mut u32, q: *mut u32); + + /// Executes an Ed25519 curve decompression on the given point. pub fn syscall_ed_decompress(point: &mut [u8; 64]); + + /// Executes an Sepc256k1 curve addition on the given points. pub fn syscall_secp256k1_add(p: *mut u32, q: *const u32); + + /// Executes an Secp256k1 curve doubling on the given point. pub fn syscall_secp256k1_double(p: *mut u32); + + /// Executes an Secp256k1 curve decompression on the given point. pub fn syscall_secp256k1_decompress(point: &mut [u8; 64], is_odd: bool); + + /// Executes a Bn254 curve addition on the given points. pub fn syscall_bn254_add(p: *mut u32, q: *const u32); + + /// Executes a Bn254 curve doubling on the given point. pub fn syscall_bn254_double(p: *mut u32); pub fn syscall_bls12381_g1_add(p: *mut u32, q: *const u32); pub fn syscall_bls12381_g1_double(p: *mut u32); @@ -40,10 +56,16 @@ extern "C" { pub fn syscall_bls12381_fp2_sub(p: *mut u32, q: *const u32); pub fn syscall_bls12381_fp2_mul(p: *mut u32, q: *const u32); pub fn syscall_enter_unconstrained() -> bool; + + /// Exits unconstrained mode. pub fn syscall_exit_unconstrained(); pub fn syscall_verify_sphinx_proof(vkey: &[u32; 8], pv_digest: &[u8; 32]); pub fn syscall_hint_len() -> usize; + + /// Reads the next element in the hint stream into the given buffer. pub fn syscall_hint_read(ptr: *mut u8, len: usize); + + /// Allocates a buffer aligned to the given alignment. pub fn sys_alloc_aligned(bytes: usize, align: usize) -> *mut u8; pub fn syscall_bls12381_g2_add(p: *mut u32, q: *const u32); pub fn syscall_bls12381_g2_double(p: *mut u32); diff --git a/zkvm/precompiles/src/secp256k1.rs b/zkvm/lib/src/secp256k1.rs similarity index 100% rename from zkvm/precompiles/src/secp256k1.rs rename to zkvm/lib/src/secp256k1.rs diff --git a/zkvm/precompiles/src/unconstrained.rs b/zkvm/lib/src/unconstrained.rs similarity index 100% rename from zkvm/precompiles/src/unconstrained.rs rename to zkvm/lib/src/unconstrained.rs diff --git a/zkvm/precompiles/src/utils.rs b/zkvm/lib/src/utils.rs similarity index 100% rename from zkvm/precompiles/src/utils.rs rename to zkvm/lib/src/utils.rs diff --git a/zkvm/precompiles/src/verify.rs b/zkvm/lib/src/verify.rs similarity index 77% rename from zkvm/precompiles/src/verify.rs rename to zkvm/lib/src/verify.rs index 187164542..9ce4fcf55 100644 --- a/zkvm/precompiles/src/verify.rs +++ b/zkvm/lib/src/verify.rs @@ -2,7 +2,7 @@ use crate::syscall_verify_sphinx_proof; /// Verifies the next proof in the proof input stream given a pkey digest and public values digest. /// -/// Note: sp1_zkvm must also have feature `verify` enabled for this function to work. +/// Note: sphinx_zkvm must also have feature `verify` enabled for this function to work. pub fn verify_sphinx_proof(pkey_digest: &[u32; 8], pv_digest: &[u8; 32]) { unsafe { syscall_verify_sphinx_proof(pkey_digest, pv_digest);