Skip to content

feat: add getLeafValue procedure #2262

Merged
partylikeits1983 merged 35 commits intoagglayerfrom
ajl-agglayer-get-leaf-value
Jan 21, 2026
Merged

feat: add getLeafValue procedure #2262
partylikeits1983 merged 35 commits intoagglayerfrom
ajl-agglayer-get-leaf-value

Conversation

@partylikeits1983
Copy link
Contributor

@partylikeits1983 partylikeits1983 commented Jan 12, 2026

Resolves #2220
Builds on top of: #2238

This PR implements this solidity function in MASM:

function getLeafValue(
    uint8 leafType,
    uint32 originNetwork,
    address originAddress,
    uint32 destinationNetwork,
    address destinationAddress,
    uint256 amount,
    bytes32 metadataHash
) public pure returns (bytes32) {
    return
        keccak256(
            abi.encodePacked(
                leafType,
                originNetwork,
                originAddress,
                destinationNetwork,
                destinationAddress,
                amount,
                metadataHash
            )
        );
}

To quickly test that the masm implementation of get_leaf_value matches the agglayer Solidity implementation, you can expirement by running this basic solidity contract in Remix:

Link to Remix: Remix

Copy and paste this code into remix and run this testtest_keccak_hash_get_leaf_value:

cargo test test_keccak_hash_get_leaf_value --package miden-testing
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract KeccakU256 {
    function getLeafValue(
        uint8 leafType,
        uint32 originNetwork,
        address originAddress,
        uint32 destinationNetwork,
        address destinationAddress,
        uint256 amount,
        bytes32 metadataHash
    ) public pure returns (bytes32) {
        return keccak256(
            abi.encodePacked(
                leafType,
                originNetwork,
                originAddress,
                destinationNetwork,
                destinationAddress,
                amount,
                metadataHash
            )
        );
    }

    function hashFixedLeafHardhat() external pure returns (bytes32) {
        uint8 leafType = 0;
        uint32 originNetwork = 0;
        address tokenAddress = 0x1234567890123456789012345678901234567890;
        uint32 destinationNetwork = 1;
        address destinationAddress = 0x0987654321098765432109876543210987654321;
        uint256 amount = 1;
        bytes32 metadataHash =
            0x2cdc14cacf6fec86a549f0e4d01e83027d3b10f29fa527c1535192c1ca1aac81;

        return getLeafValue(
            leafType,
            originNetwork,
            tokenAddress,
            destinationNetwork,
            destinationAddress,
            amount,
            metadataHash
        );
    }
}

@partylikeits1983 partylikeits1983 changed the base branch from next to agglayer January 12, 2026 16:47
@partylikeits1983 partylikeits1983 added the no changelog This PR does not require an entry in the `CHANGELOG.md` file label Jan 12, 2026
@partylikeits1983 partylikeits1983 self-assigned this Jan 12, 2026
@partylikeits1983 partylikeits1983 added the agglayer PRs or issues related to AggLayer bridging integration label Jan 12, 2026
Co-authored-by: Marti <marti@miden.team>
@partylikeits1983 partylikeits1983 changed the base branch from agglayer to ajl-agglayer-asset-conversion January 13, 2026 16:10
@partylikeits1983 partylikeits1983 changed the base branch from ajl-agglayer-asset-conversion to ajl-solidity-type-conversions January 13, 2026 16:10
@partylikeits1983 partylikeits1983 marked this pull request as ready for review January 13, 2026 16:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@mmagician
Copy link
Collaborator

mmagician commented Jan 14, 2026

Also, for completeness we should be looking at V2 of the AggLayer contracts. For getLeafValue the logic doesn't change, but it does for its caller _verifyLeafBridge

@partylikeits1983
Copy link
Contributor Author

@mmagician Lets first merge #2238, then will rebase this PR against agglayer branch. Same with #2270

Base automatically changed from ajl-solidity-type-conversions to agglayer January 16, 2026 08:13
Base automatically changed from agglayer to next January 16, 2026 08:48
@partylikeits1983 partylikeits1983 changed the base branch from next to agglayer January 19, 2026 23:32
Copy link
Collaborator

