From a9933174b3acb381c75383c1e5227975f3c7cbc5 Mon Sep 17 00:00:00 2001 From: VolodymyrBg Date: Mon, 4 Aug 2025 15:36:13 +0300 Subject: [PATCH 1/2] fix: return differentiated errors from InsertedGER::verify instead of bool --- .../src/bridge/inserted_ger.rs | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/crates/aggchain-proof-core/src/bridge/inserted_ger.rs b/crates/aggchain-proof-core/src/bridge/inserted_ger.rs index 879655cd..05bad217 100644 --- a/crates/aggchain-proof-core/src/bridge/inserted_ger.rs +++ b/crates/aggchain-proof-core/src/bridge/inserted_ger.rs @@ -2,6 +2,18 @@ use agglayer_primitives::Digest; use serde::{Deserialize, Serialize}; use unified_bridge::{L1InfoTreeLeaf, MerkleProof}; +/// Errors that can occur during GER verification +#[derive(Debug, thiserror::Error)] +pub enum GerVerificationError { + /// The provided L1 info root does not match the proof root + #[error("L1 info root mismatch: expected {expected:?}, got {got:?}")] + L1InfoRootMismatch { expected: Digest, got: Digest }, + + /// The Merkle proof verification failed + #[error("Merkle proof verification failed for leaf hash {leaf_hash:?} at index {index}")] + MerkleProofVerificationFailed { leaf_hash: Digest, index: u32 }, +} + /// Data to verify the legitimacy of one inserted GER. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct InsertedGER { @@ -17,16 +29,25 @@ pub struct InsertedGER { impl InsertedGER { /// Verify the inclusion proof against one L1 info root. - pub fn verify(&self, l1_info_root: Digest) -> bool { - // TODO: return differentiated errors + pub fn verify(&self, l1_info_root: Digest) -> Result<(), GerVerificationError> { if l1_info_root != self.proof.root { - return false; + return Err(GerVerificationError::L1InfoRootMismatch { + expected: self.proof.root, + got: l1_info_root, + }); + } + + let leaf_hash = self.l1_info_tree_leaf.hash(); + let index = self.l1_info_tree_leaf.l1_info_tree_index; + + if !self.proof.verify(leaf_hash, index) { + return Err(GerVerificationError::MerkleProofVerificationFailed { + leaf_hash, + index, + }); } - self.proof.verify( - self.l1_info_tree_leaf.hash(), - self.l1_info_tree_leaf.l1_info_tree_index, - ) + Ok(()) } /// Returns the inserted GER. From 7a4aae361d2b0465ea9d5c0a6523336dce219dab Mon Sep 17 00:00:00 2001 From: VolodymyrBg Date: Mon, 4 Aug 2025 15:40:51 +0300 Subject: [PATCH 2/2] Update mod.rs --- crates/aggchain-proof-core/src/bridge/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/aggchain-proof-core/src/bridge/mod.rs b/crates/aggchain-proof-core/src/bridge/mod.rs index a7946d3f..856f7ceb 100644 --- a/crates/aggchain-proof-core/src/bridge/mod.rs +++ b/crates/aggchain-proof-core/src/bridge/mod.rs @@ -384,7 +384,7 @@ impl BridgeConstraintsInput { .bridge_witness .inserted_gers .iter() - .find(|ger| !ger.verify(self.l1_info_root)); + .find(|ger| ger.verify(self.l1_info_root).is_err()); if let Some(wrong_ger) = maybe_wrong_inserted_ger { return Err(BridgeConstraintsError::InvalidMerklePathGERToL1Root {