Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions crates/aggchain-proof-core/src/bridge/inserted_ger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion crates/aggchain-proof-core/src/bridge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading