@aztec/stdlib 4.0.4 → 4.1.0-rc.2

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.
Files changed (98) hide show
  1. package/dest/block/l2_block.d.ts +9 -1
  2. package/dest/block/l2_block.d.ts.map +1 -1
  3. package/dest/block/l2_block.js +12 -2
  4. package/dest/block/l2_block_source.d.ts +6 -1
  5. package/dest/block/l2_block_source.d.ts.map +1 -1
  6. package/dest/checkpoint/checkpoint.d.ts +2 -1
  7. package/dest/checkpoint/checkpoint.d.ts.map +1 -1
  8. package/dest/checkpoint/checkpoint.js +9 -4
  9. package/dest/checkpoint/index.d.ts +2 -1
  10. package/dest/checkpoint/index.d.ts.map +1 -1
  11. package/dest/checkpoint/index.js +1 -0
  12. package/dest/checkpoint/validate.d.ts +36 -0
  13. package/dest/checkpoint/validate.d.ts.map +1 -0
  14. package/dest/checkpoint/validate.js +120 -0
  15. package/dest/config/sequencer-config.d.ts +2 -4
  16. package/dest/config/sequencer-config.d.ts.map +1 -1
  17. package/dest/config/sequencer-config.js +1 -3
  18. package/dest/interfaces/allowed_element.d.ts +26 -20
  19. package/dest/interfaces/allowed_element.d.ts.map +1 -1
  20. package/dest/interfaces/allowed_element.js +8 -8
  21. package/dest/interfaces/archiver.d.ts +1 -1
  22. package/dest/interfaces/archiver.d.ts.map +1 -1
  23. package/dest/interfaces/archiver.js +1 -0
  24. package/dest/interfaces/aztec-node-admin.d.ts +61 -30
  25. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  26. package/dest/interfaces/aztec-node.d.ts +10 -5
  27. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  28. package/dest/interfaces/aztec-node.js +3 -2
  29. package/dest/interfaces/block-builder.d.ts +11 -5
  30. package/dest/interfaces/block-builder.d.ts.map +1 -1
  31. package/dest/interfaces/block-builder.js +7 -2
  32. package/dest/interfaces/configs.d.ts +57 -32
  33. package/dest/interfaces/configs.d.ts.map +1 -1
  34. package/dest/interfaces/configs.js +5 -2
  35. package/dest/interfaces/validator.d.ts +67 -28
  36. package/dest/interfaces/validator.d.ts.map +1 -1
  37. package/dest/interfaces/validator.js +6 -3
  38. package/dest/kernel/private_kernel_tail_circuit_public_inputs.d.ts +2 -1
  39. package/dest/kernel/private_kernel_tail_circuit_public_inputs.d.ts.map +1 -1
  40. package/dest/kernel/private_kernel_tail_circuit_public_inputs.js +4 -0
  41. package/dest/p2p/checkpoint_proposal.d.ts +1 -6
  42. package/dest/p2p/checkpoint_proposal.d.ts.map +1 -1
  43. package/dest/p2p/checkpoint_proposal.js +0 -12
  44. package/dest/slashing/tally.d.ts +7 -2
  45. package/dest/slashing/tally.d.ts.map +1 -1
  46. package/dest/slashing/tally.js +30 -2
  47. package/dest/tests/mocks.d.ts +4 -2
  48. package/dest/tests/mocks.d.ts.map +1 -1
  49. package/dest/tests/mocks.js +13 -8
  50. package/dest/tx/block_header.d.ts +3 -1
  51. package/dest/tx/block_header.d.ts.map +1 -1
  52. package/dest/tx/block_header.js +4 -0
  53. package/dest/tx/simulated_tx.d.ts +5 -2
  54. package/dest/tx/simulated_tx.d.ts.map +1 -1
  55. package/dest/tx/simulated_tx.js +4 -1
  56. package/dest/tx/tx.d.ts +6 -5
  57. package/dest/tx/tx.d.ts.map +1 -1
  58. package/dest/tx/tx.js +18 -6
  59. package/dest/tx/validator/error_texts.d.ts +5 -1
  60. package/dest/tx/validator/error_texts.d.ts.map +1 -1
  61. package/dest/tx/validator/error_texts.js +4 -0
  62. package/dest/update-checker/index.d.ts +3 -2
  63. package/dest/update-checker/index.d.ts.map +1 -1
  64. package/dest/update-checker/index.js +2 -1
  65. package/dest/update-checker/package_version.d.ts +3 -0
  66. package/dest/update-checker/package_version.d.ts.map +1 -0
  67. package/dest/update-checker/package_version.js +11 -0
  68. package/dest/update-checker/version_checker.d.ts +25 -0
  69. package/dest/update-checker/version_checker.d.ts.map +1 -0
  70. package/dest/update-checker/version_checker.js +50 -0
  71. package/package.json +9 -9
  72. package/src/block/l2_block.ts +13 -1
  73. package/src/block/l2_block_source.ts +6 -0
  74. package/src/checkpoint/checkpoint.ts +12 -3
  75. package/src/checkpoint/index.ts +1 -0
  76. package/src/checkpoint/validate.ts +230 -0
  77. package/src/config/sequencer-config.ts +2 -5
  78. package/src/interfaces/allowed_element.ts +29 -9
  79. package/src/interfaces/archiver.ts +1 -0
  80. package/src/interfaces/aztec-node.ts +14 -4
  81. package/src/interfaces/block-builder.ts +25 -5
  82. package/src/interfaces/configs.ts +22 -8
  83. package/src/interfaces/validator.ts +18 -3
  84. package/src/kernel/private_kernel_tail_circuit_public_inputs.ts +9 -0
  85. package/src/p2p/checkpoint_proposal.ts +0 -17
  86. package/src/slashing/tally.ts +34 -1
  87. package/src/tests/mocks.ts +18 -7
  88. package/src/tx/block_header.ts +6 -0
  89. package/src/tx/simulated_tx.ts +8 -1
  90. package/src/tx/tx.ts +20 -11
  91. package/src/tx/validator/error_texts.ts +4 -0
  92. package/src/update-checker/index.ts +2 -1
  93. package/src/update-checker/package_version.ts +17 -0
  94. package/src/update-checker/version_checker.ts +65 -0
  95. package/dest/update-checker/update-checker.d.ts +0 -49
  96. package/dest/update-checker/update-checker.d.ts.map +0 -1
  97. package/dest/update-checker/update-checker.js +0 -130
  98. package/src/update-checker/update-checker.ts +0 -166
