Skip to content
Merged
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
18 changes: 9 additions & 9 deletions crates/miden-protocol/asm/kernels/transaction/lib/account.masm
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use $kernel::account_delta
use $kernel::account_id
use $kernel::asset_vault
use $kernel::constants
use $kernel::constants::ACCOUNT_PROCEDURE_DATA_LENGTH
use $kernel::constants::EMPTY_SMT_ROOT
use $kernel::constants::STORAGE_SLOT_TYPE_MAP
use $kernel::constants::STORAGE_SLOT_TYPE_VALUE
use $kernel::memory
use miden::core::collections::smt
use miden::core::collections::sorted_array
Expand Down Expand Up @@ -120,9 +123,6 @@ const ACCOUNT_TREE_DEPTH=64
# The number of field elements it takes to store one account storage slot.
const ACCOUNT_STORAGE_SLOT_DATA_LENGTH=8

# The number of field elements it takes to store one account procedure.
const ACCOUNT_PROCEDURE_DATA_LENGTH=4

# The offset of the slot type in the storage slot.
const ACCOUNT_SLOT_TYPE_OFFSET=1

Expand Down Expand Up @@ -538,7 +538,7 @@ pub proc set_item
# => [slot_type, slot_ptr, VALUE]

# assert slot_type is value
exec.constants::get_storage_slot_type_value eq
push.STORAGE_SLOT_TYPE_VALUE eq
assert.err=ERR_ACCOUNT_SETTING_VALUE_ITEM_ON_NON_VALUE_SLOT
# => [slot_ptr, VALUE]

Expand Down Expand Up @@ -632,7 +632,7 @@ pub proc set_map_item
# => [slot_type, slot_ptr, KEY, NEW_VALUE]

# assert slot_type is map
exec.constants::get_storage_slot_type_map eq
push.STORAGE_SLOT_TYPE_MAP eq
assert.err=ERR_ACCOUNT_SETTING_MAP_ITEM_ON_NON_MAP_SLOT
# => [slot_ptr, KEY, NEW_VALUE]

Expand Down Expand Up @@ -1310,7 +1310,7 @@ pub proc insert_new_storage
dup exec.get_storage_slot_type
# => [slot_type, slot_idx]

exec.constants::get_storage_slot_type_map eq
push.STORAGE_SLOT_TYPE_MAP eq
# => [is_map_slot_type, slot_idx]

if.true
Expand Down Expand Up @@ -1354,7 +1354,7 @@ proc insert_and_validate_storage_map

# overwrite the map root with the root of an empty SMT, so we can insert the entries of
# the map into an empty map and then check whether the resulting root matches MAP_ROOT.
exec.constants::get_empty_smt_root
push.EMPTY_SMT_ROOT
dup.8
# => [slot_ptr, EMPTY_SMT_ROOT, MAP_ROOT, slot_ptr]

Expand Down Expand Up @@ -1674,7 +1674,7 @@ proc get_map_item_raw
# => [slot_type, slot_ptr, KEY]

# assert slot_type is map
exec.constants::get_storage_slot_type_map eq
push.STORAGE_SLOT_TYPE_MAP eq
assert.err=ERR_ACCOUNT_READING_MAP_VALUE_FROM_NON_MAP_SLOT
# => [slot_ptr, KEY]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use $kernel::account
use $kernel::asset
use $kernel::asset_vault
use $kernel::constants
use $kernel::constants::STORAGE_SLOT_TYPE_VALUE
use $kernel::link_map
use $kernel::memory
use miden::core::crypto::hashes::rpo256
Expand Down Expand Up @@ -149,7 +149,7 @@ proc update_slot_delta
# => [storage_slot_type, slot_idx, RATE, RATE, PERM]

# check if slot is of type value
exec.constants::get_storage_slot_type_value eq
push.STORAGE_SLOT_TYPE_VALUE eq
# => [is_value_slot_type, slot_idx, RATE, RATE, PERM]

if.true
Expand Down
148 changes: 16 additions & 132 deletions crates/miden-protocol/asm/kernels/transaction/lib/constants.masm
Original file line number Diff line number Diff line change
Expand Up @@ -2,152 +2,36 @@
# =================================================================================================

# The number of elements in a Word
const WORD_SIZE=4
pub const WORD_SIZE = 4

# The maximum number of input values associated with a single note.
const MAX_INPUTS_PER_NOTE=1024
pub const MAX_INPUTS_PER_NOTE = 1024

# The maximum number of assets that can be stored in a single note.
const MAX_ASSETS_PER_NOTE=256
pub const MAX_ASSETS_PER_NOTE = 256

