Skip to content

chore: refactor miden::protocol from ASSET to ASSET_KEY and ASSET_VALUE#2410

Open
PhilippGackstatter wants to merge 42 commits intopgackst-kernel-asset-key-valuefrom
pgackst-user-asset-key-value
Open

chore: refactor miden::protocol from ASSET to ASSET_KEY and ASSET_VALUE#2410
PhilippGackstatter wants to merge 42 commits intopgackst-kernel-asset-key-valuefrom
pgackst-user-asset-key-value

Conversation

@PhilippGackstatter
Copy link
Contributor

@PhilippGackstatter PhilippGackstatter commented Feb 6, 2026

Changes miden::protocol asset APIs to take ASSET_KEY and ASSET_VALUE instead of just ASSET to adapt to the kernel changes from #2396.

This PR, like #2396, also keeps the key and value layout of assets unchanged and only deals with expanding assets from one to two words for simplicity.

Migration

  • SWAP note storage previously stored just REQUESTED_ASSET. Now it stores REQUESTED_ASSET_KEY and REQUESTED_ASSET_VALUE.
  • miden::standards::wallets::basic::move_asset_to_note no longer returns parameters (motivated by add_asset_to_note procedure results overhead when calling from Rust #1717).
  • Rename miden::protocol::asset::build_(non_)fungible_asset -> miden::protocol::asset::create_(non_)fungible_asset, for consistency with the miden::protocol::faucet procedures of the same name.
    • We generally use create_ and build_ interchangeably in APIs and it would be nice to be more consistent there.
  • The following procedures now take or return an asset vault key in addition to the asset value:
    • miden::protocol::faucet::create_fungible_asset
    • miden::protocol::faucet::create_non_fungible_asset
    • miden::protocol::faucet::mint
    • miden::protocol::faucet::burn
    • miden::protocol::asset::create_fungible_asset
    • miden::protocol::asset::create_non_fungible_asset
    • miden::protocol::native_account::add_asset
    • miden::protocol::native_account::remove_asset
    • miden::protocol::output_note::add_asset
    • miden::standards::wallets::basic::move_asset_to_note

Notable Changes

  • bridge_out.masm needed a bigger update:
    • keccak hashing includes asset key and value
    • burn note serial derivation takes asset key for now - maybe it should take the whole asset? But, this could also be changed separately.
  • Moves the asset vault key build procedures to shared utils for access in both miden::protocol. This logic will change when the layout changes, but some procedure to create a vault key will probably remain at least until generalized assets and maybe beyond.
  • Moves mock::util library to miden-standards to be able to provide exec-wrappers for basic::wallet::move_asset_to_note.
  • Unifies the asset preservation test in test_epilogue since one of the tests was testing the wrong condition and needed fixing anyway.

part of #2328

@PhilippGackstatter PhilippGackstatter force-pushed the pgackst-user-asset-key-value branch from 599ba84 to 4143ebe Compare February 6, 2026 13:35
@PhilippGackstatter PhilippGackstatter marked this pull request as ready for review February 6, 2026 13:42
@PhilippGackstatter PhilippGackstatter force-pushed the pgackst-user-asset-key-value branch from 4143ebe to d94dc4e Compare February 6, 2026 15:30
@PhilippGackstatter PhilippGackstatter force-pushed the pgackst-user-asset-key-value branch from d94dc4e to b1af2ca Compare February 6, 2026 15:36
@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
@PhilippGackstatter PhilippGackstatter requested review from Fumuran and igamigo and removed request for bobbinth February 9, 2026 18:27
Copy link
Collaborator

@igamigo igamigo left a comment

Choose a reason for hiding this comment

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

Not a full review yet but leaving some comments, overall looks great.

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.

review TBC

Comment on lines +20 to +21
const CREATE_BURN_NOTE_ASSET_KEY_LOC=0
const CREATE_BURN_NOTE_ASSET_VALUE_LOC=4
Copy link
Collaborator

Choose a reason for hiding this comment

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

not for this PR, but I do wonder if there are better ways to name these constants. I ran into the issue of defining memory locals for similar (w.r.t. function) constants in different procedures, only to find that names get unnecessarily long.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, agreed. My favorite thing would be constants that can be defined in a procedure body to make them scoped and accessible in only that body, e.g.:

@locals(9)
proc create_burn_note
    const ASSET_KEY_LOC = 0
    const ASSET_VALUE_LOC = ASSET_KEY_LOC + ASSET_VALUE_MEMORY_OFFSET

    loc_storew_be.ASSET_KEY_LOC
    swapw
    # => [ASSET_VALUE, ASSET_KEY]

    loc_storew_be.ASSET_VALUE_LOC
    dropw dupw
    # => [ASSET_KEY, ASSET_KEY]
end

Alternatively, we could define these in the @locals attribute:

@locals(
    ASSET_KEY = 0,
    ASSET_VALUE = ASSET_KEY + ASSET_VALUE_MEMORY_OFFSET,
)
proc create_burn_note
    loc_storew_be.ASSET_KEY
    # ...
end

The assembler could translate these into globally defined constants under the hood to not require a new MASM feature, though this may be a bit too much magic for an assembly language.

cc @bitwalker in case you have thoughts for how difficult this would be to add

Copy link
Collaborator

Choose a reason for hiding this comment

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

great suggestion!

Copy link
Contributor

Copilot AI commented Feb 23, 2026

@mmagician I've opened a new pull request, #2498, to work on those changes. Once the pull request is ready, I'll request review from you.

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.

LGTM

Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you! Not a full review yet, but I left a few small comments inline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

5 participants