@aztec/constants 0.0.1-commit.993d240 → 0.0.1-commit.9a89641

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/constants.ts CHANGED
@@ -4,14 +4,38 @@ import { Fr } from '@aztec/foundation/curves/bn254';
4
4
  // Re-export L2 block number constants with proper BlockNumber type
5
5
  // Note: The generated constants are plain numbers, but we provide typed versions here
6
6
  import {
7
+ DA_GAS_PER_FIELD,
7
8
  GENESIS_BLOCK_HEADER_HASH as GENESIS_BLOCK_HEADER_HASH_BIGINT,
8
9
  INITIAL_CHECKPOINT_NUMBER as INITIAL_CHECKPOINT_NUM_RAW,
9
10
  INITIAL_L2_BLOCK_NUM as INITIAL_L2_BLOCK_NUM_RAW,
11
+ MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT as MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT_RAW,
12
+ MAX_TX_BLOB_DATA_SIZE_IN_FIELDS,
10
13
  } from './constants.gen.js';
11
14
 
12
15
  // Typescript-land-only constants
13
16
  export const SPONSORED_FPC_SALT = BigInt(0);
14
17
 
18
+ /**
19
+ * Network-minimum per-block budget multiplier for L2 gas / tx count. Operators may configure a higher value,
20
+ * but never lower: a node admitting txs under a smaller multiplier would accept work it can never pack.
21
+ */
22
+ export const MIN_PER_BLOCK_ALLOCATION_MULTIPLIER = 1.2;
23
+
24
+ /**
25
+ * Network-minimum per-block budget multiplier for DA gas / blob fields. See
26
+ * {@link MIN_PER_BLOCK_ALLOCATION_MULTIPLIER}. The DA-specific operator knob and its runtime enforcement land
27
+ * with the network tx admission limits (#23947); until then this constant is documentation of the network
28
+ * minimum only.
29
+ */
30
+ export const MIN_PER_BLOCK_DA_ALLOCATION_MULTIPLIER = 1.5;
31
+
32
+ /**
33
+ * The most DA gas a single tx can consume. A tx's effects cannot encode more than
34
+ * MAX_TX_BLOB_DATA_SIZE_IN_FIELDS fields in a blob, each costing DA_GAS_PER_FIELD, so this is the maximum
35
+ * DA gas a tx could ever use; declaring a higher limit is rejected by inbound validation.
36
+ */
37
+ export const MAX_TX_DA_GAS = MAX_TX_BLOB_DATA_SIZE_IN_FIELDS * DA_GAS_PER_FIELD;
38
+
15
39
  // Autogenerated constants loaded from noir-land
16
40
  // eslint-disable-next-line import-x/export
17
41
  export * from './constants.gen.js';
