Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f4fcd16
feat: add native asset claim amount as element in NoteStorage of CLAI…
partylikeits1983 Feb 18, 2026
ae80508
chore: merge agglayer
partylikeits1983 Feb 18, 2026
dcb4642
feat: add output note assertion checks
partylikeits1983 Feb 19, 2026
431fdc7
refactor: rm debug statement
partylikeits1983 Feb 19, 2026
1509773
Update crates/miden-testing/tests/agglayer/bridge_in.rs
partylikeits1983 Feb 19, 2026
f3bed9f
refactor: cleanup test & rm leftover comments
partylikeits1983 Feb 19, 2026
3fa4539
wip: consume P2ID by destination AccountId
partylikeits1983 Feb 20, 2026
1f96b6b
feat: add solidity-compat test for generating local claimAsset() para…
partylikeits1983 Feb 20, 2026
7fa4f81
feat: add solidity-compat test for generating local claimAsset() para…
partylikeits1983 Feb 20, 2026
50cb54b
feat: consume output P2ID note from CLAIM note
partylikeits1983 Feb 20, 2026
b4ee5ba
chore: merge latest ajl-claim-asset-local-data-solidity
partylikeits1983 Feb 20, 2026
ab00d11
fix: taplo fmt
partylikeits1983 Feb 20, 2026
07f74a0
refactor: rename solidity compat test files & claimAsset vector JSON …
partylikeits1983 Feb 20, 2026
cca8cdf
refactor: rename testing methods & update test comments
partylikeits1983 Feb 20, 2026
39b1bce
chore: merge latest ajl-claim-asset-local-data-solidity & refactor CL…
partylikeits1983 Feb 20, 2026
01266fa
Update crates/miden-testing/tests/agglayer/bridge_in.rs
partylikeits1983 Feb 20, 2026
489f10d
Update crates/miden-testing/tests/agglayer/bridge_in.rs
partylikeits1983 Feb 20, 2026
06b59e0
chore: merge latest ajl-claim-asset-local-data-solidity
partylikeits1983 Feb 20, 2026
1f049b6
chore: merge latest agglayer
partylikeits1983 Feb 23, 2026
70e3392
refactor: add warnings in comments & update TODO regarding u256 scaling
partylikeits1983 Feb 23, 2026
af2a066
chore: merge latest agglayer
partylikeits1983 Feb 23, 2026
e49f49a
refactor: assert mock destination account ID matches claim data
partylikeits1983 Feb 23, 2026
3be6bfd
fix: load amount BE-felt from mem
mmagician Feb 23, 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
45 changes: 32 additions & 13 deletions crates/miden-agglayer/asm/bridge/agglayer_faucet.masm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const CLAIM_NOTE_DATA_MEM_ADDR = 712

const OUTPUT_NOTE_STORAGE_MEM_ADDR = 0
const OUTPUT_NOTE_TAG_MEM_ADDR = 574
const OUTPUT_NOTE_FAUCET_AMOUNT = 575
const OUTPUT_NOTE_SERIAL_NUM_MEM_ADDR = 568
const OUTPUT_NOTE_ASSET_AMOUNT_MEM_ADDR_0 = 549
const OUTPUT_NOTE_ASSET_AMOUNT_MEM_ADDR_1 = 550
Expand All @@ -57,8 +58,8 @@ const DESTINATION_ADDRESS_3 = 547
const DESTINATION_ADDRESS_4 = 548

# Memory locals in claim
const CLAIM_PREFIX_MEM_LOC = 5
const CLAIM_SUFFIX_MEM_LOC = 6
const CLAIM_PREFIX_MEM_LOC = 8
const CLAIM_SUFFIX_MEM_LOC = 9
const CLAIM_AMOUNT_MEM_LOC_0 = 0
const CLAIM_AMOUNT_MEM_LOC_1 = 4

Expand Down Expand Up @@ -94,6 +95,7 @@ pub proc get_origin_token_address
push.CONVERSION_INFO_1_SLOT[0..2]
exec.active_account::get_item
# => [addr3, addr2, addr1, addr0]

exec.word::reverse
# => [addr0, addr1, addr2, addr3]

