@aztec/constants 0.0.1-commit.2ed92850 → 0.0.1-commit.3100065

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.js CHANGED
@@ -2,17 +2,40 @@ import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
2
2
  import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  // Re-export L2 block number constants with proper BlockNumber type
4
4
  // Note: The generated constants are plain numbers, but we provide typed versions here
5
- import { GENESIS_BLOCK_HEADER_HASH as GENESIS_BLOCK_HEADER_HASH_BIGINT, INITIAL_CHECKPOINT_NUMBER as INITIAL_CHECKPOINT_NUM_RAW, INITIAL_L2_BLOCK_NUM as INITIAL_L2_BLOCK_NUM_RAW } from './constants.gen.js';
5
+ import { DA_GAS_PER_FIELD, GENESIS_BLOCK_HEADER_HASH as GENESIS_BLOCK_HEADER_HASH_BIGINT, INITIAL_CHECKPOINT_NUMBER as INITIAL_CHECKPOINT_NUM_RAW, INITIAL_L2_BLOCK_NUM as INITIAL_L2_BLOCK_NUM_RAW, MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT as MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT_RAW, MAX_TX_BLOB_DATA_SIZE_IN_FIELDS } from './constants.gen.js';
6
6
  // Typescript-land-only constants
7
7
  export const SPONSORED_FPC_SALT = BigInt(0);
8
+ /**
9
+ * Network-minimum per-block budget multiplier for L2 gas / tx count. Operators may configure a higher value,
10
+ * but never lower: a node admitting txs under a smaller multiplier would accept work it can never pack.
11
+ */ export const MIN_PER_BLOCK_ALLOCATION_MULTIPLIER = 1.2;
12
+ /**
13
+ * Network-minimum per-block budget multiplier for DA gas / blob fields. See
14
+ * {@link MIN_PER_BLOCK_ALLOCATION_MULTIPLIER}. The DA-specific operator knob and its runtime enforcement land
15
+ * with the network tx admission limits (#23947); until then this constant is documentation of the network
16
+ * minimum only.
17
+ */ export const MIN_PER_BLOCK_DA_ALLOCATION_MULTIPLIER = 1.5;
18
+ /**
19
+ * The most DA gas a single tx can consume. A tx's effects cannot encode more than
20
+ * MAX_TX_BLOB_DATA_SIZE_IN_FIELDS fields in a blob, each costing DA_GAS_PER_FIELD, so this is the maximum
21
+ * DA gas a tx could ever use; declaring a higher limit is rejected by inbound validation.
22
+ */ export const MAX_TX_DA_GAS = MAX_TX_BLOB_DATA_SIZE_IN_FIELDS * DA_GAS_PER_FIELD;
8
23
  // Autogenerated constants loaded from noir-land
9
24
  // eslint-disable-next-line import-x/export
10
25
  export * from './constants.gen.js';
11
- /** The initial L2 block number (typed as BlockNumber). This is the first block number in the Aztec L2 chain. */ // Shadow the export from constants.gen above
12
- // eslint-disable-next-line import-x/export
26
+ /** The initial L2 block number (typed as BlockNumber). This is the first block number in the Aztec L2 chain. */ // eslint-disable-next-line import-x/export
13
27
  export const INITIAL_L2_BLOCK_NUM = BlockNumber(INITIAL_L2_BLOCK_NUM_RAW);
14
- /** The initial L2 checkpoint number (typed as CheckpointNumber). This is the first checkpoint number in the Aztec L2 chain. */ // Shadow the export from constants.gen above
15
- export const INITIAL_L2_CHECKPOINT_NUM = CheckpointNumber(INITIAL_CHECKPOINT_NUM_RAW);
16
- /** The block header hash for the genesis block 0. */ // Shadow the export from constants.gen above
17
- // eslint-disable-next-line import-x/export
28
+ /** The initial L2 checkpoint number (typed as CheckpointNumber). This is the first checkpoint number in the Aztec L2 chain. */ // eslint-disable-next-line import-x/export
29
+ export const INITIAL_CHECKPOINT_NUMBER = CheckpointNumber(INITIAL_CHECKPOINT_NUM_RAW);
30
+ /** The block header hash for the genesis block 0. */ // eslint-disable-next-line import-x/export
18
31
  export const GENESIS_BLOCK_HEADER_HASH = new Fr(GENESIS_BLOCK_HEADER_HASH_BIGINT);
