@aztec/stdlib 0.0.1-commit.f504929 → 0.0.1-commit.f81dbcf

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 (153) 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 +14 -8
  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/epoch-helpers/index.d.ts +5 -1
  19. package/dest/epoch-helpers/index.d.ts.map +1 -1
  20. package/dest/epoch-helpers/index.js +4 -2
  21. package/dest/gas/gas_fees.d.ts +1 -1
  22. package/dest/gas/gas_fees.d.ts.map +1 -1
  23. package/dest/gas/gas_fees.js +1 -4
  24. package/dest/interfaces/allowed_element.d.ts +25 -1
  25. package/dest/interfaces/allowed_element.d.ts.map +1 -1
  26. package/dest/interfaces/allowed_element.js +8 -2
  27. package/dest/interfaces/archiver.d.ts +1 -1
  28. package/dest/interfaces/archiver.d.ts.map +1 -1
  29. package/dest/interfaces/archiver.js +3 -2
  30. package/dest/interfaces/aztec-node-admin.d.ts +55 -7
  31. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  32. package/dest/interfaces/aztec-node.d.ts +11 -6
  33. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  34. package/dest/interfaces/aztec-node.js +5 -2
  35. package/dest/interfaces/block-builder.d.ts +17 -9
  36. package/dest/interfaces/block-builder.d.ts.map +1 -1
  37. package/dest/interfaces/block-builder.js +12 -5
  38. package/dest/interfaces/configs.d.ts +42 -7
  39. package/dest/interfaces/configs.d.ts.map +1 -1
  40. package/dest/interfaces/configs.js +2 -1
  41. package/dest/interfaces/merkle_tree_operations.d.ts +9 -19
  42. package/dest/interfaces/merkle_tree_operations.d.ts.map +1 -1
  43. package/dest/interfaces/prover-client.d.ts +6 -1
  44. package/dest/interfaces/prover-client.d.ts.map +1 -1
  45. package/dest/interfaces/prover-client.js +7 -1
  46. package/dest/interfaces/validator.d.ts +65 -6
  47. package/dest/interfaces/validator.d.ts.map +1 -1
  48. package/dest/interfaces/validator.js +6 -3
  49. package/dest/kernel/private_kernel_tail_circuit_public_inputs.d.ts +2 -1
  50. package/dest/kernel/private_kernel_tail_circuit_public_inputs.d.ts.map +1 -1
  51. package/dest/kernel/private_kernel_tail_circuit_public_inputs.js +4 -0
  52. package/dest/logs/log_filter.d.ts +4 -1
  53. package/dest/logs/log_filter.d.ts.map +1 -1
  54. package/dest/logs/log_filter.js +2 -1
  55. package/dest/logs/tx_scoped_l2_log.d.ts +3 -1
  56. package/dest/logs/tx_scoped_l2_log.d.ts.map +1 -1
  57. package/dest/logs/tx_scoped_l2_log.js +7 -0
  58. package/dest/messaging/l2_to_l1_membership.d.ts +32 -6
  59. package/dest/messaging/l2_to_l1_membership.d.ts.map +1 -1
  60. package/dest/messaging/l2_to_l1_membership.js +69 -26
  61. package/dest/p2p/block_proposal.d.ts +2 -2
  62. package/dest/p2p/block_proposal.d.ts.map +1 -1
  63. package/dest/p2p/block_proposal.js +1 -1
  64. package/dest/p2p/checkpoint_proposal.d.ts +2 -7
  65. package/dest/p2p/checkpoint_proposal.d.ts.map +1 -1
  66. package/dest/p2p/checkpoint_proposal.js +14 -24
  67. package/dest/p2p/peer_error.d.ts +3 -1
  68. package/dest/p2p/peer_error.d.ts.map +1 -1
  69. package/dest/p2p/peer_error.js +5 -0
  70. package/dest/slashing/tally.d.ts +5 -6
  71. package/dest/slashing/tally.d.ts.map +1 -1
  72. package/dest/slashing/tally.js +19 -10
  73. package/dest/tests/mocks.d.ts +4 -2
  74. package/dest/tests/mocks.d.ts.map +1 -1
  75. package/dest/tests/mocks.js +13 -8
  76. package/dest/tx/block_header.d.ts +3 -1
  77. package/dest/tx/block_header.d.ts.map +1 -1
  78. package/dest/tx/block_header.js +4 -0
  79. package/dest/tx/tx.d.ts +6 -5
  80. package/dest/tx/tx.d.ts.map +1 -1
  81. package/dest/tx/tx.js +18 -6
  82. package/dest/tx/tx_receipt.d.ts +7 -2
  83. package/dest/tx/tx_receipt.d.ts.map +1 -1
  84. package/dest/tx/tx_receipt.js +6 -3
  85. package/dest/tx/validator/error_texts.d.ts +6 -1
  86. package/dest/tx/validator/error_texts.d.ts.map +1 -1
  87. package/dest/tx/validator/error_texts.js +6 -0
  88. package/dest/update-checker/index.d.ts +3 -2
  89. package/dest/update-checker/index.d.ts.map +1 -1
  90. package/dest/update-checker/index.js +2 -1
  91. package/dest/update-checker/package_version.d.ts +3 -0
  92. package/dest/update-checker/package_version.d.ts.map +1 -0
  93. package/dest/update-checker/package_version.js +24 -0
  94. package/dest/update-checker/version_checker.d.ts +25 -0
  95. package/dest/update-checker/version_checker.d.ts.map +1 -0
  96. package/dest/update-checker/version_checker.js +50 -0
  97. package/dest/validators/errors.d.ts +6 -1
  98. package/dest/validators/errors.d.ts.map +1 -1
  99. package/dest/validators/errors.js +7 -0
  100. package/dest/versioning/versioning.d.ts +4 -2
  101. package/dest/versioning/versioning.d.ts.map +1 -1
  102. package/dest/versioning/versioning.js +4 -1
  103. package/package.json +9 -9
  104. package/src/block/l2_block.ts +13 -1
  105. package/src/block/l2_block_source.ts +14 -7
  106. package/src/checkpoint/checkpoint.ts +12 -3
  107. package/src/checkpoint/index.ts +1 -0
  108. package/src/checkpoint/validate.ts +230 -0
  109. package/src/config/sequencer-config.ts +2 -5
  110. package/src/epoch-helpers/index.ts +3 -0
  111. package/src/gas/gas_fees.ts +1 -7
  112. package/src/interfaces/allowed_element.ts +28 -4
  113. package/src/interfaces/archiver.ts +3 -2
  114. package/src/interfaces/aztec-node.ts +23 -5
  115. package/src/interfaces/block-builder.ts +30 -11
  116. package/src/interfaces/configs.ts +12 -4
  117. package/src/interfaces/merkle_tree_operations.ts +8 -18
  118. package/src/interfaces/prover-client.ts +8 -0
  119. package/src/interfaces/validator.ts +18 -3
  120. package/src/kernel/private_kernel_tail_circuit_public_inputs.ts +9 -0
  121. package/src/logs/log_filter.ts +5 -0
  122. package/src/logs/tx_scoped_l2_log.ts +16 -0
  123. package/src/messaging/l2_to_l1_membership.ts +98 -33
  124. package/src/p2p/block_proposal.ts +1 -1
  125. package/src/p2p/checkpoint_proposal.ts +24 -38
  126. package/src/p2p/peer_error.ts +7 -0
  127. package/src/slashing/tally.ts +22 -4
  128. package/src/tests/mocks.ts +18 -7
  129. package/src/tx/block_header.ts +6 -0
  130. package/src/tx/tx.ts +20 -11
  131. package/src/tx/tx_receipt.ts +7 -2
  132. package/src/tx/validator/error_texts.ts +7 -0
  133. package/src/update-checker/index.ts +2 -1
  134. package/src/update-checker/package_version.ts +30 -0
  135. package/src/update-checker/version_checker.ts +65 -0
  136. package/src/validators/errors.ts +9 -0
  137. package/src/versioning/versioning.ts +4 -1
  138. package/dest/ha-signing/config.d.ts +0 -101
  139. package/dest/ha-signing/config.d.ts.map +0 -1
  140. package/dest/ha-signing/config.js +0 -92
  141. package/dest/ha-signing/index.d.ts +0 -3
  142. package/dest/ha-signing/index.d.ts.map +0 -1
  143. package/dest/ha-signing/index.js +0 -2
  144. package/dest/ha-signing/types.d.ts +0 -85
  145. package/dest/ha-signing/types.d.ts.map +0 -1
  146. package/dest/ha-signing/types.js +0 -32
  147. package/dest/update-checker/update-checker.d.ts +0 -49
  148. package/dest/update-checker/update-checker.d.ts.map +0 -1
  149. package/dest/update-checker/update-checker.js +0 -130
  150. package/src/ha-signing/config.ts +0 -149
  151. package/src/ha-signing/index.ts +0 -18
  152. package/src/ha-signing/types.ts +0 -112
  153. package/src/update-checker/update-checker.ts +0 -166
