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