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: verify_compressed #725

Merged
merged 5 commits into from
May 13, 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
7 changes: 4 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
- "sdk/**"
- ".github/workflows/**"
merge_group:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
Expand Down Expand Up @@ -167,11 +167,12 @@ jobs:
- name: Run cargo prove new
run: |
cargo prove new fibonacci

- name: Build program and run script
run: |
cd fibonacci
cd program
cargo prove build
cd ../script
SP1_DEV=1 RUST_LOG=info cargo run --release
cargo add sp1-sdk --path $GITHUB_WORKSPACE/sdk
SP1_DEV=1 RUST_LOG=info cargo run --release
2 changes: 1 addition & 1 deletion cli/src/assets/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ name = "unnamed-program"
edition = "2021"

[dependencies]
sp1-zkvm = { git = "https://github.com/succinctlabs/sp1.git", rev = "v1.0.0-testnet" }
sp1-zkvm = { git = "https://github.com/succinctlabs/sp1.git", branch = "main" }
4 changes: 2 additions & 2 deletions cli/src/assets/script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name = "unnamed-script"
edition = "2021"

[dependencies]
sp1-sdk = { git = "https://github.com/succinctlabs/sp1.git", rev = "v1.0.0-testnet" }
sp1-sdk = { git = "https://github.com/succinctlabs/sp1.git", branch = "main" }

[build-dependencies]
sp1-helper = { git = "https://github.com/succinctlabs/sp1.git", rev = "v1.0.0-testnet" }
sp1-helper = { git = "https://github.com/succinctlabs/sp1.git", branch = "main" }
6 changes: 4 additions & 2 deletions cli/src/assets/script/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn main() {
stdin.write(&n);
let client = ProverClient::new();
let (pk, vk) = client.setup(ELF);
let mut proof = client.prove(&pk, stdin).expect("proving failed");
let mut proof = client.prove_compressed(&pk, stdin).expect("proving failed");

// Read output.
let a = proof.public_values.read::<u128>();
Expand All @@ -20,7 +20,9 @@ fn main() {
println!("b: {}", b);

// Verify proof.
client.verify(&proof, &vk).expect("verification failed");
client
.verify_compressed(&proof, &vk)
.expect("verification failed");

// Save proof.
proof
Expand Down
38 changes: 12 additions & 26 deletions sdk/src/provers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ use anyhow::Result;
pub use local::LocalProver;
pub use mock::MockProver;
pub use network::NetworkProver;
use sha2::{Digest, Sha256};
use sp1_core::air::PublicValues;
use sp1_core::stark::MachineProof;
use sp1_core::stark::MachineVerificationError;
use sp1_core::stark::StarkGenericConfig;
use sp1_prover::CoreSC;
use sp1_prover::SP1CoreProofData;
use sp1_prover::SP1Prover;
use sp1_prover::SP1ReduceProof;
use sp1_prover::{SP1ProvingKey, SP1Stdin, SP1VerifyingKey};

/// An implementation of [crate::ProverClient].
Expand Down Expand Up @@ -42,32 +40,20 @@ pub trait Prover: Send + Sync {
proof: &SP1Proof,
vkey: &SP1VerifyingKey,
) -> Result<(), MachineVerificationError<CoreSC>> {
let pv = PublicValues::from_vec(proof.proof[0].public_values.clone());
let pv_digest: [u8; 32] = Sha256::digest(proof.public_values.as_slice()).into();
if pv_digest != *pv.commit_digest_bytes() {
return Err(MachineVerificationError::InvalidPublicValuesDigest);
}
let machine_proof = MachineProof {
shard_proofs: proof.proof.clone(),
};
let sp1_prover = self.sp1_prover();
let mut challenger = sp1_prover.core_machine.config().challenger();
sp1_prover
.core_machine
.verify(&vkey.vk, &machine_proof, &mut challenger)
self.sp1_prover()
.verify(&SP1CoreProofData(proof.proof.clone()), vkey)
}

/// Verify that a compressed SP1 proof is valid given its vkey and metadata.
fn verify_compressed(&self, proof: &SP1CompressedProof, vkey: &SP1VerifyingKey) -> Result<()> {
// TODO: implement verification of the digest of the public values matching
let sp1_prover = self.sp1_prover();
let machine_proof = MachineProof {
shard_proofs: vec![proof.proof.clone()],
};
let mut challenger = sp1_prover.compress_machine.config().challenger();
Ok(sp1_prover
.compress_machine
.verify(&vkey.vk, &machine_proof, &mut challenger)?)
self.sp1_prover()
.verify_compressed(
&SP1ReduceProof {
proof: proof.proof.clone(),
},
vkey,
)
.map_err(|e| e.into())
}

/// Verify that a SP1 Groth16 proof is valid given its vkey and metadata.
Expand Down
Loading