Skip to content

Commit

Permalink
fix: verify_compressed
Browse files Browse the repository at this point in the history
  • Loading branch information
ctian1 committed May 13, 2024
1 parent 2f57e1e commit d5246ea
Showing 1 changed file with 12 additions and 26 deletions.
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

0 comments on commit d5246ea

Please sign in to comment.