32
+ /**
33
+ * The RAW DA capacity of a checkpoint's blobs: `BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB * DA_GAS_PER_FIELD`.
34
+ * This value is NOT attainable by transactions. The blob encoding reserves overhead fields that no tx pays
35
+ * DA gas for: a checkpoint-end marker field plus per-block block-end fields (7 for the first block in a
36
+ * checkpoint, 6 for each subsequent block — see `@aztec/blob-lib` encoding). The true tx-usable DA budget
37
+ * is lower and block-count-dependent; consumers budgeting tx data should subtract the encoding overhead (as
38
+ * `CheckpointBuilder` and the network tx gas limits in `@aztec/stdlib/gas` do) rather than use this value
39
+ * directly.
40
+ */ // eslint-disable-next-line import-x/export
41
+ export const MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT = MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT_RAW;
@@ -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/vm2/common/aztec_constants.hpp';
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
- 'PUBLIC_CHECKS_ADDRESS',
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,21 +122,31 @@ 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 = [
130
+ 'BLOCK_HEADER_HASH',
131
+ 'SALTED_INITIALIZATION_HASH',
116
132
  'PARTIAL_ADDRESS',
117
- 'CONTRACT_ADDRESS_V1',
133
+ 'CONTRACT_ADDRESS_V2',
118
134
  'CONTRACT_CLASS_ID',
119
135
  'PUBLIC_KEYS_HASH',
136
+ 'SINGLE_PUBLIC_KEY_HASH',
120
137
  'NOTE_HASH_NONCE',
121
138
  'UNIQUE_NOTE_HASH',
122
139
  'SILOED_NOTE_HASH',
123
- 'OUTER_NULLIFIER',
124
- 'PUBLIC_LEAF_INDEX',
140
+ 'SILOED_NULLIFIER',
141
+ 'PUBLIC_LEAF_SLOT',
142
+ 'PUBLIC_STORAGE_MAP_SLOT',
125
143
  'PUBLIC_CALLDATA',
126
- 'PUBLIC_BYTECODE'
144
+ 'PUBLIC_BYTECODE',
145
+ 'MERKLE_HASH',
146
+ 'NULLIFIER_MERKLE',
147
+ 'PUBLIC_DATA_MERKLE',
148
+ 'WRITTEN_SLOTS_MERKLE',
149
+ 'RETRIEVED_BYTECODES_MERKLE'
127
150
  ];
