Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
12124d4
feat: wip CLAIM note flow reorientation
partylikeits1983 Feb 27, 2026
79d2cac
wip: build MINT note from aggbridge
partylikeits1983 Feb 27, 2026
d951740
wip: created MINT note encodes incorrect public P2ID or public P2ID …
partylikeits1983 Feb 27, 2026
ce6e21d
feat: working e2e CLAIM flow reordering
partylikeits1983 Feb 27, 2026
57cfbb5
fix: cleanup rm debug.stack
partylikeits1983 Feb 27, 2026
c8d1afb
refactor: improve readability of MINT note memory addresses
partylikeits1983 Mar 2, 2026
7fd9d76
refactor: fix stack comments
partylikeits1983 Mar 2, 2026
8dff792
fix: rm println statements
partylikeits1983 Mar 2, 2026
2225fe0
Update crates/miden-agglayer/asm/agglayer/bridge/bridge_config.masm
partylikeits1983 Mar 2, 2026
7588547
Update crates/miden-agglayer/asm/agglayer/bridge/bridge_config.masm
partylikeits1983 Mar 2, 2026
bd4c3ef
Update crates/miden-agglayer/asm/agglayer/bridge/bridge_config.masm
partylikeits1983 Mar 2, 2026
7e5d734
Update crates/miden-agglayer/asm/agglayer/bridge/bridge_config.masm
partylikeits1983 Mar 2, 2026
512df0c
Update crates/miden-agglayer/asm/note_scripts/CLAIM.masm
partylikeits1983 Mar 2, 2026
74cb97e
Update crates/miden-agglayer/asm/agglayer/bridge/bridge_config.masm
partylikeits1983 Mar 2, 2026
7f5ba6f
Update crates/miden-agglayer/asm/agglayer/bridge/bridge_config.masm
partylikeits1983 Mar 2, 2026
a77b9a2
Update crates/miden-agglayer/asm/agglayer/bridge/bridge_in.masm
partylikeits1983 Mar 2, 2026
6a602df
Update crates/miden-agglayer/asm/agglayer/bridge/bridge_in.masm
partylikeits1983 Mar 2, 2026
433dcc4
Update crates/miden-agglayer/asm/agglayer/bridge/bridge_in.masm
partylikeits1983 Mar 2, 2026
a0d43bf
feat: add CGI chain hash computation
Fumuran Feb 24, 2026
1e5f5aa
test: [WiP-1] first iteration, not building
Fumuran Feb 24, 2026
8c3dcdf
test: [WiP-2] building state
Fumuran Feb 25, 2026
5f707de
test: updated script, failing
Fumuran Feb 25, 2026
558257d
test: update script (passing)
Fumuran Feb 25, 2026
4450f37
refactor: improve bridge_in doc comments
partylikeits1983 Mar 2, 2026
eb33668
refactor: add constants for memory addresses
partylikeits1983 Mar 3, 2026
1f6e699
refactor: cleanup memory layout in bridge_in
partylikeits1983 Mar 3, 2026
3d2fa15
fix: update comment in CLAIM note
partylikeits1983 Mar 3, 2026
66ae6d3
refactor: remove redundant dropw
partylikeits1983 Mar 3, 2026
aa46318
Merge branch 'agglayer' into ajl-reorient-claim-note-flow
partylikeits1983 Mar 4, 2026
435c5d0
refactor: use execution_hint::ALWAYS
partylikeits1983 Mar 4, 2026
55ff197
refactor: rm redundant const note type
partylikeits1983 Mar 4, 2026
d0b0a78
refactor: simplify loc_store/load ops in bridge_in
partylikeits1983 Mar 4, 2026
46cb5f8
refactor: decompose build_mint_output_note into modular helpers
partylikeits1983 Mar 4, 2026
5503ae3
refactor: remove pad(x) stack comments from exec'ed procs
partylikeits1983 Mar 4, 2026
b22874f
feat: add constants for attachement types
partylikeits1983 Mar 4, 2026
ef477d5
refactor: create ctorage slots for CGI chain hash, use actiual proced…
Fumuran Mar 4, 2026
2d5149b
Merge branch 'ajl-reorient-claim-note-flow' into andrew-compute-cgi-c…
Fumuran Mar 4, 2026
f9db262
Merge branch 'agglayer' into ajl-reorient-claim-note-flow
partylikeits1983 Mar 6, 2026
3ec49db
Merge branch 'ajl-reorient-claim-note-flow' into andrew-compute-cgi-c…
Fumuran Mar 6, 2026
38e6ea1
refactor: incapsulate CGI hash computation
Fumuran Mar 6, 2026
548d34f
fix: add call to verify_u256_scale_down procedure
partylikeits1983 Mar 9, 2026
88de009
refactor: use ATTACHMENT_KIND_NONE const
partylikeits1983 Mar 10, 2026
af0deeb
fix: use truncate_stack proc for FPI call & exec compatibility
partylikeits1983 Mar 10, 2026
58c84d6
refactor: add get_scale & get_scale_inner for call vs exec
partylikeits1983 Mar 11, 2026
9892099
test: update solidity contracts to generate CGI chain hash. Test is f…
Fumuran Mar 11, 2026
9e015fe
Merge branch 'ajl-reorient-claim-note-flow' into andrew-compute-cgi-c…
Fumuran Mar 12, 2026
877b06a
test: fix bug, test is passing
Fumuran Mar 12, 2026
a40feb9
chore: fix doc format
Fumuran Mar 12, 2026
c46c53e
refactor: use local memory for TOKEN_ADDR_HASH_PTR
partylikeits1983 Mar 12, 2026
b41c7dd
refactor: look up faucet by token address only once during claim
partylikeits1983 Mar 12, 2026
09dd8d8
fix: fix array comment syntax
partylikeits1983 Mar 12, 2026
5558907
refactor: rm pad comments from exec'ed proc
partylikeits1983 Mar 13, 2026
93dab0e
refactor: rm swapw & replace w padw
partylikeits1983 Mar 13, 2026
b52096e
fix: update comment
partylikeits1983 Mar 13, 2026
6da3bac
refactor: refactor is_token_registered proc
partylikeits1983 Mar 13, 2026
22e5fc3
chore: more explicit mem constant names
mmagician Mar 14, 2026
cfb6211
fix: explicit pad before FPI call
mmagician Mar 14, 2026
f22e0cd
refactor: remove unused bridge account ID storage slot from AggLayer …
partylikeits1983 Mar 16, 2026
dc72124
chore: opinionated improvements to #2528 (#2602)
mmagician Mar 16, 2026
c416871
chore: merge latest agglayer into ajl-reorient-claim-note-flow
partylikeits1983 Mar 16, 2026
2679ca1
refactor: move bridge & faucet code from lib.rs to dedicated modules
partylikeits1983 Mar 16, 2026
aedbf55
Merge branch 'ajl-reorient-claim-note-flow' into andrew-compute-cgi-c…
Fumuran Mar 16, 2026
be00e01
refactor: remove unused code, update list of bridge storage slots, up…
Fumuran Mar 16, 2026
dfca654
Merge branch 'agglayer' into andrew-compute-cgi-chain-hash
Fumuran Mar 17, 2026
faad1c2
refactor: create constants for local memory offsets
Fumuran Mar 17, 2026
1c4e2d8
refactor: move verifyLeafBridgeHarness to helpers, remove unused code…
Fumuran Mar 17, 2026
91d1443
Merge branch 'agglayer' into andrew-compute-cgi-chain-hash
Fumuran Mar 17, 2026
4563a0f
test: generate CGI chain hash during ClaimAssetTestVectorsRollupTx
Fumuran Mar 17, 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
8 changes: 8 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@
path = crates/miden-agglayer/solidity-compat/lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable.git
branch = release-v4.9
[submodule "crates/miden-agglayer/solidity-compat/lib/openzeppelin-contracts"]
path = crates/miden-agglayer/solidity-compat/lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts.git
branch = release-v5.0
[submodule "crates/miden-agglayer/solidity-compat/lib/openzeppelin-contracts-upgradeable5"]
path = crates/miden-agglayer/solidity-compat/lib/openzeppelin-contracts-upgradeable5
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable.git
branch = release-v5.0
Comment thread
mmagician marked this conversation as resolved.
96 changes: 91 additions & 5 deletions crates/miden-agglayer/asm/agglayer/bridge/bridge_in.masm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use miden::standards::note_tag
use miden::standards::note_tag::DEFAULT_TAG
use miden::standards::attachments::network_account_target
use miden::standards::note::execution_hint::ALWAYS
use miden::protocol::native_account
use miden::protocol::active_account

