Skip to content

Commit 8063220

Browse files
committed
feat: add leafType param
1 parent 2cbfeb1 commit 8063220

5 files changed

Lines changed: 37 additions & 17 deletions

File tree

crates/miden-agglayer/asm/bridge/agglayer_faucet.masm

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use miden::core::mem
1515
const BRIDGE_ID_SLOT = word("miden::agglayer::faucet")
1616

1717
const PROOF_DATA_WORD_LEN = 134
18-
const LEAF_DATA_WORD_LEN = 6
18+
const LEAF_DATA_WORD_LEN = 8
1919
const OUTPUT_NOTE_DATA_WORD_LEN = 2
2020

2121
const PROOF_DATA_START_PTR = 0
@@ -31,8 +31,10 @@ const CLAIM_NOTE_DATA_MEM_ADDR = 712
3131
const OUTPUT_NOTE_INPUTS_MEM_ADDR = 0
3232
const OUTPUT_NOTE_TAG_MEM_ADDR = 574
3333
const OUTPUT_NOTE_SERIAL_NUM_MEM_ADDR = 568
34-
const OUTPUT_NOTE_ASSET_AMOUNT_MEM_ADDR_0 = 548
35-
const OUTPUT_NOTE_ASSET_AMOUNT_MEM_ADDR_1 = 552
34+
const OUTPUT_NOTE_ASSET_AMOUNT_MEM_ADDR_0 = 552
35+
const OUTPUT_NOTE_ASSET_AMOUNT_MEM_ADDR_1 = 556
36+
const OUTPUT_NOTE_DESTINATION_ACCOUNT_ID_PREFIX_MEM_ADDR = 547
37+
const OUTPUT_NOTE_DESTINATION_ACCOUNT_ID_SUFFIX_MEM_ADDR = 548
3638

3739
# P2ID output note constants
3840
const P2ID_SCRIPT_ROOT = [13362761878458161062, 15090726097241769395, 444910447169617901, 3558201871398422326]
@@ -97,7 +99,7 @@ end
9799
# Inputs: []
98100
# Outputs: [prefix, suffix]
99101
proc get_destination_account_id
100-
mem_load.543 mem_load.544
102+
mem_load.OUTPUT_NOTE_DESTINATION_ACCOUNT_ID_PREFIX_MEM_ADDR mem_load.OUTPUT_NOTE_DESTINATION_ACCOUNT_ID_SUFFIX_MEM_ADDR
101103
end
102104

103105
# Inputs: [PROOF_DATA_KEY, LEAF_DATA_KEY, OUTPUT_NOTE_DATA_KEY]
@@ -208,7 +210,6 @@ end
208210
#! destinationAddress[5], // Destination address (5 felts, address as 5 u32 felts)
209211
#! amount[8], // Amount of tokens (8 felts, uint256 as 8 u32 felts)
210212
#! metadata[8], // ABI encoded metadata (8 felts, fixed size)
211-
#! EMPTY_WORD // padding
212213
#! ],
213214
#! OUTPUT_NOTE_DATA_KEY => [
214215
#! output_p2id_serial_num[4], // P2ID note serial number (4 felts, Word)

crates/miden-agglayer/asm/bridge/bridge_in.masm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ end
2020
#! rollupExitRoot[8], // Rollup exit root hash (8 felts, bytes32 as 8 u32 felts)
2121
#! ],
2222
#! LEAF_DATA_KEY => [
23+
#! leafType[1], // Leaf type (1 felt, uint32)
2324
#! originNetwork[1], // Origin network identifier (1 felt, uint32)
2425
#! originTokenAddress[5], // Origin token address (5 felts, address as 5 u32 felts)
2526
#! destinationNetwork[1], // Destination network identifier (1 felt, uint32)

crates/miden-agglayer/asm/note_scripts/CLAIM.masm

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use miden::core::mem
1111
# =================================================================================================
1212

1313
const PROOF_DATA_SIZE = 536
14-
const LEAF_DATA_SIZE = 24
14+
const LEAF_DATA_SIZE = 32
1515
const OUTPUT_NOTE_SIZE = 8
1616

1717
const PROOF_DATA_START_PTR = 0
@@ -68,20 +68,22 @@ end
6868
#! ]
6969
#!
7070
#! LEAF_DATA_KEY => [
71+
#! leafType[1], // Leaf type (1 felt, uint32)
72+
#! padding[3], // padding (3 felts)
7173
#! originNetwork[1], // Origin network identifier (1 felt, uint32)
7274
#! originTokenAddress[5], // Origin token address (5 felts, address as 5 u32 felts)
7375
#! destinationNetwork[1], // Destination network identifier (1 felt, uint32)
7476
#! destinationAddress[5], // Destination address (5 felts, address as 5 u32 felts)
7577
#! amount[8], // Amount of tokens (8 felts, uint256 as 8 u32 felts)
7678
#! metadata[8], // ABI encoded metadata (8 felts, fixed size)
77-
#! EMPTY_WORD // padding
7879
#! ]
7980
#!
8081
#! TODO: Will be removed in future PR
8182
#! OUTPUT_NOTE_DATA_KEY => [
8283
#! output_p2id_serial_num[4], // P2ID note serial number (4 felts, Word)
8384
#! target_faucet_account_id[2], // Target faucet account ID (2 felts, prefix and suffix)
8485
#! output_note_tag[1], // P2ID output note tag
86+
#! padding[1], // padding (1 felt)
8587
#! ]
8688
#!
8789
#! Invocation: exec
@@ -151,16 +153,18 @@ end
151153
#! - globalIndex [512..519]: 8 felts
152154
#! - mainnetExitRoot [520..527]: 8 felts
153155
#! - rollupExitRoot [528..535]: 8 felts
154-
#! - originNetwork [536] : 1 felt
155-
#! - originTokenAddress [537..541]: 5 felts
156-
#! - destinationNetwork [542] : 1 felt
157-
#! - destinationAddress [543..547]: 5 felts
158-
#! - amount [548..555]: 8 felts
159-
#! - metadata [556..563]: 8 felts
160-
#! - EMPTY_WORD [564..567]: 4 felts
156+
#! - leafType [536] : 1 felt
157+
#! - padding [537..539]: 3 felts
158+
#! - originNetwork [540] : 1 felt
159+
#! - originTokenAddress [541..545]: 5 felts
160+
#! - destinationNetwork [546] : 1 felt
161+
#! - destinationAddress [547..551]: 5 felts
162+
#! - amount [552..559]: 8 felts
163+
#! - metadata [560..567]: 8 felts
161164
#! - output_p2id_serial_num [568..571]: 4 felts
162165
#! - target_faucet_account_id [572..573]: 2 felts
163166
#! - output_note_tag [574] : 1 felt
167+
#! - padding [575] : 1 felt
164168
#!
165169
#! Where:
166170
#! - smtProofLocalExitRoot: SMT proof for local exit root (bytes32[_DEPOSIT_CONTRACT_TREE_DEPTH])
@@ -172,17 +176,19 @@ end
172176
#! - Top 191 bits are ignored (not required to be zero), so indexers must decode it exactly like the contract does
173177
#! - mainnetExitRoot: Mainnet exit root hash (bytes32 as 8 u32 felts)
174178
#! - rollupExitRoot: Rollup exit root hash (bytes32 as 8 u32 felts)
179+
#! - leafType: Leaf type (uint32): [0] transfer Ether / ERC20 tokens, [1] message
175180
#! - originNetwork: Origin network identifier (uint32)
176181
#! - originTokenAddress: Origin token address (address as 5 u32 felts)
177182
#! - destinationNetwork: Destination network identifier (uint32)
178183
#! - destinationAddress: Destination address (address as 5 u32 felts)
179184
#! - amount: Amount of tokens (uint256 as 8 u32 felts)
180185
#! - metadata: ABI encoded metadata (fixed size)
181-
#! - EMPTY_WORD: Padding word
186+
#! - padding (3 felts)
182187
#! - output_p2id_serial_num: P2ID note serial number (Word)
183188
#! - target_faucet_account_id: Target agglayer faucet account ID (prefix and suffix). Only this specific
184189
#! account can consume the note - any other account will cause a panic.
185190
#! - output_note_tag: P2ID output note tag
191+
#! - padding (1 felt)
186192
#!
187193
#! Panics if:
188194
#! - account does not expose claim procedure.

