@aztec/constants 0.0.1-commit.3469e52 → 0.0.1-commit.350e0a4d

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