# TYPE ALIASES
# =================================================================================================
Expand All @@ -37,6 +39,14 @@ const ERR_SMT_ROOT_VERIFICATION_FAILED = "merkle proof verification failed: prov
# CONSTANTS
# =================================================================================================

# Storage slots
# -------------------------------------------------------------------------------------------------

# Storage slot constants for the CGI (claimed global index) chain hash.
# It is stored in two separate value slots.
const CGI_CHAIN_HASH_LO_SLOT_NAME = word("miden::agglayer::bridge::cgi_chain_hash_lo")
const CGI_CHAIN_HASH_HI_SLOT_NAME = word("miden::agglayer::bridge::cgi_chain_hash_hi")

# Data sizes
# -------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -172,6 +182,7 @@ const CLAIM_DEST_ID_SUFFIX_LOCAL = 1
#! - the Merkle proof for the provided leaf-index tuple against the computed GER is invalid.
#!
#! Invocation: call
@locals(8) # leaf value
pub proc verify_leaf_bridge
# get the leaf value. We have all the necessary leaf data in the advice map
exec.get_leaf_value
Expand All @@ -180,8 +191,16 @@ pub proc verify_leaf_bridge
movupw.3 dropw
# => [LEAF_VALUE[8], PROOF_DATA_KEY, pad(4)]