crates/miden-agglayer/src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ pub struct ClaimNoteParams<'a, R: FeltRng> {
351351
pub mainnet_exit_root: &'a [u8; 32],
352352
/// Rollup exit root hash (bytes32 as 32-byte array)
353353
pub rollup_exit_root: &'a [u8; 32],
354+
/// Leaf type (uint32): [0] transfer Ether / ERC20 tokens, [1] message
355+
pub leaf_type: Felt,
354356
/// Origin network identifier (uint32)
355357
pub origin_network: Felt,
356358
/// Origin token address (address as 20-byte array)
@@ -420,6 +422,12 @@ pub fn create_claim_note<R: FeltRng>(params: ClaimNoteParams<'_, R>) -> Result<N
420422
claim_inputs.extend(rollup_exit_root_felts);
421423

422424
// 2) LEAF DATA
425+
// leafType (uint32 as Felt)
426+
claim_inputs.push(params.leaf_type);
427+
428+
// padding (3 felts)
429+
claim_inputs.extend(vec![Felt::ZERO; 3]);
430+
423431
// originNetwork (uint32 as Felt)
424432
claim_inputs.push(params.origin_network);
425433

@@ -450,8 +458,6 @@ pub fn create_claim_note<R: FeltRng>(params: ClaimNoteParams<'_, R>) -> Result<N
450458
// metadata (fixed size of 8 felts)
451459
claim_inputs.extend(params.metadata);
452460

453-
let padding = vec![Felt::ZERO; 4];
454-
claim_inputs.extend(padding);
455461

456462
// 3) CLAIM NOTE DATA
457463
// TODO: deterministically compute serial number of p2id hash(GER, leaf index)
@@ -464,6 +470,7 @@ pub fn create_claim_note<R: FeltRng>(params: ClaimNoteParams<'_, R>) -> Result<N
464470

465471
// output note tag
466472
claim_inputs.push(params.output_note_tag.as_u32().into());
473+
claim_inputs.push(Felt::ZERO);
467474

468475
let inputs = NoteInputs::new(claim_inputs)?;
469476

@@ -507,6 +514,7 @@ pub type ClaimNoteTestInputs = (
507514
[u8; 32],
508515
[u8; 32],
509516
Felt,
517+
Felt,
510518
[u8; 20],
511519
Felt,
512520
[u8; 20],
@@ -568,6 +576,7 @@ pub fn claim_note_test_inputs(
568576
];
569577

570578
let origin_network = Felt::new(1);
579+
let leaf_type = Felt::new(0);
571580

572581
let origin_token_address: [u8; 20] = [
573582
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
@@ -599,6 +608,7 @@ pub fn claim_note_test_inputs(
599608
global_index,
600609
mainnet_exit_root,
601610
rollup_exit_root,
611+
leaf_type,
602612
origin_network,
603613
origin_token_address,
604614
destination_network,

crates/miden-testing/tests/agglayer/bridge_in.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ async fn test_bridge_in_claim_to_p2id() -> anyhow::Result<()> {
7878
global_index,
7979
mainnet_exit_root,
8080
rollup_exit_root,
81+
leaf_type,
8182
origin_network,
8283
origin_token_address,
8384
destination_network,
@@ -95,6 +96,7 @@ async fn test_bridge_in_claim_to_p2id() -> anyhow::Result<()> {
9596
global_index,
9697
mainnet_exit_root: &mainnet_exit_root,
9798
rollup_exit_root: &rollup_exit_root,
99+
leaf_type,
98100
origin_network,
99101
origin_token_address: &origin_token_address,
100102
destination_network,

0 commit comments

Comments
 (0)