Expand Down Expand Up @@ -224,14 +226,14 @@ end
# Inputs: []
# Outputs: [U256[0], U256[1]]
proc get_raw_claim_amount
mem_load.OUTPUT_NOTE_ASSET_AMOUNT_MEM_ADDR_0
mem_load.OUTPUT_NOTE_ASSET_AMOUNT_MEM_ADDR_1
mem_load.OUTPUT_NOTE_ASSET_AMOUNT_MEM_ADDR_2
mem_load.OUTPUT_NOTE_ASSET_AMOUNT_MEM_ADDR_3
mem_load.OUTPUT_NOTE_ASSET_AMOUNT_MEM_ADDR_4
mem_load.OUTPUT_NOTE_ASSET_AMOUNT_MEM_ADDR_5
mem_load.OUTPUT_NOTE_ASSET_AMOUNT_MEM_ADDR_6
mem_load.OUTPUT_NOTE_ASSET_AMOUNT_MEM_ADDR_7
mem_load.OUTPUT_NOTE_ASSET_AMOUNT_MEM_ADDR_6
mem_load.OUTPUT_NOTE_ASSET_AMOUNT_MEM_ADDR_5
mem_load.OUTPUT_NOTE_ASSET_AMOUNT_MEM_ADDR_4
mem_load.OUTPUT_NOTE_ASSET_AMOUNT_MEM_ADDR_3
mem_load.OUTPUT_NOTE_ASSET_AMOUNT_MEM_ADDR_2
mem_load.OUTPUT_NOTE_ASSET_AMOUNT_MEM_ADDR_1
mem_load.OUTPUT_NOTE_ASSET_AMOUNT_MEM_ADDR_0
end

# Inputs: [U256[0], U256[1]]
Expand Down Expand Up @@ -298,6 +300,12 @@ end
#! Inputs: [prefix, suffix, AMOUNT[0], AMOUNT[1]]
#! Outputs: []
#!
#! WARNING: This procedure currently assumes the claim amount fits within 128 bits (i.e. AMOUNT[1]
#! is all zeros). This assumption holds for all practical token amounts but is not explicitly
#! enforced here. See the TODO below.
#!
#! TODO: Add an explicit assertion that AMOUNT[1] is zero.
#!
#! Note: This procedure will be refactored in a follow-up to use leaf data to build the output note.
@locals(8)
proc build_p2id_output_note
Expand Down Expand Up @@ -330,10 +338,16 @@ proc build_p2id_output_note
mem_load.OUTPUT_NOTE_TAG_MEM_ADDR
# => [tag, RECIPIENT]

# TODO: implement scale down logic; stubbed out for now
padw loc_loadw_be.BUILD_P2ID_AMOUNT_MEM_LOC_1 padw loc_loadw_be.BUILD_P2ID_AMOUNT_MEM_LOC_0
# => [AMOUNT[0], AMOUNT[1], tag, note_type, RECIPIENT]
exec.asset_conversion::verify_u256_to_native_amount_conversion_stubbed

mem_load.OUTPUT_NOTE_FAUCET_AMOUNT movdn.8
# => [AMOUNT[0], AMOUNT[1], native_amount, tag, note_type, RECIPIENT]

exec.get_scale movdn.8
# => [AMOUNT[0], AMOUNT[1], scale, native_amount, tag, note_type, RECIPIENT]

exec.asset_conversion::verify_u256_to_native_amount_conversion
# => [amount, tag, note_type, RECIPIENT]

exec.faucets::distribute
Expand All @@ -345,6 +359,9 @@ end
#! This procedure validates the rollup exit root Merkle Proof via FPI against the agglayer bridge,
#! and if validation passes, mints the asset and creates an output note for the recipient.
#!
#! WARNING: The EVM claim asset amount is currently assumed to fit within 128 bits. See the WARNING in
#! build_p2id_output_note for details.
#!
#! TODO: Expand this description to cover the double-spend protection mechanism in detail.
#! Double-spend can be prevented in two ways:
#! 1) While it's possible to create two identical P2ID notes, only one can actually be consumed.
Expand Down Expand Up @@ -403,8 +420,8 @@ pub proc claim
# VALIDATE CLAIM
mem_loadw_be.PROOF_DATA_KEY_MEM_ADDR
# => [PROOF_DATA_KEY, pad(12)]
swapw
mem_loadw_be.LEAF_DATA_KEY_MEM_ADDR