# duplicate the leaf value to use it later during the CGI chain hash computation
movupw.2 dupw.2 dupw.2
# => [LEAF_VALUE[8], PROOF_DATA_KEY, LEAF_VALUE[8], pad(4)]

# delegate proof verification
exec.verify_leaf
# => [LEAF_VALUE[8], pad(8)]

# update the CGI chain hash
exec.update_cgi_chain_hash
# => [pad(16)]
end

Expand Down Expand Up @@ -483,9 +502,7 @@ end

#! Verify leaf and checks that it has not been claimed.
#!
#! Inputs:
#! Operand stack: [LEAF_VALUE[8], PROOF_DATA_KEY]
#!
#! Inputs: [LEAF_VALUE[8], PROOF_DATA_KEY]
#! Outputs: []
#!
#! Panics if:
Expand Down Expand Up @@ -514,8 +531,7 @@ proc verify_leaf
# => [LEAF_VALUE[8]]

# 3. load global index from memory
padw mem_loadw_le.GLOBAL_INDEX_PTR
padw push.GLOBAL_INDEX_PTR add.4 mem_loadw_le swapw
push.GLOBAL_INDEX_PTR exec.utils::mem_load_double_word
Comment thread
mmagician marked this conversation as resolved.
# => [GLOBAL_INDEX[8], LEAF_VALUE[8]]

# Determine if we're dealing with a deposit from mainnet or from a rollup.
Expand Down Expand Up @@ -903,3 +919,73 @@ proc calculate_root(
padw loc_loadw_le.CUR_HASH_HI_LOCAL padw loc_loadw_le.CUR_HASH_LO_LOCAL
# => [ROOT_LO, ROOT_HI]
end

#! Updates the claimed global index (CGI) chain hash by recomputing it and storing into the
#! corresponding storage slot.
#!
#! The resulting hash is computed as a sequential hash of leaf value, global index, and previous
#! value of the CGI chain hash:
#! NEW_CGI_CHAIN_HASH[8] = Keccak256(OLD_CGI_CHAIN_HASH[8], Keccak256(GLOBAL_INDEX[8], LEAF_VALUE[8]))
#!
#! Inputs: [LEAF_VALUE[8]]
#! Outputs: []
#!
#! Invocation: exec
proc update_cgi_chain_hash
# load the required CGI chain data values onto the stack
exec.load_cgi_chain_hash_data
# => [GLOBAL_INDEX[8], LEAF_VALUE[8], OLD_CGI_CHAIN_HASH[8]]

# compute the new CGI chain hash
exec.keccak256::merge swapdw
# => [OLD_CGI_CHAIN_HASH[8], Keccak256(GLOBAL_INDEX, LEAF_VALUE)]

exec.keccak256::merge
# => [NEW_CGI_CHAIN_HASH[8]]

# store the new CGI chain hash
exec.store_cgi_chain_hash
# => []
end

#! Loads the old CGI chain hash, the leaf value, and the global index onto the stack as a
#! preparation for the new CGI chain hash computation.
#!
#! Inputs: [LEAF_VALUE[8]]
#! Outputs: [GLOBAL_INDEX[8], LEAF_VALUE[8], OLD_CGI_CHAIN_HASH[8]]
#!
#! Invocation: exec
proc load_cgi_chain_hash_data
# load the old CGI chain hash onto the stack
push.CGI_CHAIN_HASH_HI_SLOT_NAME[0..2]
exec.active_account::get_item
# => [OLD_CGI_CHAIN_HASH_HI, LEAF_VALUE[8]]

push.CGI_CHAIN_HASH_LO_SLOT_NAME[0..2]
exec.active_account::get_item
# => [OLD_CGI_CHAIN_HASH[8], LEAF_VALUE[8]]

# move the leaf value to the top of the stack
swapdw
# => [LEAF_VALUE[8], OLD_CGI_CHAIN_HASH[8]]

# load the global index onto the stack
push.GLOBAL_INDEX_PTR exec.utils::mem_load_double_word
# => [GLOBAL_INDEX[8], LEAF_VALUE[8], OLD_CGI_CHAIN_HASH[8]]
end

#! Stores the computed global index (CGI) chain hash into the corresponding storage slots.
#!
#! Inputs: [NEW_CGI_CHAIN_HASH_LO, NEW_CGI_CHAIN_HASH_HI]
#! Outputs: []
#!
#! Invocation: exec
proc store_cgi_chain_hash
push.CGI_CHAIN_HASH_LO_SLOT_NAME[0..2]
exec.native_account::set_item dropw
# => [NEW_CGI_CHAIN_HASH_HI]

push.CGI_CHAIN_HASH_HI_SLOT_NAME[0..2]
exec.native_account::set_item dropw
# => []
end
12 changes: 12 additions & 0 deletions crates/miden-agglayer/solidity-compat/foundry.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,22 @@
"rev": "1801b0541f4fda118a10798fd3486bb7051c5dd6"
}
},
"lib/openzeppelin-contracts": {
"branch": {
"name": "release-v5.0",
"rev": "dbb6104ce834628e473d2173bbc9d47f81a9eec3"
}
},
"lib/openzeppelin-contracts-upgradeable": {
"branch": {
"name": "release-v4.9",
"rev": "2d081f24cac1a867f6f73d512f2022e1fa987854"
}
},
"lib/openzeppelin-contracts-upgradeable5": {
"branch": {
"name": "release-v5.0",
"rev": "723f8cab09cdae1aca9ec9cc1cfa040c2d4b06c1"
}
}
}
4 changes: 3 additions & 1 deletion crates/miden-agglayer/solidity-compat/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ libs = ["lib"]
optimizer = true
optimizer_runs = 200
out = "out"
solc = "0.8.20"
solc = "0.8.28"
src = "src"
via_ir = true

remappings = [
"@agglayer/=lib/agglayer-contracts/contracts/",
"@openzeppelin/contracts-upgradeable4/=lib/openzeppelin-contracts-upgradeable/contracts/",
"@openzeppelin/contracts-upgradeable5/=lib/openzeppelin-contracts-upgradeable5/contracts/",
"@openzeppelin/contracts5/=lib/openzeppelin-contracts/contracts/",
]

# Emit extra output for test vector generation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"amount": 100000000000000000000,
"amount": "100000000000000000000",
"claimed_global_index_hash_chain": "0xbce0afc98c69ea85e9cfbf98c87c58a77c12d857551f1858530341392f70c22d",
"deposit_count": 1,
"description": "L1 bridgeAsset transaction test vectors with valid Merkle proofs",
"destination_address": "0x00000000AA0000000000bb000000cc000000Dd00",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"amount": 100000000000000,
"claimed_global_index_hash_chain": "0xd2bb2f0231ee9ea0c88e89049bea6dbcf7dd96a1015ca9e66ab38ef3c8dc928e",
"destination_address": "0x00000000b0E79c68cafC54802726C6F102Cca300",
"destination_network": 20,
"global_exit_root": "0xe1cbfbde30bd598ee9aa2ac913b60d53e3297e51ed138bf86c500dd7d2391e7d",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"amount": "100000000000000000000",
"claimed_global_index_hash_chain": "0x68ace2f015593d5f6de5338c9eca6e748764574491b9f0eed941a2b49db1a7a3",
"deposit_count": 3,
"description": "Rollup deposit test vectors with valid two-level Merkle proofs (non-zero indices)",
"destination_address": "0x00000000AA0000000000bb000000cc000000Dd00",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,32 @@
pragma solidity ^0.8.20;