# The maximum number of notes that can be consumed in a single transaction.
const MAX_INPUT_NOTES_PER_TX=1024
pub const MAX_INPUT_NOTES_PER_TX = 1024

# The size of the memory segment allocated to each note.
const NOTE_MEM_SIZE=2048
pub const NOTE_MEM_SIZE = 2048

# The depth of the Merkle tree used to commit to notes produced in a block.
const NOTE_TREE_DEPTH=16
pub const NOTE_TREE_DEPTH = 16

# The maximum number of notes that can be created in a single transaction.
const MAX_OUTPUT_NOTES_PER_TX=1024
pub const MAX_OUTPUT_NOTES_PER_TX = 1024

# TYPES
# =================================================================================================

# Type of storage slot item in the account storage
const STORAGE_SLOT_TYPE_VALUE=0
const STORAGE_SLOT_TYPE_MAP=1
const STORAGE_SLOT_TYPE_ARRAY=2
# The number of field elements per account procedure data entry (procedure MAST root).
pub const ACCOUNT_PROCEDURE_DATA_LENGTH = 4

# PROCEDURES
# TYPES
# =================================================================================================

#! Returns the number of elements in a Word.
#!
#! Inputs: []
#! Outputs: [word_size]
#!
#! Where:
#! - word_size is the number of elements in a Word.
pub proc get_word_size
push.WORD_SIZE
end

#! Returns the max allowed number of input values per note.
#!
#! Inputs: []
#! Outputs: [max_inputs_per_note]
#!
#! Where:
#! - max_inputs_per_note is the max inputs per note.
pub use ::$kernel::util::note::get_max_inputs_per_note

#! Returns the max allowed number of assets per note.
#!
#! Inputs: []
#! Outputs: [max_assets_per_note]
#!
#! Where:
#! - max_assets_per_note is the max assets per note.
pub proc get_max_assets_per_note
push.MAX_ASSETS_PER_NOTE
end

#! Returns the maximum number of notes that can be consumed in a single transaction.
#!
#! Inputs: []
#! Outputs: [max_num_input_notes]
#!
#! Where:
#! - max_num_input_notes is the max number of input notes.
pub proc get_max_num_input_notes
push.MAX_INPUT_NOTES_PER_TX
end

#! Returns the size of the memory segment allocated to each note.
#!
#! Inputs: []
#! Outputs: [note_mem_size]
#!
#! Where:
#! - note_mem_size is the size of the memory segment allocated to each note.
pub proc get_note_mem_size
push.NOTE_MEM_SIZE
end
# Root of an empty Sparse Merkle Tree
pub const EMPTY_SMT_ROOT = [15321474589252129342, 17373224439259377994, 15071539326562317628, 3312677166725950353]

#! Returns the depth of the Merkle tree used to commit to notes produced in a block.
#!
#! Inputs: []
#! Outputs: [note_tree_depth]
#!
#! Where:
#! - note_tree_depth is the depth of the Merkle tree used to commit to notes produced in a block.
pub proc get_note_tree_depth
push.NOTE_TREE_DEPTH
end

#! Returns the maximum number of notes that can be created in a single transaction.
#!
#! Inputs: []
#! Outputs: [max_num_output_notes]
#!
#! Where:
#! - max_num_output_notes is the max number of notes that can be created in a single transaction.
pub proc get_max_num_output_notes
push.MAX_OUTPUT_NOTES_PER_TX
end

#! Returns the root of an empty Sparse Merkle Tree.
#!
#! Inputs: []
#! Outputs: [EMPTY_SMT_ROOT]
#!
#! Where:
#! - EMPTY_SMT_ROOT is the root of an empty Sparse Merkle Tree.
pub proc get_empty_smt_root
push.15321474589252129342.17373224439259377994.15071539326562317628.3312677166725950353
end

#! Returns the type of storage slot value in the account storage.
#!
#! Inputs: []
#! Outputs: [type_storage_value]
#!
#! Where:
#! - type_storage_value is the type of storage slot item in the account storage.
pub proc get_storage_slot_type_value
push.STORAGE_SLOT_TYPE_VALUE
end

#! Returns the type of storage slot map in the account storage.
#!
#! Inputs: []
#! Outputs: [type_storage_map]
#!
#! Where:
#! - type_storage_map is the type of storage slot item in the account storage.
pub proc get_storage_slot_type_map
push.STORAGE_SLOT_TYPE_MAP
end

#! Returns the type of storage slot array in the account storage.
#!
#! Inputs: []
#! Outputs: [type_storage_array]
#!
#! Where:
#! - type_storage_array is the type of storage slot item in the account storage.
pub proc get_storage_slot_type_array
push.STORAGE_SLOT_TYPE_ARRAY
end
# Type of storage slot item in the account storage
pub const STORAGE_SLOT_TYPE_VALUE = 0
pub const STORAGE_SLOT_TYPE_MAP = 1
pub const STORAGE_SLOT_TYPE_ARRAY = 2
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use $kernel::account
use $kernel::account_delta
use $kernel::asset_vault
use $kernel::constants
use $kernel::constants::NOTE_MEM_SIZE
use $kernel::memory
use $kernel::note

Expand Down Expand Up @@ -187,7 +187,7 @@ proc build_output_vault
# => [note_data_ptr, output_note_end_ptr]

# increment output note pointer and check if we should loop again
exec.constants::get_note_mem_size add dup.1 dup.1 neq
push.NOTE_MEM_SIZE add dup.1 dup.1 neq
# => [should_loop, output_note_ptr, output_notes_end_ptr]
end

Expand Down
14 changes: 6 additions & 8 deletions crates/miden-protocol/asm/kernels/transaction/lib/memory.masm
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use $kernel::constants
use $kernel::constants::ACCOUNT_PROCEDURE_DATA_LENGTH
use $kernel::constants::MAX_ASSETS_PER_NOTE
use $kernel::constants::NOTE_MEM_SIZE
use miden::core::mem

# ERRORS
Expand Down Expand Up @@ -166,10 +168,6 @@ const NATIVE_ACCOUNT_DATA_PTR=8192
# The length of the memory interval that the account data occupies.
const ACCOUNT_DATA_LENGTH=8192

# The number of field elements it takes to store one account procedure.
# TODO: Duplicated in account.masm, can we remove that?
const ACCOUNT_PROCEDURE_DATA_LENGTH=4

# The offsets at which the account data is stored relative to the start of the account data segment.
const ACCT_ID_AND_NONCE_OFFSET=0
const ACCT_NONCE_OFFSET=3
Expand Down Expand Up @@ -1513,7 +1511,7 @@ end
#! - idx is the index of the input note.
#! - note_ptr is the memory address of the data segment for the input note with `idx`.
pub proc get_input_note_ptr
exec.constants::get_note_mem_size mul add.INPUT_NOTE_DATA_SECTION_OFFSET
push.NOTE_MEM_SIZE mul add.INPUT_NOTE_DATA_SECTION_OFFSET
end

#! Set the note id of the input note.
Expand Down Expand Up @@ -1834,7 +1832,7 @@ end
#! - i is the index of the output note.
#! - ptr is the memory address of the data segment for output note i.
pub proc get_output_note_ptr
exec.constants::get_note_mem_size mul add.OUTPUT_NOTE_SECTION_OFFSET
push.NOTE_MEM_SIZE mul add.OUTPUT_NOTE_SECTION_OFFSET
end

#! Returns the output note recipient.
Expand Down Expand Up @@ -1922,7 +1920,7 @@ pub proc set_output_note_num_assets
# => [note_ptr + offset, num_assets]

# check note number of assets limit
dup.1 exec.constants::get_max_assets_per_note lt assert.err=ERR_NOTE_NUM_OF_ASSETS_EXCEED_LIMIT
dup.1 push.MAX_ASSETS_PER_NOTE lt assert.err=ERR_NOTE_NUM_OF_ASSETS_EXCEED_LIMIT

mem_store
end
Expand Down
4 changes: 2 additions & 2 deletions crates/miden-protocol/asm/kernels/transaction/lib/note.masm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use miden::core::crypto::hashes::rpo256

use $kernel::constants
use $kernel::constants::NOTE_MEM_SIZE
use $kernel::memory

# ERRORS
Expand Down Expand Up @@ -31,7 +31,7 @@ pub proc increment_active_input_note_ptr
# => [orig_input_note_ptr]

# increment the pointer
exec.constants::get_note_mem_size add
push.NOTE_MEM_SIZE add
# => [active_input_note_ptr]

# set the active input note pointer to the incremented value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use $kernel::account
use $kernel::memory
use $kernel::note
use $kernel::asset
use $kernel::constants
use $kernel::constants::MAX_OUTPUT_NOTES_PER_TX
use miden::core::word

# CONSTANTS
Expand Down Expand Up @@ -372,7 +372,7 @@ proc increment_num_output_notes
# => [note_idx]

# assert that there is space for a new note
dup exec.constants::get_max_num_output_notes lt
dup push.MAX_OUTPUT_NOTES_PER_TX lt
assert.err=ERR_TX_NUMBER_OF_OUTPUT_NOTES_EXCEEDS_LIMIT
# => [note_idx]

Expand Down
Loading
Loading