diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index f0cc4ca51a..500033f728 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -120,14 +120,14 @@ jobs: env: CARGO_INCREMENTAL: 1 - # - name: Add wasm target - # run: rustup target add wasm32-unknown-unknown + - name: Add wasm target + run: rustup target add wasm32-unknown-unknown - # - name: Check wasm compatibility for sdk - # uses: actions-rs/cargo@v1 - # with: - # command: check - # args: -p sp1-sdk --target wasm32-unknown-unknown --no-default-features + - name: Check wasm compatibility for sdk + uses: actions-rs/cargo@v1 + with: + command: check + args: -p sp1-sdk --target wasm32-unknown-unknown --no-default-features examples: name: Examples @@ -270,55 +270,55 @@ jobs: --commit-hash "${{ github.sha }}" \ --author "${{ github.event.pull_request.user.login || github.actor }}" - # low-memory: - # name: Low Memory - # strategy: - # matrix: - # mem_limit: [16, 32, 64] - # runs-on: - # [ - # runs-on, - # "ram=${{ matrix.mem_limit}}", - # family=c7a, - # image=ubuntu22-full-x64, - # "run-id=${{ github.run_id }}", - # ] - # env: - # CARGO_NET_GIT_FETCH_WITH_CLI: "true" - # steps: - # - name: Checkout sources - # uses: actions/checkout@v4 + low-memory: + name: Low Memory + strategy: + matrix: + mem_limit: [16, 32, 64] + runs-on: + [ + runs-on, + "ram=${{ matrix.mem_limit}}", + family=c7a, + image=ubuntu22-full-x64, + "run-id=${{ github.run_id }}", + ] + env: + CARGO_NET_GIT_FETCH_WITH_CLI: "true" + steps: + - name: Checkout sources + uses: actions/checkout@v4 - # - name: Setup CI - # uses: ./.github/actions/setup + - name: Setup CI + uses: ./.github/actions/setup - # - name: Install SP1 toolchain - # run: | - # curl -L https://sp1.succinct.xyz | bash - # ~/.sp1/bin/sp1up - # ~/.sp1/bin/cargo-prove prove --version + - name: Install SP1 toolchain + run: | + curl -L https://sp1.succinct.xyz | bash + ~/.sp1/bin/sp1up + ~/.sp1/bin/cargo-prove prove --version - # - name: Install SP1 CLI - # run: | - # cd crates/cli - # cargo install --force --locked --path . - # cd ~ + - name: Install SP1 CLI + run: | + cd crates/cli + cargo install --force --locked --path . + cd ~ - # - name: Run tendermint script - # run: | - # cd examples/tendermint/program - # cargo add sp1-zkvm --path $GITHUB_WORKSPACE/crates/zkvm/entrypoint - # cargo prove build - # cd ../script - # cargo remove sp1-sdk - # cargo add sp1-sdk --path $GITHUB_WORKSPACE/crates/sdk - # SP1_DEV=1 RUST_LOG=info cargo run --release + - name: Run tendermint script + run: | + cd examples/tendermint/program + cargo add sp1-zkvm --path $GITHUB_WORKSPACE/crates/zkvm/entrypoint + cargo prove build + cd ../script + cargo remove sp1-sdk + cargo add sp1-sdk --path $GITHUB_WORKSPACE/crates/sdk + SP1_DEV=1 RUST_LOG=info cargo run --release - # - name: Run cycle tracking script - # run: | - # cd examples/cycle-tracking/script - # cargo add sp1-sdk --path $GITHUB_WORKSPACE/crates/sdk - # SP1_DEV=1 RUST_LOG=info cargo run --release + - name: Run cycle tracking script + run: | + cd examples/cycle-tracking/script + cargo add sp1-sdk --path $GITHUB_WORKSPACE/crates/sdk + SP1_DEV=1 RUST_LOG=info cargo run --release # toolchain-test: # name: "Test toolchain installation (${{ matrix.name }})" diff --git a/Cargo.lock b/Cargo.lock index 0ec5620974..91c462d689 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6916,6 +6916,7 @@ dependencies = [ "serde", "serde_json", "slack-rust-rs", + "sp1-core-executor", "sp1-cuda", "sp1-prover", "sp1-sdk", diff --git a/crates/core/machine/src/lib.rs b/crates/core/machine/src/lib.rs index f50ee422c6..16fd571c95 100644 --- a/crates/core/machine/src/lib.rs +++ b/crates/core/machine/src/lib.rs @@ -30,7 +30,7 @@ pub mod utils; /// 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 SP1_CIRCUIT_VERSION: &str = "v3.0.0-rc4"; +pub const SP1_CIRCUIT_VERSION: &str = "v3.0.0"; // Re-export the `SP1ReduceProof` struct from sp1_core_machine. // diff --git a/crates/cuda/src/lib.rs b/crates/cuda/src/lib.rs index f299d59d52..f63a65c744 100644 --- a/crates/cuda/src/lib.rs +++ b/crates/cuda/src/lib.rs @@ -91,7 +91,7 @@ impl SP1CudaProver { /// [SP1ProverClient] that can be used to communicate with the container. pub fn new() -> Result> { let container_name = "sp1-gpu"; - let image_name = "public.ecr.aws/succinct-labs/sp1-gpu:445c33b"; + let image_name = "public.ecr.aws/succinct-labs/sp1-gpu:7e66232"; let cleaned_up = Arc::new(AtomicBool::new(false)); let cleanup_name = container_name; diff --git a/crates/perf/Cargo.toml b/crates/perf/Cargo.toml index fd4e92c8b2..3cc77b6fc9 100644 --- a/crates/perf/Cargo.toml +++ b/crates/perf/Cargo.toml @@ -11,6 +11,7 @@ categories = { workspace = true } [dependencies] sp1-prover = { workspace = true } +sp1-core-executor = { workspace = true, features = ["programs"] } sp1-sdk = { workspace = true } p3-baby-bear = { workspace = true } sp1-stark = { workspace = true } diff --git a/crates/perf/run_s3.sh b/crates/perf/run_s3.sh index f26278ee9b..a9a0ef7a06 100755 --- a/crates/perf/run_s3.sh +++ b/crates/perf/run_s3.sh @@ -14,9 +14,10 @@ aws s3 cp s3://sp1-testing-suite/$s3_path/program.bin /tmp/program.bin aws s3 cp s3://sp1-testing-suite/$s3_path/stdin.bin /tmp/stdin.bin # Set environment variables -export RUSTFLAGS="-Copt-level=3 -Ctarget-cpu=native" +export RUSTFLAGS="-Copt-level=3 -Ctarget-cpu=native -Cdebuginfo=2" export RUST_BACKTRACE=1 export RUST_LOG=debug +export SP1_DEBUG=1 # Run moongate-perf -cargo run --release -p sp1-perf -- --program /tmp/program.bin --stdin /tmp/stdin.bin --mode $stage \ No newline at end of file +cargo run -p sp1-perf -- --program /tmp/program.bin --stdin /tmp/stdin.bin --mode $stage \ No newline at end of file diff --git a/crates/perf/src/main.rs b/crates/perf/src/main.rs index f4151493dc..baeffbc49b 100644 --- a/crates/perf/src/main.rs +++ b/crates/perf/src/main.rs @@ -1,8 +1,10 @@ use std::time::{Duration, Instant}; use clap::{command, Parser, ValueEnum}; +use sp1_core_executor::programs::tests::VERIFY_PROOF_ELF; use sp1_cuda::SP1CudaProver; use sp1_prover::components::DefaultProverComponents; +use sp1_prover::HashableKey; use sp1_sdk::{self, ProverClient, SP1Context, SP1Prover, SP1Stdin}; use sp1_stark::SP1ProverOpts; @@ -17,7 +19,7 @@ struct PerfArgs { pub mode: ProverMode, } -#[derive(Debug, Clone)] +#[derive(Default, Debug, Clone)] #[allow(dead_code)] struct PerfResult { pub cycles: u64, @@ -71,22 +73,15 @@ fn main() { let (_, verify_core_duration) = time_operation(|| prover.verify(&core_proof.proof, &vk)); - let (compress_proof, compress_duration) = time_operation(|| { - prover - .compress( - &vk, - core_proof, - stdin.proofs.iter().map(|(proof, _)| proof.clone()).collect(), - opts, - ) - .unwrap() - }); + let proofs = stdin.proofs.into_iter().map(|(proof, _)| proof).collect::>(); + let (compress_proof, compress_duration) = + time_operation(|| prover.compress(&vk, core_proof.clone(), proofs, opts).unwrap()); let (_, verify_compressed_duration) = time_operation(|| prover.verify_compressed(&compress_proof, &vk)); let (shrink_proof, shrink_duration) = - time_operation(|| prover.shrink(compress_proof, opts).unwrap()); + time_operation(|| prover.shrink(compress_proof.clone(), opts).unwrap()); let (_, verify_shrink_duration) = time_operation(|| prover.verify_shrink(&shrink_proof, &vk)); @@ -97,6 +92,30 @@ fn main() { let (_, verify_wrap_duration) = time_operation(|| prover.verify_wrap_bn254(&wrapped_bn254_proof, &vk)); + // Generate a proof that verifies two deferred proofs from the proof above. + let (pk_verify_proof, vk_verify_proof) = prover.setup(VERIFY_PROOF_ELF); + let pv = core_proof.public_values.to_vec(); + + let mut stdin = SP1Stdin::new(); + let vk_u32 = vk.hash_u32(); + stdin.write::<[u32; 8]>(&vk_u32); + stdin.write::>>(&vec![pv.clone(), pv.clone()]); + stdin.write_proof(compress_proof.clone(), vk.vk.clone()); + stdin.write_proof(compress_proof.clone(), vk.vk.clone()); + + let context = SP1Context::default(); + let (core_proof, _) = time_operation(|| { + prover.prove_core(&pk_verify_proof, &stdin, opts, context).unwrap() + }); + let deferred_proofs = + stdin.proofs.into_iter().map(|(proof, _)| proof).collect::>(); + let (compress_proof, _) = time_operation(|| { + prover + .compress(&vk_verify_proof, core_proof.clone(), deferred_proofs, opts) + .unwrap() + }); + prover.verify_compressed(&compress_proof, &vk_verify_proof).unwrap(); + let result = PerfResult { cycles, execution_duration, @@ -126,15 +145,9 @@ fn main() { prover.verify(&core_proof.proof, &vk).expect("Proof verification failed") }); - let (compress_proof, compress_duration) = time_operation(|| { - server - .compress( - &vk, - core_proof, - stdin.proofs.iter().map(|(proof, _)| proof.clone()).collect(), - ) - .unwrap() - }); + let proofs = stdin.proofs.into_iter().map(|(proof, _)| proof).collect::>(); + let (compress_proof, compress_duration) = + time_operation(|| server.compress(&vk, core_proof, proofs).unwrap()); let (_, verify_compressed_duration) = time_operation(|| prover.verify_compressed(&compress_proof, &vk)); @@ -147,10 +160,9 @@ fn main() { let (_, wrap_duration) = time_operation(|| server.wrap_bn254(shrink_proof).unwrap()); - // TODO: Verify wrapped bn254 proofs. + // TODO: FIX // let (_, verify_wrap_duration) = // time_operation(|| prover.verify_wrap_bn254(&wrapped_bn254_proof, &vk)); - let verify_wrap_duration = Duration::from_secs(0); let result = PerfResult { cycles, @@ -162,7 +174,7 @@ fn main() { shrink_duration, verify_shrink_duration, wrap_duration, - verify_wrap_duration, + ..Default::default() }; println!("{:?}", result); diff --git a/crates/prover/vk_map.bin b/crates/prover/vk_map.bin index bced2e747f..afa7df3b13 100644 Binary files a/crates/prover/vk_map.bin and b/crates/prover/vk_map.bin differ diff --git a/crates/recursion/circuit/src/machine/deferred.rs b/crates/recursion/circuit/src/machine/deferred.rs index 1afc3cb014..0f38620a7d 100644 --- a/crates/recursion/circuit/src/machine/deferred.rs +++ b/crates/recursion/circuit/src/machine/deferred.rs @@ -181,6 +181,10 @@ where // Get the current public values. let current_public_values: &RecursionPublicValues> = shard_proof.public_values.as_slice().borrow(); + // Assert that the `vk_root` is the same as the witnessed one. + for (elem, expected) in current_public_values.vk_root.iter().zip(vk_root.iter()) { + builder.assert_felt_eq(*elem, *expected); + } // Assert that the public values are valid. assert_recursion_public_values_valid::(builder, current_public_values);