Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Changes
- Added validation of leaf type on CLAIM note processing to prevent message leaves from being processed as asset claims ([#2730](https://github.com/0xMiden/protocol/pull/2730)).

- [BREAKING] Renamed `native_asset_id` to `fee_faucet_id` ([#2718](https://github.com/0xMiden/protocol/pull/2718)).
- Added `AssetAmount` wrapper type for validated fungible asset amounts ([#2721](https://github.com/0xMiden/protocol/pull/2721)).
- [BREAKING] Renamed `ProvenBatch::new` to `new_unchecked` ([#2687](https://github.com/0xMiden/miden-base/issues/2687)).
- Added `ShortCapitalString` type and related `TokenSymbol` and `RoleSymbol` types ([#2690](https://github.com/0xMiden/protocol/pull/2690)).
Expand Down
56 changes: 28 additions & 28 deletions crates/miden-protocol/asm/kernels/transaction/lib/epilogue.masm
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ end
#! Outputs: [fee_amount]
#!
#! Where:
#! - fee_amount is the computed fee amount of the transaction in the native asset.
#! - fee_amount is the computed fee amount of the transaction in the fee asset.
proc compute_fee
# get the number of cycles the transaction has taken to execute up this point
clk
Expand All @@ -276,27 +276,27 @@ proc compute_fee
# => [verification_cost]
end

#! Creates the fee asset with the provided fee amount and the native asset ID of the transaction's
#! Creates the fee asset with the provided fee amount and the fee faucet ID of the transaction's
#! reference block as the faucet ID.
#!
#! Inputs: [fee_amount]
#! Outputs: [FEE_ASSET_KEY, FEE_ASSET_VALUE]
#!
#! Where:
#! - fee_amount is the computed fee amount of the transaction in the native asset.
#! - fee_amount is the computed fee amount of the transaction in the fee asset.
#! - FEE_ASSET_KEY is the asset vault key of the fee asset.
#! - FEE_ASSET_VALUE is the fungible asset with amount set to fee_amount and the faucet ID set to
#! the native asset.
proc create_native_fee_asset
exec.memory::get_native_asset_id
# => [native_asset_id_suffix, native_asset_id_prefix, fee_amount]
#! the fee faucet.
proc create_fee_asset
exec.memory::get_fee_faucet_id
# => [fee_faucet_id_suffix, fee_faucet_id_prefix, fee_amount]

# assume the fee asset does not have callbacks
# this should be addressed more holistically with a fee construction refactor
push.0
# => [enable_callbacks, native_asset_id_suffix, native_asset_id_prefix, fee_amount]
# => [enable_callbacks, fee_faucet_id_suffix, fee_faucet_id_prefix, fee_amount]

# SAFETY: native asset ID should be fungible and amount should not be exceeded
# SAFETY: fee faucet ID should be fungible and amount should not be exceeded
exec.fungible_asset::create_unchecked
# => [FEE_ASSET_KEY, FEE_ASSET_VALUE]
end
Expand All @@ -309,12 +309,12 @@ end
#! check. That's okay, because the logic is entirely determined by the transaction kernel.
#!
#! Inputs: []
#! Outputs: [native_asset_id_suffix, native_asset_id_prefix, fee_amount]
#! Outputs: [fee_faucet_id_suffix, fee_faucet_id_prefix, fee_amount]
#!
#! Where:
#! - fee_amount is the computed fee amount of the transaction in the native asset.
#! - native_asset_id_{prefix,suffix} are the prefix and suffix felts of the faucet that issues the
#! native asset.
#! - fee_amount is the computed fee amount of the transaction in the fee asset.
#! - fee_faucet_id_{prefix,suffix} are the prefix and suffix felts of the faucet that issues the
#! fee asset.
#!
#! Panics if:
#! - the account vault contains less than the computed fee.
Expand All @@ -323,19 +323,19 @@ proc compute_and_remove_fee
exec.compute_fee dup
# => [fee_amount, fee_amount]

# build the native asset from the fee amount
exec.create_native_fee_asset
# build the fee asset from the fee amount
exec.create_fee_asset
# => [FEE_ASSET_KEY, FEE_ASSET_VALUE, fee_amount]

emit.EPILOGUE_BEFORE_TX_FEE_REMOVED_FROM_ACCOUNT_EVENT
# => [FEE_ASSET_KEY, FEE_ASSET_VALUE, fee_amount]

# prepare the return value
exec.asset::key_to_faucet_id
# => [native_asset_id_suffix, native_asset_id_prefix, FEE_ASSET_KEY, FEE_ASSET_VALUE, fee_amount]
# => [fee_faucet_id_suffix, fee_faucet_id_prefix, FEE_ASSET_KEY, FEE_ASSET_VALUE, fee_amount]

movdn.9 movdn.9
# => [FEE_ASSET_KEY, FEE_ASSET_VALUE, native_asset_id_suffix, native_asset_id_prefix, fee_amount]
# => [FEE_ASSET_KEY, FEE_ASSET_VALUE, fee_faucet_id_suffix, fee_faucet_id_prefix, fee_amount]

# remove the fee from the native account's vault
# note that this deliberately does not use account::remove_asset_from_vault, because that
Expand All @@ -347,11 +347,11 @@ proc compute_and_remove_fee

# fetch the vault root ptr
exec.memory::get_account_vault_root_ptr movdn.8
# => [FEE_ASSET_KEY, FEE_ASSET_VALUE, account_vault_root_ptr, native_asset_id_suffix, native_asset_id_prefix, fee_amount]
# => [FEE_ASSET_KEY, FEE_ASSET_VALUE, account_vault_root_ptr, fee_faucet_id_suffix, fee_faucet_id_prefix, fee_amount]

# remove the asset from the account vault
exec.asset_vault::remove_fungible_asset dropw
# => [native_asset_id_suffix, native_asset_id_prefix, fee_amount]
# => [fee_faucet_id_suffix, fee_faucet_id_prefix, fee_amount]
end

# TRANSACTION EPILOGUE PROCEDURE
Expand All @@ -373,16 +373,16 @@ end
#! Inputs: []
#! Outputs: [
#! OUTPUT_NOTES_COMMITMENT, ACCOUNT_UPDATE_COMMITMENT,
#! native_asset_id_suffix, native_asset_id_prefix, fee_amount, tx_expiration_block_num
#! fee_faucet_id_suffix, fee_faucet_id_prefix, fee_amount, tx_expiration_block_num
#! ]
#!
#! Where:
#! - OUTPUT_NOTES_COMMITMENT is the commitment of the output notes.
#! - ACCOUNT_UPDATE_COMMITMENT is the hash of the the final account commitment and account
#! delta commitment.
#! - fee_amount is the computed fee amount of the transaction denominated in the native asset.
#! - native_asset_id_{prefix,suffix} are the prefix and suffix felts of the faucet that issues the
#! native asset.
#! - fee_amount is the computed fee amount of the transaction denominated in the fee asset.
#! - fee_faucet_id_{prefix,suffix} are the prefix and suffix felts of the faucet that issues the
#! fee asset.
#! - tx_expiration_block_num is the transaction expiration block number.
#!
#! Locals:
Expand Down Expand Up @@ -471,11 +471,11 @@ pub proc finalize_transaction
# ------ Compute fees ------

exec.compute_and_remove_fee
# => [native_asset_id_suffix, native_asset_id_prefix, fee_amount]
# => [fee_faucet_id_suffix, fee_faucet_id_prefix, fee_amount]

# pad to word size so we can store the info as a word
push.0 movdn.3
# => [native_asset_id_suffix, native_asset_id_prefix, fee_amount, 0]
# => [fee_faucet_id_suffix, fee_faucet_id_prefix, fee_amount, 0]

# store fee info in local memory
loc_storew_le.4 dropw
Expand Down Expand Up @@ -521,14 +521,14 @@ pub proc finalize_transaction

# load fee asset from local
padw loc_loadw_le.4 swapw
# => [ACCOUNT_UPDATE_COMMITMENT, [native_asset_id_suffix, native_asset_id_prefix, fee_amount, 0]]
# => [ACCOUNT_UPDATE_COMMITMENT, [fee_faucet_id_suffix, fee_faucet_id_prefix, fee_amount, 0]]

# replace 0 with expiration block num
exec.memory::get_expiration_block_num swap.8 drop
# => [ACCOUNT_UPDATE_COMMITMENT, [native_asset_id_suffix, native_asset_id_prefix, fee_amount, tx_expiration_block_num]]
# => [ACCOUNT_UPDATE_COMMITMENT, [fee_faucet_id_suffix, fee_faucet_id_prefix, fee_amount, tx_expiration_block_num]]

# load output notes commitment from local
padw loc_loadw_le.0
# => [OUTPUT_NOTES_COMMITMENT, ACCOUNT_UPDATE_COMMITMENT,
# native_asset_id_suffix, native_asset_id_prefix, fee_amount, tx_expiration_block_num]
# fee_faucet_id_suffix, fee_faucet_id_prefix, fee_amount, tx_expiration_block_num]
end
24 changes: 12 additions & 12 deletions crates/miden-protocol/asm/kernels/transaction/lib/memory.masm
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,16 @@ const VALIDATOR_KEY_COMMITMENT_PTR=824
const BLOCK_METADATA_PTR=828

# The memory address at which the fee parameters are stored. These occupy a double word.
# [0, verification_base_fee, native_asset_id_suffix, native_asset_id_prefix]
# [0, verification_base_fee, fee_faucet_id_suffix, fee_faucet_id_prefix]
# [0, 0, 0, 0]
const FEE_PARAMETERS_PTR=832

# The memory address at which the verification base fee is stored.
const VERIFICATION_BASE_FEE_PTR = FEE_PARAMETERS_PTR + 1

# The memory address at which the native asset ID is stored.
const NATIVE_ASSET_ID_SUFFIX_PTR = FEE_PARAMETERS_PTR + 2
const NATIVE_ASSET_ID_PREFIX_PTR = FEE_PARAMETERS_PTR + 3
# The memory address at which the fee faucet ID is stored.
const FEE_FAUCET_ID_SUFFIX_PTR = FEE_PARAMETERS_PTR + 2
const FEE_FAUCET_ID_PREFIX_PTR = FEE_PARAMETERS_PTR + 3

# The memory address at which the note root is stored
const NOTE_ROOT_PTR=840
Expand Down Expand Up @@ -766,18 +766,18 @@ pub proc get_blk_timestamp
mem_load.BLOCK_METADATA_TIMESTAMP_PTR
end

#! Returns the faucet ID of the native asset as defined in the transaction's reference block.
#! Returns the faucet ID of the fee asset as defined in the transaction's reference block.
#!
#! Inputs: []
#! Outputs: [native_asset_id_suffix, native_asset_id_prefix]
#! Outputs: [fee_faucet_id_suffix, fee_faucet_id_prefix]
#!
#! Where:
#! - native_asset_id_{prefix,suffix} are the prefix and suffix felts of the faucet ID that defines
#! the native asset.
pub proc get_native_asset_id
mem_load.NATIVE_ASSET_ID_PREFIX_PTR
mem_load.NATIVE_ASSET_ID_SUFFIX_PTR
# => [native_asset_id_suffix, native_asset_id_prefix]
#! - fee_faucet_id_{prefix,suffix} are the prefix and suffix felts of the faucet ID that defines
#! the fee asset.
pub proc get_fee_faucet_id
mem_load.FEE_FAUCET_ID_PREFIX_PTR
mem_load.FEE_FAUCET_ID_SUFFIX_PTR
# => [fee_faucet_id_suffix, fee_faucet_id_prefix]
end

#! Returns the verification base fee from the transaction's reference block.
Expand Down
10 changes: 5 additions & 5 deletions crates/miden-protocol/asm/kernels/transaction/lib/prologue.masm
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const ERR_PROLOGUE_GLOBAL_INPUTS_PROVIDED_DO_NOT_MATCH_BLOCK_COMMITMENT="the pro

const ERR_PROLOGUE_GLOBAL_INPUTS_PROVIDED_DO_NOT_MATCH_BLOCK_NUMBER_COMMITMENT="the provided global inputs do not match the block number commitment"

const ERR_PROLOGUE_NATIVE_ASSET_ID_IS_NOT_FUNGIBLE="native asset account ID in reference block is not of type fungible faucet"
const ERR_PROLOGUE_FEE_FAUCET_ID_IS_NOT_FUNGIBLE="fee faucet account ID in reference block is not of type fungible faucet"

const ERR_PROLOGUE_VERIFICATION_BASE_FEE_MUST_BE_U32="verification base fee must fit into a u32"

Expand Down Expand Up @@ -170,7 +170,7 @@ end
#! TX_KERNEL_COMMITMENT
#! VALIDATOR_KEY_COMMITMENT,
#! [block_num, version, timestamp, 0],
#! [0, verification_base_fee, native_asset_id_suffix, native_asset_id_prefix],
#! [0, verification_base_fee, fee_faucet_id_suffix, fee_faucet_id_prefix],
#! [0, 0, 0, 0],
#! NOTE_ROOT,
#! ]
Expand All @@ -189,8 +189,8 @@ end
#! - block_num is the reference block number.
#! - version is the current protocol version.
#! - timestamp is the current timestamp.
#! - native_asset_id_{prefix, suffix} are the prefix and suffix felts of the faucet ID that defines
#! the native asset.
#! - fee_faucet_id_{prefix, suffix} are the prefix and suffix felts of the faucet ID that defines
#! the fee asset.
#! - verification_base_fee is the base fee capturing the cost for the verification of a
#! transaction.
#! - NOTE_ROOT is the root of the tree with all notes created in the block.
Expand Down Expand Up @@ -1089,7 +1089,7 @@ end
#! TX_KERNEL_COMMITMENT
#! VALIDATOR_KEY_COMMITMENT,
#! [block_num, version, timestamp, 0],
#! [0, verification_base_fee, native_asset_id_suffix, native_asset_id_prefix]
#! [0, verification_base_fee, fee_faucet_id_suffix, fee_faucet_id_prefix]
#! [0, 0, 0, 0]
#! NOTE_ROOT,
#! kernel_version
Expand Down
12 changes: 6 additions & 6 deletions crates/miden-protocol/asm/kernels/transaction/main.masm
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const EPILOGUE_END_EVENT=event("miden::protocol::tx::epilogue_end")
#! ]
#! Outputs: [
#! OUTPUT_NOTES_COMMITMENT, ACCOUNT_UPDATE_COMMITMENT,
#! native_asset_id_suffix, native_asset_id_prefix, fee_amount, tx_expiration_block_num,
#! fee_faucet_id_suffix, fee_faucet_id_prefix, fee_amount, tx_expiration_block_num,
#! pad(4)
#! ]
#!
Expand All @@ -69,9 +69,9 @@ const EPILOGUE_END_EVENT=event("miden::protocol::tx::epilogue_end")
#! - OUTPUT_NOTES_COMMITMENT is the commitment to the notes created by the transaction.
#! - ACCOUNT_UPDATE_COMMITMENT is the hash of the the final account commitment and account
#! delta commitment.
#! - fee_amount is the computed fee amount of the transaction denominated in the native asset.
#! - native_asset_id_{prefix,suffix} are the prefix and suffix felts of the faucet that issues the
#! native asset.
#! - fee_amount is the computed fee amount of the transaction denominated in the fee asset.
#! - fee_faucet_id_{prefix,suffix} are the prefix and suffix felts of the faucet that issues the
#! fee asset.
#! - tx_expiration_block_num is the transaction expiration block number.
@locals(1)
proc main
Expand Down Expand Up @@ -175,12 +175,12 @@ proc main
# execute the transaction epilogue
exec.epilogue::finalize_transaction
# => [OUTPUT_NOTES_COMMITMENT, ACCOUNT_UPDATE_COMMITMENT,
# native_asset_id_suffix, native_asset_id_prefix, fee_amount, tx_expiration_block_num, pad(16)]
# fee_faucet_id_suffix, fee_faucet_id_prefix, fee_amount, tx_expiration_block_num, pad(16)]

# truncate the stack to contain 16 elements in total
repeat.3 movupw.3 dropw end
# => [OUTPUT_NOTES_COMMITMENT, ACCOUNT_UPDATE_COMMITMENT,
# native_asset_id_suffix, native_asset_id_prefix, fee_amount, tx_expiration_block_num, pad(4)]
# fee_faucet_id_suffix, fee_faucet_id_prefix, fee_amount, tx_expiration_block_num, pad(4)]

emit.EPILOGUE_END_EVENT
end
Expand Down
40 changes: 20 additions & 20 deletions crates/miden-protocol/src/block/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use crate::{Felt, Hasher, Word, ZERO};
/// block.
/// - `tx_kernel_commitment` a commitment to all transaction kernels supported by this block.
/// - `validator_key` is the public key of the validator that is expected to sign the block.
/// - `fee_parameters` are the parameters defining the base fees and the native asset, see
/// - `fee_parameters` are the parameters defining the base fees and the fee faucet, see
/// [`FeeParameters`] for more details.
/// - `timestamp` is the time when the block was created, in seconds since UNIX epoch. Current
/// representation is sufficient to represent time up to year 2106.
Expand Down Expand Up @@ -218,7 +218,7 @@ impl BlockHeader {
/// The sub commitment is computed as a sequential hash of the following fields:
/// `prev_block_commitment`, `chain_commitment`, `account_root`, `nullifier_root`, `note_root`,
/// `tx_commitment`, `tx_kernel_commitment`, `validator_key_commitment`, `version`, `timestamp`,
/// `block_num`, `native_asset_id`, `verification_base_fee` (all fields except the `note_root`).
/// `block_num`, `fee_faucet_id`, `verification_base_fee` (all fields except the `note_root`).
#[allow(clippy::too_many_arguments)]
fn compute_sub_commitment(
version: u32,
Expand All @@ -245,8 +245,8 @@ impl BlockHeader {
elements.extend([
ZERO,
Felt::from(fee_parameters.verification_base_fee()),
fee_parameters.native_asset_id().suffix(),
fee_parameters.native_asset_id().prefix().as_felt(),
fee_parameters.fee_faucet_id().suffix(),
fee_parameters.fee_faucet_id().prefix().as_felt(),
]);
elements.extend([ZERO, ZERO, ZERO, ZERO]);
Hasher::hash_elements(&elements)
Expand Down Expand Up @@ -332,8 +332,8 @@ impl Deserializable for BlockHeader {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FeeParameters {
/// The [`AccountId`] of the fungible faucet whose assets are accepted for fee payments in the
/// transaction kernel, or in other words, the native asset of the blockchain.
native_asset_id: AccountId,
/// transaction kernel, or in other words, the fee faucet of the blockchain.
fee_faucet_id: AccountId,
/// The base fee (in base units) capturing the cost for the verification of a transaction.
verification_base_fee: u32,
}
Expand All @@ -347,24 +347,24 @@ impl FeeParameters {
/// # Errors
///
/// Returns an error if:
/// - the provided native asset ID is not a fungible faucet account ID.
pub fn new(native_asset_id: AccountId, verification_base_fee: u32) -> Result<Self, FeeError> {
if !matches!(native_asset_id.account_type(), AccountType::FungibleFaucet) {
return Err(FeeError::NativeAssetIdNotFungible {
account_type: native_asset_id.account_type(),
/// - the provided fee faucet ID is not a fungible faucet account ID.
pub fn new(fee_faucet_id: AccountId, verification_base_fee: u32) -> Result<Self, FeeError> {
if !matches!(fee_faucet_id.account_type(), AccountType::FungibleFaucet) {
return Err(FeeError::FeeFaucetIdNotFungible {
account_type: fee_faucet_id.account_type(),
});
}

Ok(Self { native_asset_id, verification_base_fee })
Ok(Self { fee_faucet_id, verification_base_fee })
}

// PUBLIC ACCESSORS
// --------------------------------------------------------------------------------------------

/// Returns the [`AccountId`] of the faucet whose assets are accepted for fee payments in the
/// transaction kernel, or in other words, the native asset of the blockchain.
pub fn native_asset_id(&self) -> AccountId {
self.native_asset_id
/// transaction kernel, or in other words, the fee faucet of the blockchain.
pub fn fee_faucet_id(&self) -> AccountId {
self.fee_faucet_id
}

/// Returns the base fee capturing the cost for the verification of a transaction.
Expand All @@ -378,17 +378,17 @@ impl FeeParameters {

impl Serializable for FeeParameters {
fn write_into<W: ByteWriter>(&self, target: &mut W) {
self.native_asset_id.write_into(target);
self.fee_faucet_id.write_into(target);
self.verification_base_fee.write_into(target);
}
}

impl Deserializable for FeeParameters {
fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
let native_asset_id = source.read()?;
let fee_faucet_id = source.read()?;
let verification_base_fee = source.read()?;

Self::new(native_asset_id, verification_base_fee)
Self::new(fee_faucet_id, verification_base_fee)
.map_err(|err| DeserializationError::InvalidValue(err.to_string()))
}
}
Expand Down Expand Up @@ -426,11 +426,11 @@ mod tests {
/// Tests that the fee parameters constructor fails when the provided account ID is not a
/// fungible faucet.
#[test]
fn fee_parameters_fail_when_native_asset_is_not_fungible() {
fn fee_parameters_fail_when_fee_faucet_is_not_fungible() {
assert_matches!(
FeeParameters::new(ACCOUNT_ID_PUBLIC_NON_FUNGIBLE_FAUCET.try_into().unwrap(), 0)
.unwrap_err(),
FeeError::NativeAssetIdNotFungible { .. }
FeeError::FeeFaucetIdNotFungible { .. }
);
}
}
Loading
Loading