Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
43 changes: 43 additions & 0 deletions versioned_docs/version-0.14/reference/protocol/asset.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,49 @@ A callback is not invoked in any of these cases:

This means assets with callbacks enabled can still be used even if the faucet has not (yet) registered a callback procedure.

## Encoding

Every native asset occupies two words (64 bytes): an `ASSET_KEY` (vault key) that identifies the asset in an account vault SMT, and an `ASSET_VALUE` that carries the asset payload.

### `ASSET_KEY` / `AssetVaultKey` layout

The vault key is a [`Word`](https://docs.rs/miden-protocol) with this limb order (matching `AssetVaultKey::to_word()` in v0.14):

```text
[
asset_id_suffix, // Felt
asset_id_prefix, // Felt
faucet_id_suffix_and_metadata, // Felt
faucet_id_prefix // Felt
]
```

Where `faucet_id_suffix_and_metadata` packs:

```text
[ faucet_id_suffix (56 bits) | 7 zero bits | callbacks_enabled (1 bit) ]
```

The low byte of the faucet account-id suffix is reserved for metadata (it is zero in a bare faucet id). The least-significant bit of that byte is the [`AssetCallbackFlag`](#callbacks): `0` disabled, `1` enabled.

### Fungible vs non-fungible keys

| Kind | `asset_id_*` limbs | Meaning |
| --- | --- | --- |
| Fungible | both zero | All fungible units from a faucet share one vault leaf and merge by amount. |
| Non-fungible | taken from `DATA_HASH[0..2]` | Each NFT has a distinct key (and therefore a distinct leaf). |

### `ASSET_VALUE` layout

| Kind | Value word |
| --- | --- |
| Fungible | `[amount, 0, 0, 0]` — `amount ≤ 2⁶³−1` |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1: The maximum fungible amount in v0.14.6 is 2⁶³−2³¹, not 2⁶³−1. Could we update this row so it matches FungibleAsset::MAX_AMOUNT and FUNGIBLE_ASSET_MAX_AMOUNT?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch — updated both places (the vault ASSET_VALUE table row and the earlier fungible-asset prose) to 2⁶³−2³¹, matching FungibleAsset::MAX_AMOUNT / FUNGIBLE_ASSET_MAX_AMOUNT (0x7fffffff80000000).

| Non-fungible | full 4-limb `DATA_HASH` of the NFT payload |

### Stdlib helpers

When building assets from arbitrary code (not as the faucet itself), use `miden::protocol::asset::create_fungible_asset` / `create_non_fungible_asset`. Both take an `enable_callbacks` flag so the metadata bit is set explicitly — see [Protocol library](./protocol_library.md#asset-procedures-midenprotocolasset).

## Alternative asset models

:::note
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,4 @@ Asset procedures provide utilities for creating fungible and non-fungible assets
| Procedure | Description | Context |
| -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `create_fungible_asset` | Builds a fungible asset for the specified fungible faucet and amount.<br/><br/>**Inputs:** `[enable_callbacks, faucet_id_suffix, faucet_id_prefix, amount]`<br/>**Outputs:** `[ASSET_KEY, ASSET_VALUE]` | Any |
| `create_non_fungible_asset` | Builds a non-fungible asset for the specified non-fungible faucet and data hash.<br/><br/>**Inputs:** `[faucet_id_suffix, faucet_id_prefix, DATA_HASH]`<br/>**Outputs:** `[ASSET_KEY, ASSET_VALUE]` | Any |
| `create_non_fungible_asset` | Builds a non-fungible asset for the specified non-fungible faucet and data hash.<br/><br/>**Inputs:** `[enable_callbacks, faucet_id_suffix, faucet_id_prefix, DATA_HASH]`<br/>**Outputs:** `[ASSET_KEY, ASSET_VALUE]` | Any |