Skip to content

AggLayer: implement verify_leaf #2277

@mmagician

Description

@mmagician

To continue speccing the procedures for claim verification, we have verify_leaf_bridge that calls verify_leaf.
Its procedure signature should be as follows:

const PROOF_DATA_PTR = 0
const SMT_PROOF_LOCAL_EXIT_ROOT_PTR = 0 # local SMT proof is first
const GLOBAL_INDEX_PTR = PROOF_DATA_PTR + 2 * 256 # 512
const EXIT_ROOTS_PTR = GLOBAL_INDEX_PTR + 8 # 520
const MAINNET_EXIT_ROOT_PTR = GLOBAL_INDEX_PTR # it's the first exit root

# Operand stack: [PROOF_DATA_KEY, LEAF_VALUE[8]]
proc verify_leaf

    # 0. Load everything from the advice map into memory

    # 1. Compute GER from mainnet + rollup exit roots that are in the advice map (under PROOF_DATA_KEY)
    push.EXIT_ROOTS_PTR
    # => [exit_roots_ptr, LEAF_VALUE[8]]
    exec.crypto_utils::compute_ger
    # => [GER[8], LEAF_VALUE[8]]

    # 2. Assert the GER is valid
    exec.assert_valid_ger
    # => []

    # 3. Inspect `globalIndex` to see if we're dealing with a deposit from mainnet or from a rollup
    # probably use mem_stream to get the two words comprising global index:
    # => [GLOBAL_INDEX[8], LEAF_VALUE[8]]
    # For v0.1, let's only implement the mainnet branch:
    # => bit manipulation to assert mainnet, and to get leaf_index (it's a single Felt)
    # => [leaf_index]

    # the merkle proof and root are in memory, lets pass the right pointers to the verify_merkle_proof helper procedure
    push.SMT_PROOF_LOCAL_EXIT_ROOT_PTR
    push.MAINNET_EXIT_ROOT_PTR

    # internally, call the equivalent of `verifyMerkleProof(leafValue, smtProofLocalExitRoot, leafIndex, mainnetExitRoot)
    # Once we start implementing verify_merkle_proof, see if we should rearrange the stack?
    # => [mainnet_exit_root_ptr, smt_proof_local_exit_root_ptr, leaf_index, LEAF_VALUE[8]]
    movdn.10
    # => [smt_proof_local_exit_root_ptr, leaf_index, LEAF_VALUE[8], mainnet_exit_root_ptr]
    exec.crypto_utils::verify_merkle_proof
end

For 1., we can replicate calculateGlobalExitRoot which just applies a keccak hash to the two exit root values.

For 2. we check whether the bridge contract has this GER saved in storage. Currently the bridge only holds a single GER, soon an array.

Metadata

Metadata

Assignees

No one assigned

    Labels

    agglayerPRs or issues related to AggLayer bridging integration

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions