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
31 changes: 13 additions & 18 deletions crates/miden-agglayer/asm/bridge/agglayer_faucet.masm
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const P2ID_OUTPUT_NOTE_AMOUNT_MEM_PTR = 611

const ERR_INVALID_CLAIM_PROOF = "invalid claim proof"

#! Inputs: [PROOF_DATA_KEY, LEAF_DATA_KEY]
#! Inputs: [LEAF_DATA_KEY, PROOF_DATA_KEY]
#! Outputs: []
#!
#! Panics if:
Expand All @@ -57,28 +57,23 @@ const ERR_INVALID_CLAIM_PROOF = "invalid claim proof"
#!
#! Invocation: exec
proc validate_claim
# Get bridge_in::check_claim_proof procedure MAST root
procref.bridge_in::check_claim_proof
# => [BRIDGE_PROC_MAST_ROOT]
# get bridge_in::verify_leaf_bridge procedure MAST root
procref.bridge_in::verify_leaf_bridge
# => [BRIDGE_PROC_MAST_ROOT, LEAF_DATA_KEY, PROOF_DATA_KEY]

push.BRIDGE_ID_SLOT[0..2]
# => [bridge_id_idx, BRIDGE_PROC_MAST_ROOT]
# => [bridge_id_idx, BRIDGE_PROC_MAST_ROOT, LEAF_DATA_KEY, PROOF_DATA_KEY]

# Get Bridge AccountId
# get bridge account ID
exec.active_account::get_item
# => [bridge_account_id_prefix, bridge_account_id_suffix, 0, 0, BRIDGE_PROC_MAST_ROOT]
# => [bridge_account_id_prefix, bridge_account_id_suffix, 0, 0, BRIDGE_PROC_MAST_ROOT, LEAF_DATA_KEY, PROOF_DATA_KEY]

movup.2 drop movup.2 drop
# => [bridge_account_id_prefix, bridge_account_id_suffix, BRIDGE_PROC_MAST_ROOT]
# => [bridge_account_id_prefix, bridge_account_id_suffix, BRIDGE_PROC_MAST_ROOT, LEAF_DATA_KEY, PROOF_DATA_KEY]

# Call check_claim_proof procedure on Bridge
# Calling: bridge_in::check_claim_proof
# call bridge_in::verify_leaf_bridge
exec.tx::execute_foreign_procedure
# => [validation_result]

# Assert valid proof data
assert.err=ERR_INVALID_CLAIM_PROOF drop
# => []
# => []
end

# Inputs: []
Expand Down Expand Up @@ -228,9 +223,9 @@ pub proc claim
# => []

# VALIDATE CLAIM
mem_loadw_be.LEAF_DATA_KEY_MEM_ADDR padw
mem_loadw_be.PROOF_DATA_KEY_MEM_ADDR
# => [PROOF_DATA_KEY, LEAF_DATA_KEY]
mem_loadw_be.PROOF_DATA_KEY_MEM_ADDR swapw
mem_loadw_be.LEAF_DATA_KEY_MEM_ADDR
# => [LEAF_DATA_KEY, PROOF_DATA_KEY]

# Errors on invalid proof
exec.validate_claim
Expand Down
32 changes: 23 additions & 9 deletions crates/miden-agglayer/asm/bridge/bridge_in.masm
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ pub proc get_rollup_exit_root
push.0.0.0.0.0.0.0.0 # dummy GER
end

#! Checks the validity of the GET proof
#! Computes the leaf value and verifies it against the AggLayer bridge.
#!
#! Inputs:
#! Operand stack: [PROOF_DATA_KEY, LEAF_DATA_KEY, pad(8)]
#! Operand stack: [LEAF_DATA_KEY, PROOF_DATA_KEY, pad(8)]
#! Advice map: {
#! PROOF_DATA_KEY => [
#! smtProofLocalExitRoot[256], // SMT proof for local exit root (256 felts, bytes32[_DEPOSIT_CONTRACT_TREE_DEPTH])
Expand All @@ -30,14 +30,28 @@ end
#! ],
#! }
#!
#! Outputs: [pad(16)]
#!
#! Invocation: call
pub proc check_claim_proof
exec.get_rollup_exit_root
# => [GER_ROOT[8], CLAIM_NOTE_RPO_COMMITMENT]
pub proc verify_leaf_bridge
# get the leaf value. We have all the necessary leaf data in the advice map
exec.crypto_utils::get_leaf_value
# => [LEAF_VALUE[8], PROOF_DATA_KEY, pad(8)]

movupw.3 dropw
# => [LEAF_VALUE[8], PROOF_DATA_KEY, pad(4)]

# Check CLAIM note proof data against current GER
exec.crypto_utils::verify_claim_proof
# => [is_valid_claim_proof]
# delegate proof verification (stubbed for now)
exec.verify_leaf
end

swap drop
#! Verify leaf and checks that it has not been claimed.
#!
#! Inputs:
#! Operand stack: [LEAF_VALUE[8], PROOF_DATA_KEY, pad(4)]
#! Invocation: exec
proc verify_leaf
# TODO: Awaiting https://github.com/0xMiden/miden-base/issues/2277
dropw dropw dropw
# => [pad(16)]
end
Loading