@@ -6,10 +6,10 @@ import { Fr } from '@aztec/foundation/curves/bn254';
6
6
  import type { EthAddress } from '@aztec/foundation/eth-address';
7
7
  import { Signature } from '@aztec/foundation/eth-signature';
8
8
  import { BufferReader, serializeSignedBigInt, serializeToBuffer } from '@aztec/foundation/serialize';
9
+ import { DutyType, type SigningContext } from '@aztec/validator-ha-signer/types';
9
10
 
10
11
  import type { L2BlockInfo } from '../block/l2_block_info.js';
11
12
  import { MAX_TXS_PER_BLOCK } from '../deserialization/index.js';
12
- import { DutyType, type SigningContext } from '../ha-signing/index.js';
13
13
  import { CheckpointHeader } from '../rollup/checkpoint_header.js';
14
14
  import { BlockHeader } from '../tx/block_header.js';
15
15
  import { TxHash } from '../tx/index.js';
@@ -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
@@ -195,29 +178,32 @@ export class CheckpointProposal extends Gossipable {
195
178
  blockNumber: lastBlockInfo?.blockHeader?.globalVariables.blockNumber ?? BlockNumber(0),
196
179
  dutyType: DutyType.CHECKPOINT_PROPOSAL,
197
180
  };
198
- const checkpointSignature = await payloadSigner(checkpointHash, checkpointContext);
199
181
 
