@aztec/constants 0.0.1-commit.a072138 → 0.0.1-commit.a5db02d
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 -138
- package/dest/constants.gen.d.ts.map +1 -1
- package/dest/constants.gen.js +178 -138
- package/dest/constants.js +30 -7
- package/dest/scripts/constants.in.js +79 -29
- package/package.json +9 -2
- package/src/constants.gen.ts +177 -137
- package/src/constants.ts +38 -5
|
@@ -3,9 +3,23 @@ import { dirname, join } from 'path';
|
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
4
|
const NOIR_CONSTANTS_FILE = '../../../../noir-projects/noir-protocol-circuits/crates/types/src/constants.nr';
|
|
5
5
|
const TS_CONSTANTS_FILE = '../constants.gen.ts';
|
|
6
|
-
const CPP_AZTEC_CONSTANTS_FILE = '../../../../barretenberg/cpp/src/barretenberg/
|
|
6
|
+
const CPP_AZTEC_CONSTANTS_FILE = '../../../../barretenberg/cpp/src/barretenberg/aztec/aztec_constants.hpp';
|
|
7
7
|
const PIL_AZTEC_CONSTANTS_FILE = '../../../../barretenberg/cpp/pil/vm2/constants_gen.pil';
|
|
8
8
|
const SOLIDITY_CONSTANTS_FILE = '../../../../l1-contracts/src/core/libraries/ConstantsGen.sol';
|
|
9
|
+
// Additional Noir source files (outside constants.nr) to extract specific constants from, keyed by
|
|
10
|
+
// file path (relative to this script) and the exact constant names to pull from each. Used for
|
|
11
|
+
// constants that are defined alongside circuit code rather than in constants.nr, so they can be
|
|
12
|
+
// exported to the generated TS constants without duplicating their definition. The referenced
|
|
13
|
+
// constants may depend on constants.nr values, which are in scope because they are evaluated after
|
|
14
|
+
// the main file's constants.
|
|
15
|
+
const ADDITIONAL_NOIR_CONSTANT_FILES = [
|
|
16
|
+
{
|
|
17
|
+
file: '../../../../noir-projects/noir-protocol-circuits/crates/types/src/blob_data/tx_blob_data.nr',
|
|
18
|
+
constants: [
|
|
19
|
+
'MAX_TX_BLOB_DATA_SIZE_IN_FIELDS'
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
];
|
|
9
23
|
// Whitelist of constants that will be copied to aztec_constants.hpp.
|
|
10
24
|
// We don't copy everything as just a handful are needed, and updating them breaks the cache and triggers expensive bb builds.
|
|
11
25
|
const CPP_CONSTANTS = [
|
|
@@ -21,12 +35,10 @@ const CPP_CONSTANTS = [
|
|
|
21
35
|
'MEM_TAG_U128',
|
|
22
36
|
'MEM_TAG_FF',
|
|
23
37
|
'MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS',
|
|
24
|
-
'CANONICAL_AUTH_REGISTRY_ADDRESS',
|
|
25
38
|
'CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS',
|
|
26
39
|
'CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS',
|
|
27
|
-
'MULTI_CALL_ENTRYPOINT_ADDRESS',
|
|
28
40
|
'FEE_JUICE_ADDRESS',
|
|
29
|
-
'
|
|
41
|
+
'TX_DA_GAS_OVERHEAD',
|
|
30
42
|
'FEE_JUICE_BALANCES_SLOT',
|
|
31
43
|
'UPDATED_CLASS_IDS_SLOT',
|
|
32
44
|
'UPDATES_DELAYED_PUBLIC_MUTABLE_VALUES_LEN',
|
|
@@ -42,6 +54,7 @@ const CPP_CONSTANTS = [
|
|
|
42
54
|
'MAX_NOTE_HASHES_PER_TX',
|
|
43
55
|
'MAX_NULLIFIERS_PER_TX',
|
|
44
56
|
'MAX_L2_TO_L1_MSGS_PER_TX',
|
|
57
|
+
'MAX_PROCESSABLE_L2_GAS',
|
|
45
58
|
'MAX_PUBLIC_LOGS_PER_TX',
|
|
46
59
|
'MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX',
|
|
47
60
|
'MAX_PUBLIC_CALLS_TO_UNIQUE_CONTRACT_CLASS_IDS',
|
|
@@ -109,15 +122,18 @@ const CPP_CONSTANTS = [
|
|
|
109
122
|
'FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH',
|
|
110
123
|
'PUBLIC_LOGS_LENGTH',
|
|
111
124
|
'PUBLIC_LOG_HEADER_LENGTH',
|
|
125
|
+
'PUBLIC_TX_L2_GAS_OVERHEAD',
|
|
112
126
|
'MAX_PROTOCOL_CONTRACTS',
|
|
113
127
|
'DEFAULT_MAX_DEBUG_LOG_MEMORY_READS'
|
|
114
128
|
];
|
|
115
129
|
const CPP_GENERATORS = [
|
|
116
130
|
'BLOCK_HEADER_HASH',
|
|
131
|
+
'SALTED_INITIALIZATION_HASH',
|
|
117
132
|
'PARTIAL_ADDRESS',
|
|
118
|
-
'
|
|
133
|
+
'CONTRACT_ADDRESS_V2',
|
|
119
134
|
'CONTRACT_CLASS_ID',
|
|
120
135
|
'PUBLIC_KEYS_HASH',
|
|
136
|
+
'SINGLE_PUBLIC_KEY_HASH',
|
|
121
137
|
'NOTE_HASH_NONCE',
|
|
122
138
|
'UNIQUE_NOTE_HASH',
|
|
123
139
|
'SILOED_NOTE_HASH',
|
|
@@ -125,7 +141,12 @@ const CPP_GENERATORS = [
|
|
|
125
141
|
'PUBLIC_LEAF_SLOT',
|
|
126
142
|
'PUBLIC_STORAGE_MAP_SLOT',
|
|
127
143
|
'PUBLIC_CALLDATA',
|
|
128
|
-
'PUBLIC_BYTECODE'
|
|
144
|
+
'PUBLIC_BYTECODE',
|
|
145
|
+
'MERKLE_HASH',
|
|
146
|
+
'NULLIFIER_MERKLE',
|
|
147
|
+
'PUBLIC_DATA_MERKLE',
|
|
148
|
+
'WRITTEN_SLOTS_MERKLE',
|
|
149
|
+
'RETRIEVED_BYTECODES_MERKLE'
|
|
129
150
|
];
|
|
130
151
|
const PIL_CONSTANTS = [
|
|
131
152
|
'MAX_ETH_ADDRESS_VALUE',
|
|
@@ -159,12 +180,9 @@ const PIL_CONSTANTS = [
|
|
|
159
180
|
'L1_TO_L2_MSG_TREE_HEIGHT',
|
|
160
181
|
'UPDATED_CLASS_IDS_SLOT',
|
|
161
182
|
'UPDATES_DELAYED_PUBLIC_MUTABLE_VALUES_LEN',
|
|
162
|
-
'CANONICAL_AUTH_REGISTRY_ADDRESS',
|
|
163
183
|
'CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS',
|
|
164
184
|
'CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS',
|
|
165
|
-
'MULTI_CALL_ENTRYPOINT_ADDRESS',
|
|
166
185
|
'FEE_JUICE_ADDRESS',
|
|
167
|
-
'PUBLIC_CHECKS_ADDRESS',
|
|
168
186
|
'FEE_JUICE_BALANCES_SLOT',
|
|
169
187
|
'TIMESTAMP_OF_CHANGE_BIT_SIZE',
|
|
170
188
|
'UPDATES_DELAYED_PUBLIC_MUTABLE_METADATA_BIT_SIZE',
|
|
@@ -248,10 +266,10 @@ const PIL_CONSTANTS = [
|
|
|
248
266
|
'AVM_DYN_GAS_ID_RETURNDATACOPY',
|
|
249
267
|
'AVM_DYN_GAS_ID_TORADIX',
|
|
250
268
|
'AVM_DYN_GAS_ID_BITWISE',
|
|
251
|
-
'
|
|
269
|
+
'AVM_DYN_GAS_ID_EMITPUBLICLOG',
|
|
252
270
|
'AVM_DYN_GAS_ID_SSTORE',
|
|
253
271
|
'AVM_SUBTRACE_ID_GETCONTRACTINSTANCE',
|
|
254
|
-
'
|
|
272
|
+
'AVM_SUBTRACE_ID_EMITPUBLICLOG',
|
|
255
273
|
'AVM_EXEC_OP_ID_GETENVVAR',
|
|
256
274
|
'AVM_EXEC_OP_ID_MOV',
|
|
257
275
|
'AVM_EXEC_OP_ID_JUMP',
|
|
@@ -300,10 +318,12 @@ const PIL_CONSTANTS = [
|
|
|
300
318
|
'MAX_PROTOCOL_CONTRACTS'
|
|
301
319
|
];
|
|
302
320
|
const PIL_GENERATORS = [
|
|
321
|
+
'SALTED_INITIALIZATION_HASH',
|
|
303
322
|
'PARTIAL_ADDRESS',
|
|
304
|
-
'
|
|
323
|
+
'CONTRACT_ADDRESS_V2',
|
|
305
324
|
'CONTRACT_CLASS_ID',
|
|
306
325
|
'PUBLIC_KEYS_HASH',
|
|
326
|
+
'SINGLE_PUBLIC_KEY_HASH',
|
|
307
327
|
'NOTE_HASH_NONCE',
|
|
308
328
|
'UNIQUE_NOTE_HASH',
|
|
309
329
|
'SILOED_NOTE_HASH',
|
|
@@ -311,7 +331,12 @@ const PIL_GENERATORS = [
|
|
|
311
331
|
'PUBLIC_LEAF_SLOT',
|
|
312
332
|
'PUBLIC_STORAGE_MAP_SLOT',
|
|
313
333
|
'PUBLIC_CALLDATA',
|
|
314
|
-
'PUBLIC_BYTECODE'
|
|
334
|
+
'PUBLIC_BYTECODE',
|
|
335
|
+
'MERKLE_HASH',
|
|
336
|
+
'NULLIFIER_MERKLE',
|
|
337
|
+
'PUBLIC_DATA_MERKLE',
|
|
338
|
+
'WRITTEN_SLOTS_MERKLE',
|
|
339
|
+
'RETRIEVED_BYTECODES_MERKLE'
|
|
315
340
|
];
|
|
316
341
|
const SOLIDITY_CONSTANTS = [
|
|
317
342
|
'MAX_FIELD_VALUE',
|
|
@@ -325,7 +350,7 @@ const SOLIDITY_CONSTANTS = [
|
|
|
325
350
|
'INITIAL_CHECKPOINT_NUMBER',
|
|
326
351
|
'GENESIS_ARCHIVE_ROOT',
|
|
327
352
|
'FEE_JUICE_ADDRESS',
|
|
328
|
-
'
|
|
353
|
+
'MAX_CHECKPOINTS_PER_EPOCH'
|
|
329
354
|
];
|
|
330
355
|
/**
|
|
331
356
|
* Processes a collection of constants and generates code to export them as TypeScript constants.
|
|
@@ -417,30 +442,30 @@ const SOLIDITY_CONSTANTS = [
|
|
|
417
442
|
}
|
|
418
443
|
/**
|
|
419
444
|
* Generate the constants file in Typescript.
|
|
420
|
-
*/ function generateTypescriptConstants({ constants,
|
|
445
|
+
*/ function generateTypescriptConstants({ constants, domainSeparatorEnum }, targetPath) {
|
|
421
446
|
const result = [
|
|
422
447
|
'// GENERATED FILE - DO NOT EDIT, RUN yarn remake-constants',
|
|
423
448
|
processConstantsTS(constants),
|
|
424
|
-
processEnumTS('
|
|
449
|
+
processEnumTS('DomainSeparator', domainSeparatorEnum)
|
|
425
450
|
].join('\n');
|
|
426
451
|
fs.writeFileSync(targetPath, result);
|
|
427
452
|
}
|
|
428
453
|
/**
|
|
429
454
|
* Generate the constants file in C++.
|
|
430
|
-
*/ function generateCppConstants({ constants,
|
|
455
|
+
*/ function generateCppConstants({ constants, domainSeparatorEnum }, targetPath) {
|
|
431
456
|
const resultCpp = `// GENERATED FILE - DO NOT EDIT, RUN yarn remake-constants in yarn-project/constants
|
|
432
457
|
#pragma once
|
|
433
458
|
|
|
434
|
-
${processConstantsCpp(constants,
|
|
459
|
+
${processConstantsCpp(constants, domainSeparatorEnum)}
|
|
435
460
|
`;
|
|
436
461
|
fs.writeFileSync(targetPath, resultCpp);
|
|
437
462
|
}
|
|
438
463
|
/**
|
|
439
464
|
* Generate the constants file in PIL.
|
|
440
|
-
*/ function generatePilConstants({ constants,
|
|
465
|
+
*/ function generatePilConstants({ constants, domainSeparatorEnum }, targetPath) {
|
|
441
466
|
const resultPil = `// GENERATED FILE - DO NOT EDIT, RUN yarn remake-constants in yarn-project/constants
|
|
442
467
|
namespace constants;
|
|
443
|
-
${processConstantsPil(constants,
|
|
468
|
+
${processConstantsPil(constants, domainSeparatorEnum)}
|
|
444
469
|
\n`;
|
|
445
470
|
fs.writeFileSync(targetPath, resultPil);
|
|
446
471
|
}
|
|
@@ -468,16 +493,19 @@ ${processConstantsSolidity(constants)}
|
|
|
468
493
|
}
|
|
469
494
|
/**
|
|
470
495
|
* Parse the content of the constants file in Noir.
|
|
471
|
-
*/ function parseNoirFile(fileContent) {
|
|
496
|
+
*/ function parseNoirFile(fileContent, { stripLineComments = false } = {}) {
|
|
472
497
|
const constantsExpressions = [];
|
|
473
|
-
const
|
|
498
|
+
const domainSeparatorEnum = {};
|
|
474
499
|
const emptyExpression = ()=>({
|
|
475
500
|
name: '',
|
|
476
501
|
content: []
|
|
477
502
|
});
|
|
478
503
|
let expression = emptyExpression();
|
|
479
504
|
fileContent.split('\n').forEach((l)=>{
|
|
480
|
-
|
|
505
|
+
// Strip trailing `//` line comments so multi-line expressions with inline comments (e.g.
|
|
506
|
+
// MAX_TX_BLOB_DATA_SIZE_IN_FIELDS) parse correctly. Disabled for constants.nr to keep its
|
|
507
|
+
// existing parsing behavior byte-for-byte unchanged.
|
|
508
|
+
const line = (stripLineComments ? l.replace(/\/\/.*$/, '') : l).trim();
|
|
481
509
|
if (!line) {
|
|
482
510
|
// Empty line.
|
|
483
511
|
return;
|
|
@@ -492,7 +520,7 @@ ${processConstantsSolidity(constants)}
|
|
|
492
520
|
const [, indexName] = name.match(/DOM_SEP__(\w+)/) || [];
|
|
493
521
|
if (indexName) {
|
|
494
522
|
// Generator index.
|
|
495
|
-
|
|
523
|
+
domainSeparatorEnum[indexName] = +value;
|
|
496
524
|
} else if (end) {
|
|
497
525
|
// A single line of expression.
|
|
498
526
|
constantsExpressions.push([
|
|
@@ -537,10 +565,9 @@ ${processConstantsSolidity(constants)}
|
|
|
537
565
|
console.warn(`Unknown content: ${line}`);
|
|
538
566
|
}
|
|
539
567
|
});
|
|
540
|
-
const constants = evaluateExpressions(constantsExpressions);
|
|
541
568
|
return {
|
|
542
|
-
|
|
543
|
-
|
|
569
|
+
constantsExpressions,
|
|
570
|
+
domainSeparatorEnum
|
|
544
571
|
};
|
|
545
572
|
}
|
|
546
573
|
/**
|
|
@@ -567,7 +594,11 @@ ${processConstantsSolidity(constants)}
|
|
|
567
594
|
.replace(/\(/g, '( ').replace(/\)/g, ' )')// We also make some space around common operators
|
|
568
595
|
.replace(/\+/g, ' + ').replace(/(?<!\/)\*(?!\/)/, ' * ')// We split the expression into terms...
|
|
569
596
|
.split(/\s+/)// ...and then we convert each term to a BigInt if it is a number.
|
|
570
|
-
.map((term)=>
|
|
597
|
+
.map((term)=>{
|
|
598
|
+
// Remove underscores from numeric literals (e.g., 6_000_000 -> 6000000)
|
|
599
|
+
const termWithoutUnderscores = term.replace(/_/g, '');
|
|
600
|
+
return isNaN(+termWithoutUnderscores) ? term : `BigInt('${termWithoutUnderscores}')`;
|
|
601
|
+
})// .. also, we convert the known bigints to BigInts.
|
|
571
602
|
.map((term)=>knownBigInts.includes(term) ? `BigInt(${term})` : term)// We join the terms back together.
|
|
572
603
|
.join(' ');
|
|
573
604
|
return `var ${name} = ${guardedRhs};`;
|
|
@@ -585,7 +616,26 @@ ${processConstantsSolidity(constants)}
|
|
|
585
616
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
586
617
|
const noirConstantsFile = join(__dirname, NOIR_CONSTANTS_FILE);
|
|
587
618
|
const noirConstants = fs.readFileSync(noirConstantsFile, 'utf-8');
|
|
588
|
-
const
|
|
619
|
+
const { constantsExpressions, domainSeparatorEnum } = parseNoirFile(noirConstants);
|
|
620
|
+
// Pull in explicitly-listed constants defined outside constants.nr (e.g. alongside circuit code).
|
|
621
|
+
// They are appended after the main constants so they can reference them when evaluated together.
|
|
622
|
+
for (const { file, constants: names } of ADDITIONAL_NOIR_CONSTANT_FILES){
|
|
623
|
+
const additionalContent = fs.readFileSync(join(__dirname, file), 'utf-8');
|
|
624
|
+
const { constantsExpressions: additionalExpressions } = parseNoirFile(additionalContent, {
|
|
625
|
+
stripLineComments: true
|
|
626
|
+
});
|
|
627
|
+
for (const name of names){
|
|
628
|
+
const expression = additionalExpressions.find(([exprName])=>exprName === name);
|
|
629
|
+
if (!expression) {
|
|
630
|
+
throw new Error(`Constant ${name} not found in ${file}`);
|
|
631
|
+
}
|
|
632
|
+
constantsExpressions.push(expression);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
const parsedContent = {
|
|
636
|
+
constants: evaluateExpressions(constantsExpressions),
|
|
637
|
+
domainSeparatorEnum
|
|
638
|
+
};
|
|
589
639
|
// Typescript
|
|
590
640
|
const tsTargetPath = join(__dirname, TS_CONSTANTS_FILE);
|
|
591
641
|
generateTypescriptConstants(parsedContent, tsTargetPath);
|
package/package.json
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/constants",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.a5db02d",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"inherits": [
|
|
6
6
|
"../package.common.json"
|
|
7
7
|
],
|
|
8
|
+
"typedocOptions": {
|
|
9
|
+
"entryPoints": [
|
|
10
|
+
"./src/constants.gen.ts"
|
|
11
|
+
],
|
|
12
|
+
"name": "Constants",
|
|
13
|
+
"tsconfig": "./tsconfig.json"
|
|
14
|
+
},
|
|
8
15
|
"exports": {
|
|
9
16
|
".": "./dest/constants.js"
|
|
10
17
|
},
|
|
@@ -16,7 +23,7 @@
|
|
|
16
23
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
17
24
|
},
|
|
18
25
|
"dependencies": {
|
|
19
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
26
|
+
"@aztec/foundation": "0.0.1-commit.a5db02d",
|
|
20
27
|
"tslib": "^2.4.0"
|
|
21
28
|
},
|
|
22
29
|
"devDependencies": {
|