Skip to content

chore: refactor tx kernel from ASSET to ASSET_KEY and ASSET_VALUE#2396

Open
PhilippGackstatter wants to merge 48 commits intonextfrom
pgackst-kernel-asset-key-value
Open

chore: refactor tx kernel from ASSET to ASSET_KEY and ASSET_VALUE#2396
PhilippGackstatter wants to merge 48 commits intonextfrom
pgackst-kernel-asset-key-value

Conversation

@PhilippGackstatter
Copy link
Contributor

@PhilippGackstatter PhilippGackstatter commented Feb 4, 2026

This PR refactors the tx kernel internals from the previous ASSET to ASSET_KEY and ASSET_VALUE. I.e. assets are now represented by two instead of one word.

To keep this change managable:

  • The asset key is temporarily derived from the asset value at the kernel procedure API boundary (api.masm). In one of the next PRs, this will go away and the kernel procedures will instead take the key in addition to the value.
    • Importantly, the asset value is unchanged: It still has the same layout as before. So, in isolation, this change is weird because the key can always be derived from the value, but this is a temporary thing and in a subsequent PR, the faucet ID will be removed from the asset value.
  • Most changes are only in the tx kernel, but it wasn't possible to keep them entirely contained there. The one change that bleeds through in this PR is that the assets commitment is computed over key and value instead of just the value. This affects the get_assets kernel procedure.

Notable changes

  • Computing assets commitment is now both conceptually easier and also easier in the implementation. It uses the various double-word hash procedures from miden::core.
    • Simplify NoteAssets by implementing SequentialCommit.
  • output_note::add_asset was refactored heavily. It now uses a single procedure for both fungible and non-fungible assets which should prepare nicely for the unified assets in the short-term future.
    • add_asset_raw logic can later be generalized to: if asset is found and can be merged (merge procedure is not EMPTY_WORD) it will call it, otherwise it will abort.
  • Semantically, asset origin checks (for faucet mint and burn) or whether an asset is fungible or non-fungible is now checked against the vault key instead of the asset value.
  • asset_vault::remove_asset takes the ASSET_KEY and ASSET_VALUE to remove from the vault. The reason the value is required is so an asset can be partially removed from the vault, e.g. "remove 30 tokens from the total of 80 tokens in the vault". This can work similarly in the future with assets that are splittable (e.g. fungible assets).
  • faucet::burn currently returns the same ASSET_VALUE that it takes as input. It should either be removed (in line with add_asset_to_note procedure results overhead when calling from Rust #1717) , or return the previous value of the vault. I think the latter makes the most sense as it makes the API strictly more useful. For that reason, I kept the return value so we can more easily change this in the future. The same applies to native_account::remove_asset.
  • Fix procedure signature of mint_fungible_asset. It previously suggested it returned the same asset it took, but it actually returns the merged asset.

Review

The most heavily refactored modules are asset, asset_vault, output_note.

Note that asset.masm will change again when changing layouts of asset keys and values, so a very deep review may not be necessary at this point.

I tried to keep the commits organized by the module that was refactored (and what conceptually was updated as a consequence), so reviewing by commit should be mostly fine.

Migration

Calls to {input_note, active_note, output_note}::get_assets must be updated since the returned memory layout has changed from previous [ASSET] to [ASSET_KEY, ASSET_VALUE].

Potential Follow-Ups

part of #2328

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 WIP :)

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.

LVGTM!

@mmagician
Copy link
Collaborator

@copilot work on the nits from @mmagician 's PR review

Copy link
Contributor

Copilot AI commented Feb 12, 2026

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

Copilot AI and others added 14 commits February 12, 2026 19:30
…it ASSET_PTR constants, rename variables, add test

Co-authored-by: mmagician <8402446+mmagician@users.noreply.github.com>
…logue

Co-authored-by: mmagician <8402446+mmagician@users.noreply.github.com>
Co-authored-by: mmagician <8402446+mmagician@users.noreply.github.com>
Co-authored-by: mmagician <8402446+mmagician@users.noreply.github.com>
Co-authored-by: mmagician <8402446+mmagician@users.noreply.github.com>
refactor: address review nits for asset key/value refactoring
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! I left some comments inline, but pretty much everything could be addressed in follow-up PRs.

# check if the asset is fungible
exec.is_fungible_asset
# => [is_fungible_asset, ASSET]
# => [is_fungible_asset, ASSET_KEY, ASSET_VALUE]
Copy link
Contributor

Choose a reason for hiding this comment

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

This validates key and value separately, but doesn’t check they match. If a caller can pass mismatched key/value, origin checks will use the key and ignore the faucet ID in the value.

Should we assert build_asset_vault_key(ASSET_VALUE) == ASSET_KEY here (or in validate_*) and/or add a test?

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.

6 participants