128
151
  const PIL_CONSTANTS = [
129
152
  'MAX_ETH_ADDRESS_VALUE',
@@ -157,12 +180,9 @@ const PIL_CONSTANTS = [
157
180
  'L1_TO_L2_MSG_TREE_HEIGHT',
158
181
  'UPDATED_CLASS_IDS_SLOT',
159
182
  'UPDATES_DELAYED_PUBLIC_MUTABLE_VALUES_LEN',
160
- 'CANONICAL_AUTH_REGISTRY_ADDRESS',
161
183
  'CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS',
162
184
  'CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS',
163
- 'MULTI_CALL_ENTRYPOINT_ADDRESS',
164
185
  'FEE_JUICE_ADDRESS',
165
- 'PUBLIC_CHECKS_ADDRESS',
166
186
  'FEE_JUICE_BALANCES_SLOT',
167
187
  'TIMESTAMP_OF_CHANGE_BIT_SIZE',
168
188
  'UPDATES_DELAYED_PUBLIC_MUTABLE_METADATA_BIT_SIZE',
@@ -246,10 +266,10 @@ const PIL_CONSTANTS = [
246
266
  'AVM_DYN_GAS_ID_RETURNDATACOPY',
247
267
  'AVM_DYN_GAS_ID_TORADIX',
248
268
  'AVM_DYN_GAS_ID_BITWISE',
249
- 'AVM_DYN_GAS_ID_EMITUNENCRYPTEDLOG',
269
+ 'AVM_DYN_GAS_ID_EMITPUBLICLOG',
250
270
  'AVM_DYN_GAS_ID_SSTORE',
251
271
  'AVM_SUBTRACE_ID_GETCONTRACTINSTANCE',
252
- 'AVM_SUBTRACE_ID_EMITUNENCRYPTEDLOG',
272
+ 'AVM_SUBTRACE_ID_EMITPUBLICLOG',
253
273
  'AVM_EXEC_OP_ID_GETENVVAR',
254
274
  'AVM_EXEC_OP_ID_MOV',
255
275
  'AVM_EXEC_OP_ID_JUMP',
@@ -298,17 +318,25 @@ const PIL_CONSTANTS = [
298
318
  'MAX_PROTOCOL_CONTRACTS'
299
319
  ];
300
320
  const PIL_GENERATORS = [
321
+ 'SALTED_INITIALIZATION_HASH',
301
322
  'PARTIAL_ADDRESS',
302
- 'CONTRACT_ADDRESS_V1',
323
+ 'CONTRACT_ADDRESS_V2',
303
324
  'CONTRACT_CLASS_ID',
304
325
  'PUBLIC_KEYS_HASH',
326
+ 'SINGLE_PUBLIC_KEY_HASH',
305
327
  'NOTE_HASH_NONCE',
306
328
  'UNIQUE_NOTE_HASH',
307
329
  'SILOED_NOTE_HASH',
308
- 'OUTER_NULLIFIER',
309
- 'PUBLIC_LEAF_INDEX',
330
+ 'SILOED_NULLIFIER',
331
+ 'PUBLIC_LEAF_SLOT',
332
+ 'PUBLIC_STORAGE_MAP_SLOT',
310
333
  'PUBLIC_CALLDATA',
311
- 'PUBLIC_BYTECODE'
334
+ 'PUBLIC_BYTECODE',
335
+ 'MERKLE_HASH',
336
+ 'NULLIFIER_MERKLE',
337
+ 'PUBLIC_DATA_MERKLE',
338
+ 'WRITTEN_SLOTS_MERKLE',
339
+ 'RETRIEVED_BYTECODES_MERKLE'
312
340
  ];
313
341
  const SOLIDITY_CONSTANTS = [
314
342
  'MAX_FIELD_VALUE',
@@ -322,7 +350,7 @@ const SOLIDITY_CONSTANTS = [
322
350
  'INITIAL_CHECKPOINT_NUMBER',
323
351
  'GENESIS_ARCHIVE_ROOT',
324
352
  'FEE_JUICE_ADDRESS',
325
- 'AZTEC_MAX_EPOCH_DURATION'
353
+ 'MAX_CHECKPOINTS_PER_EPOCH'
326
354
  ];
327
355
  /**
328
356
  * Processes a collection of constants and generates code to export them as TypeScript constants.
@@ -357,7 +385,7 @@ const SOLIDITY_CONSTANTS = [
357
385
  });
358
386
  Object.entries(generatorIndices).forEach(([key, value])=>{
359
387
  if (CPP_GENERATORS.includes(key)) {
360
- code.push(`#define DOM_SEP__${key} ${value}`);
388
+ code.push(`#define DOM_SEP__${key} ${value}UL`);
361
389
  }
362
390
  });
363
391
  return code.join('\n');
@@ -414,30 +442,30 @@ const SOLIDITY_CONSTANTS = [
414
442
  }
415
443
  /**
416
444
  * Generate the constants file in Typescript.
417
- */ function generateTypescriptConstants({ constants, generatorIndexEnum }, targetPath) {
445
+ */ function generateTypescriptConstants({ constants, domainSeparatorEnum }, targetPath) {
418
446
  const result = [
419
447
  '// GENERATED FILE - DO NOT EDIT, RUN yarn remake-constants',
420
448
  processConstantsTS(constants),
421
- processEnumTS('GeneratorIndex', generatorIndexEnum)
449
+ processEnumTS('DomainSeparator', domainSeparatorEnum)
422
450
  ].join('\n');
423
451
  fs.writeFileSync(targetPath, result);
424
452
  }
425
453
  /**
426
454
  * Generate the constants file in C++.
427
- */ function generateCppConstants({ constants, generatorIndexEnum }, targetPath) {
455
+ */ function generateCppConstants({ constants, domainSeparatorEnum }, targetPath) {
428
456
  const resultCpp = `// GENERATED FILE - DO NOT EDIT, RUN yarn remake-constants in yarn-project/constants
429
457
  #pragma once
430
458
 
431
- ${processConstantsCpp(constants, generatorIndexEnum)}
459
+ ${processConstantsCpp(constants, domainSeparatorEnum)}
432
460
  `;
433
461
  fs.writeFileSync(targetPath, resultCpp);
434
462
  }
435
463
  /**
436
464
  * Generate the constants file in PIL.
437
- */ function generatePilConstants({ constants, generatorIndexEnum }, targetPath) {
465
+ */ function generatePilConstants({ constants, domainSeparatorEnum }, targetPath) {
438
466
  const resultPil = `// GENERATED FILE - DO NOT EDIT, RUN yarn remake-constants in yarn-project/constants
439
467
  namespace constants;
440
- ${processConstantsPil(constants, generatorIndexEnum)}
468
+ ${processConstantsPil(constants, domainSeparatorEnum)}
441
469
  \n`;
442
470
  fs.writeFileSync(targetPath, resultPil);
443
471
  }
@@ -465,16 +493,19 @@ ${processConstantsSolidity(constants)}
465
493
  }
466
494
  /**
467
495
  * Parse the content of the constants file in Noir.
468
- */ function parseNoirFile(fileContent) {
496
+ */ function parseNoirFile(fileContent, { stripLineComments = false } = {}) {
469
497
  const constantsExpressions = [];
470
- const generatorIndexEnum = {};
498
+ const domainSeparatorEnum = {};
471
499
  const emptyExpression = ()=>({
472
500
  name: '',
473
501
  content: []
474
502
  });
475
503
  let expression = emptyExpression();
476
504
  fileContent.split('\n').forEach((l)=>{
477
- const line = l.trim();
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();
478
509
  if (!line) {
479
510
  // Empty line.
480
511
  return;
@@ -489,7 +520,7 @@ ${processConstantsSolidity(constants)}
489
520
  const [, indexName] = name.match(/DOM_SEP__(\w+)/) || [];
490
521
  if (indexName) {
491
522
  // Generator index.
492
- generatorIndexEnum[indexName] = +value;
523
+ domainSeparatorEnum[indexName] = +value;
493
524
  } else if (end) {
494
525
  // A single line of expression.
495
526
  constantsExpressions.push([
@@ -534,10 +565,9 @@ ${processConstantsSolidity(constants)}
534
565
  console.warn(`Unknown content: ${line}`);
535
566
  }
536
567
  });
537
- const constants = evaluateExpressions(constantsExpressions);
538
568
  return {
539
- constants,
540
- generatorIndexEnum
569
+ constantsExpressions,
570
+ domainSeparatorEnum
541
571
  };
542
572
  }
543
573
  /**
@@ -564,7 +594,11 @@ ${processConstantsSolidity(constants)}
564
594
  .replace(/\(/g, '( ').replace(/\)/g, ' )')// We also make some space around common operators
565
595
  .replace(/\+/g, ' + ').replace(/(?<!\/)\*(?!\/)/, ' * ')// We split the expression into terms...
566
596
  .split(/\s+/)// ...and then we convert each term to a BigInt if it is a number.
567
- .map((term)=>isNaN(+term) ? term : `BigInt('${term}')`)// .. also, we convert the known bigints to BigInts.
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.
568
602
  .map((term)=>knownBigInts.includes(term) ? `BigInt(${term})` : term)// We join the terms back together.
569
603
  .join(' ');
570
604
  return `var ${name} = ${guardedRhs};`;
@@ -582,7 +616,26 @@ ${processConstantsSolidity(constants)}
582
616
  const __dirname = dirname(fileURLToPath(import.meta.url));
583
617
  const noirConstantsFile = join(__dirname, NOIR_CONSTANTS_FILE);
584
618
  const noirConstants = fs.readFileSync(noirConstantsFile, 'utf-8');
585
- const parsedContent = parseNoirFile(noirConstants);
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
+ };
586
639
  // Typescript
587
640
  const tsTargetPath = join(__dirname, TS_CONSTANTS_FILE);
588
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.2ed92850",
3
+ "version": "0.0.1-commit.3100065",
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.2ed92850",
26
+ "@aztec/foundation": "0.0.1-commit.3100065",
20
27
  "tslib": "^2.4.0"
21
28
  },
22
29
  "devDependencies": {