Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
46143c8
feat: add Solidity<>Miden address type conversion functions
partylikeits1983 Jan 9, 2026
3c84da6
fix: formatting
partylikeits1983 Jan 9, 2026
c71d9df
refactor: rm unnecessary indirection
partylikeits1983 Jan 9, 2026
779ab24
refactor: use crypto util functions
partylikeits1983 Jan 9, 2026
a8238b6
refactor: implement suggestions & refactor
partylikeits1983 Jan 9, 2026
5dd9c85
refactor: update logic & comments to little endian
partylikeits1983 Jan 9, 2026
99bcee7
Update crates/miden-agglayer/src/utils.rs
partylikeits1983 Jan 9, 2026
2d0a89a
refactor: improve EthAddress representation clarity and MASM alignment
partylikeits1983 Jan 9, 2026
3d45e7f
refactor: simplify ethereum_address_to_account_id proc
partylikeits1983 Jan 9, 2026
43cbcf3
fix: clippy
partylikeits1983 Jan 9, 2026
049e8be
fix: lint doc check
partylikeits1983 Jan 9, 2026
99161e3
refactor: use u32assert2
partylikeits1983 Jan 9, 2026
3dc29f6
refactor: simplify from_account_id() & u32 check
partylikeits1983 Jan 9, 2026
4c6289d
revert: undo drop addr4 in ethereum_address_to_account_id
partylikeits1983 Jan 9, 2026
a5f3309
Merge branch 'ajl-solidity-type-conversions' into ajl-agglayer-get-le…
partylikeits1983 Jan 12, 2026
576f907
feat: init getLeafValue() test
partylikeits1983 Jan 12, 2026
a8e35d3
feat: implement AdviceMap key based getLeafValue procedure
partylikeits1983 Jan 12, 2026
a1a1c3d
Update crates/miden-agglayer/src/eth_address.rs
partylikeits1983 Jan 13, 2026
359b3ef
refactor: update test name
partylikeits1983 Jan 13, 2026
1264d24
refactor: rename to EthAddressFormat
partylikeits1983 Jan 13, 2026
2288c0d
refactor: rearrange EthAddressFormat
partylikeits1983 Jan 13, 2026
d9c309a
refactor: rename file to eth_address_format
partylikeits1983 Jan 13, 2026
393ee03
Merge branch 'agglayer' into ajl-solidity-type-conversions
partylikeits1983 Jan 14, 2026
3c3c29e
fix: update script roots
partylikeits1983 Jan 14, 2026
a926316
Merge branch 'ajl-solidity-type-conversions' into ajl-agglayer-get-le…
mmagician Jan 14, 2026
af29827
chore: pipe words to memory
mmagician Jan 14, 2026
d6b9954
refactor: add stack comments
partylikeits1983 Jan 14, 2026
f9f2d57
chore: pipe words to memory instead of manual `adv_loadw`
partylikeits1983 Jan 14, 2026
d61f836
refactor: deduplicate execute_program_with_default_host
partylikeits1983 Jan 14, 2026
d51bed1
feat: add hardcoded expected hash to test
partylikeits1983 Jan 14, 2026
1388770
fix: verify hash matches commitment
mmagician Jan 15, 2026
f200752
fix: put data under correct key in advice map
mmagician Jan 15, 2026
8ebdc7b
chore: merge agglayer
partylikeits1983 Jan 19, 2026
1567d89
fix: rm redundant file
partylikeits1983 Jan 20, 2026
c1aec4d
Merge branch 'agglayer' into ajl-agglayer-get-leaf-value
partylikeits1983 Jan 21, 2026
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/miden-agglayer/asm/bridge/bridge_in.masm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ end
#! Invocation: call
pub proc check_claim_proof
exec.get_rollup_exit_root
# => [GER_ROOT[8], CLAIM_NOTE_RPO_COMMITMENT]
# => [GER_ROOT[8], PROOF_DATA_KEY, LEAF_DATA_KEY]

# Check CLAIM note proof data against current GER
exec.crypto_utils::verify_claim_proof
Expand Down
78 changes: 56 additions & 22 deletions crates/miden-agglayer/asm/bridge/crypto_utils.masm
Original file line number Diff line number Diff line change
@@ -1,32 +1,66 @@
use miden::core::crypto::hashes::keccak256