@mmagician mmagician left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM bar the duplicated file ✅

@partylikeits1983 partylikeits1983 merged commit 193c618 into agglayer Jan 21, 2026
15 checks passed
@partylikeits1983 partylikeits1983 deleted the ajl-agglayer-get-leaf-value branch January 21, 2026 14:32
const LEAF_DATA_NUM_WORDS = 8
const LEAF_DATA_START_PTR = 0

#! Given the leaf data key returns the leaf value.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: might have been good to explain somewhere (briefly) that LFEAF_VALUE is just a sequential hash of LEAF_DATA using `Keccak hash function.

mmagician added a commit that referenced this pull request Jan 27, 2026
mmagician added a commit that referenced this pull request Jan 27, 2026
mmagician added a commit that referenced this pull request Jan 27, 2026
commit 193c618
Merge: 2dfa097 c1aec4d
Author: Alexander John Lee <77119221+partylikeits1983@users.noreply.github.com>
Date:   Wed Jan 21 09:32:04 2026 -0500

    Merge pull request #2262 from 0xMiden/ajl-agglayer-get-leaf-value

    feat: add `getLeafValue` procedure

commit c1aec4d
Merge: 1567d89 2dfa097
Author: riemann <aleqvids@gmail.com>
Date:   Wed Jan 21 09:00:06 2026 -0500

    Merge branch 'agglayer' into ajl-agglayer-get-leaf-value

commit 1567d89
Author: riemann <aleqvids@gmail.com>
Date:   Tue Jan 20 11:09:03 2026 -0500

    fix: rm redundant file

commit 8ebdc7b
Merge: f200752 1a3b8a3
Author: riemann <aleqvids@gmail.com>
Date:   Mon Jan 19 18:31:18 2026 -0500

    chore: merge agglayer

commit f200752
Author: Marti <marti@miden.team>
Date:   Thu Jan 15 11:27:09 2026 +0000

    fix: put data under correct key in advice map

commit 1388770
Author: Marti <marti@miden.team>
Date:   Thu Jan 15 11:26:40 2026 +0000

    fix: verify hash matches commitment

commit d51bed1
Author: riemann <aleqvids@gmail.com>
Date:   Wed Jan 14 14:44:10 2026 -0500

    feat: add hardcoded expected hash to test

commit d61f836
Author: riemann <aleqvids@gmail.com>
Date:   Wed Jan 14 14:38:11 2026 -0500

    refactor: deduplicate execute_program_with_default_host

commit f9f2d57
Merge: a926316 d6b9954
Author: Alexander John Lee <77119221+partylikeits1983@users.noreply.github.com>
Date:   Wed Jan 14 13:00:24 2026 -0500

    chore: pipe words to memory instead of manual `adv_loadw`

commit d6b9954
Author: riemann <aleqvids@gmail.com>
Date:   Wed Jan 14 12:52:09 2026 -0500

    refactor: add stack comments

commit af29827
Author: Marti <marti@miden.team>
Date:   Wed Jan 14 11:36:41 2026 +0000

    chore: pipe words to memory

commit a926316
Merge: 359b3ef 3c3c29e
Author: Marti <marti@miden.team>
Date:   Wed Jan 14 10:23:10 2026 +0000

    Merge branch 'ajl-solidity-type-conversions' into ajl-agglayer-get-leaf-value

commit 3c3c29e
Author: riemann <aleqvids@gmail.com>
Date:   Tue Jan 13 20:25:30 2026 -0500

    fix: update script roots

commit 393ee03
Merge: d9c309a f93dc34
Author: riemann <aleqvids@gmail.com>
Date:   Tue Jan 13 19:49:30 2026 -0500

    Merge branch 'agglayer' into ajl-solidity-type-conversions

commit d9c309a
Author: riemann <aleqvids@gmail.com>
Date:   Tue Jan 13 14:54:47 2026 -0500

    refactor: rename file to eth_address_format

commit 2288c0d
Author: riemann <aleqvids@gmail.com>
Date:   Tue Jan 13 14:51:32 2026 -0500

    refactor: rearrange EthAddressFormat

commit 1264d24
Author: riemann <aleqvids@gmail.com>
Date:   Tue Jan 13 14:42:40 2026 -0500

    refactor: rename to EthAddressFormat