swapw mem_loadw_be.LEAF_DATA_KEY_MEM_ADDR
# => [LEAF_DATA_KEY, PROOF_DATA_KEY, pad(8)]

# Errors on invalid proof
Expand All @@ -414,8 +431,10 @@ pub proc claim
# Create P2ID output note
loc_loadw_be.CLAIM_AMOUNT_MEM_LOC_1 swapw loc_loadw_be.CLAIM_AMOUNT_MEM_LOC_0
# => [AMOUNT[0], AMOUNT[1], pad(8)]

loc_load.CLAIM_SUFFIX_MEM_LOC loc_load.CLAIM_PREFIX_MEM_LOC
# => [prefix, suffix, AMOUNT[0], AMOUNT[1], pad(8)]

exec.build_p2id_output_note
# => [pad(16)]
end
Expand Down
5 changes: 0 additions & 5 deletions crates/miden-agglayer/asm/bridge/asset_conversion.masm
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,3 @@ pub proc verify_u256_to_native_amount_conversion
assert.err=ERR_REMAINDER_TOO_LARGE
# => [y]
end

# TODO: Rm & use verify_u256_to_native_amount_conversion
pub proc verify_u256_to_native_amount_conversion_stubbed
repeat.7 drop end
end
7 changes: 4 additions & 3 deletions crates/miden-agglayer/asm/note_scripts/CLAIM.masm
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ end
#! output_p2id_serial_num[4], // P2ID note serial number (4 felts, Word)
#! target_faucet_account_id[2], // Target faucet account ID (2 felts, prefix and suffix)
#! output_note_tag[1], // P2ID output note tag
#! padding[1], // padding (1 felt)
#! miden_claim_amount[1], // Miden claim amount (1 felt)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not a fan on this naming, maybe it should be native_claim_amount?

#! ]
#!
#! Invocation: exec
Expand Down Expand Up @@ -164,7 +164,7 @@ end
#! - output_p2id_serial_num [568..571]: 4 felts
#! - target_faucet_account_id [572..573]: 2 felts
#! - output_note_tag [574] : 1 felt
#! - padding [575] : 1 felt
#! - miden_claim_amount [575] : 1 felt
#!
#! Where:
#! - smtProofLocalExitRoot: SMT proof for local exit root (bytes32[_DEPOSIT_CONTRACT_TREE_DEPTH])
Expand All @@ -188,7 +188,8 @@ end
#! - target_faucet_account_id: Target agglayer faucet account ID (prefix and suffix). Only this specific
#! account can consume the note - any other account will cause a panic.
#! - output_note_tag: P2ID output note tag
#! - padding (1 felt)
#! - miden_claim_amount: Scaled-down Miden token amount (Felt). This is the Y value computed from
#! scaling down the Ethereum amount (X) by the scale exponent: Y = floor(X / 10^scale_exp)
#!
#! Panics if:
#! - account does not expose claim procedure.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"amount": 1000000000000000,
"amount": 100000000000000000000,
"deposit_count": 1,
"description": "L1 bridgeAsset transaction test vectors with valid Merkle proofs",
"destination_address": "0x00000000AA0000000000bb000000cc000000Dd00",
"destination_network": 20,
"global_exit_root": "0xbb7f9cbe48190e8859cbaecc54c8957863c786862bde7cff62df0a8b5adc19bb",
"global_exit_root": "0xc84f1e3744c151b345a8899034b3677c0fdbaf45aa3aaf18a3f97dbcf70836cb",
"global_index": "0x0000000000000000000000000000000000000000000000010000000000000000",
"leaf_type": 0,
"leaf_value": "0x8e5f0c4b8526561e30a89f900185ec681cc620fe3cadd8b281fb929063bd27ac",
"local_exit_root": "0x3e9a88b19d477b03175f9db12ba6b20eb33c0fe7a271667031685f034caf5af6",
"mainnet_exit_root": "0x3e9a88b19d477b03175f9db12ba6b20eb33c0fe7a271667031685f034caf5af6",
"leaf_value": "0x9d85d7c56264697df18f458b4b12a457b87b7e7f7a9b16dcb368514729ef680d",
"local_exit_root": "0xc9e095ea4cfe19b7e9a6d1aff6c55914ccc8df34954f9f6a2ad8e42d2632a0ab",
"mainnet_exit_root": "0xc9e095ea4cfe19b7e9a6d1aff6c55914ccc8df34954f9f6a2ad8e42d2632a0ab",
"metadata": "0x000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000a5465737420546f6b656e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000045445535400000000000000000000000000000000000000000000000000000000",
"metadata_hash": "0x4d0d9fb7f9ab2f012da088dc1c228173723db7e09147fe4fea2657849d580161",
"origin_network": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract ClaimAssetTestVectorsLocalTx is Test, DepositContractV2, DepositContrac
address originTokenAddress = 0x2DC70fb75b88d2eB4715bc06E1595E6D97c34DFF;
uint32 destinationNetwork = 20;
address destinationAddress = 0x00000000AA0000000000bb000000cc000000Dd00;
uint256 amount = 1000000000000000;
uint256 amount = 100000000000000000000;

