Skip to content

feat(Agglayer): add scaled down quotient to CLAIM note NoteStorage#2336

Closed
partylikeits1983 wants to merge 63 commits intoagglayer-newfrom
ajl-add-scale-down-quotient-claim-note
Closed

feat(Agglayer): add scaled down quotient to CLAIM note NoteStorage#2336
partylikeits1983 wants to merge 63 commits intoagglayer-newfrom
ajl-add-scale-down-quotient-claim-note

Conversation

@partylikeits1983
Copy link
Contributor

@partylikeits1983 partylikeits1983 commented Jan 23, 2026

This PR utilizes the scale_u256_to_native_amount procedure during the claim asset flow.

Changes this PR introduces:

  • Additional input value to CLAIM note NoteStorage
  • Removal of stubbed out scale_u256_to_native_amount procedure
  • Added storage of originTokenAddress[5] & scaling factor to aggfaucet across two slots.
  • Validates the origin_token_address in the CLAIM note NoteStorage matches the origin_token_address in the agglayer faucet metadata.

Builds on: #2331
Resolves: #2011 (comment)
Partially resolves faucet registry issue: #2172

partylikeits1983 and others added 30 commits January 8, 2026 19:14
Co-authored-by: igamigo <ignacio.amigo@lambdaclass.com>
Co-authored-by: Marti <marti@miden.team>
@partylikeits1983 partylikeits1983 changed the base branch from next to agglayer January 23, 2026 22:23
@partylikeits1983 partylikeits1983 added no changelog This PR does not require an entry in the `CHANGELOG.md` file agglayer PRs or issues related to AggLayer bridging integration labels Jan 23, 2026
@partylikeits1983 partylikeits1983 changed the base branch from agglayer to ajl-u256-felt-downscale-procedure January 23, 2026 22:50
@partylikeits1983 partylikeits1983 self-assigned this Jan 23, 2026
@partylikeits1983 partylikeits1983 marked this pull request as ready for review January 23, 2026 23:29
Comment on lines 16 to +23
# The slot in this component's storage layout where the bridge account ID is stored.
const BRIDGE_ID_SLOT = word("miden::agglayer::faucet")

# The slots where origin token address and scaling factor are stored
# AGGFAUCET_METADATA_SLOT_0: [tok0, tok1, tok2, tok3]
# AGGFAUCET_METADATA_SLOT_1: [tok4, scaling_factor, 0, 0]
const AGGFAUCET_METADATA_SLOT_0 = word("miden::agglayer::aggfaucet_metadata_0")
const AGGFAUCET_METADATA_SLOT_1 = word("miden::agglayer::aggfaucet_metadata_1")
Copy link
Contributor

Choose a reason for hiding this comment

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

A few comments on this:

  • Would it not be more convenient to store the token address as 8 felts (each holding a u32 value)? I'm assuming here that this would allow us to re-use the native serialization of the AggLayer format.
  • I would probably separate token address from other metadata as I'm imagining we'd need more metadata for the faucet. Or are we using basic fungible faucet metadata slot for that?
  • For slot names, we should make the convention consistent. Specifically, I'd use miden::agglayer::faucet as the namespace and then add slot names within that namespace.
  • I would also maybe provide a high level description of the storage layout for the whole faucet, and after that would declare all constants (would make it a bit easier to read.

Overall, for slots, I'd probably have something like this:

const BRIDGE_ID_SLOT = word("miden::agglayer::faucet::bridge_account_id")
const FAUCET_METADATA = word("miden::agglayer::faucet::metadata")
const TOKEN_ADDRESS_SLOT_0 = word("miden::agglayer::faucet::token_address_0")
const TOKEN_ADDRESS_SLOT_1 = word("miden::agglayer::faucet::token_address_1")

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah - scratch the first point above. Token address is only 20 bytes, so, we already have u32 representation - and we don't need more than 5 elements for them.

#! Outputs: [origin_token_addr[0], origin_token_addr[1], origin_token_addr[2], origin_token_addr[3], origin_token_addr[4]]
#!
#! Invocation: exec
proc get_origin_token_address
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe not for this PR, but I'd make this procedure a part of the public interface. Since public interface procedures need to be invoked via the call instruction, we'd need to have two procedures:

  • This one, which I'd rename into something like get_origin_token_address_internal.
  • The public procedure which would handle the padding and then call this procedure.

mem_load.ORIGIN_TOKEN_ADDRESS_2
mem_load.ORIGIN_TOKEN_ADDRESS_3
mem_load.ORIGIN_TOKEN_ADDRESS_4
# => [ORIGIN_TOKEN_ADDRESS_CLAIM[5]]
Copy link
Contributor

Choose a reason for hiding this comment

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

Relying on memory layout in this way feels a bit fragile to me. I'd try to make this procedure a bit more stateless. One approach is to pass in the memory pointer to where the token address is stored as an input - i.e., something like:

#! Inputs:  [token_address_ptr]
#! Outputs: []
proc assert_origin_address_eq_storage_address
    padw dup.4 mem_loadw_be
    movup.4 add.4 mem_load

    ...
end

This would take a few more cycles, but I don't think that's an issue.

@partylikeits1983 partylikeits1983 marked this pull request as draft January 26, 2026 17:11
Comment on lines +145 to +151
#! Reads the origin token address from the aggfaucet metadata storage slots.
#!
#! Inputs: []
#! Outputs: [origin_token_addr[0], origin_token_addr[1], origin_token_addr[2], origin_token_addr[3], origin_token_addr[4]]
#!
#! Invocation: exec
proc get_origin_token_address
Copy link
Collaborator

Choose a reason for hiding this comment

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

These changes don't seem related to how CLAIM note handles scaling down - ideally would have been a separate PR

@mmagician mmagician added the pr-from-maintainers PRs that come from internal contributors or integration partners. They should be given priority label Feb 9, 2026
@partylikeits1983 partylikeits1983 force-pushed the ajl-u256-felt-downscale-procedure branch from db9825d to 3ea2737 Compare February 13, 2026 08:40
Base automatically changed from ajl-u256-felt-downscale-procedure to agglayer-new February 18, 2026 09:34
@partylikeits1983
Copy link
Contributor Author

Closing in favor of #2460

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.

4 participants