import "forge-std/Test.sol";
import "@agglayer/v2/lib/DepositContractV2.sol";
import "@agglayer/lib/GlobalExitRootLib.sol";
import "@agglayer/interfaces/IBasePolygonZkEVMGlobalExitRoot.sol";
import "./DepositContractTestHelpers.sol";

contract MockGlobalExitRootManagerLocal is IBasePolygonZkEVMGlobalExitRoot {
mapping(bytes32 => uint256) public override globalExitRootMap;

function updateExitRoot(bytes32) external override {}

function setGlobalExitRoot(bytes32 globalExitRoot) external {
globalExitRootMap[globalExitRoot] = block.number;
}
}

/**
* @title ClaimAssetTestVectorsLocalTx
* @notice Test contract that generates test vectors for an L1 bridgeAsset transaction.
* This simulates calling bridgeAsset() on the PolygonZkEVMBridgeV2 contract
* and captures all relevant data including VALID Merkle proofs.
* Uses BridgeL2SovereignChain to get the authoritative claimedGlobalIndexHashChain.
*
* Run with: forge test -vv --match-contract ClaimAssetTestVectorsLocalTx
*
* The output can be used to verify Miden's ability to process L1 bridge transactions.
*/
contract ClaimAssetTestVectorsLocalTx is Test, DepositContractV2, DepositContractTestHelpers {
contract ClaimAssetTestVectorsLocalTx is Test, DepositContractTestHelpers {
/**
* @notice Generates bridge asset test vectors with VALID Merkle proofs.
* Simulates a user calling bridgeAsset() to bridge tokens from L1 to Miden.
Expand Down Expand Up @@ -95,6 +106,36 @@ contract ClaimAssetTestVectorsLocalTx is Test, DepositContractV2, DepositContrac
// extracts it via uint32(globalIndex) in _verifyLeaf()
uint256 globalIndex = (uint256(1) << 64) | uint256(leafIndex);

// ====== COMPUTE CLAIMED GLOBAL INDEX HASH CHAIN ======
// Use the actual BridgeL2SovereignChain to compute the authoritative value

// Set up the global exit root manager
MockGlobalExitRootManagerLocal gerManager = new MockGlobalExitRootManagerLocal();
gerManager.setGlobalExitRoot(globalExitRoot);
globalExitRootManager = IBasePolygonZkEVMGlobalExitRoot(address(gerManager));

// Use a non-zero network ID to match sovereign-chain requirements
networkID = 10;

// Call _verifyLeafBridge to update claimedGlobalIndexHashChain
this.verifyLeafBridgeHarness(
smtProofLocal,
smtProofRollup,
globalIndex,
mainnetExitRoot,
rollupExitRoot,
leafType,
originNetwork,
originTokenAddress,
destinationNetwork,
destinationAddress,
amount,
metadataHash
);

// Read the updated claimedGlobalIndexHashChain
bytes32 claimedHashChain = claimedGlobalIndexHashChain;

// ====== SERIALIZE SMT PROOFS ======
_serializeProofs(obj, smtProofLocal, smtProofRollup);

Expand All @@ -115,6 +156,7 @@ contract ClaimAssetTestVectorsLocalTx is Test, DepositContractV2, DepositContrac
{
vm.serializeUint(obj, "deposit_count", depositCountValue);
vm.serializeBytes32(obj, "global_index", bytes32(globalIndex));
vm.serializeBytes32(obj, "claimed_global_index_hash_chain", claimedHashChain);
vm.serializeBytes32(obj, "local_exit_root", localExitRoot);
vm.serializeBytes32(obj, "mainnet_exit_root", mainnetExitRoot);
vm.serializeBytes32(obj, "rollup_exit_root", rollupExitRoot);
Expand Down
Loading
Loading