Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: connect deferred vk root #1649

Merged
merged 12 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 51 additions & 51 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }})"
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/core/machine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down
2 changes: 1 addition & 1 deletion crates/cuda/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl SP1CudaProver {
/// [SP1ProverClient] that can be used to communicate with the container.
pub fn new() -> Result<Self, Box<dyn StdError>> {
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;
Expand Down
1 change: 1 addition & 0 deletions crates/perf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
5 changes: 3 additions & 2 deletions crates/perf/run_s3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
cargo run -p sp1-perf -- --program /tmp/program.bin --stdin /tmp/stdin.bin --mode $stage
60 changes: 36 additions & 24 deletions crates/perf/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -17,7 +19,7 @@ struct PerfArgs {
pub mode: ProverMode,
}

#[derive(Debug, Clone)]
#[derive(Default, Debug, Clone)]
#[allow(dead_code)]
struct PerfResult {
pub cycles: u64,
Expand Down Expand Up @@ -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::<Vec<_>>();
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));
Expand All @@ -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<Vec<u8>>>(&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::<Vec<_>>();
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,
Expand Down Expand Up @@ -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::<Vec<_>>();
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));
Expand All @@ -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,
Expand All @@ -162,7 +174,7 @@ fn main() {
shrink_duration,
verify_shrink_duration,
wrap_duration,
verify_wrap_duration,
..Default::default()
};

println!("{:?}", result);
Expand Down
Binary file modified crates/prover/vk_map.bin
Binary file not shown.
4 changes: 4 additions & 0 deletions crates/recursion/circuit/src/machine/deferred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ where
// Get the current public values.
let current_public_values: &RecursionPublicValues<Felt<C::F>> =
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::<C, SC>(builder, current_public_values);

Expand Down
Loading