200
- if (!lastBlockInfo) {
201
- return new CheckpointProposal(checkpointHeader, archiveRoot, feeAssetPriceModifier, checkpointSignature);
182
+ if (lastBlockInfo) {
183
+ // Sign block proposal before signing checkpoint proposal to ensure HA protection
184
+ const lastBlockProposal = await BlockProposal.createProposalFromSigner(
185
+ lastBlockInfo.blockHeader,
186
+ lastBlockInfo.indexWithinCheckpoint,
187
+ checkpointHeader.inHash,
188
+ archiveRoot,
189
+ lastBlockInfo.txHashes,
190
+ lastBlockInfo.txs,
191
+ payloadSigner,
192
+ );
193
+
194
+ const checkpointSignature = await payloadSigner(checkpointHash, checkpointContext);
195
+
196
+ return new CheckpointProposal(checkpointHeader, archiveRoot, feeAssetPriceModifier, checkpointSignature, {
197
+ blockHeader: lastBlockInfo.blockHeader,
198
+ indexWithinCheckpoint: lastBlockInfo.indexWithinCheckpoint,
199
+ txHashes: lastBlockInfo.txHashes,
200
+ signature: lastBlockProposal.signature,
201
+ signedTxs: lastBlockProposal.signedTxs,
202
+ });
202
203
  }
203
204
 
204
- const lastBlockProposal = await BlockProposal.createProposalFromSigner(
205
- lastBlockInfo.blockHeader,
206
- lastBlockInfo.indexWithinCheckpoint,
207
- checkpointHeader.inHash,
208
- archiveRoot,
209
- lastBlockInfo.txHashes,
210
- lastBlockInfo.txs,
211
- payloadSigner,
212
- );
213
-
214
- return new CheckpointProposal(checkpointHeader, archiveRoot, feeAssetPriceModifier, checkpointSignature, {
215
- blockHeader: lastBlockInfo.blockHeader,
216
- indexWithinCheckpoint: lastBlockInfo.indexWithinCheckpoint,
217
- txHashes: lastBlockInfo.txHashes,
218
- signature: lastBlockProposal.signature,
219
- signedTxs: lastBlockProposal.signedTxs,
220
- });
205
+ const checkpointSignature = await payloadSigner(checkpointHash, checkpointContext);
206
+ return new CheckpointProposal(checkpointHeader, archiveRoot, feeAssetPriceModifier, checkpointSignature);
221
207
  }