commit 359b3ef
Author: riemann <aleqvids@gmail.com>
Date:   Tue Jan 13 14:17:43 2026 -0500

    refactor: update test name

commit a1a1c3d
Author: Alexander John Lee <77119221+partylikeits1983@users.noreply.github.com>
Date:   Tue Jan 13 10:01:44 2026 -0500

    Update crates/miden-agglayer/src/eth_address.rs

    Co-authored-by: Marti <marti@miden.team>

commit a8e35d3
Author: riemann <aleqvids@gmail.com>
Date:   Mon Jan 12 18:24:46 2026 -0500

    feat: implement AdviceMap key based getLeafValue procedure

commit 576f907
Author: riemann <aleqvids@gmail.com>
Date:   Mon Jan 12 11:43:31 2026 -0500

    feat: init getLeafValue() test

commit a5f3309
Merge: ee0765c 4c6289d
Author: riemann <aleqvids@gmail.com>
Date:   Mon Jan 12 10:21:09 2026 -0500

    Merge branch 'ajl-solidity-type-conversions' into ajl-agglayer-get-leaf-value

commit 4c6289d
Author: riemann <aleqvids@gmail.com>
Date:   Fri Jan 9 17:48:11 2026 -0500

    revert: undo drop addr4 in ethereum_address_to_account_id

commit 3dc29f6
Author: riemann <aleqvids@gmail.com>
Date:   Fri Jan 9 17:46:28 2026 -0500

    refactor: simplify from_account_id() & u32 check

commit 99161e3
Author: riemann <aleqvids@gmail.com>
Date:   Fri Jan 9 17:21:11 2026 -0500

    refactor: use u32assert2

commit 049e8be
Author: riemann <aleqvids@gmail.com>
Date:   Fri Jan 9 17:17:56 2026 -0500

    fix: lint doc check

commit 43cbcf3
Author: riemann <aleqvids@gmail.com>
Date:   Fri Jan 9 16:58:57 2026 -0500

    fix: clippy

commit 3d45e7f
Author: riemann <aleqvids@gmail.com>
Date:   Fri Jan 9 16:50:34 2026 -0500

    refactor: simplify ethereum_address_to_account_id proc

commit 2d0a89a
Author: riemann <aleqvids@gmail.com>
Date:   Fri Jan 9 16:31:33 2026 -0500

    refactor: improve EthAddress representation clarity and MASM alignment

commit 99bcee7
Author: Alexander John Lee <77119221+partylikeits1983@users.noreply.github.com>
Date:   Fri Jan 9 16:12:06 2026 -0500

    Update crates/miden-agglayer/src/utils.rs

    Co-authored-by: igamigo <ignacio.amigo@lambdaclass.com>

commit 5dd9c85
Author: riemann <aleqvids@gmail.com>
Date:   Fri Jan 9 14:36:20 2026 -0500

    refactor:  update logic & comments to little endian

commit a8238b6
Author: riemann <aleqvids@gmail.com>
Date:   Fri Jan 9 12:03:10 2026 -0500

    refactor: implement suggestions & refactor

commit 779ab24
Author: riemann <aleqvids@gmail.com>
Date:   Thu Jan 8 21:27:11 2026 -0500

    refactor: use crypto util functions

commit c71d9df
Author: riemann <aleqvids@gmail.com>
Date:   Thu Jan 8 19:58:20 2026 -0500

    refactor: rm unnecessary indirection

commit 3c84da6
Author: riemann <aleqvids@gmail.com>
Date:   Thu Jan 8 19:17:49 2026 -0500

    fix: formatting

commit 46143c8
Author: riemann <aleqvids@gmail.com>
Date:   Thu Jan 8 19:14:48 2026 -0500

    feat: add Solidity<>Miden address type conversion functions
mmagician added a commit that referenced this pull request Jan 27, 2026
Co-authored-by: Alexander John Lee <77119221+partylikeits1983@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agglayer PRs or issues related to AggLayer bridging integration no changelog This PR does not require an entry in the `CHANGELOG.md` file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement getLeafValue() in MASM

4 participants