#! Given the leaf data returns the leaf value.
const LEAF_DATA_BYTES = 113

#! Given the leaf data key returns the leaf value.
#!
#! Inputs: [leaf_type, origin_network, ORIGIN_ADDRESS, destination_network, DESTINATION_ADDRESS, amount, METADATA_HASH]
#! Inputs:
#! Operand stack: [LEAF_DATA_KEY]
#! Advice map: {
#! LEAF_DATA_KEY => [
#! originNetwork[1], // Origin network identifier (1 felt, uint32)
#! originTokenAddress[5], // Origin token address (5 felts, address as 5 u32 felts)
#! destinationNetwork[1], // Destination network identifier (1 felt, uint32)
#! destinationAddress[5], // Destination address (5 felts, address as 5 u32 felts)
#! amount[8], // Amount of tokens (8 felts, uint256 as 8 u32 felts)
#! metadata[8], // ABI encoded metadata (8 felts, fixed size)
#! EMPTY_WORD // padding
#! ],
#! }
#! Outputs: [LEAF_VALUE]
#!
#! Where:
#! - leaf_type is the leaf type: [0] transfer Ether / ERC20 tokens, [1] message.
#! - origin_network is the origin network identifier.
#! - ORIGIN_ADDRESS is the origin token address (5 elements)
#! - destination_network is the destination network identifier.
#! - DESTINATION_ADDRESS is the destination address (5 elements).
#! - amount is the amount: [0] Amount of tokens/ether, [1] Amount of ether.
#! - METADATA_HASH is the hash of the metadata (8 elements).
#! - LEAF_VALUE is the computed leaf value (8 elements).
#!
#! This function computes the keccak256 hash of the abi.encodePacked data.
#!
#! Invocation: exec
pub proc get_leaf_value
# TODO: implement getLeafValue()
# https://github.com/agglayer/agglayer-contracts/blob/e468f9b0967334403069aa650d9f1164b1731ebb/contracts/v2/lib/DepositContractV2.sol#L22

# stubbed out:
push.1.1.1.1
push.1.1.1.1

# exec.keccak256::hash_bytes
adv.push_mapval
# => [len, LEAF_DATA_KEY]

dropw
# => []

# @dev what should the starting mem ptr be?
# writing AdviceStack into memory starting at mem address 0
push.0
repeat.7
# => [loc_ptr]

padw
# => [EMPTY_WORD, loc_ptr]

adv_loadw
# => [VALS, loc_ptr]

movup.4 dup movdn.5
# => [loc_ptr, VALS, loc_ptr]

mem_storew_be dropw
# => [loc_ptr]

add.4
# => [loc_ptr+4]
end
# => [loc_ptr]

adv_push.1 swap
# => [loc_ptr, data]

mem_store
# => []

push.LEAF_DATA_BYTES.0
# => [mem_ptr, len_bytes]

exec.keccak256::hash_bytes
# => [LEAF_VALUE[8]]
end

Expand All @@ -36,7 +70,7 @@ end
#! and that the leaf has not been previously claimed.
#!
#! Inputs:
#! Operand stack: [GER_ROOT[8], CLAIM_PROOF_RPO_COMMITMENT, pad(12)]
#! Operand stack: [GER_ROOT[8], PROOF_DATA_KEY, LEAF_DATA_KEY, pad(12)]
#! Advice map: {
#! PROOF_DATA_KEY => [
#! smtProofLocalExitRoot[256], // SMT proof for local exit root (256 felts, bytes32[_DEPOSIT_CONTRACT_TREE_DEPTH])
Expand Down
88 changes: 88 additions & 0 deletions crates/miden-agglayer/asm/bridge/eth_address.masm
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
use miden::core::crypto::hashes::keccak256
use miden::core::word

# CONSTANTS
# =================================================================================================

const U32_MAX=4294967295
const TWO_POW_32=4294967296

const ERR_NOT_U32="address limb is not u32"
const ERR_ADDR4_NONZERO="most-significant 4 bytes (addr4) must be zero"
const ERR_FELT_OUT_OF_FIELD="combined u64 doesn't fit in field"


# ETHEREUM ADDRESS PROCEDURES
# =================================================================================================