@@ -27,3 +51,15 @@ export const INITIAL_CHECKPOINT_NUMBER: CheckpointNumber = CheckpointNumber(INIT
27
51
  /** The block header hash for the genesis block 0. */
28
52
  // eslint-disable-next-line import-x/export
29
53
  export const GENESIS_BLOCK_HEADER_HASH = new Fr(GENESIS_BLOCK_HEADER_HASH_BIGINT);
54
+
55
+ /**
56
+ * The RAW DA capacity of a checkpoint's blobs: `BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB * DA_GAS_PER_FIELD`.
57
+ * This value is NOT attainable by transactions. The blob encoding reserves overhead fields that no tx pays
58
+ * DA gas for: a checkpoint-end marker field plus per-block block-end fields (7 for the first block in a
59
+ * checkpoint, 6 for each subsequent block — see `@aztec/blob-lib` encoding). The true tx-usable DA budget
60
+ * is lower and block-count-dependent; consumers budgeting tx data should subtract the encoding overhead (as
61
+ * `CheckpointBuilder` and the network tx gas limits in `@aztec/stdlib/gas` do) rather than use this value
62
+ * directly.
63
+ */
64
+ // eslint-disable-next-line import-x/export
65
+ export const MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT = MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT_RAW;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uc3RhbnRzLmluLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc2NyaXB0cy9jb25zdGFudHMuaW4udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.in.d.ts","sourceRoot":"","sources":["../../src/scripts/constants.in.ts"],"names":[],"mappings":""}
@@ -1,620 +0,0 @@
1
- import * as fs from 'fs';
2
- import { dirname, join } from 'path';
3
- import { fileURLToPath } from 'url';
4
- const NOIR_CONSTANTS_FILE = '../../../../noir-projects/noir-protocol-circuits/crates/types/src/constants.nr';
5
- const TS_CONSTANTS_FILE = '../constants.gen.ts';
6
- const CPP_AZTEC_CONSTANTS_FILE = '../../../../barretenberg/cpp/src/barretenberg/aztec/aztec_constants.hpp';
7
- const PIL_AZTEC_CONSTANTS_FILE = '../../../../barretenberg/cpp/pil/vm2/constants_gen.pil';
8
- const SOLIDITY_CONSTANTS_FILE = '../../../../l1-contracts/src/core/libraries/ConstantsGen.sol';
9
- // Whitelist of constants that will be copied to aztec_constants.hpp.
10
- // We don't copy everything as just a handful are needed, and updating them breaks the cache and triggers expensive bb builds.
11
- const CPP_CONSTANTS = [
12
- 'MAX_ETH_ADDRESS_BIT_SIZE',
13
- 'MAX_ETH_ADDRESS_VALUE',
14
- 'GENESIS_BLOCK_HEADER_HASH',
15
- 'GENESIS_ARCHIVE_ROOT',
16
- 'MEM_TAG_U1',
17
- 'MEM_TAG_U8',
18
- 'MEM_TAG_U16',
19
- 'MEM_TAG_U32',
20
- 'MEM_TAG_U64',
21
- 'MEM_TAG_U128',
22
- 'MEM_TAG_FF',
23
- 'MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS',
24
- 'CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS',
25
- 'CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS',
26
- 'FEE_JUICE_ADDRESS',
27
- 'TX_DA_GAS_OVERHEAD',
28
- 'FEE_JUICE_BALANCES_SLOT',
29
- 'UPDATED_CLASS_IDS_SLOT',
30
- 'UPDATES_DELAYED_PUBLIC_MUTABLE_VALUES_LEN',
31
- 'PUBLIC_DATA_TREE_HEIGHT',
32
- 'NULLIFIER_TREE_HEIGHT',
33
- 'NULLIFIER_SUBTREE_HEIGHT',
34
- 'NOTE_HASH_TREE_HEIGHT',
35
- 'L1_TO_L2_MSG_TREE_HEIGHT',
36
- 'ARCHIVE_HEIGHT',
37
- 'TIMESTAMP_OF_CHANGE_BIT_SIZE',
38
- 'UPDATES_DELAYED_PUBLIC_MUTABLE_METADATA_BIT_SIZE',
39
- 'MAX_ENQUEUED_CALLS_PER_TX',
40
- 'MAX_NOTE_HASHES_PER_TX',
41
- 'MAX_NULLIFIERS_PER_TX',
42
- 'MAX_L2_TO_L1_MSGS_PER_TX',
43
- 'MAX_PROCESSABLE_L2_GAS',
44
- 'MAX_PUBLIC_LOGS_PER_TX',
45
- 'MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX',
46
- 'MAX_PUBLIC_CALLS_TO_UNIQUE_CONTRACT_CLASS_IDS',
47
- 'MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX',
48
- 'MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX',
49
- 'AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_ROW_IDX',
50
- 'AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_CHAIN_ID_ROW_IDX',
51
- 'AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_VERSION_ROW_IDX',
52
- 'AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_BLOCK_NUMBER_ROW_IDX',
53
- 'AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_SLOT_NUMBER_ROW_IDX',
54
- 'AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_TIMESTAMP_ROW_IDX',
55
- 'AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_COINBASE_ROW_IDX',
56
- 'AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_FEE_RECIPIENT_ROW_IDX',
57
- 'AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_GAS_FEES_ROW_IDX',
58
- 'AVM_PUBLIC_INPUTS_PROTOCOL_CONTRACTS_ROW_IDX',
59
- 'AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_ROW_IDX',
60
- 'AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_L1_TO_L2_MESSAGE_TREE_ROW_IDX',
61
- 'AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_NOTE_HASH_TREE_ROW_IDX',
62
- 'AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_NULLIFIER_TREE_ROW_IDX',
63
- 'AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_PUBLIC_DATA_TREE_ROW_IDX',
64
- 'AVM_PUBLIC_INPUTS_START_GAS_USED_ROW_IDX',
65
- 'AVM_PUBLIC_INPUTS_GAS_SETTINGS_ROW_IDX',
66
- 'AVM_PUBLIC_INPUTS_FEE_PAYER_ROW_IDX',
67
- 'AVM_PUBLIC_INPUTS_PUBLIC_SETUP_CALL_REQUESTS_ROW_IDX',
68
- 'AVM_PUBLIC_INPUTS_PUBLIC_APP_LOGIC_CALL_REQUESTS_ROW_IDX',
69
- 'AVM_PUBLIC_INPUTS_PUBLIC_TEARDOWN_CALL_REQUEST_ROW_IDX',
70
- 'AVM_PUBLIC_INPUTS_PREVIOUS_NON_REVERTIBLE_ACCUMULATED_DATA_ARRAY_LENGTHS_ROW_IDX',
71
- 'AVM_PUBLIC_INPUTS_PREVIOUS_REVERTIBLE_ACCUMULATED_DATA_ARRAY_LENGTHS_ROW_IDX',
72
- 'AVM_PUBLIC_INPUTS_PREVIOUS_NON_REVERTIBLE_ACCUMULATED_DATA_ROW_IDX',
73
- 'AVM_PUBLIC_INPUTS_PREVIOUS_NON_REVERTIBLE_ACCUMULATED_DATA_NOTE_HASHES_ROW_IDX',
74
- 'AVM_PUBLIC_INPUTS_PREVIOUS_NON_REVERTIBLE_ACCUMULATED_DATA_NULLIFIERS_ROW_IDX',
75
- 'AVM_PUBLIC_INPUTS_PREVIOUS_NON_REVERTIBLE_ACCUMULATED_DATA_L2_TO_L1_MSGS_ROW_IDX',
76
- 'AVM_PUBLIC_INPUTS_PREVIOUS_REVERTIBLE_ACCUMULATED_DATA_ROW_IDX',
77
- 'AVM_PUBLIC_INPUTS_PREVIOUS_REVERTIBLE_ACCUMULATED_DATA_NOTE_HASHES_ROW_IDX',
78
- 'AVM_PUBLIC_INPUTS_PREVIOUS_REVERTIBLE_ACCUMULATED_DATA_NULLIFIERS_ROW_IDX',
79
- 'AVM_PUBLIC_INPUTS_PREVIOUS_REVERTIBLE_ACCUMULATED_DATA_L2_TO_L1_MSGS_ROW_IDX',
80
- 'AVM_PUBLIC_INPUTS_END_TREE_SNAPSHOTS_ROW_IDX',
81
- 'AVM_PUBLIC_INPUTS_END_TREE_SNAPSHOTS_L1_TO_L2_MESSAGE_TREE_ROW_IDX',
82
- 'AVM_PUBLIC_INPUTS_END_TREE_SNAPSHOTS_NOTE_HASH_TREE_ROW_IDX',
83
- 'AVM_PUBLIC_INPUTS_END_TREE_SNAPSHOTS_NULLIFIER_TREE_ROW_IDX',
84
- 'AVM_PUBLIC_INPUTS_END_TREE_SNAPSHOTS_PUBLIC_DATA_TREE_ROW_IDX',
85
- 'AVM_PUBLIC_INPUTS_END_GAS_USED_ROW_IDX',
86
- 'AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_NOTE_HASHES_ROW_IDX',
87
- 'AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_NULLIFIERS_ROW_IDX',
88
- 'AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_L2_TO_L1_MSGS_ROW_IDX',
89
- 'AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_PUBLIC_LOGS_ROW_IDX',
90
- 'AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_PUBLIC_DATA_WRITES_ROW_IDX',
91
- 'AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ROW_IDX',
92
- 'AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_NOTE_HASHES_ROW_IDX',
93
- 'AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_NULLIFIERS_ROW_IDX',
94
- 'AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_L2_TO_L1_MSGS_ROW_IDX',
95
- 'AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_PUBLIC_LOGS_ROW_IDX',
96
- 'AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_PUBLIC_DATA_WRITES_ROW_IDX',
97
- 'AVM_PUBLIC_INPUTS_TRANSACTION_FEE_ROW_IDX',
98
- 'AVM_PUBLIC_INPUTS_REVERTED_ROW_IDX',
99
- 'AVM_PUBLIC_INPUTS_COLUMNS_MAX_LENGTH',
100
- 'AVM_NUM_PUBLIC_INPUT_COLUMNS',
101
- 'AVM_PUBLIC_INPUTS_COLUMNS_COMBINED_LENGTH',
102
- 'AVM_WRITTEN_PUBLIC_DATA_SLOTS_TREE_HEIGHT',
103
- 'AVM_WRITTEN_PUBLIC_DATA_SLOTS_TREE_INITIAL_ROOT',
104
- 'AVM_WRITTEN_PUBLIC_DATA_SLOTS_TREE_INITIAL_SIZE',
105
- 'NOTE_HASH_TREE_LEAF_COUNT',
106
- 'L1_TO_L2_MSG_TREE_LEAF_COUNT',
107
- 'FLAT_PUBLIC_LOGS_HEADER_LENGTH',
108
- 'FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH',
109
- 'PUBLIC_LOGS_LENGTH',
110
- 'PUBLIC_LOG_HEADER_LENGTH',
111
- 'PUBLIC_TX_L2_GAS_OVERHEAD',
112
- 'MAX_PROTOCOL_CONTRACTS',
113
- 'DEFAULT_MAX_DEBUG_LOG_MEMORY_READS'
114
- ];
115
- const CPP_GENERATORS = [
116
- 'BLOCK_HEADER_HASH',
117
- 'SALTED_INITIALIZATION_HASH',
118
- 'PARTIAL_ADDRESS',
119
- 'CONTRACT_ADDRESS_V2',
120
- 'CONTRACT_CLASS_ID',
121
- 'PUBLIC_KEYS_HASH',
122
- 'SINGLE_PUBLIC_KEY_HASH',
123
- 'NOTE_HASH_NONCE',
124
- 'UNIQUE_NOTE_HASH',
125
- 'SILOED_NOTE_HASH',
126
- 'SILOED_NULLIFIER',
127
- 'PUBLIC_LEAF_SLOT',
128
- 'PUBLIC_STORAGE_MAP_SLOT',
129
- 'PUBLIC_CALLDATA',
130
- 'PUBLIC_BYTECODE',
131
- 'MERKLE_HASH',
132
- 'NULLIFIER_MERKLE',
133
- 'PUBLIC_DATA_MERKLE',
134
- 'WRITTEN_SLOTS_MERKLE',
135
- 'RETRIEVED_BYTECODES_MERKLE'
136
- ];
137
- const PIL_CONSTANTS = [
138
- 'MAX_ETH_ADDRESS_VALUE',
139
- 'MEM_TAG_U1',
140
- 'MEM_TAG_U8',
141
- 'MEM_TAG_U16',
142
- 'MEM_TAG_U32',
143
- 'MEM_TAG_U64',
144
- 'MEM_TAG_U128',
145
- 'MEM_TAG_FF',
146
- 'AVM_BITWISE_AND_OP_ID',
147
- 'AVM_BITWISE_OR_OP_ID',
148
- 'AVM_BITWISE_XOR_OP_ID',
149
- 'AVM_KECCAKF1600_NUM_ROUNDS',
150
- 'AVM_KECCAKF1600_STATE_SIZE',
151
- 'AVM_TX_PHASE_VALUE_START',
152
- 'AVM_TX_PHASE_VALUE_SETUP',
153
- 'AVM_TX_PHASE_VALUE_LAST',
154
- 'AVM_HIGHEST_MEM_ADDRESS',
155
- 'AVM_MEMORY_NUM_BITS',
156
- 'AVM_MEMORY_SIZE',
157
- 'MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS',
158
- 'MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX',
159
- 'MAX_NOTE_HASHES_PER_TX',
160
- 'GRUMPKIN_ONE_X',
161
- 'GRUMPKIN_ONE_Y',
162
- 'AVM_PC_SIZE_IN_BITS',
163
- 'PUBLIC_DATA_TREE_HEIGHT',
164
- 'NULLIFIER_TREE_HEIGHT',
165
- 'NOTE_HASH_TREE_HEIGHT',
166
- 'L1_TO_L2_MSG_TREE_HEIGHT',
167
- 'UPDATED_CLASS_IDS_SLOT',
168
- 'UPDATES_DELAYED_PUBLIC_MUTABLE_VALUES_LEN',
169
- 'CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS',
170
- 'CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS',
171
- 'FEE_JUICE_ADDRESS',
172
- 'FEE_JUICE_BALANCES_SLOT',
173
- 'TIMESTAMP_OF_CHANGE_BIT_SIZE',
174
- 'UPDATES_DELAYED_PUBLIC_MUTABLE_METADATA_BIT_SIZE',
175
- 'UPDATES_SHARED_MUTABLE_METADATA_BIT_SIZE',
176
- 'MAX_ENQUEUED_CALLS_PER_TX',
177
- 'MAX_NOTE_HASHES_PER_TX',
178
- 'MAX_NULLIFIERS_PER_TX',
179
- 'MAX_L2_TO_L1_MSGS_PER_TX',
180
- 'MAX_PUBLIC_LOGS_PER_TX',
181
- 'MAX_PUBLIC_CALLS_TO_UNIQUE_CONTRACT_CLASS_IDS',
182
- 'MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX',
183
- 'MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX',
184
- 'AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_ROW_IDX',
185
- 'AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_CHAIN_ID_ROW_IDX',
186
- 'AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_VERSION_ROW_IDX',
187
- 'AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_BLOCK_NUMBER_ROW_IDX',
188
- 'AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_SLOT_NUMBER_ROW_IDX',
189
- 'AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_TIMESTAMP_ROW_IDX',
190
- 'AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_COINBASE_ROW_IDX',
191
- 'AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_FEE_RECIPIENT_ROW_IDX',
192
- 'AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_GAS_FEES_ROW_IDX',
193
- 'AVM_PUBLIC_INPUTS_PROTOCOL_CONTRACTS_ROW_IDX',
194
- 'AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_ROW_IDX',
195
- 'AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_L1_TO_L2_MESSAGE_TREE_ROW_IDX',
196
- 'AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_NOTE_HASH_TREE_ROW_IDX',
197
- 'AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_NULLIFIER_TREE_ROW_IDX',
198
- 'AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_PUBLIC_DATA_TREE_ROW_IDX',
199
- 'AVM_PUBLIC_INPUTS_START_GAS_USED_ROW_IDX',
200
- 'AVM_PUBLIC_INPUTS_GAS_SETTINGS_ROW_IDX',
201
- 'AVM_PUBLIC_INPUTS_GAS_SETTINGS_GAS_LIMITS_ROW_IDX',
202
- 'AVM_PUBLIC_INPUTS_GAS_SETTINGS_TEARDOWN_GAS_LIMITS_ROW_IDX',
203
- 'AVM_PUBLIC_INPUTS_FEE_PAYER_ROW_IDX',
204
- 'AVM_PUBLIC_INPUTS_PUBLIC_SETUP_CALL_REQUESTS_ROW_IDX',
205
- 'AVM_PUBLIC_INPUTS_PUBLIC_APP_LOGIC_CALL_REQUESTS_ROW_IDX',
206
- 'AVM_PUBLIC_INPUTS_PUBLIC_TEARDOWN_CALL_REQUEST_ROW_IDX',
207
- 'AVM_PUBLIC_INPUTS_PREVIOUS_NON_REVERTIBLE_ACCUMULATED_DATA_ARRAY_LENGTHS_ROW_IDX',
208
- 'AVM_PUBLIC_INPUTS_PREVIOUS_REVERTIBLE_ACCUMULATED_DATA_ARRAY_LENGTHS_ROW_IDX',
209
- 'AVM_PUBLIC_INPUTS_PREVIOUS_NON_REVERTIBLE_ACCUMULATED_DATA_ROW_IDX',
210
- 'AVM_PUBLIC_INPUTS_PREVIOUS_NON_REVERTIBLE_ACCUMULATED_DATA_NOTE_HASHES_ROW_IDX',
211
- 'AVM_PUBLIC_INPUTS_PREVIOUS_NON_REVERTIBLE_ACCUMULATED_DATA_NULLIFIERS_ROW_IDX',
212
- 'AVM_PUBLIC_INPUTS_PREVIOUS_NON_REVERTIBLE_ACCUMULATED_DATA_L2_TO_L1_MSGS_ROW_IDX',
213
- 'AVM_PUBLIC_INPUTS_PREVIOUS_REVERTIBLE_ACCUMULATED_DATA_ROW_IDX',
214
- 'AVM_PUBLIC_INPUTS_PREVIOUS_REVERTIBLE_ACCUMULATED_DATA_NOTE_HASHES_ROW_IDX',
215
- 'AVM_PUBLIC_INPUTS_PREVIOUS_REVERTIBLE_ACCUMULATED_DATA_NULLIFIERS_ROW_IDX',
216
- 'AVM_PUBLIC_INPUTS_PREVIOUS_REVERTIBLE_ACCUMULATED_DATA_L2_TO_L1_MSGS_ROW_IDX',
217
- 'AVM_PUBLIC_INPUTS_END_TREE_SNAPSHOTS_ROW_IDX',
218
- 'AVM_PUBLIC_INPUTS_END_TREE_SNAPSHOTS_L1_TO_L2_MESSAGE_TREE_ROW_IDX',
219
- 'AVM_PUBLIC_INPUTS_END_TREE_SNAPSHOTS_NOTE_HASH_TREE_ROW_IDX',
220
- 'AVM_PUBLIC_INPUTS_END_TREE_SNAPSHOTS_NULLIFIER_TREE_ROW_IDX',
221
- 'AVM_PUBLIC_INPUTS_END_TREE_SNAPSHOTS_PUBLIC_DATA_TREE_ROW_IDX',
222
- 'AVM_PUBLIC_INPUTS_END_GAS_USED_ROW_IDX',
223
- 'AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_NOTE_HASHES_ROW_IDX',
224
- 'AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_NULLIFIERS_ROW_IDX',
225
- 'AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_L2_TO_L1_MSGS_ROW_IDX',
226
- 'AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_PUBLIC_LOGS_ROW_IDX',
227
- 'AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_PUBLIC_DATA_WRITES_ROW_IDX',
228
- 'AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ROW_IDX',
229
- 'AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_NOTE_HASHES_ROW_IDX',
230
- 'AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_NULLIFIERS_ROW_IDX',
231
- 'AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_L2_TO_L1_MSGS_ROW_IDX',
232
- 'AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_PUBLIC_LOGS_ROW_IDX',
233
- 'AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_PUBLIC_DATA_WRITES_ROW_IDX',
234
- 'AVM_PUBLIC_INPUTS_TRANSACTION_FEE_ROW_IDX',
235
- 'AVM_PUBLIC_INPUTS_REVERTED_ROW_IDX',
236
- 'AVM_PUBLIC_INPUTS_COLUMNS_MAX_LENGTH',
237
- 'AVM_NUM_PUBLIC_INPUT_COLUMNS',
238
- 'AVM_PUBLIC_INPUTS_COLUMNS_COMBINED_LENGTH',
239
- 'AVM_SUBTRACE_ID_EXECUTION',
240
- 'AVM_SUBTRACE_ID_ALU',
241
- 'AVM_SUBTRACE_ID_CAST',
242
- 'AVM_SUBTRACE_ID_SET',
243
- 'AVM_SUBTRACE_ID_BITWISE',
244
- 'AVM_SUBTRACE_ID_POSEIDON2_PERM',
245
- 'AVM_SUBTRACE_ID_TO_RADIX',
246
- 'AVM_SUBTRACE_ID_ECC',
247
- 'AVM_SUBTRACE_ID_KECCAKF1600',
248
- 'AVM_SUBTRACE_ID_CALLDATA_COPY',
249
- 'AVM_SUBTRACE_ID_SHA256_COMPRESSION',
250
- 'AVM_SUBTRACE_ID_RETURNDATA_COPY',
251
- 'AVM_DYN_GAS_ID_CALLDATACOPY',
252
- 'AVM_DYN_GAS_ID_RETURNDATACOPY',
253
- 'AVM_DYN_GAS_ID_TORADIX',
254
- 'AVM_DYN_GAS_ID_BITWISE',
255
- 'AVM_DYN_GAS_ID_EMITPUBLICLOG',
256
- 'AVM_DYN_GAS_ID_SSTORE',
257
- 'AVM_SUBTRACE_ID_GETCONTRACTINSTANCE',
258
- 'AVM_SUBTRACE_ID_EMITPUBLICLOG',
259
- 'AVM_EXEC_OP_ID_GETENVVAR',
260
- 'AVM_EXEC_OP_ID_MOV',
261
- 'AVM_EXEC_OP_ID_JUMP',
262
- 'AVM_EXEC_OP_ID_JUMPI',
263
- 'AVM_EXEC_OP_ID_CALL',
264
- 'AVM_EXEC_OP_ID_STATICCALL',
265
- 'AVM_EXEC_OP_ID_INTERNALCALL',
266
- 'AVM_EXEC_OP_ID_INTERNALRETURN',
267
- 'AVM_EXEC_OP_ID_RETURN',
268
- 'AVM_EXEC_OP_ID_REVERT',
269
- 'AVM_EXEC_OP_ID_SUCCESSCOPY',
270
- 'AVM_EXEC_OP_ID_ALU_ADD',
271
- 'AVM_EXEC_OP_ID_ALU_SUB',
272
- 'AVM_EXEC_OP_ID_ALU_MUL',
273
- 'AVM_EXEC_OP_ID_ALU_DIV',
274
- 'AVM_EXEC_OP_ID_ALU_FDIV',
275
- 'AVM_EXEC_OP_ID_ALU_EQ',
276
- 'AVM_EXEC_OP_ID_ALU_LT',
277
- 'AVM_EXEC_OP_ID_ALU_LTE',
278
- 'AVM_EXEC_OP_ID_ALU_NOT',
279
- 'AVM_EXEC_OP_ID_ALU_SHL',
280
- 'AVM_EXEC_OP_ID_ALU_SHR',
281
- 'AVM_EXEC_OP_ID_ALU_TRUNCATE',
282
- 'AVM_EXEC_OP_ID_RETURNDATASIZE',
283
- 'AVM_EXEC_OP_ID_DEBUGLOG',
284
- 'AVM_EXEC_OP_ID_SLOAD',
285
- 'AVM_EXEC_OP_ID_SSTORE',
286
- 'AVM_EXEC_OP_ID_NOTEHASH_EXISTS',
287
- 'AVM_EXEC_OP_ID_EMIT_NOTEHASH',
288
- 'AVM_EXEC_OP_ID_L1_TO_L2_MESSAGE_EXISTS',
289
- 'AVM_EXEC_OP_ID_NULLIFIER_EXISTS',
290
- 'AVM_EXEC_OP_ID_EMIT_NULLIFIER',
291
- 'AVM_EXEC_OP_ID_SENDL2TOL1MSG',
292
- 'AVM_WRITTEN_PUBLIC_DATA_SLOTS_TREE_HEIGHT',
293
- 'AVM_WRITTEN_PUBLIC_DATA_SLOTS_TREE_INITIAL_ROOT',
294
- 'AVM_WRITTEN_PUBLIC_DATA_SLOTS_TREE_INITIAL_SIZE',
295
- 'AVM_RETRIEVED_BYTECODES_TREE_HEIGHT',
296
- 'AVM_RETRIEVED_BYTECODES_TREE_INITIAL_ROOT',
297
- 'AVM_RETRIEVED_BYTECODES_TREE_INITIAL_SIZE',
298
- 'NOTE_HASH_TREE_LEAF_COUNT',
299
- 'L1_TO_L2_MSG_TREE_LEAF_COUNT',
300
- 'FLAT_PUBLIC_LOGS_HEADER_LENGTH',
301
- 'FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH',
302
- 'PUBLIC_LOGS_LENGTH',
303
- 'PUBLIC_LOG_HEADER_LENGTH',
304
- 'MAX_PROTOCOL_CONTRACTS'
305
- ];
306
- const PIL_GENERATORS = [
307
- 'SALTED_INITIALIZATION_HASH',
308
- 'PARTIAL_ADDRESS',
309
- 'CONTRACT_ADDRESS_V2',
310
- 'CONTRACT_CLASS_ID',
311
- 'PUBLIC_KEYS_HASH',
312
- 'SINGLE_PUBLIC_KEY_HASH',
313
- 'NOTE_HASH_NONCE',
314
- 'UNIQUE_NOTE_HASH',
315
- 'SILOED_NOTE_HASH',
316
- 'SILOED_NULLIFIER',
317
- 'PUBLIC_LEAF_SLOT',
318
- 'PUBLIC_STORAGE_MAP_SLOT',
319
- 'PUBLIC_CALLDATA',
320
- 'PUBLIC_BYTECODE',
321
- 'MERKLE_HASH',
322
- 'NULLIFIER_MERKLE',
323
- 'PUBLIC_DATA_MERKLE',
324
- 'WRITTEN_SLOTS_MERKLE',
325
- 'RETRIEVED_BYTECODES_MERKLE'
326
- ];
327
- const SOLIDITY_CONSTANTS = [
328
- 'MAX_FIELD_VALUE',
329
- 'MAX_L2_TO_L1_MSGS_PER_TX',
330
- 'EMPTY_EPOCH_OUT_HASH',
331
- 'L1_TO_L2_MSG_SUBTREE_HEIGHT',
332
- 'NUM_MSGS_PER_BASE_PARITY',
333
- 'NUM_BASE_PARITY_PER_ROOT_PARITY',
334
- 'BLS12_POINT_COMPRESSED_BYTES',
335
- 'ROOT_ROLLUP_PUBLIC_INPUTS_LENGTH',
336
- 'INITIAL_CHECKPOINT_NUMBER',
337
- 'GENESIS_ARCHIVE_ROOT',
338
- 'FEE_JUICE_ADDRESS',
339
- 'MAX_CHECKPOINTS_PER_EPOCH'
340
- ];
341
- /**
342
- * Processes a collection of constants and generates code to export them as TypeScript constants.
343
- *
344
- * @param constants - An object containing key-value pairs representing constants.
345
- * @returns A string containing code that exports the constants as TypeScript constants.
346
- */ function processConstantsTS(constants) {
347
- const code = [];
348
- Object.entries(constants).forEach(([key, value])=>{
349
- code.push(`export const ${key} = ${+value > Number.MAX_SAFE_INTEGER ? value + 'n' : value};`);
350
- });
351
- return code.join('\n');
352
- }
353
- /**
354
- * Processes a collection of constants and generates code to export them as cpp constants.
355
- * Required to ensure consistency between the constants used in pil and used in the vm witness generator.
356
- *
357
- * @param constants - An object containing key-value pairs representing constants.
358
- * @returns A string containing code that exports the constants as cpp constants.
359
- */ function processConstantsCpp(constants, generatorIndices) {
360
- const code = [];
361
- Object.entries(constants).forEach(([key, value])=>{
362
- if (CPP_CONSTANTS.includes(key) || key.startsWith('AVM_')) {
363
- if (BigInt(value) <= 2n ** 31n - 1n) {
364
- code.push(`#define ${key} ${value}`);
365
- } else if (BigInt(value) <= 2n ** 64n - 1n) {
366
- code.push(`#define ${key} 0x${BigInt(value).toString(16)}`); // hex literals
367
- } else {
368
- code.push(`#define ${key} "0x${BigInt(value).toString(16).padStart(64, '0')}"`); // stringify large numbers
369
- }
370
- }
371
- });
372
- Object.entries(generatorIndices).forEach(([key, value])=>{
373
- if (CPP_GENERATORS.includes(key)) {
374
- code.push(`#define DOM_SEP__${key} ${value}UL`);
375
- }
376
- });
377
- return code.join('\n');
378
- }
379
- /**
380
- * Processes a collection of constants and generates code to export them as PIL constants.
381
- * Required to ensure consistency between the constants used in pil and used in the vm witness generator.
382
- *
383
- * @param constants - An object containing key-value pairs representing constants.
384
- * @returns A string containing code that exports the constants as cpp constants.
385
- */ function processConstantsPil(constants, generatorIndices) {
386
- const code = [];
387
- Object.entries(constants).forEach(([key, value])=>{
388
- if (PIL_CONSTANTS.includes(key)) {
389
- code.push(` pol ${key} = ${value};`);
390
- }
391
- });
392
- Object.entries(generatorIndices).forEach(([key, value])=>{
393
- if (PIL_GENERATORS.includes(key)) {
394
- code.push(` pol DOM_SEP__${key} = ${value};`);
395
- }
396
- });
397
- return code.join('\n');
398
- }
399
- /**
400
- * Processes an enum and generates code to export it as a TypeScript enum.
401
- *
402
- * @param enumName - The name of the enum.
403
- * @param enumValues - An object containing key-value pairs representing enum values.
404
- * @returns A string containing code that exports the enum as a TypeScript enum.
405
- */ function processEnumTS(enumName, enumValues) {
406
- const code = [];
407
- code.push(`export enum ${enumName} {`);
408
- Object.entries(enumValues).forEach(([key, value])=>{
409
- code.push(` ${key} = ${value},`);
410
- });
411
- code.push('}');
412
- return code.join('\n');
413
- }
414
- /**
415
- * Processes a collection of constants and generates code to export them as Solidity constants.
416
- *
417
- * @param constants - An object containing key-value pairs representing constants.
418
- * @param prefix - A prefix to add to the constant names.
419
- * @returns A string containing code that exports the constants as Noir constants.
420
- */ function processConstantsSolidity(constants, prefix = '') {
421
- const code = [];
422
- Object.entries(constants).forEach(([key, value])=>{
423
- if (SOLIDITY_CONSTANTS.includes(key)) {
424
- code.push(` uint256 internal constant ${prefix}${key} = ${value};`);
425
- }
426
- });
427
- return code.join('\n');
428
- }
429
- /**
430
- * Generate the constants file in Typescript.
431
- */ function generateTypescriptConstants({ constants, domainSeparatorEnum }, targetPath) {
432
- const result = [
433
- '// GENERATED FILE - DO NOT EDIT, RUN yarn remake-constants',
434
- processConstantsTS(constants),
435
- processEnumTS('DomainSeparator', domainSeparatorEnum)
436
- ].join('\n');
437
- fs.writeFileSync(targetPath, result);
438
- }
439
- /**
440
- * Generate the constants file in C++.
441
- */ function generateCppConstants({ constants, domainSeparatorEnum }, targetPath) {
442
- const resultCpp = `// GENERATED FILE - DO NOT EDIT, RUN yarn remake-constants in yarn-project/constants
443
- #pragma once
444
-
445
- ${processConstantsCpp(constants, domainSeparatorEnum)}
446
- `;
447
- fs.writeFileSync(targetPath, resultCpp);
448
- }
449
- /**
450
- * Generate the constants file in PIL.
451
- */ function generatePilConstants({ constants, domainSeparatorEnum }, targetPath) {
452
- const resultPil = `// GENERATED FILE - DO NOT EDIT, RUN yarn remake-constants in yarn-project/constants
453
- namespace constants;
454
- ${processConstantsPil(constants, domainSeparatorEnum)}
455
- \n`;
456
- fs.writeFileSync(targetPath, resultPil);
457
- }
458
- /**
459
- * Generate the constants file in Solidity.
460
- */ function generateSolidityConstants({ constants }, targetPath) {
461
- const resultSolidity = `// GENERATED FILE - DO NOT EDIT, RUN yarn remake-constants in yarn-project/constants
462
- // SPDX-License-Identifier: Apache-2.0
463
- // Copyright 2023 Aztec Labs.
464
- pragma solidity >=0.8.27;
465
-
466
- /**
467
- * @title Constants Library
468
- * @author Aztec Labs
469
- * @notice Library that contains constants used throughout the Aztec protocol
470
- */
471
- library Constants {
472
- // Prime field modulus
473
- uint256 internal constant P =
474
- 21888242871839275222246405745257275088548364400416034343698204186575808495617;
475
-
476
- ${processConstantsSolidity(constants)}
477
- }\n`;
478
- fs.writeFileSync(targetPath, resultSolidity);
479
- }
480
- /**
481
- * Parse the content of the constants file in Noir.
482
- */ function parseNoirFile(fileContent) {
483
- const constantsExpressions = [];
484
- const domainSeparatorEnum = {};
485
- const emptyExpression = ()=>({
486
- name: '',
487
- content: []
488
- });
489
- let expression = emptyExpression();
490
- fileContent.split('\n').forEach((l)=>{
491
- const line = l.trim();
492
- if (!line) {
493
- // Empty line.
494
- return;
495
- }
496
- if (line.match(/^\/\/|^\s*\/?\*/)) {
497
- // Comment.
498
- return;
499
- }
500
- {
501
- const [, name, _type, value, end] = line.match(/global\s+(\w+)(\s*:\s*\w+)?\s*=\s*([^;]*)(;)?/) || [];
502
- if (name && value) {
503
- const [, indexName] = name.match(/DOM_SEP__(\w+)/) || [];
504
- if (indexName) {
505
- // Generator index.
506
- domainSeparatorEnum[indexName] = +value;
507
- } else if (end) {
508
- // A single line of expression.
509
- constantsExpressions.push([
510
- name,
511
- value
512
- ]);
513
- } else {
514
- // The first line of an expression.
515
- expression = {
516
- name,
517
- content: [
518
- value
519
- ]
520
- };
521
- }
522
- return;
523
- } else if (name) {
524
- // This case happens if we have only a name, with the value being on the next line
525
- expression = {
526
- name,
527
- content: []
528
- };
529
- return;
530
- }
531
- }
532
- if (expression.name) {
533
- // The expression continues...
534
- const [, content, end] = line.match(/\s*([^;]+)(;)?/) || [];
535
- expression.content.push(content);
536
- if (end) {
537
- // The last line of an expression.
538
- constantsExpressions.push([
539
- expression.name,
540
- expression.content.join('')
541
- ]);
542
- expression = emptyExpression();
543
- }
544
- return;
545
- }
546
- if (!line.includes('use crate')) {
547
- // eslint-disable-next-line no-console
548
- console.warn(`Unknown content: ${line}`);
549
- }
550
- });
551
- const constants = evaluateExpressions(constantsExpressions);
552
- return {
553
- constants,
554
- domainSeparatorEnum
555
- };
556
- }
557
- /**
558
- * Converts constants defined as expressions to constants with actual values.
559
- * @param expressions Ordered list of expressions of the type: "CONSTANT_NAME: expression".
560
- * where the expression is a string that can be evaluated to a number.
561
- * For example: "CONSTANT_NAME: 2 + 2" or "CONSTANT_NAME: CONSTANT_A * CONSTANT_B".
562
- * @returns Parsed expressions of the form: "CONSTANT_NAME: number_as_string".
563
- */ function evaluateExpressions(expressions) {
564
- const constants = {};
565
- const knownBigInts = [
566
- 'AZTEC_EPOCH_DURATION',
567
- 'FEE_RECIPIENT_LENGTH'
568
- ];
569
- // Create JS expressions. It is not as easy as just evaluating the expression!
570
- // We basically need to convert everything to BigInts, otherwise things don't fit.
571
- // However, (1) the bigints need to be initialized from strings; (2) everything needs to
572
- // be a bigint, even the actual constant values!
573
- const prelude = expressions.map(([name, rhs])=>{
574
- const guardedRhs = rhs// Remove 'as u8', 'as u32' and 'as u64' castings
575
- .replaceAll(' as u8', '').replaceAll(' as u32', '').replaceAll(' as u64', '')// Remove the 'AztecAddress::from_field(...)' pattern.
576
- // Also copes with the noir formatter re-formatting over multiple lines.
577
- .replace(/AztecAddress::from_field\(\s*(0x[a-fA-F0-9]+|\d+)\s*,?\s*\)/gs, '$1')// We make some space around the parentheses, so that constant numbers are still split.
578
- .replace(/\(/g, '( ').replace(/\)/g, ' )')// We also make some space around common operators
579
- .replace(/\+/g, ' + ').replace(/(?<!\/)\*(?!\/)/, ' * ')// We split the expression into terms...
580
- .split(/\s+/)// ...and then we convert each term to a BigInt if it is a number.
581
- .map((term)=>{
582
- // Remove underscores from numeric literals (e.g., 6_000_000 -> 6000000)
583
- const termWithoutUnderscores = term.replace(/_/g, '');
584
- return isNaN(+termWithoutUnderscores) ? term : `BigInt('${termWithoutUnderscores}')`;
585
- })// .. also, we convert the known bigints to BigInts.
586
- .map((term)=>knownBigInts.includes(term) ? `BigInt(${term})` : term)// We join the terms back together.
587
- .join(' ');
588
- return `var ${name} = ${guardedRhs};`;
589
- }).join('\n');
590
- // Extract each value from the expressions. Observe that this will still be a string,
591
- // so that we can then choose to express it as BigInt or Number depending on the size.
592
- for (const [name, _] of expressions){
593
- constants[name] = eval(prelude + `; BigInt(${name}).toString()`);
594
- }
595
- return constants;
596
- }
597
- /**
598
- * Convert the Noir constants to TypeScript and Solidity.
599
- */ function main() {
600
- const __dirname = dirname(fileURLToPath(import.meta.url));
601
- const noirConstantsFile = join(__dirname, NOIR_CONSTANTS_FILE);
602
- const noirConstants = fs.readFileSync(noirConstantsFile, 'utf-8');
603
- const parsedContent = parseNoirFile(noirConstants);
604
- // Typescript
605
- const tsTargetPath = join(__dirname, TS_CONSTANTS_FILE);
606
- generateTypescriptConstants(parsedContent, tsTargetPath);
607
- // Cpp
608
- const cppTargetPath = join(__dirname, CPP_AZTEC_CONSTANTS_FILE);
609
- generateCppConstants(parsedContent, cppTargetPath);
610
- // PIL
611
- const pilTargetPath = join(__dirname, PIL_AZTEC_CONSTANTS_FILE);
612
- generatePilConstants(parsedContent, pilTargetPath);
613
- // Solidity
614
- const solidityTargetPath = join(__dirname, SOLIDITY_CONSTANTS_FILE);
615
- fs.mkdirSync(dirname(solidityTargetPath), {
616
- recursive: true
617
- });
618
- generateSolidityConstants(parsedContent, solidityTargetPath);
619
- }
620
- main();