Skip to content

Commit d9e77f8

Browse files
committed
refactor: fallback verification with dummy proof
1 parent f114f03 commit d9e77f8

File tree

5 files changed

+73
-7
lines changed

5 files changed

+73
-7
lines changed

consensus/types/src/execution_proof_id.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ use tree_hash::TreeHash;
99
/// TODO(zkproofs): The number 8 is a parameter that we will want to configure in the future
1010
pub const EXECUTION_PROOF_TYPE_COUNT: u8 = 8;
1111

12+
/// TODO(ethproofs): Added to handle when proof generation fails.
13+
///
14+
/// Special proof ID reserved for fallback proofs
15+
pub const FALLBACK_EXECUTION_PROOF_ID: u8 = 255;
16+
1217
/// ExecutionProofId identifies which zkVM/proof system a proof belongs to.
1318
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
1419
pub struct ExecutionProofId(u8);
@@ -81,11 +86,22 @@ impl ExecutionProofId {
8186
}
8287
}
8388

89+
/// Creates a fallback ExecutionProofId (255)
90+
/// Used for dummy proofs when Ethproofs API fails or times out
91+
pub fn fallback() -> Self {
92+
Self(FALLBACK_EXECUTION_PROOF_ID)
93+
}
94+
8495
/// Returns the inner u8 value
8596
pub fn as_u8(&self) -> u8 {
8697
self.0
8798
}
8899

100+
/// Check if this is a fallback proof ID
101+
pub fn is_fallback(&self) -> bool {
102+
self.0 == FALLBACK_EXECUTION_PROOF_ID
103+
}
104+
89105
/// Returns the subnet ID as a usize
90106
pub fn as_usize(&self) -> usize {
91107
self.0 as usize

zkvm_execution_layer/src/dummy_proof_gen.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use async_trait::async_trait;
66
use std::time::Duration;
77
use tokio::time::sleep;
88
use tracing::{debug, warn};
9+
use types::execution_proof_id::FALLBACK_EXECUTION_PROOF_ID;
910
use types::{ExecutionBlockHash, ExecutionProof, ExecutionProofId, Hash256, Slot};
1011

1112
/// TODO(ethproofs): Implementation of proof generation for demo.
@@ -36,23 +37,33 @@ impl DummyProofGenerator {
3637
}
3738
}
3839

39-
/// TODO(ethproofs): Used when Ethproofs API fails or verification fails.
40+
/// TODO(ethproofs): Fallback when the Ethproofs API fails or test verification fails.
4041
///
41-
/// Create a fallback dummy proof
42+
/// Create a fallback dummy proof with a reserved fallback proof ID
4243
fn create_dummy_proof(
4344
&self,
4445
slot: Slot,
4546
payload_hash: &ExecutionBlockHash,
4647
block_root: &Hash256,
4748
) -> ProofGenerationResult<ExecutionProof> {
4849
let dummy_data = format!(
49-
"ethproofs_fallback_subnet_{:?}_slot_{:?}_hash_{:?}",
50-
self.proof_id, slot, payload_hash
50+
"ethproofs_fallback_proof_id_{}_slot_{}_hash_{}",
51+
FALLBACK_EXECUTION_PROOF_ID,
52+
slot.as_u64(),
53+
payload_hash
5154
)
5255
.into_bytes();
5356

54-
ExecutionProof::new(self.proof_id, slot, *payload_hash, *block_root, dummy_data)
55-
.map_err(ProofGenerationError::ProofGenerationFailed)
57+
// Use the fallback proof ID to mark this as a dummy proof
58+
let fallback_proof_id = ExecutionProofId::fallback();
59+
ExecutionProof::new(
60+
fallback_proof_id,
61+
slot,
62+
*payload_hash,
63+
*block_root,
64+
dummy_data,
65+
)
66+
.map_err(ProofGenerationError::ProofGenerationFailed)
5667
}
5768
}
5869

@@ -178,7 +189,8 @@ mod tests {
178189
assert!(result.is_ok());
179190

180191
let proof = result.unwrap();
181-
assert_eq!(proof.proof_id, subnet);
192+
193+
assert!(proof.proof_id.is_fallback());
182194
assert_eq!(proof.slot, slot);
183195
assert_eq!(proof.block_hash, block_hash);
184196
assert_eq!(proof.block_root, block_root);

zkvm_execution_layer/src/ethproofs_demo.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,15 @@ pub async fn download_proof_binary(proof_id: u64) -> Result<Vec<u8>, String> {
162162
/// 2. Running the cryptographic verification function
163163
/// 3. Returning whether the proof is valid
164164
pub fn validate_proof(proof: &ExecutionProof) -> bool {
165+
// Check if this is a fallback proof (created when Ethproofs API failed/timed out)
166+
if proof.proof_id.is_fallback() {
167+
debug!(
168+
proof_id = %proof.proof_id,
169+
"[Ethproofs] Fallback proof detected, skipping verification"
170+
);
171+
return true;
172+
}
173+
165174
// Get the prover UUID for this proof_id from the hardcoded mapping
166175
let prover_uuid = match VERIFIER_STORE.get_prover_uuid_for_proof_id(proof.proof_id) {
167176
Some(uuid) => uuid,
Binary file not shown.

zkvm_execution_layer/src/verifiers/pico.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,38 @@ impl ProofVerifier for PicoVerifier {
9696
#[cfg(test)]
9797
mod tests {
9898
use super::*;
99+
use std::path::PathBuf;
99100

100101
#[test]
101102
fn test_pico_verifier_name() {
102103
assert_eq!(PicoVerifier::name(), "pico");
103104
}
105+
106+
#[test]
107+
fn test_pico_verifier_with_real_proof() {
108+
// Path to the test proof file
109+
let proof_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
110+
.join("src/test_proofs/brevis_79041a5b-ee8d-49b3-8207-86c7debf8e13_542871.bin");
111+
112+
// Path to the verification key file
113+
let vk_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
114+
.join("src/verification_keys/brevis_79041a5b-ee8d-49b3-8207-86c7debf8e13.bin");
115+
116+
// Read the proof and verification key
117+
let proof_data = std::fs::read(&proof_path)
118+
.expect("Failed to read test proof file");
119+
let vk_data = std::fs::read(&vk_path)
120+
.expect("Failed to read test verification key file");
121+
122+
// Verify the proof
123+
let result = PicoVerifier::verify(&proof_data, &vk_data);
124+
125+
// Log the result for debugging
126+
eprintln!("Proof size: {} bytes", proof_data.len());
127+
eprintln!("VK size: {} bytes", vk_data.len());
128+
eprintln!("Verification result: {:?}", result);
129+
130+
// The result should be Ok with a boolean (true if valid, false if invalid)
131+
assert!(result.is_ok(), "Verification should not error: {:?}", result.err());
132+
}
104133
}

0 commit comments

Comments
 (0)