222
208
 
223
209
  /**
@@ -15,3 +15,10 @@ export enum PeerErrorSeverity {
15
15
  */
16
16
  HighToleranceError = 'HighToleranceError',
17
17
  }
18
+
19
+ /** Severities ordered from mildest to harshest. */
20
+ export const PeerErrorSeverityByHarshness = [
21
+ PeerErrorSeverity.HighToleranceError,
22
+ PeerErrorSeverity.MidToleranceError,
23
+ PeerErrorSeverity.LowToleranceError,
24
+ ] as const;
@@ -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';
@@ -13,7 +14,8 @@ import type { Offense, ValidatorSlashVote } from './types.js';
13
14
  * @param epochsForCommittees - Array of epochs corresponding to each committee
14
15
  * @param settings - Settings including slashingAmounts and optional validator override lists
15
16
  * @param settings.maxSlashedValidators - If set, limits the total number of [validator, epoch] pairs
16
- * with non-zero votes.
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.
17
19
  * @returns Array of ValidatorSlashVote, where each vote is how many slash units the validator in that position should be slashed
18
20
  */
19
21
  export function getSlashConsensusVotesFromOffenses(
@@ -26,7 +28,8 @@ export function getSlashConsensusVotesFromOffenses(
26
28
  targetCommitteeSize: number;
27
29
  maxSlashedValidators?: number;
28
30
  },
29
- ): { votes: ValidatorSlashVote[]; truncatedCount: number } {
31
+ logger: Logger = createLogger('slasher:tally'),
32
+ ): ValidatorSlashVote[] {
30
33
  const { slashingAmounts, targetCommitteeSize, maxSlashedValidators } = settings;
31
34
 
32
35
  if (committees.length !== epochsForCommittees.length) {
@@ -58,7 +61,7 @@ export function getSlashConsensusVotesFromOffenses(
58
61
 
59
62
  // if a cap is set, zero out the lowest-vote [validator, epoch] pairs so that the most severe slashes stay.
60
63
  if (maxSlashedValidators === undefined) {
61
- return { votes, truncatedCount: 0 };
64
+ return votes;
62
65
  }
63
66
 
64
67
  const nonZeroByDescendingVote = [...votes.entries()].filter(([, vote]) => vote > 0).sort(([, a], [, b]) => b - a);
@@ -68,7 +71,22 @@ export function getSlashConsensusVotesFromOffenses(
68
71
  votes[idx] = 0;
69
72
  }
70
73
 
71
- return { votes, truncatedCount: toTruncate.length };
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
+
89
+ return votes;
72
90
  }
73
91
 
74
92
  /** Returns the slash vote for the given amount to slash. */
@@ -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(),
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
 
@@ -1,4 +1,4 @@
1
- import { BlockNumber, BlockNumberSchema } from '@aztec/foundation/branded-types';
1
+ import { BlockNumber, BlockNumberSchema, EpochNumber, EpochNumberSchema } from '@aztec/foundation/branded-types';
2
2
 
3
3
  import { z } from 'zod';
4
4
 
@@ -15,7 +15,7 @@ export enum TxStatus {
15
15
  PROPOSED = 'proposed',
16
16
  CHECKPOINTED = 'checkpointed',
17
17
  PROVEN = 'proven',
18
- FINALIZED = 'finalized', // TODO(#13569): Implement finalized status properly
18
+ FINALIZED = 'finalized',
19
19
  }
20
20
 
21
21
  /** Tx status sorted by finalization progress. */
@@ -58,6 +58,8 @@ export class TxReceipt {
58
58
  public blockHash?: BlockHash,
59
59
  /** The block number in which the transaction was included. */
60
60
  public blockNumber?: BlockNumber,
61
+ /** The epoch number in which the transaction was included. */
62
+ public epochNumber?: EpochNumber,
61
63
  /**
62
64
  * Debug logs collected during public function execution. Served only when the node is in test mode and placed on
63
65
  * the receipt only because it's a convenient place for it (the logs are printed out by the wallet when a mined
@@ -109,6 +111,7 @@ export class TxReceipt {
109
111
  error: z.string().optional(),
110
112
  blockHash: BlockHash.schema.optional(),
111
113
  blockNumber: BlockNumberSchema.optional(),
114
+ epochNumber: EpochNumberSchema.optional(),
112
115
  transactionFee: schemas.BigInt.optional(),
113
116
  debugLogs: z.array(DebugLog.schema).optional(),
114
117
  })
@@ -123,6 +126,7 @@ export class TxReceipt {
123
126
  transactionFee?: bigint;
124
127
  blockHash?: BlockHash;
125
128
  blockNumber?: BlockNumber;
129
+ epochNumber?: EpochNumber;
126
130
  debugLogs?: DebugLog[];
127
131
  }) {
128
132
  return new TxReceipt(
@@ -133,6 +137,7 @@ export class TxReceipt {
133
137
  fields.transactionFee,
134
138
  fields.blockHash,
135
139
  fields.blockNumber,
140
+ fields.epochNumber,
136
141
  fields.debugLogs,
137
142
  );
138
143
  }
@@ -7,6 +7,9 @@ export const TX_ERROR_GAS_LIMIT_TOO_HIGH = 'Gas limit is higher than the amount
7
7
  // Phases
8
8
  export const TX_ERROR_SETUP_FUNCTION_NOT_ALLOWED = 'Setup function not on allow list';
9
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';
10
13
 
11
14
  // Nullifiers
12
15
  export const TX_ERROR_DUPLICATE_NULLIFIER_IN_TX = 'Duplicate nullifier in tx';
@@ -38,5 +41,9 @@ export const TX_ERROR_SIZE_ABOVE_LIMIT = 'Transaction size above size limit';
38
41
  // Block header
39
42
  export const TX_ERROR_BLOCK_HEADER = 'Block header not found';
40
43
 
44
+ // Contract instance
45
+ export const TX_ERROR_INCORRECT_CONTRACT_ADDRESS = 'Incorrect contract instance deployment address';
46
+ export const TX_ERROR_MALFORMED_CONTRACT_INSTANCE_LOG = 'Failed to parse contract instance deployment log';
47
+
41
48
  // General
42
49
  export const TX_ERROR_DURING_VALIDATION = 'Unexpected error during validation';
@@ -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,30 @@
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 the package.json, or undefined if not found. */
7
+ export function getPackageVersion(): string | undefined {
8
+ const dir = dirname(fileURLToPath(import.meta.url));
9
+
10
+ // Try the release-please manifest first (works in dev/repo checkout).
11
+ try {
12
+ const releasePleaseManifestPath = resolve(dir, '../../../../.release-please-manifest.json');
13
+ return JSON.parse(readFileSync(releasePleaseManifestPath).toString())['.'];
14
+ } catch {
15
+ // Not in a repo checkout, fall through.
16
+ }
17
+
18
+ // Fall back to the stdlib package.json version (works in npm-installed packages).
19
+ try {
20
+ const packageJsonPath = resolve(dir, '../../package.json');
21
+ const version = JSON.parse(readFileSync(packageJsonPath).toString()).version;
22
+ if (version && version !== '0.1.0') {
23
+ return version;
24
+ }
25
+ } catch {
26
+ // No package.json found either.
27
+ }
28
+
29
+ return undefined;
30
+ }
@@ -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
+ }
@@ -36,6 +36,15 @@ export class FailedToReExecuteTransactionsError extends ValidatorError {
36
36
  }
37
37
  }
38
38
 
39
+ export class ReExInitialStateMismatchError extends ValidatorError {
40
+ constructor(
41
+ public readonly expectedArchiveRoot: Fr,
42
+ public readonly actualArchiveRoot: Fr,
43
+ ) {
44
+ super('Re-execution initial state mismatch');
45
+ }
46
+ }
47
+
39
48
  export class ReExStateMismatchError extends ValidatorError {
40
49
  constructor(
41
50
  public readonly expectedArchiveRoot: Fr,
@@ -115,7 +115,7 @@ export function validatePartialComponentVersionsMatch(
115
115
  }
116
116
 
117
117
  /** Returns a Koa middleware that injects the versioning info as headers. */
118
- export function getVersioningMiddleware(versions: Partial<ComponentsVersions>) {
118
+ export function getVersioningMiddleware(versions: Partial<ComponentsVersions>, opts?: { packageVersion?: string }) {
119
119
  return async (ctx: Koa.Context, next: () => Promise<void>) => {
120
120
  try {
121
121
  await next();
@@ -128,6 +128,9 @@ export function getVersioningMiddleware(versions: Partial<ComponentsVersions>) {
128
128
  ctx.set(`x-aztec-${key}`, value.toString());
129
129
  }
130
130
  }
131
+ if (opts?.packageVersion) {
132
+ ctx.set('x-aztec-packageVersion', opts.packageVersion);
133
+ }
131
134
  }
132
135
  };
133
136
  }
@@ -1,101 +0,0 @@
1
- import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
2
- import { type ConfigMappingsType } from '@aztec/foundation/config';
3
- import { EthAddress } from '@aztec/foundation/eth-address';
4
- import { z } from 'zod';
5
- /**
6
- * Configuration for the Validator HA Signer
7
- *
8
- * This config is used for distributed locking and slashing protection
9
- * when running multiple validator nodes in a high-availability setup.
10
- */
11
- export interface ValidatorHASignerConfig {
12
- /** Whether HA signing / slashing protection is enabled */
13
- haSigningEnabled: boolean;
14
- /** L1 contract addresses (rollup address required) */
15
- l1Contracts: Pick<L1ContractAddresses, 'rollupAddress'>;
16
- /** Unique identifier for this node */
17
- nodeId: string;
18
- /** How long to wait between polls when a duty is being signed (ms) */
19
- pollingIntervalMs: number;
20
- /** Maximum time to wait for a duty being signed to complete (ms) */
21
- signingTimeoutMs: number;
22
- /** Maximum age of a stuck duty in ms (defaults to 2x hardcoded Aztec slot duration if not set) */
23
- maxStuckDutiesAgeMs?: number;
24
- /** Optional: clean up old duties after this many hours (disabled if not set) */
25
- cleanupOldDutiesAfterHours?: number;
26
- /**
27
- * PostgreSQL connection string
28
- * Format: postgresql://user:password@host:port/database
29
- */
30
- databaseUrl?: string;
31
- /**
32
- * PostgreSQL connection pool configuration
33
- */
34
- /** Maximum number of clients in the pool (default: 10) */
35
- poolMaxCount?: number;
36
- /** Minimum number of clients in the pool (default: 0) */
37
- poolMinCount?: number;
38
- /** Idle timeout in milliseconds (default: 10000) */
39
- poolIdleTimeoutMs?: number;
40
- /** Connection timeout in milliseconds (default: 0, no timeout) */
41
- poolConnectionTimeoutMs?: number;
42
- }
43
- export declare const validatorHASignerConfigMappings: ConfigMappingsType<ValidatorHASignerConfig>;
44
- export declare const defaultValidatorHASignerConfig: ValidatorHASignerConfig;
45
- /**
46
- * Returns the validator HA signer configuration from environment variables.
47
- * Note: If an environment variable is not set, the default value is used.
48
- * @returns The validator HA signer configuration.
49
- */
50
- export declare function getConfigEnvVars(): ValidatorHASignerConfig;
51
- export declare const ValidatorHASignerConfigSchema: z.ZodObject<{
52
- haSigningEnabled: z.ZodBoolean;
53
- l1Contracts: z.ZodObject<{
54
- rollupAddress: z.ZodType<EthAddress, z.ZodTypeDef, EthAddress>;
55
- }, "strip", z.ZodTypeAny, {
56
- rollupAddress: EthAddress;
57
- }, {
58
- rollupAddress: EthAddress;
59
- }>;
60
- nodeId: z.ZodString;
61
- pollingIntervalMs: z.ZodNumber;
62
- signingTimeoutMs: z.ZodNumber;
63
- maxStuckDutiesAgeMs: z.ZodOptional<z.ZodNumber>;
64
- cleanupOldDutiesAfterHours: z.ZodOptional<z.ZodNumber>;
65
- databaseUrl: z.ZodOptional<z.ZodString>;
66
- poolMaxCount: z.ZodOptional<z.ZodNumber>;
67
- poolMinCount: z.ZodOptional<z.ZodNumber>;
68
- poolIdleTimeoutMs: z.ZodOptional<z.ZodNumber>;
69
- poolConnectionTimeoutMs: z.ZodOptional<z.ZodNumber>;
70
- }, "strip", z.ZodTypeAny, {
71
- haSigningEnabled: boolean;
72
- l1Contracts: {
73
- rollupAddress: EthAddress;
74
- };
75
- nodeId: string;
76
- pollingIntervalMs: number;
77
- signingTimeoutMs: number;
78
- maxStuckDutiesAgeMs?: number | undefined;
79
- cleanupOldDutiesAfterHours?: number | undefined;
80
- databaseUrl?: string | undefined;
81
- poolMaxCount?: number | undefined;
82
- poolMinCount?: number | undefined;
83
- poolIdleTimeoutMs?: number | undefined;
84
- poolConnectionTimeoutMs?: number | undefined;
85
- }, {
86
- haSigningEnabled: boolean;
87
- l1Contracts: {
88
- rollupAddress: EthAddress;
89
- };
90
- nodeId: string;
91
- pollingIntervalMs: number;
92
- signingTimeoutMs: number;
93
- maxStuckDutiesAgeMs?: number | undefined;
94
- cleanupOldDutiesAfterHours?: number | undefined;
95
- databaseUrl?: string | undefined;
96
- poolMaxCount?: number | undefined;
97
- poolMinCount?: number | undefined;
98
- poolIdleTimeoutMs?: number | undefined;
99
- poolConnectionTimeoutMs?: number | undefined;
100
- }>;
101
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uZmlnLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaGEtc2lnbmluZy9jb25maWcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsbUJBQW1CLEVBQUUsTUFBTSx1Q0FBdUMsQ0FBQztBQUNqRixPQUFPLEVBQ0wsS0FBSyxrQkFBa0IsRUFNeEIsTUFBTSwwQkFBMEIsQ0FBQztBQUNsQyxPQUFPLEVBQUUsVUFBVSxFQ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