Skip to content

Commit a9a4d20

Browse files
committed
fix: validation on fallback proof id
1 parent bf5e471 commit a9a4d20

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

consensus/types/src/execution_proof_id.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ impl TreeHash for ExecutionProofId {
7676
impl ExecutionProofId {
7777
/// Creates a new ExecutionProofId if the value is valid
7878
pub fn new(id: u8) -> Result<Self, String> {
79-
if id < EXECUTION_PROOF_TYPE_COUNT {
79+
if id < EXECUTION_PROOF_TYPE_COUNT || id == FALLBACK_EXECUTION_PROOF_ID {
8080
Ok(Self(id))
8181
} else {
8282
Err(format!(
83-
"Invalid ExecutionProofId: {}, must be < {}",
84-
id, EXECUTION_PROOF_TYPE_COUNT
83+
"Invalid ExecutionProofId: {}, must be < {} or {}",
84+
id, EXECUTION_PROOF_TYPE_COUNT, FALLBACK_EXECUTION_PROOF_ID
8585
))
8686
}
8787
}
@@ -157,4 +157,23 @@ mod tests {
157157
assert_eq!(proof_id.as_usize(), idx);
158158
}
159159
}
160+
161+
#[test]
162+
fn test_fallback_proof_id() {
163+
// Test that fallback() creates an ID with value 255
164+
let fallback = ExecutionProofId::fallback();
165+
assert_eq!(fallback.as_u8(), FALLBACK_EXECUTION_PROOF_ID);
166+
assert!(fallback.is_fallback());
167+
168+
// Test that new(255) creates a valid fallback ID
169+
let fallback_from_new = ExecutionProofId::new(FALLBACK_EXECUTION_PROOF_ID);
170+
assert!(fallback_from_new.is_ok());
171+
assert_eq!(fallback_from_new.unwrap().as_u8(), FALLBACK_EXECUTION_PROOF_ID);
172+
173+
// Test that fallback ID can be SSZ encoded and decoded
174+
let encoded = fallback.as_ssz_bytes();
175+
let decoded = ExecutionProofId::from_ssz_bytes(&encoded);
176+
assert!(decoded.is_ok());
177+
assert_eq!(decoded.unwrap(), fallback);
178+
}
160179
}

zkvm_execution_layer/src/ethproofs_demo.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub async fn fetch_proof_from_ethproofs(
6060
block_hash: types::ExecutionBlockHash,
6161
cluster: String,
6262
) -> Result<Vec<Ethproof>, String> {
63-
const MAX_WAIT_TIME_SECS: u64 = 30;
63+
const MAX_WAIT_TIME_SECS: u64 = 15;
6464
const INITIAL_DELAY_MS: u64 = 100;
6565
const MAX_DELAY_MS: u64 = 5000;
6666

@@ -165,6 +165,8 @@ pub fn validate_proof(proof: &ExecutionProof) -> bool {
165165
// Check if this is a fallback proof (created when Ethproofs API failed/timed out)
166166
if proof.proof_id.is_fallback() {
167167
info!(
168+
slot = %proof.slot,
169+
block_hash = %proof.block_hash,
168170
proof_id = %proof.proof_id,
169171
"[Ethproofs] Fallback proof detected, skipping verification"
170172
);
@@ -188,6 +190,8 @@ pub fn validate_proof(proof: &ExecutionProof) -> bool {
188190
match store.get(&prover_uuid) {
189191
Some(vk) => {
190192
info!(
193+
slot = %proof.slot,
194+
block_hash = %proof.block_hash,
191195
prover_id = %prover_uuid,
192196
vk_size = vk.size(),
193197
proof_size = proof.proof_data.len(),
@@ -198,6 +202,8 @@ pub fn validate_proof(proof: &ExecutionProof) -> bool {
198202
match VERIFIER_STORE.get(&prover_uuid) {
199203
Some(verifier_entry) => {
200204
info!(
205+
slot = %proof.slot,
206+
block_hash = %proof.block_hash,
201207
prover_id = %prover_uuid,
202208
verifier = verifier_entry.name,
203209
"[Ethproofs] Found verifier, starting verification"
@@ -207,6 +213,8 @@ pub fn validate_proof(proof: &ExecutionProof) -> bool {
207213
match (verifier_entry.verify_fn)(&proof.proof_data, &vk.vk) {
208214
Ok(result) => {
209215
info!(
216+
slot = %proof.slot,
217+
block_hash = %proof.block_hash,
210218
prover_id = %prover_uuid,
211219
verification_result = result,
212220
"[Ethproofs] Verification completed"
@@ -215,6 +223,8 @@ pub fn validate_proof(proof: &ExecutionProof) -> bool {
215223
}
216224
Err(e) => {
217225
warn!(
226+
slot = %proof.slot,
227+
block_hash = %proof.block_hash,
218228
prover_id = %prover_uuid,
219229
error = %e,
220230
"[Ethproofs] Verification failed with error"
@@ -225,6 +235,8 @@ pub fn validate_proof(proof: &ExecutionProof) -> bool {
225235
}
226236
None => {
227237
warn!(
238+
slot = %proof.slot,
239+
block_hash = %proof.block_hash,
228240
prover_id = %prover_uuid,
229241
"[Ethproofs] No verifier registered for this prover, cannot verify proof"
230242
);
@@ -234,6 +246,8 @@ pub fn validate_proof(proof: &ExecutionProof) -> bool {
234246
}
235247
None => {
236248
warn!(
249+
slot = %proof.slot,
250+
block_hash = %proof.block_hash,
237251
prover_id = %prover_uuid,
238252
"[Ethproofs] No verification key found for this prover"
239253
);

0 commit comments

Comments
 (0)