@@ -13,6 +13,8 @@ export interface SequencerConfig {
13
13
  sequencerPollingIntervalMS?: number;
14
14
  /** The maximum number of txs to include in a block. */
15
15
  maxTxsPerBlock?: number;
16
+ /** The maximum number of txs across all blocks in a checkpoint. */
17
+ maxTxsPerCheckpoint?: number;
16
18
  /** The minimum number of txs to include in a block. */
17
19
  minTxsPerBlock?: number;
18
20
  /** The minimum number of valid txs (after execution) to include in a block. If not set, falls back to minTxsPerBlock. */
@@ -23,6 +25,8 @@ export interface SequencerConfig {
23
25
  maxL2BlockGas?: number;
24
26
  /** The maximum DA block gas. */
25
27
  maxDABlockGas?: number;
28
+ /** Per-block gas budget multiplier for both L2 and DA gas. Budget = (checkpointLimit / maxBlocks) * multiplier. */
29
+ perBlockAllocationMultiplier?: number;
26
30
  /** Recipient of block reward. */
27
31
  coinbase?: EthAddress;
28
32
  /** Address to receive fees. */
@@ -31,10 +35,8 @@ export interface SequencerConfig {
31
35
  acvmWorkingDirectory?: string;
32
36
  /** The path to the ACVM binary */
33
37
  acvmBinaryPath?: string;
34
- /** The list of functions calls allowed to run in setup */
35
- txPublicSetupAllowList?: AllowedElement[];
36
- /** Max block size */
37
- maxBlockSizeInBytes?: number;
38
+ /** Additional entries to extend the default setup allow list. */
39
+ txPublicSetupAllowListExtend?: AllowedElement[];
38
40
  /** Payload address to vote for */
39
41
  governanceProposerPayload?: EthAddress;
40
42
  /** Whether to enforce the time table when building blocks */
@@ -59,6 +61,10 @@ export interface SequencerConfig {
59
61
  broadcastInvalidBlockProposal?: boolean;
60
62
  /** Inject a fake attestation (for testing only) */
61
63
  injectFakeAttestation?: boolean;
64
+ /** Inject a malleable attestation with a high-s value (for testing only) */
65
+ injectHighSValueAttestation?: boolean;
66
+ /** Inject an attestation with an unrecoverable signature (for testing only) */
67
+ injectUnrecoverableSignatureAttestation?: boolean;
62
68
  /** Whether to run in fisherman mode: builds blocks on every slot for validation without publishing */
63
69
  fishermanMode?: boolean;
64
70
  /** Shuffle attestation ordering to create invalid ordering (for testing only) */
@@ -81,17 +87,18 @@ export const SequencerConfigSchema = zodFor<SequencerConfig>()(
81
87
  z.object({
82
88
  sequencerPollingIntervalMS: z.number().optional(),
83
89
  maxTxsPerBlock: z.number().optional(),
90
+ maxTxsPerCheckpoint: z.number().optional(),
84
91
  minValidTxsPerBlock: z.number().optional(),
85
92
  minTxsPerBlock: z.number().optional(),
86
93
  maxL2BlockGas: z.number().optional(),
87
94
  publishTxsWithProposals: z.boolean().optional(),
88
95
  maxDABlockGas: z.number().optional(),
96
+ perBlockAllocationMultiplier: z.number().optional(),
89
97
  coinbase: schemas.EthAddress.optional(),
90
98
  feeRecipient: schemas.AztecAddress.optional(),
91
99
  acvmWorkingDirectory: z.string().optional(),
92
100
  acvmBinaryPath: z.string().optional(),
93
- txPublicSetupAllowList: z.array(AllowedElementSchema).optional(),
94
- maxBlockSizeInBytes: z.number().optional(),
101
+ txPublicSetupAllowListExtend: z.array(AllowedElementSchema).optional(),
95
102
  governanceProposerPayload: schemas.EthAddress.optional(),
96
103
  l1PublishingTime: z.number().optional(),
97
104
  enforceTimeTable: z.boolean().optional(),
@@ -104,6 +111,8 @@ export const SequencerConfigSchema = zodFor<SequencerConfig>()(
104
111
  secondsBeforeInvalidatingBlockAsNonCommitteeMember: z.number(),
105
112
  broadcastInvalidBlockProposal: z.boolean().optional(),
106
113
  injectFakeAttestation: z.boolean().optional(),
114
+ injectHighSValueAttestation: z.boolean().optional(),
115
+ injectUnrecoverableSignatureAttestation: z.boolean().optional(),
107
116
  fishermanMode: z.boolean().optional(),
108
117
  shuffleAttestationOrdering: z.boolean().optional(),
109
118
  blockDurationMs: z.number().positive().optional(),
@@ -126,9 +135,14 @@ type SequencerConfigOptionalKeys =
126
135
  | 'fakeProcessingDelayPerTxMs'
127
136
  | 'fakeThrowAfterProcessingTxCount'
128
137
  | 'l1PublishingTime'
129
- | 'txPublicSetupAllowList'
138
+ | 'txPublicSetupAllowListExtend'
130
139
  | 'minValidTxsPerBlock'
131
- | 'minBlocksForCheckpoint';
140
+ | 'minBlocksForCheckpoint'
141
+ | 'maxTxsPerBlock'
142
+ | 'maxTxsPerCheckpoint'
143
+ | 'maxL2BlockGas'
144
+ | 'maxDABlockGas'
145
+ | 'perBlockAllocationMultiplier';
132
146
 
133
147
  export type ResolvedSequencerConfig = Prettify<
134
148
  Required<Omit<SequencerConfig, SequencerConfigOptionalKeys>> & Pick<SequencerConfig, SequencerConfigOptionalKeys>
@@ -59,10 +59,22 @@ export type ValidatorClientConfig = ValidatorHASignerConfig & {
59
59
 
60
60
  /** Agree to attest to equivocated checkpoint proposals (for testing purposes only) */
61
61
  attestToEquivocatedProposals?: boolean;
62
+
63
+ /** Maximum L2 gas per block for validation. Proposals exceeding this limit are rejected. */
64
+ validateMaxL2BlockGas?: number;
65
+
66
+ /** Maximum DA gas per block for validation. Proposals exceeding this limit are rejected. */
67
+ validateMaxDABlockGas?: number;
68
+
69
+ /** Maximum transactions per block for validation. Proposals exceeding this limit are rejected. */
70
+ validateMaxTxsPerBlock?: number;
71
+
72
+ /** Maximum transactions per checkpoint for validation. Proposals exceeding this limit are rejected. */
73
+ validateMaxTxsPerCheckpoint?: number;
62
74
  };
63
75
 
64
76
  export type ValidatorClientFullConfig = ValidatorClientConfig &
65
- Pick<SequencerConfig, 'txPublicSetupAllowList' | 'broadcastInvalidBlockProposal' | 'maxTxsPerBlock'> &
77
+ Pick<SequencerConfig, 'txPublicSetupAllowListExtend' | 'broadcastInvalidBlockProposal'> &
66
78
  Pick<
67
79
  SlasherConfig,
68
80
  'slashBroadcastedInvalidBlockPenalty' | 'slashDuplicateProposalPenalty' | 'slashDuplicateAttestationPenalty'
@@ -86,14 +98,17 @@ export const ValidatorClientConfigSchema = zodFor<Omit<ValidatorClientConfig, 'v
86
98
  skipCheckpointProposalValidation: z.boolean().optional(),
87
99
  skipPushProposedBlocksToArchiver: z.boolean().optional(),
88
100
  attestToEquivocatedProposals: z.boolean().optional(),
101
+ validateMaxL2BlockGas: z.number().optional(),
102
+ validateMaxDABlockGas: z.number().optional(),
103
+ validateMaxTxsPerBlock: z.number().optional(),
104
+ validateMaxTxsPerCheckpoint: z.number().optional(),
89
105
  }),
90
106
  );
91
107
 
92
108
  export const ValidatorClientFullConfigSchema = zodFor<Omit<ValidatorClientFullConfig, 'validatorPrivateKeys'>>()(
93
109
  ValidatorClientConfigSchema.extend({
94
- txPublicSetupAllowList: z.array(AllowedElementSchema).optional(),
110
+ txPublicSetupAllowListExtend: z.array(AllowedElementSchema).optional(),
95
111
  broadcastInvalidBlockProposal: z.boolean().optional(),
96
- maxTxsPerBlock: z.number().optional(),
97
112
  slashBroadcastedInvalidBlockPenalty: schemas.BigInt,
98
113
  slashDuplicateProposalPenalty: schemas.BigInt,
99
114
  slashDuplicateAttestationPenalty: schemas.BigInt,
@@ -234,6 +234,15 @@ export class PrivateKernelTailCircuitPublicInputs {
234
234
  return noteHashes.filter(n => !n.isZero());
235
235
  }
236
236
 
237
+ getNonEmptyL2ToL1Msgs() {
238
+ const l2ToL1Msgs = this.forPublic
239
+ ? this.forPublic.nonRevertibleAccumulatedData.l2ToL1Msgs.concat(
240
+ this.forPublic.revertibleAccumulatedData.l2ToL1Msgs,
241
+ )
242
+ : this.forRollup!.end.l2ToL1Msgs;
243
+ return l2ToL1Msgs.filter(m => !m.isEmpty());
244
+ }
245
+
237
246
  getNonEmptyNullifiers() {
238
247
  const nullifiers = this.forPublic
239
248
  ? this.forPublic.nonRevertibleAccumulatedData.nullifiers.concat(
@@ -101,23 +101,6 @@ export class CheckpointProposal extends Gossipable {
101
101
  return this.checkpointHeader.slotNumber;
102
102
  }
103
103
 
104
- get blockNumber(): BlockNumber {
105
- if (!this.lastBlock) {
106
- throw new Error('Cannot get blockNumber without lastBlock');
107
- }
108
- return this.lastBlock.blockHeader.getBlockNumber();
109
- }
110
-
111
- /** Convenience getter for txHashes from lastBlock */
112
- get txHashes(): TxHash[] {
113
- return this.lastBlock?.txHashes ?? [];
114
- }
115
-
116
- /** Convenience getter for txs from lastBlock */
117
- get txs(): Tx[] | undefined {
118
- return this.lastBlock?.signedTxs?.txs;
119
- }
120
-
121
104
  /**
122
105
  * Extract a BlockProposal from the last block info.
123
106
  * Uses inHash from checkpointHeader.contentCommitment.inHash
@@ -1,6 +1,7 @@
1
1
  import { sumBigint } from '@aztec/foundation/bigint';
2
2
  import { padArrayEnd } from '@aztec/foundation/collection';
3
3
  import { EthAddress } from '@aztec/foundation/eth-address';
4
+ import { type Logger, createLogger } from '@aztec/foundation/log';
4
5
  import type { PartialBy } from '@aztec/foundation/types';
5
6
 
6
7
  import { getEpochForOffense } from './helpers.js';
@@ -12,6 +13,9 @@ import type { Offense, ValidatorSlashVote } from './types.js';
12
13
  * @param committees - Array of committees (each containing array of validator addresses)
13
14
  * @param epochsForCommittees - Array of epochs corresponding to each committee
14
15
  * @param settings - Settings including slashingAmounts and optional validator override lists
16
+ * @param settings.maxSlashedValidators - If set, limits the total number of [validator, epoch] pairs
17
+ * with non-zero votes. The lowest-vote pairs are zeroed out to stay within the limit.
18
+ * @param logger - Logger, logs which validators were dropped.
15
19
  * @returns Array of ValidatorSlashVote, where each vote is how many slash units the validator in that position should be slashed
16
20
  */
17
21
  export function getSlashConsensusVotesFromOffenses(
@@ -22,9 +26,11 @@ export function getSlashConsensusVotesFromOffenses(
22
26
  slashingAmounts: [bigint, bigint, bigint];
23
27
  epochDuration: number;
24
28
  targetCommitteeSize: number;
29
+ maxSlashedValidators?: number;
25
30
  },
31
+ logger: Logger = createLogger('slasher:tally'),
26
32
  ): ValidatorSlashVote[] {
27
- const { slashingAmounts, targetCommitteeSize } = settings;
33
+ const { slashingAmounts, targetCommitteeSize, maxSlashedValidators } = settings;
28
34
 
29
35
  if (committees.length !== epochsForCommittees.length) {
30
36
  throw new Error('committees and epochsForCommittees must have the same length');
@@ -53,6 +59,33 @@ export function getSlashConsensusVotesFromOffenses(
53
59
  return padArrayEnd(votes, 0, targetCommitteeSize);
54
60
  });
55
61
 
62
+ // if a cap is set, zero out the lowest-vote [validator, epoch] pairs so that the most severe slashes stay.
63
+ if (maxSlashedValidators === undefined) {
64
+ return votes;
65
+ }
66
+
67
+ const nonZeroByDescendingVote = [...votes.entries()].filter(([, vote]) => vote > 0).sort(([, a], [, b]) => b - a);
68
+
69
+ const toTruncate = nonZeroByDescendingVote.slice(maxSlashedValidators);
70
+ for (const [idx] of toTruncate) {
71
+ votes[idx] = 0;
72
+ }
73
+
74
+ if (toTruncate.length > 0) {
75
+ const truncated = toTruncate.map(([idx]) => {
76
+ const committeeIndex = Math.floor(idx / targetCommitteeSize);
77
+ const positionInCommittee = idx % targetCommitteeSize;
78
+ return {
79
+ validator: committees[committeeIndex][positionInCommittee].toString(),
80
+ epoch: epochsForCommittees[committeeIndex],
81
+ };
82
+ });
83
+ logger.warn(
84
+ `Truncated ${toTruncate.length} validator-epoch pairs to stay within limit of ${maxSlashedValidators}`,
85
+ { truncated },
86
+ );
87
+ }
88
+
56
89
  return votes;
57
90
  }
58
91
 
@@ -98,6 +98,7 @@ export const mockTx = async (
98
98
  publicCalldataSize = 2,
99
99
  feePayer,
100
100
  chonkProof = ChonkProof.random(),
101
+ gasLimits,
101
102
  maxFeesPerGas = new GasFees(10, 10),
102
103
  maxPriorityFeesPerGas,
103
104
  gasUsed = Gas.empty(),
@@ -114,6 +115,7 @@ export const mockTx = async (
114
115
  publicCalldataSize?: number;
115
116
  feePayer?: AztecAddress;
116
117
  chonkProof?: ChonkProof;
118
+ gasLimits?: Gas;
117
119
  maxFeesPerGas?: GasFees;
118
120
  maxPriorityFeesPerGas?: GasFees;
119
121
  gasUsed?: Gas;
@@ -132,7 +134,7 @@ export const mockTx = async (
132
134
  const data = PrivateKernelTailCircuitPublicInputs.empty();
133
135
  const firstNullifier = new Nullifier(new Fr(seed + 1), Fr.ZERO, 0);
134
136
  data.constants.anchorBlockHeader = anchorBlockHeader;
135
- data.constants.txContext.gasSettings = GasSettings.default({ maxFeesPerGas, maxPriorityFeesPerGas });
137
+ data.constants.txContext.gasSettings = GasSettings.default({ gasLimits, maxFeesPerGas, maxPriorityFeesPerGas });
136
138
  data.feePayer = feePayer ?? (await AztecAddress.random());
137
139
  data.gasUsed = gasUsed;
138
140
  data.constants.txContext.chainId = chainId;
@@ -425,10 +427,13 @@ export async function mockCheckpointAndMessages(
425
427
  Partial<Parameters<typeof L2Block.random>[1]> = {},
426
428
  ) {
427
429
  const slotNumber = options.slotNumber ?? SlotNumber(Number(checkpointNumber) * 10);
430
+ const globals = GlobalVariables.random({ slotNumber, ...options });
428
431
  const blocksAndMessages = [];
432
+
429
433
  // Track the previous block's archive to ensure consecutive blocks have consistent archive roots.
430
434
  // The current block's header.lastArchive must equal the previous block's archive.
431
435
  let lastArchive: AppendOnlyTreeSnapshot | undefined = previousArchive;
436
+
432
437
  // Pass maxEffects via txOptions so it reaches TxEffect.random
433
438
  const txOptions = maxEffects !== undefined ? { maxEffects } : {};
434
439
  for (let i = 0; i < (blocks?.length ?? numBlocks); i++) {
@@ -437,11 +442,11 @@ export async function mockCheckpointAndMessages(
437
442
  block:
438
443
  blocks?.[i] ??
439
444
  (await L2Block.random(blockNumber, {
445
+ ...globals,
440
446
  checkpointNumber,
441
447
  indexWithinCheckpoint: IndexWithinCheckpoint(i),
442
448
  txsPerBlock: numTxsPerBlock,
443
449
  txOptions,
444
- slotNumber,
445
450
  ...options,
446
451
  ...makeBlockOptions(blockNumber),
447
452
  ...(lastArchive ? { lastArchive } : {}),
@@ -455,12 +460,18 @@ export async function mockCheckpointAndMessages(
455
460
 
456
461
  const messages = blocksAndMessages[0].messages;
457
462
  const inHash = computeInHashFromL1ToL2Messages(messages);
458
- const checkpoint = await Checkpoint.random(checkpointNumber, { numBlocks: 0, slotNumber, inHash, ...options });
463
+ const firstBlockLastArchive = blocksAndMessages[0].block.header.lastArchive;
464
+ const checkpoint = await Checkpoint.random(checkpointNumber, {
465
+ numBlocks: 0,
466
+ inHash,
467
+ ...options,
468
+ ...globals,
469
+ lastArchive: firstBlockLastArchive,
470
+ lastArchiveRoot: firstBlockLastArchive.root,
471
+ archive: lastArchive,
472
+ });
473
+
459
474
  checkpoint.blocks = blocksAndMessages.map(({ block }) => block);
460
- // Set the checkpoint's archive to match the last block's archive for proper chaining.
461
- // When the archiver reconstructs checkpoints from L1, it uses the checkpoint's archive root
462
- // from the L1 event to set the last block's archive. Without this, the archive chain breaks.
463
- checkpoint.archive = lastArchive!;
464
475
 
465
476
  // Return lastArchive so callers can chain it across multiple checkpoints
466
477
  return { checkpoint, messages, lastArchive };
@@ -176,6 +176,12 @@ export class BlockHeader {
176
176
  this._cachedHash = Promise.resolve(new BlockHash(hashed));
177
177
  }
178
178
 
179
+ /** Recomputes the cached hash. Used for testing when header fields are mutated via unfreeze. */
180
+ recomputeHash(): Promise<BlockHash> {
181
+ this._cachedHash = undefined;
182
+ return this.hash();
183
+ }
184
+
179
185
  static random(overrides: Partial<FieldsOf<BlockHeader>> & Partial<FieldsOf<GlobalVariables>> = {}): BlockHeader {
180
186
  return BlockHeader.from({
181
187
  lastArchive: AppendOnlyTreeSnapshot.random(),
@@ -12,9 +12,11 @@ import { Gas } from '../gas/gas.js';
12
12
  import type { GasUsed } from '../gas/gas_used.js';
13
13
  import { PrivateKernelTailCircuitPublicInputs } from '../kernel/private_kernel_tail_circuit_public_inputs.js';
14
14
  import { ChonkProof } from '../proofs/chonk_proof.js';
15
+ import type { OffchainEffect } from './offchain_effect.js';
15
16
  import {
16
17
  PrivateCallExecutionResult,
17
18
  PrivateExecutionResult,
19
+ collectOffchainEffects,
18
20
  collectSortedContractClassLogs,
19
21
  } from './private_execution_result.js';
20
22
  import { type SimulationStats, SimulationStatsSchema } from './profiling.js';
@@ -84,6 +86,11 @@ export class TxSimulationResult {
84
86
  public stats?: SimulationStats,
85
87
  ) {}
86
88
 
89
+ /** Returns offchain effects collected from private execution. */
90
+ get offchainEffects(): OffchainEffect[] {
91
+ return collectOffchainEffects(this.privateExecutionResult);
92
+ }
93
+
87
94
  get gasUsed(): GasUsed {
88
95
  return (
89
96
  this.publicOutput?.gasUsed ?? {
@@ -106,7 +113,7 @@ export class TxSimulationResult {
106
113
  .transform(TxSimulationResult.from);
107
114
  }
108
115
 
109
- static from(fields: Omit<FieldsOf<TxSimulationResult>, 'gasUsed'>) {
116
+ static from(fields: Omit<FieldsOf<TxSimulationResult>, 'gasUsed' | 'offchainEffects'>) {
110
117
  return new TxSimulationResult(
111
118
  fields.privateExecutionResult,
112
119
  fields.publicInputs,
package/src/tx/tx.ts CHANGED
@@ -1,8 +1,9 @@
1
+ import { DA_GAS_PER_FIELD, TX_DA_GAS_OVERHEAD } from '@aztec/constants';
1
2
  import { Buffer32 } from '@aztec/foundation/buffer';
2
3
  import { Fr } from '@aztec/foundation/curves/bn254';
3
4
  import type { ZodFor } from '@aztec/foundation/schemas';
4
5
  import { BufferReader, serializeArrayOfBufferableToVector, serializeToBuffer } from '@aztec/foundation/serialize';
5
- import type { FieldsOf } from '@aztec/foundation/types';
6
+ import { type FieldsOf, unfreeze } from '@aztec/foundation/types';
6
7
 
7
8
  import { z } from 'zod';
8
9
 
@@ -264,16 +265,24 @@ export class Tx extends Gossipable {
264
265
  }
265
266
 
266
267
  /**
267
- * Estimates the tx size based on its private effects. Note that the actual size of the tx
268
- * after processing will probably be larger, as public execution would generate more data.
268
+ * Returns the number of fields this tx's effects will occupy in the blob,
269
+ * based on its private side effects only. Accurate for txs without public calls.
270
+ * For txs with public calls, the actual size will be larger due to public execution outputs.
269
271
  */
270
- getEstimatedPrivateTxEffectsSize() {
271
- return (
272
- this.data.getNonEmptyNoteHashes().length * Fr.SIZE_IN_BYTES +
273
- this.data.getNonEmptyNullifiers().length * Fr.SIZE_IN_BYTES +
274
- this.data.getEmittedPrivateLogsLength() * Fr.SIZE_IN_BYTES +
275
- this.data.getEmittedContractClassLogsLength() * Fr.SIZE_IN_BYTES
276
- );
272
+ getPrivateTxEffectsSizeInFields(): number {
273
+ // 3 fields overhead: tx_start_marker, tx_hash, tx_fee.
274
+ // TX_DA_GAS_OVERHEAD is defined as N * DA_GAS_PER_FIELD, so this division is always exact.
275
+ const overheadFields = TX_DA_GAS_OVERHEAD / DA_GAS_PER_FIELD;
276
+ const noteHashes = this.data.getNonEmptyNoteHashes().length;
277
+ const nullifiers = this.data.getNonEmptyNullifiers().length;
278
+ const l2ToL1Msgs = this.data.getNonEmptyL2ToL1Msgs().length;
279
+ // Each private log occupies (emittedLength + 1) fields: content + length field
280
+ const privateLogFields = this.data.getNonEmptyPrivateLogs().reduce((acc, log) => acc + log.emittedLength + 1, 0);
281
+ // Each contract class log occupies (length + 1) fields: content + contract address
282
+ const contractClassLogFields = this.data
283
+ .getNonEmptyContractClassLogsHashes()
284
+ .reduce((acc, log) => acc + log.logHash.length + 1, 0);
285
+ return overheadFields + noteHashes + nullifiers + l2ToL1Msgs + privateLogFields + contractClassLogFields;
277
286
  }
278
287
 
279
288
  /**
@@ -309,7 +318,7 @@ export class Tx extends Gossipable {
309
318
 
310
319
  /** Recomputes the tx hash. Used for testing purposes only when a property of the tx was mutated. */
311
320
  public async recomputeHash(): Promise<TxHash> {
312
- (this as any).txHash = await Tx.computeTxHash(this);
321
+ unfreeze(this).txHash = await Tx.computeTxHash(this);
313
322
  return this.txHash;
314
323
  }
315
324
 
@@ -6,6 +6,10 @@ export const TX_ERROR_GAS_LIMIT_TOO_HIGH = 'Gas limit is higher than the amount
6
6
 
7
7
  // Phases
8
8
  export const TX_ERROR_SETUP_FUNCTION_NOT_ALLOWED = 'Setup function not on allow list';
9
+ export const TX_ERROR_SETUP_FUNCTION_UNKNOWN_CONTRACT = 'Setup function targets unknown contract';
10
+ export const TX_ERROR_SETUP_ONLY_SELF_WRONG_SENDER = 'Setup only_self function called with incorrect msg_sender';
11
+ export const TX_ERROR_SETUP_NULL_MSG_SENDER = 'Setup function called with null msg sender';
12
+ export const TX_ERROR_SETUP_WRONG_CALLDATA_LENGTH = 'Setup function called with wrong calldata length';
9
13
 
10
14
  // Nullifiers
11
15
  export const TX_ERROR_DUPLICATE_NULLIFIER_IN_TX = 'Duplicate nullifier in tx';
@@ -1 +1,2 @@
1
- export { UpdateChecker, getPackageVersion } from './update-checker.js';
1
+ export * from './package_version.js';
2
+ export * from './version_checker.js';
@@ -0,0 +1,17 @@
1
+ import { fileURLToPath } from '@aztec/foundation/url';
2
+
3
+ import { readFileSync } from 'fs';
4
+ import { dirname, resolve } from 'path';
5
+
6
+ /** Returns the package version from the release-please manifest, or undefined if not found. */
7
+ export function getPackageVersion(): string | undefined {
8
+ try {
9
+ const releasePleaseManifestPath = resolve(
10
+ dirname(fileURLToPath(import.meta.url)),
11
+ '../../../../.release-please-manifest.json',
12
+ );
13
+ return JSON.parse(readFileSync(releasePleaseManifestPath).toString())['.'];
14
+ } catch {
15
+ return undefined;
16
+ }
17
+ }
@@ -0,0 +1,65 @@
1
+ import { createLogger } from '@aztec/foundation/log';
2
+ import { RunningPromise } from '@aztec/foundation/promise';
3
+
4
+ import { EventEmitter } from 'node:events';
5
+
6
+ export type EventMap = {
7
+ newVersion: [{ name: string; currentVersion: string; latestVersion: string }];
8
+ };
9
+
10
+ export type VersionCheck = {
11
+ name: string;
12
+ currentVersion: string;
13
+ getLatestVersion: () => Promise<string | undefined>;
14
+ };
15
+
16
+ export class VersionChecker extends EventEmitter<EventMap> {
17
+ private runningPromise: RunningPromise;
18
+ constructor(
19
+ private checks: Array<VersionCheck>,
20
+ intervalCheckMs = 60_000,
21
+ private logger = createLogger('version_checker'),
22
+ ) {
23
+ super();
24
+ this.runningPromise = new RunningPromise(this.run, logger, intervalCheckMs);
25
+ }
26
+
27
+ public start(): void {
28
+ if (this.runningPromise.isRunning()) {
29
+ this.logger.warn('VersionChecker is already running');
30
+ return;
31
+ }
32
+
33
+ this.runningPromise.start();
34
+ this.logger.info('Version check started');
35
+ }
36
+
37
+ public trigger(): Promise<void> {
38
+ return this.runningPromise.trigger();
39
+ }
40
+
41
+ public async stop(): Promise<void> {
42
+ if (!this.runningPromise.isRunning()) {
43
+ this.logger.warn('VersionChecker is not running');
44
+ return;
45
+ }
46
+
47
+ await this.runningPromise.stop();
48
+ this.logger.info('Version checker stopped');
49
+ }
50
+
51
+ private run = async () => {
52
+ await Promise.allSettled(this.checks.map(check => this.checkVersion(check)));
53
+ };
54
+
55
+ private async checkVersion({ name, currentVersion, getLatestVersion }: VersionCheck): Promise<void> {
56
+ try {
57
+ const latestVersion = await getLatestVersion();
58
+ if (latestVersion && latestVersion !== currentVersion) {
59
+ this.emit('newVersion', { name, latestVersion, currentVersion });
60
+ }
61
+ } catch (err) {
62
+ this.logger.warn(`Error checking for new ${name} versions: ${err}`, { err });
63
+ }
64
+ }
65
+ }
@@ -1,49 +0,0 @@
1
- import type { ViemClient } from '@aztec/ethereum/types';
2
- import { EthAddress } from '@aztec/foundation/eth-address';
3
- import { EventEmitter } from 'events';
4
- export type EventMap = {
5
- newRollupVersion: [{
6
- currentVersion: bigint;
7
- latestVersion: bigint;
8
- }];
9
- newNodeVersion: [{
10
- currentVersion: string;
11
- latestVersion: string;
12
- }];
13
- updateNodeConfig: [object];
14
- updatePublicTelemetryConfig: [object];
15
- };
16
- type Config = {
17
- baseURL: URL;
18
- nodeVersion?: string;
19
- checkIntervalMs?: number;
20
- registryContractAddress: EthAddress;
21
- publicClient: ViemClient;
22
- fetch?: typeof fetch;
23
- };
24
- export declare class UpdateChecker extends EventEmitter<EventMap> {
25
- private updatesUrl;
26
- private nodeVersion;
27
- private rollupVersion;
28
- private fetch;
29
- private getLatestRollupVersion;
30
- private checkIntervalMs;
31
- private log;
32
- private runningPromise;
33
- private lastPatchedConfig;
34
- private lastPatchedPublicTelemetryConfig;
35
- constructor(updatesUrl: URL, nodeVersion: string | undefined, rollupVersion: bigint, fetch: typeof globalThis.fetch, getLatestRollupVersion: () => Promise<bigint>, checkIntervalMs?: number, log?: import("@aztec/foundation/log").Logger);
36
- static new(config: Config): Promise<UpdateChecker>;
37
- start(): void;
38
- stop(): Promise<void>;
39
- trigger(): Promise<void>;
40
- private runChecks;
41
- private checkRollupVersion;
42
- private checkConfig;
43
- }
44
- /**
45
- * Returns package version.
46
- */
47
- export declare function getPackageVersion(): string | undefined;
48
- export {};
49
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXBkYXRlLWNoZWNrZXIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91cGRhdGUtY2hlY2tlci91cGRhdGUtY2hlY2tlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUN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