Skip to content

refactor: reorient CLAIM note consumption flow#2528

Open
partylikeits1983 wants to merge 31 commits intoagglayerfrom
ajl-reorient-claim-note-flow
Open

refactor: reorient CLAIM note consumption flow#2528
partylikeits1983 wants to merge 31 commits intoagglayerfrom
ajl-reorient-claim-note-flow

Conversation

@partylikeits1983
Copy link
Contributor

@partylikeits1983 partylikeits1983 commented Feb 27, 2026

This PR reorients the flow in which the CLAIM note is consumed.

This PR reorients the flow from:

CLAIM -> aggfaucet -> (FPI call) bridge_in -> P2ID

CLAIM note is consumed by AggFaucet account, which does an FPI call to bridge to verify merkle proof, if valid creates P2ID note

to:

CLAIM -> bridge_in -> MINT -> aggfaucet -> P2ID

CLAIM note is consumed by AggBridge account which verifies the merkle proof, if valid creates a MINT note, which is then consumed by AggFaucet account in separate tx, which creates P2ID note.


This PR adds a mapping to the AggBridge which stores the bytes20 origin token address in the faucet registry as hash(bytes20) -> AccountId.

This is so that when creating the MINT note, the correct network note attachment target can be set. Storing the hash of the destination address as the key in a mapping, where the value is the aggfaucet AccountId is essential, as previously we only stored registered AggFaucets in a mapping like this: AccountId -> bool.


Note: Both the MINT note & P2ID note which created by the consumption of the MINT note, both use the PROOF_DATA_KEY (hash of proof data) as their serial numbers.

Resolves #2506

@partylikeits1983 partylikeits1983 self-assigned this Feb 27, 2026
@partylikeits1983 partylikeits1983 added agglayer PRs or issues related to AggLayer bridging integration pr-from-maintainers PRs that come from internal contributors or integration partners. They should be given priority labels Feb 27, 2026
@partylikeits1983 partylikeits1983 force-pushed the ajl-reorient-claim-note-flow branch from 55ee9fb to 57cfbb5 Compare February 27, 2026 22:25
@partylikeits1983 partylikeits1983 added the no changelog This PR does not require an entry in the `CHANGELOG.md` file label Feb 27, 2026
@partylikeits1983 partylikeits1983 modified the milestone: v0.14.0 Feb 27, 2026
@partylikeits1983 partylikeits1983 marked this pull request as ready for review March 2, 2026 10:46
Copy link
Contributor

@Fumuran Fumuran left a comment

Choose a reason for hiding this comment

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

Looks great, thank you! I left some nits and questions inline.

This is partial review, I only looked through the MASM code (but mostly in a way of code optimization, not the algorithm correctness).

partylikeits1983 and others added 10 commits March 2, 2026 17:39
Co-authored-by: Andrey Khmuro <andrey@polygon.technology>
Co-authored-by: Andrey Khmuro <andrey@polygon.technology>
Co-authored-by: Andrey Khmuro <andrey@polygon.technology>
Co-authored-by: Andrey Khmuro <andrey@polygon.technology>
Co-authored-by: Andrey Khmuro <andrey@polygon.technology>
Co-authored-by: Andrey Khmuro <andrey@polygon.technology>
Co-authored-by: Andrey Khmuro <andrey@polygon.technology>
Co-authored-by: Andrey Khmuro <andrey@polygon.technology>
Co-authored-by: Andrey Khmuro <andrey@polygon.technology>
@partylikeits1983 partylikeits1983 force-pushed the ajl-reorient-claim-note-flow branch from ee64a9b to 6a602df Compare March 2, 2026 14:51
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.

Overall looks good!

///
/// This note is used to register a faucet in the bridge's faucet registry.
/// It carries the faucet account ID and is always public.
/// This note is used to register a faucet in the bridge's faucet and token registries.
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's a bit strange that we have two registries now. I would at least document this better somewhere.

It seems that one is used for bridging out (we have Miden address, we check what's the eth equivalent), while the other is for bridging in (we have eth address, we query the Miden faucet addresss)

Copy link
Collaborator

Choose a reason for hiding this comment

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

actually this could go right into the spec document. We can merge that PR into the agglayer branch, and have any further PRs against this branch update the spec

mem_store.MINT_NOTE_STORAGE_NATIVE_AMOUNT
# => [pad(16)]

# Write attachment_kind = 0 [2]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

now that we've re-oriented the flow, we could reconsider where the conversion data is stored (i.e. re-consider #2172), but we can do it separately

Comment on lines +41 to +42
const CLAIM_PROOF_DATA_WORD_LEN = 134
const CLAIM_LEAF_DATA_WORD_LEN = 8
Copy link
Collaborator

Choose a reason for hiding this comment

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

while this might be refactored later (TBD on how #2535 progresses), they are currently referring to the same underlying data, let's not duplicate

const OUTPUT_NOTE_TYPE_PUBLIC = 1

# P2ID attachment constants (the P2ID note created by the faucet has no attachment)
const P2ID_ATTACHMENT_KIND_NONE = 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

loc_store.CLAIM_PREFIX_MEM_LOC loc_store.CLAIM_SUFFIX_MEM_LOC
# => [pad(7)]

exec.get_raw_claim_amount
Copy link
Collaborator

Choose a reason for hiding this comment

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

if this is unused, we should remove the proc

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah, but this introduces a critical vulnerability - now we just use the miden_claim_amount that is passed in ClaimNoteStorage while completely disregarding the amount that is part of LeafData.
So the proof verifies, and then we forget about EthAmount there and can just mint however many tokens we wish 😁

(PoC here, all tests still pass when minting 10x the amount)

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 pr-from-maintainers PRs that come from internal contributors or integration partners. They should be given priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants