Skip to content

Commit e062f75

Browse files
feat:import constants directly instead of getter procedures (#2221)
1 parent 5ae7b8a commit e062f75

11 files changed

Lines changed: 61 additions & 192 deletions

File tree

‎crates/miden-protocol/asm/kernels/transaction/lib/account.masm‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use $kernel::account_delta
22
use $kernel::account_id
33
use $kernel::asset_vault
4-
use $kernel::constants
4+
use $kernel::constants::ACCOUNT_PROCEDURE_DATA_LENGTH
5+
use $kernel::constants::EMPTY_SMT_ROOT
6+
use $kernel::constants::STORAGE_SLOT_TYPE_MAP
7+
use $kernel::constants::STORAGE_SLOT_TYPE_VALUE
58
use $kernel::memory
69
use miden::core::collections::smt
710
use miden::core::collections::sorted_array
@@ -120,9 +123,6 @@ const ACCOUNT_TREE_DEPTH=64
120123
# The number of field elements it takes to store one account storage slot.
121124
const ACCOUNT_STORAGE_SLOT_DATA_LENGTH=8
122125

123-
# The number of field elements it takes to store one account procedure.
124-
const ACCOUNT_PROCEDURE_DATA_LENGTH=4
125-
126126
# The offset of the slot type in the storage slot.
127127
const ACCOUNT_SLOT_TYPE_OFFSET=1
128128

@@ -538,7 +538,7 @@ pub proc set_item
538538
# => [slot_type, slot_ptr, VALUE]
539539

540540
# assert slot_type is value
541-
exec.constants::get_storage_slot_type_value eq
541+
push.STORAGE_SLOT_TYPE_VALUE eq
542542
assert.err=ERR_ACCOUNT_SETTING_VALUE_ITEM_ON_NON_VALUE_SLOT
543543
# => [slot_ptr, VALUE]
544544

@@ -632,7 +632,7 @@ pub proc set_map_item
632632
# => [slot_type, slot_ptr, KEY, NEW_VALUE]
633633

634634
# assert slot_type is map
635-
exec.constants::get_storage_slot_type_map eq
635+
push.STORAGE_SLOT_TYPE_MAP eq
636636
assert.err=ERR_ACCOUNT_SETTING_MAP_ITEM_ON_NON_MAP_SLOT
637637
# => [slot_ptr, KEY, NEW_VALUE]
638638

@@ -1310,7 +1310,7 @@ pub proc insert_new_storage
13101310
dup exec.get_storage_slot_type
13111311
# => [slot_type, slot_idx]
13121312

1313-
exec.constants::get_storage_slot_type_map eq
1313+
push.STORAGE_SLOT_TYPE_MAP eq
13141314
# => [is_map_slot_type, slot_idx]
13151315

13161316
if.true
@@ -1354,7 +1354,7 @@ proc insert_and_validate_storage_map
13541354

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

@@ -1674,7 +1674,7 @@ proc get_map_item_raw
16741674
# => [slot_type, slot_ptr, KEY]
16751675

16761676
# assert slot_type is map
1677-
exec.constants::get_storage_slot_type_map eq
1677+
push.STORAGE_SLOT_TYPE_MAP eq
16781678
assert.err=ERR_ACCOUNT_READING_MAP_VALUE_FROM_NON_MAP_SLOT
16791679
# => [slot_ptr, KEY]
16801680

‎crates/miden-protocol/asm/kernels/transaction/lib/account_delta.masm‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use $kernel::account
22
use $kernel::asset
33
use $kernel::asset_vault
4-
use $kernel::constants
4+
use $kernel::constants::STORAGE_SLOT_TYPE_VALUE
55
use $kernel::link_map
66
use $kernel::memory
77
use miden::core::crypto::hashes::rpo256
@@ -149,7 +149,7 @@ proc update_slot_delta
149149
# => [storage_slot_type, slot_idx, RATE, RATE, PERM]
150150

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

155155
if.true

‎crates/miden-protocol/asm/kernels/transaction/lib/constants.masm‎

Lines changed: 16 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -2,152 +2,36 @@
22
# =================================================================================================
33

44
# The number of elements in a Word
5-
const WORD_SIZE=4
5+
pub const WORD_SIZE = 4
66

77
# The maximum number of input values associated with a single note.
8-
const MAX_INPUTS_PER_NOTE=1024
8+
pub const MAX_INPUTS_PER_NOTE = 1024
99

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

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

1616
# The size of the memory segment allocated to each note.
17-
const NOTE_MEM_SIZE=2048
17+
pub const NOTE_MEM_SIZE = 2048
1818

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

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

25-
# TYPES
26-
# =================================================================================================
27-
28-
# Type of storage slot item in the account storage
29-
const STORAGE_SLOT_TYPE_VALUE=0
30-
const STORAGE_SLOT_TYPE_MAP=1
31-
const STORAGE_SLOT_TYPE_ARRAY=2
25+
# The number of field elements per account procedure data entry (procedure MAST root).
26+
pub const ACCOUNT_PROCEDURE_DATA_LENGTH = 4
3227

33-
# PROCEDURES
28+
# TYPES
3429
# =================================================================================================
3530

36-
#! Returns the number of elements in a Word.
37-
#!
38-
#! Inputs: []
39-
#! Outputs: [word_size]
40-
#!
41-
#! Where:
42-
#! - word_size is the number of elements in a Word.
43-
pub proc get_word_size
44-
push.WORD_SIZE
45-
end
46-
47-
#! Returns the max allowed number of input values per note.
48-
#!
49-
#! Inputs: []
50-
#! Outputs: [max_inputs_per_note]
51-
#!
52-
#! Where:
53-
#! - max_inputs_per_note is the max inputs per note.
54-
pub use ::$kernel::util::note::get_max_inputs_per_note
55-
56-
#! Returns the max allowed number of assets per note.
57-
#!
58-
#! Inputs: []
59-
#! Outputs: [max_assets_per_note]
60-
#!
61-
#! Where:
62-
#! - max_assets_per_note is the max assets per note.
63-
pub proc get_max_assets_per_note
64-
push.MAX_ASSETS_PER_NOTE
65-
end
66-
67-
#! Returns the maximum number of notes that can be consumed in a single transaction.
68-
#!
69-
#! Inputs: []
70-
#! Outputs: [max_num_input_notes]
71-
#!
72-
#! Where:
73-
#! - max_num_input_notes is the max number of input notes.
74-
pub proc get_max_num_input_notes
75-
push.MAX_INPUT_NOTES_PER_TX
76-
end
77-
78-
#! Returns the size of the memory segment allocated to each note.
79-
#!
80-
#! Inputs: []
81-
#! Outputs: [note_mem_size]
82-
#!
83-
#! Where:
84-
#! - note_mem_size is the size of the memory segment allocated to each note.
85-
pub proc get_note_mem_size
86-
push.NOTE_MEM_SIZE
87-
end
31+
# Root of an empty Sparse Merkle Tree
32+
pub const EMPTY_SMT_ROOT = [15321474589252129342, 17373224439259377994, 15071539326562317628, 3312677166725950353]
8833

89-
#! Returns the depth of the Merkle tree used to commit to notes produced in a block.
90-
#!
91-
#! Inputs: []
92-
#! Outputs: [note_tree_depth]
93-
#!
94-
#! Where:
95-
#! - note_tree_depth is the depth of the Merkle tree used to commit to notes produced in a block.
96-
pub proc get_note_tree_depth
97-
push.NOTE_TREE_DEPTH
98-
end
99-
100-
#! Returns the maximum number of notes that can be created in a single transaction.
101-
#!
102-
#! Inputs: []
103-
#! Outputs: [max_num_output_notes]
104-
#!
105-
#! Where:
106-
#! - max_num_output_notes is the max number of notes that can be created in a single transaction.
107-
pub proc get_max_num_output_notes
108-
push.MAX_OUTPUT_NOTES_PER_TX
109-
end
110-
111-
#! Returns the root of an empty Sparse Merkle Tree.
112-
#!
113-
#! Inputs: []
114-
#! Outputs: [EMPTY_SMT_ROOT]
115-
#!
116-
#! Where:
117-
#! - EMPTY_SMT_ROOT is the root of an empty Sparse Merkle Tree.
118-
pub proc get_empty_smt_root
119-
push.15321474589252129342.17373224439259377994.15071539326562317628.3312677166725950353
120-
end
121-
122-
#! Returns the type of storage slot value in the account storage.
123-
#!
124-
#! Inputs: []
125-
#! Outputs: [type_storage_value]
126-
#!
127-
#! Where:
128-
#! - type_storage_value is the type of storage slot item in the account storage.
129-
pub proc get_storage_slot_type_value
130-
push.STORAGE_SLOT_TYPE_VALUE
131-
end
132-
133-
#! Returns the type of storage slot map in the account storage.
134-
#!
135-
#! Inputs: []
136-
#! Outputs: [type_storage_map]
137-
#!
138-
#! Where:
139-
#! - type_storage_map is the type of storage slot item in the account storage.
140-
pub proc get_storage_slot_type_map
141-
push.STORAGE_SLOT_TYPE_MAP
142-
end
143-
144-
#! Returns the type of storage slot array in the account storage.
145-
#!
146-
#! Inputs: []
147-
#! Outputs: [type_storage_array]
148-
#!
149-
#! Where:
150-
#! - type_storage_array is the type of storage slot item in the account storage.
151-
pub proc get_storage_slot_type_array
152-
push.STORAGE_SLOT_TYPE_ARRAY
153-
end
34+
# Type of storage slot item in the account storage
35+
pub const STORAGE_SLOT_TYPE_VALUE = 0
36+
pub const STORAGE_SLOT_TYPE_MAP = 1
37+
pub const STORAGE_SLOT_TYPE_ARRAY = 2

‎crates/miden-protocol/asm/kernels/transaction/lib/epilogue.masm‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use $kernel::account
22
use $kernel::account_delta
33
use $kernel::asset_vault
4-
use $kernel::constants
4+
use $kernel::constants::NOTE_MEM_SIZE
55
use $kernel::memory
66
use $kernel::note
77

@@ -187,7 +187,7 @@ proc build_output_vault
187187
# => [note_data_ptr, output_note_end_ptr]
188188

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

‎crates/miden-protocol/asm/kernels/transaction/lib/memory.masm‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use $kernel::constants
1+
use $kernel::constants::ACCOUNT_PROCEDURE_DATA_LENGTH
2+
use $kernel::constants::MAX_ASSETS_PER_NOTE
3+
use $kernel::constants::NOTE_MEM_SIZE
24
use miden::core::mem
35

46
# ERRORS
@@ -166,10 +168,6 @@ const NATIVE_ACCOUNT_DATA_PTR=8192
166168
# The length of the memory interval that the account data occupies.
167169
const ACCOUNT_DATA_LENGTH=8192
168170

169-
# The number of field elements it takes to store one account procedure.
170-
# TODO: Duplicated in account.masm, can we remove that?
171-
const ACCOUNT_PROCEDURE_DATA_LENGTH=4
172-
173171
# The offsets at which the account data is stored relative to the start of the account data segment.
174172
const ACCT_ID_AND_NONCE_OFFSET=0
175173
const ACCT_NONCE_OFFSET=3
@@ -1513,7 +1511,7 @@ end
15131511
#! - idx is the index of the input note.
15141512
#! - note_ptr is the memory address of the data segment for the input note with `idx`.
15151513
pub proc get_input_note_ptr
1516-
exec.constants::get_note_mem_size mul add.INPUT_NOTE_DATA_SECTION_OFFSET
1514+
push.NOTE_MEM_SIZE mul add.INPUT_NOTE_DATA_SECTION_OFFSET
15171515
end
15181516

15191517
#! Set the note id of the input note.
@@ -1834,7 +1832,7 @@ end
18341832
#! - i is the index of the output note.
18351833
#! - ptr is the memory address of the data segment for output note i.
18361834
pub proc get_output_note_ptr
1837-
exec.constants::get_note_mem_size mul add.OUTPUT_NOTE_SECTION_OFFSET
1835+
push.NOTE_MEM_SIZE mul add.OUTPUT_NOTE_SECTION_OFFSET
18381836
end
18391837

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

19241922
# check note number of assets limit
1925-
dup.1 exec.constants::get_max_assets_per_note lt assert.err=ERR_NOTE_NUM_OF_ASSETS_EXCEED_LIMIT
1923+
dup.1 push.MAX_ASSETS_PER_NOTE lt assert.err=ERR_NOTE_NUM_OF_ASSETS_EXCEED_LIMIT
19261924

19271925
mem_store
19281926
end

‎crates/miden-protocol/asm/kernels/transaction/lib/note.masm‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use miden::core::crypto::hashes::rpo256
22

3-
use $kernel::constants
3+
use $kernel::constants::NOTE_MEM_SIZE
44
use $kernel::memory
55

66
# ERRORS
@@ -31,7 +31,7 @@ pub proc increment_active_input_note_ptr
3131
# => [orig_input_note_ptr]
3232

3333
# increment the pointer
34-
exec.constants::get_note_mem_size add
34+
push.NOTE_MEM_SIZE add
3535
# => [active_input_note_ptr]
3636

3737
# set the active input note pointer to the incremented value

‎crates/miden-protocol/asm/kernels/transaction/lib/output_note.masm‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use $kernel::account
22
use $kernel::memory
33
use $kernel::note
44
use $kernel::asset
5-
use $kernel::constants
5+
use $kernel::constants::MAX_OUTPUT_NOTES_PER_TX
66
use miden::core::word
77

88
# CONSTANTS
@@ -372,7 +372,7 @@ proc increment_num_output_notes
372372
# => [note_idx]
373373

374374
# assert that there is space for a new note
375-
dup exec.constants::get_max_num_output_notes lt
375+
dup push.MAX_OUTPUT_NOTES_PER_TX lt
376376
assert.err=ERR_TX_NUMBER_OF_OUTPUT_NOTES_EXCEEDS_LIMIT
377377
# => [note_idx]
378378

0 commit comments

Comments
 (0)