Skip to content

Commit 57d4a69

Browse files
committed
fix tests
1 parent 8fecd20 commit 57d4a69

File tree

6 files changed

+35
-62
lines changed

6 files changed

+35
-62
lines changed

crates/risc0/src/groth16_verifier.rs

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,19 @@ pub fn verify_groth16(receipt: &ProofReceipt, verification_key: &[u8; 32]) -> Zk
2626
.map_err(|e| strata_zkvm::ZkVmError::ProofVerificationError(e.to_string()))
2727
}
2828

29-
// #[cfg(test)]
30-
// mod tests {
31-
// use risc0_zkvm::{serde::to_vec, Receipt};
32-
// use strata_zkvm::Proof;
33-
34-
// use super::verify_groth16;
35-
// #[test]
36-
// fn test_groth16_verification() {
37-
// let input: u32 = 1;
38-
39-
// // Note: This is generated in prover.rs
40-
// let vk = [
41-
// 48, 77, 52, 1, 100, 95, 109, 135, 223, 56, 83, 146, 244, 21, 237, 63, 198, 105, 2,
42-
// 75, 135, 48, 52, 165, 178, 24, 200, 186, 174, 191, 212, 184,
43-
// ];
44-
45-
// // Note: This is written in prover.rs
46-
// let raw_proof = include_bytes!("../tests/proofs/proof-groth16.bin");
47-
48-
// let proof = Proof::new(raw_proof.to_vec());
49-
// let receipt: Receipt = bincode::deserialize(proof.as_bytes()).unwrap();
50-
// let seal = Proof::new(receipt.inner.groth16().unwrap().clone().seal);
51-
52-
// let public_params_raw: Vec<u8> = to_vec(&input)
53-
// .unwrap()
54-
// .clone()
55-
// .into_iter()
56-
// .flat_map(|x| x.to_le_bytes().to_vec()) // Convert each u32 to 4 u8 bytes
57-
// .collect();
58-
// let res = verify_groth16(&seal, &vk, &public_params_raw);
59-
// assert!(res.is_ok());
60-
// }
61-
// }
29+
#[cfg(test)]
30+
mod tests {
31+
use strata_zkvm::ProofReceipt;
32+
33+
use super::verify_groth16;
34+
#[test]
35+
fn test_groth16_verification() {
36+
let vk_hex = "0963493f27db6efac281ea2900ff4c611a93703cb9109dbd2231484121d08384";
37+
let vk: [u8; 32] = hex::decode(vk_hex).unwrap().try_into().unwrap();
38+
let proof_file = format!("./proofs/fibonacci_risc0_{}.proof.bin", vk_hex);
39+
40+
let receipt = ProofReceipt::load(proof_file).unwrap();
41+
let res = verify_groth16(&receipt, &vk);
42+
assert!(res.is_ok(), "groth16 proof verification must succeed");
43+
}
44+
}

crates/sp1/src/groth16_verifier.rs

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,20 @@ pub fn verify_groth16(receipt: &ProofReceipt, vkey_hash: &[u8; 32]) -> ZkVmResul
1818
.map_err(|e| ZkVmError::ProofVerificationError(e.to_string()))
1919
}
2020

21-
// // NOTE: SP1 prover runs in release mode only; therefore run the tests on release mode only
22-
// #[cfg(test)]
23-
// mod tests {
24-
25-
// use sp1_sdk::SP1ProofWithPublicValues;
26-
// use strata_primitives::buf::Buf32;
27-
28-
// use super::*;
29-
30-
// #[test]
31-
// fn test_groth16_verification() {
32-
// let sp1_vkey_hash = "0x00efb1120491119751e75bc55bc95b64d33f973ecf68fcf5cbff08506c5788f9";
33-
// let vk_buf32: Buf32 = sp1_vkey_hash.parse().unwrap();
34-
// let vk_hash_str = hex::encode(vk_buf32.as_bytes());
35-
// let vk_hash_str = format!("0x{}", vk_hash_str);
36-
// assert_eq!(sp1_vkey_hash, vk_hash_str);
37-
38-
// let sp1_proof_with_public_values =
39-
// SP1ProofWithPublicValues::load("tests/proofs/proof-groth16.bin").unwrap();
40-
41-
// let proof = Proof::new(sp1_proof_with_public_values.bytes());
42-
// let sp1_public_inputs = sp1_proof_with_public_values.public_values.to_vec();
43-
44-
// verify_groth16(&proof, &vk_buf32.0, &sp1_public_inputs)
45-
// .expect("proof verification must succeed");
46-
// }
47-
// }
21+
#[cfg(test)]
22+
mod tests {
23+
use strata_zkvm::ProofReceipt;
24+
25+
use crate::verify_groth16;
26+
27+
#[test]
28+
fn test_groth16_verification() {
29+
let vk_hex = "00bf077c28baa685b0a9ec0b8d47eb51bc98f5c048f5aa386ea156fe24995a35";
30+
let vk: [u8; 32] = hex::decode(vk_hex).unwrap().try_into().unwrap();
31+
let proof_file = format!("./proofs/fibonacci_sp1_0x{}.proof.bin", vk_hex);
32+
33+
let receipt = ProofReceipt::load(proof_file).unwrap();
34+
let res = verify_groth16(&receipt, &vk);
35+
assert!(res.is_ok(), "groth16 proof verification must succeed");
36+
}
37+
}

crates/sp1/src/proof.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl TryFrom<SP1ProofReceipt> for ProofReceipt {
5050
fn try_from(value: SP1ProofReceipt) -> Result<Self, Self::Error> {
5151
let sp1_receipt = value.as_ref();
5252

53-
// If there's a Groth16 representation, just re-use its bytes;
53+
// If there's a Groth16 representation, just reuse its bytes;
5454
// otherwise, serialize the entire proof.
5555
let proof_bytes = match sp1_receipt.proof.clone().try_as_groth_16() {
5656
Some(_) => sp1_receipt.bytes(),

examples/fibonacci/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl ZkVmProver for FibProver {
2525
type Output = i32;
2626

2727
fn proof_type() -> strata_zkvm::ProofType {
28-
ProofType::Core
28+
ProofType::Groth16
2929
}
3030

3131
fn prepare_input<'a, B>(input: &'a Self::Input) -> ZkVmInputResult<B::Input>

0 commit comments

Comments
 (0)