bytes memory metadata = abi.encode("Test Token", "TEST", uint8(18));
bytes32 metadataHash = keccak256(metadata);
Expand Down
8 changes: 5 additions & 3 deletions crates/miden-agglayer/src/claim_note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,14 @@ pub struct OutputNoteData {
pub target_faucet_account_id: AccountId,
/// P2ID output note tag
pub output_note_tag: NoteTag,
/// Miden claim amount (scaled-down token amount as Felt)
pub miden_claim_amount: Felt,
}

impl OutputNoteData {
/// Converts the output note data to a vector of field elements for note storage
pub fn to_elements(&self) -> Vec<Felt> {
const OUTPUT_NOTE_DATA_ELEMENT_COUNT: usize = 8; // 4 + 2 + 1 + 1 (serial_num + account_id + tag + padding)
const OUTPUT_NOTE_DATA_ELEMENT_COUNT: usize = 8; // 4 + 2 + 1 + 1 (serial_num + account_id + tag + miden_claim_amount)
let mut elements = Vec::with_capacity(OUTPUT_NOTE_DATA_ELEMENT_COUNT);

// P2ID note serial number (4 felts as Word)
Expand All @@ -199,8 +201,8 @@ impl OutputNoteData {
// Output note tag
elements.push(Felt::new(self.output_note_tag.as_u32() as u64));

// Padding
elements.extend(vec![Felt::ZERO; 1]);
// Miden claim amount
elements.push(self.miden_claim_amount);

elements
}
Expand Down
2 changes: 1 addition & 1 deletion crates/miden-testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ miden-protocol = { features = ["std"], workspace = true }
primitive-types = { workspace = true }
rstest = { workspace = true }
serde = { features = ["derive"], workspace = true }
serde_json = { version = "1.0" }
serde_json = { features = ["arbitrary_precision"], version = "1.0" }
tokio = { features = ["macros", "rt"], workspace = true }
winter-rand-utils = { version = "0.13" }
23 changes: 22 additions & 1 deletion crates/miden-testing/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use alloc::string::String;
use alloc::vec::Vec;

use miden_crypto::Word;
use miden_processor::crypto::RpoRandomCoin;
use miden_protocol::account::AccountId;
use miden_protocol::asset::Asset;
use miden_protocol::crypto::rand::FeltRng;
use miden_protocol::note::{Note, NoteType};
use miden_protocol::errors::NoteError;
use miden_protocol::note::{Note, NoteAssets, NoteMetadata, NoteTag, NoteType};
use miden_protocol::testing::storage::prepare_assets;
use miden_standards::code_builder::CodeBuilder;
use miden_standards::note::P2idNoteStorage;
use miden_standards::testing::note::NoteBuilder;
use rand::SeedableRng;
use rand::rngs::SmallRng;
Expand Down Expand Up @@ -263,3 +266,21 @@ fn note_script_that_creates_notes<'note>(

Ok(out)
}

/// Generates a P2ID note - Pay-to-ID note with an exact serial number
pub fn create_p2id_note_exact(
sender: AccountId,
target: AccountId,
assets: Vec<Asset>,
note_type: NoteType,
serial_num: Word,
) -> Result<Note, NoteError> {
let recipient = P2idNoteStorage::new(target).into_recipient(serial_num);

let tag = NoteTag::with_account_target(target);

let metadata = NoteMetadata::new(sender, note_type).with_tag(tag);
let vault = NoteAssets::new(assets)?;

Ok(Note::new(vault, metadata, recipient))
}
Loading