#! Builds a single felt from two u32 limbs (little-endian limb order).
#! Conceptually, this is packing a 64-bit word (lo + (hi << 32)) into a field element.
#! This proc additionally verifies that the packed value did *not* reduce mod p by round-tripping
#! through u32split and comparing the limbs.
#!
#! Inputs: [lo, hi]
#! Outputs: [felt]
proc build_felt
# --- validate u32 limbs ---
u32assert2.err=ERR_NOT_U32
# => [lo, hi]

# keep copies for the overflow check
dup.1 dup.1
# => [lo, hi, lo, hi]

# felt = (hi * 2^32) + lo
swap
push.TWO_POW_32 mul
add
# => [felt, lo, hi]

# ensure no reduction mod p happened:
# split felt back into (hi, lo) and compare to inputs
dup u32split
# => [hi2, lo2, felt, lo, hi]

movup.4 assert_eq.err=ERR_FELT_OUT_OF_FIELD
# => [lo2, felt, lo]

movup.2 assert_eq.err=ERR_FELT_OUT_OF_FIELD
# => [felt]
end

#! Converts an Ethereum address (address[5] type) back into an AccountId [prefix, suffix] type.
#!
#! The Ethereum address is represented as 5 u32 limbs (20 bytes total) in *little-endian limb order*:
#! addr0 = bytes[16..19] (least-significant 4 bytes)
#! addr1 = bytes[12..15]
#! addr2 = bytes[ 8..11]
#! addr3 = bytes[ 4.. 7]
#! addr4 = bytes[ 0.. 3] (most-significant 4 bytes)
#!
#! The most-significant 4 bytes must be zero for a valid AccountId conversion (addr4 == 0).
#! The remaining 16 bytes are treated as two 8-byte words (conceptual u64 values):
#! prefix = (addr3 << 32) | addr2 # bytes[4..11]
#! suffix = (addr1 << 32) | addr0 # bytes[12..19]
#!
#! These 8-byte words are represented as field elements by packing two u32 limbs into a felt.
#! The packing is done via build_felt, which validates limbs are u32 and checks the packed value
#! did not reduce mod p (i.e. the word fits in the field).
#!
#! Inputs: [addr0, addr1, addr2, addr3, addr4]
#! Outputs: [prefix, suffix]
#!
#! Invocation: exec
pub proc ethereum_address_to_account_id
# addr4 must be 0 (most-significant limb)
movup.4
eq.0 assert.err=ERR_ADDR4_NONZERO
# => [addr0, addr1, addr2, addr3]

exec.build_felt
# => [suffix, addr2, addr3]

movdn.2
# => [addr2, addr3, suffix]

exec.build_felt
# => [prefix, suffix]
end
9 changes: 9 additions & 0 deletions crates/miden-agglayer/src/errors/agglayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ use miden_protocol::errors::MasmError;
// AGGLAYER ERRORS
// ================================================================================================

/// Error Message: "most-significant 4 bytes (addr4) must be zero"
pub const ERR_ADDR4_NONZERO: MasmError = MasmError::from_static_str("most-significant 4 bytes (addr4) must be zero");

/// Error Message: "B2AGG script requires exactly 1 note asset"
pub const ERR_B2AGG_WRONG_NUMBER_OF_ASSETS: MasmError = MasmError::from_static_str("B2AGG script requires exactly 1 note asset");
/// Error Message: "B2AGG script expects exactly 6 note inputs"
Expand All @@ -17,8 +20,14 @@ pub const ERR_B2AGG_WRONG_NUMBER_OF_INPUTS: MasmError = MasmError::from_static_s
/// Error Message: "CLAIM's target account address and transaction address do not match"
pub const ERR_CLAIM_TARGET_ACCT_MISMATCH: MasmError = MasmError::from_static_str("CLAIM's target account address and transaction address do not match");

/// Error Message: "combined u64 doesn't fit in field"
pub const ERR_FELT_OUT_OF_FIELD: MasmError = MasmError::from_static_str("combined u64 doesn't fit in field");

/// Error Message: "invalid claim proof"
pub const ERR_INVALID_CLAIM_PROOF: MasmError = MasmError::from_static_str("invalid claim proof");

/// Error Message: "address limb is not u32"
pub const ERR_NOT_U32: MasmError = MasmError::from_static_str("address limb is not u32");

/// Error Message: "maximum scaling factor is 18"
pub const ERR_SCALE_AMOUNT_EXCEEDED_LIMIT: MasmError = MasmError::from_static_str("maximum scaling factor is 18");
Loading