@aztec/stdlib 3.0.0-nightly.20250910 → 3.0.0-nightly.20250912

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 (72) hide show
  1. package/dest/block/index.d.ts +2 -0
  2. package/dest/block/index.d.ts.map +1 -1
  3. package/dest/block/index.js +2 -0
  4. package/dest/block/l2_block.d.ts +2 -8
  5. package/dest/block/l2_block.d.ts.map +1 -1
  6. package/dest/block/l2_block.js +5 -3
  7. package/dest/block/l2_block_info.d.ts +41 -0
  8. package/dest/block/l2_block_info.d.ts.map +1 -0
  9. package/dest/block/l2_block_info.js +40 -0
  10. package/dest/block/l2_block_source.d.ts +1 -428
  11. package/dest/block/l2_block_source.d.ts.map +1 -1
  12. package/dest/block/l2_block_source.js +0 -28
  13. package/dest/block/published_l2_block.d.ts +25 -1
  14. package/dest/block/published_l2_block.d.ts.map +1 -1
  15. package/dest/block/published_l2_block.js +20 -1
  16. package/dest/block/test/l2_tips_store_test_suite.d.ts.map +1 -1
  17. package/dest/block/test/l2_tips_store_test_suite.js +2 -1
  18. package/dest/block/validate_block_result.d.ts +222 -0
  19. package/dest/block/validate_block_result.d.ts.map +1 -0
  20. package/dest/block/validate_block_result.js +83 -0
  21. package/dest/interfaces/archiver.d.ts +43 -0
  22. package/dest/interfaces/archiver.d.ts.map +1 -1
  23. package/dest/interfaces/archiver.js +10 -1
  24. package/dest/interfaces/aztec-node-admin.d.ts +17 -3
  25. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  26. package/dest/interfaces/aztec-node-admin.js +6 -1
  27. package/dest/p2p/block_attestation.d.ts +1 -0
  28. package/dest/p2p/block_attestation.d.ts.map +1 -1
  29. package/dest/p2p/block_attestation.js +3 -0
  30. package/dest/p2p/block_proposal.d.ts +2 -2
  31. package/dest/p2p/block_proposal.d.ts.map +1 -1
  32. package/dest/p2p/block_proposal.js +3 -1
  33. package/dest/p2p/consensus_payload.d.ts +1 -0
  34. package/dest/p2p/consensus_payload.d.ts.map +1 -1
  35. package/dest/p2p/consensus_payload.js +6 -4
  36. package/dest/tests/mocks.d.ts +1 -1
  37. package/dest/tests/mocks.d.ts.map +1 -1
  38. package/dest/tests/mocks.js +5 -8
  39. package/dest/tx/content_commitment.d.ts +1 -0
  40. package/dest/tx/content_commitment.d.ts.map +1 -1
  41. package/dest/tx/content_commitment.js +3 -0
  42. package/dest/tx/partial_state_reference.d.ts +1 -0
  43. package/dest/tx/partial_state_reference.d.ts.map +1 -1
  44. package/dest/tx/partial_state_reference.js +3 -0
  45. package/dest/tx/proposed_block_header.d.ts +1 -0
  46. package/dest/tx/proposed_block_header.d.ts.map +1 -1
  47. package/dest/tx/proposed_block_header.js +3 -0
  48. package/dest/tx/state_reference.d.ts +1 -0
  49. package/dest/tx/state_reference.d.ts.map +1 -1
  50. package/dest/tx/state_reference.js +3 -0
  51. package/dest/update-checker/update-checker.d.ts +1 -1
  52. package/dest/update-checker/update-checker.d.ts.map +1 -1
  53. package/dest/update-checker/update-checker.js +1 -1
  54. package/package.json +8 -8
  55. package/src/block/index.ts +2 -0
  56. package/src/block/l2_block.ts +6 -11
  57. package/src/block/l2_block_info.ts +63 -0
  58. package/src/block/l2_block_source.ts +1 -51
  59. package/src/block/published_l2_block.ts +38 -5
  60. package/src/block/test/l2_tips_store_test_suite.ts +7 -6
  61. package/src/block/validate_block_result.ts +122 -0
  62. package/src/interfaces/archiver.ts +38 -1
  63. package/src/interfaces/aztec-node-admin.ts +12 -1
  64. package/src/p2p/block_attestation.ts +4 -0
  65. package/src/p2p/block_proposal.ts +5 -3
  66. package/src/p2p/consensus_payload.ts +7 -4
  67. package/src/tests/mocks.ts +5 -5
  68. package/src/tx/content_commitment.ts +4 -0
  69. package/src/tx/partial_state_reference.ts +8 -0
  70. package/src/tx/proposed_block_header.ts +13 -0
  71. package/src/tx/state_reference.ts +4 -0
  72. package/src/update-checker/update-checker.ts +1 -1
@@ -0,0 +1,122 @@
1
+ import { EthAddress } from '@aztec/foundation/eth-address';
2
+ import { type ZodFor, schemas } from '@aztec/foundation/schemas';
3
+ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
4
+
5
+ import { z } from 'zod';
6
+
7
+ import { BlockInfoSchema, type L2BlockInfo, deserializeBlockInfo, serializeBlockInfo } from './l2_block_info.js';
8
+ import { CommitteeAttestation } from './proposal/committee_attestation.js';
9
+
10
+ /** Subtype for invalid block validation results */
11
+ export type ValidateBlockNegativeResult =
12
+ | {
13
+ valid: false;
14
+ /** Identifiers from the invalid block */
15
+ block: L2BlockInfo;
16
+ /** Committee members at the epoch this block was proposed */
17
+ committee: EthAddress[];
18
+ /** Epoch in which this block was proposed */
19
+ epoch: bigint;
20
+ /** Proposer selection seed for the epoch */
21
+ seed: bigint;
22
+ /** List of committee members who signed this block proposal */
23
+ attestors: EthAddress[];
24
+ /** Committee attestations for this block as they were posted to L1 */
25
+ attestations: CommitteeAttestation[];
26
+ /** Reason for the block being invalid: not enough attestations were posted */
27
+ reason: 'insufficient-attestations';
28
+ }
29
+ | {
30
+ valid: false;
31
+ /** Identifiers from the invalid block */
32
+ block: L2BlockInfo;
33
+ /** Committee members at the epoch this block was proposed */
34
+ committee: EthAddress[];
35
+ /** Epoch in which this block was proposed */
36
+ epoch: bigint;
37
+ /** Proposer selection seed for the epoch */
38
+ seed: bigint;
39
+ /** List of committee members who signed this block proposal */
40
+ attestors: EthAddress[];
41
+ /** Committee attestations for this block as they were posted to L1 */
42
+ attestations: CommitteeAttestation[];
43
+ /** Reason for the block being invalid: an invalid attestation was posted */
44
+ reason: 'invalid-attestation';
45
+ /** Index in the attestations array of the invalid attestation posted */
46
+ invalidIndex: number;
47
+ };
48
+
49
+ /** Result type for validating a block attestations */
50
+ export type ValidateBlockResult = { valid: true } | ValidateBlockNegativeResult;
51
+
52
+ export const ValidateBlockResultSchema = z.union([
53
+ z.object({ valid: z.literal(true) }),
54
+ z.object({
55
+ valid: z.literal(false),
56
+ block: BlockInfoSchema,
57
+ committee: z.array(schemas.EthAddress),
58
+ epoch: schemas.BigInt,
59
+ seed: schemas.BigInt,
60
+ attestors: z.array(schemas.EthAddress),
61
+ attestations: z.array(CommitteeAttestation.schema),
62
+ reason: z.literal('insufficient-attestations'),
63
+ }),
64
+ z.object({
65
+ valid: z.literal(false),
66
+ block: BlockInfoSchema,
67
+ committee: z.array(schemas.EthAddress),
68
+ epoch: schemas.BigInt,
69
+ seed: schemas.BigInt,
70
+ attestors: z.array(schemas.EthAddress),
71
+ attestations: z.array(CommitteeAttestation.schema),
72
+ reason: z.literal('invalid-attestation'),
73
+ invalidIndex: z.number(),
74
+ }),
75
+ ]) satisfies ZodFor<ValidateBlockResult>;
76
+
77
+ export function serializeValidateBlockResult(result: ValidateBlockResult): Buffer {
78
+ if (result.valid) {
79
+ return serializeToBuffer(true);
80
+ }
81
+
82
+ const l2Block = serializeBlockInfo(result.block);
83
+ return serializeToBuffer(
84
+ result.valid,
85
+ result.reason,
86
+ l2Block.length,
87
+ l2Block,
88
+ result.committee.length,
89
+ result.committee,
90
+ result.epoch,
91
+ result.seed ?? 0n,
92
+ result.attestors.length,
93
+ result.attestors,
94
+ result.attestations.length,
95
+ result.attestations,
96
+ result.reason === 'invalid-attestation' ? result.invalidIndex : 0,
97
+ );
98
+ }
99
+
100
+ export function deserializeValidateBlockResult(bufferOrReader: Buffer | BufferReader): ValidateBlockResult {
101
+ const reader = BufferReader.asReader(bufferOrReader);
102
+ const valid = reader.readBoolean();
103
+ if (valid) {
104
+ return { valid };
105
+ }
106
+ const reason = reader.readString() as 'insufficient-attestations' | 'invalid-attestation';
107
+ const block = deserializeBlockInfo(reader.readBuffer());
108
+ const committee = reader.readVector(EthAddress);
109
+ const epoch = reader.readBigInt();
110
+ const seed = reader.readBigInt();
111
+ const attestors = reader.readVector(EthAddress);
112
+ const attestations = reader.readVector(CommitteeAttestation);
113
+ const invalidIndex = reader.readNumber();
114
+ if (reason === 'insufficient-attestations') {
115
+ return { valid, reason, block, committee, epoch, seed, attestors, attestations: attestations };
116
+ } else if (reason === 'invalid-attestation') {
117
+ return { valid, reason, block, committee, epoch, seed, attestors, invalidIndex, attestations: attestations };
118
+ } else {
119
+ const _: never = reason;
120
+ throw new Error(`Unknown reason: ${reason}`);
121
+ }
122
+ }
@@ -1,10 +1,12 @@
1
+ import type { L1ContractAddresses } from '@aztec/ethereum';
1
2
  import type { ApiSchemaFor } from '@aztec/foundation/schemas';
2
3
 
3
4
  import { z } from 'zod';
4
5
 
5
6
  import { L2Block } from '../block/l2_block.js';
6
- import { type L2BlockSource, L2TipsSchema, ValidateBlockResultSchema } from '../block/l2_block_source.js';
7
+ import { type L2BlockSource, L2TipsSchema } from '../block/l2_block_source.js';
7
8
  import { PublishedL2Block } from '../block/published_l2_block.js';
9
+ import { ValidateBlockResultSchema } from '../block/validate_block_result.js';
8
10
  import {
9
11
  ContractClassPublicSchema,
10
12
  type ContractDataSource,
@@ -23,6 +25,41 @@ import { TxReceipt } from '../tx/tx_receipt.js';
23
25
  import { GetContractClassLogsResponseSchema, GetPublicLogsResponseSchema } from './get_logs_response.js';
24
26
  import type { L2LogsSource } from './l2_logs_source.js';
25
27
 
28
+ /**
29
+ * The archiver configuration.
30
+ */
31
+ export type ArchiverSpecificConfig = {
32
+ /** The polling interval in ms for retrieving new L2 blocks and encrypted logs. */
33
+ archiverPollingIntervalMS?: number;
34
+
35
+ /** The number of L2 blocks the archiver will attempt to download at a time. */
36
+ archiverBatchSize?: number;
37
+
38
+ /** The polling interval viem uses in ms */
39
+ viemPollingIntervalMS?: number;
40
+
41
+ /** The deployed L1 contract addresses */
42
+ l1Contracts: L1ContractAddresses;
43
+
44
+ /** The max number of logs that can be obtained in 1 "getPublicLogs" call. */
45
+ maxLogs?: number;
46
+
47
+ /** The maximum possible size of the archiver DB in KB. Overwrites the general dataStoreMapSizeKB. */
48
+ archiverStoreMapSizeKb?: number;
49
+
50
+ /** Whether to skip validating block attestations (use only for testing). */
51
+ skipValidateBlockAttestations?: boolean;
52
+ };
53
+
54
+ export const ArchiverSpecificConfigSchema = z.object({
55
+ archiverPollingIntervalMS: schemas.Integer.optional(),
56
+ archiverBatchSize: schemas.Integer.optional(),
57
+ viemPollingIntervalMS: schemas.Integer.optional(),
58
+ maxLogs: schemas.Integer.optional(),
59
+ archiverStoreMapSizeKb: schemas.Integer.optional(),
60
+ skipValidateBlockAttestations: z.boolean().optional(),
61
+ });
62
+
26
63
  export type ArchiverApi = Omit<
27
64
  L2BlockSource & L2LogsSource & ContractDataSource & L1ToL2MessageSource,
28
65
  'start' | 'stop'
@@ -5,6 +5,7 @@ import { z } from 'zod';
5
5
  import type { ApiSchemaFor } from '../schemas/schemas.js';
6
6
  import { type Offense, OffenseSchema, type SlashPayloadRound, SlashPayloadRoundSchema } from '../slashing/index.js';
7
7
  import { type ComponentsVersions, getVersioningResponseHandler } from '../versioning/index.js';
8
+ import { type ArchiverSpecificConfig, ArchiverSpecificConfigSchema } from './archiver.js';
8
9
  import { type SequencerConfig, SequencerConfigSchema } from './configs.js';
9
10
  import { type ProverConfig, ProverConfigSchema } from './prover-client.js';
10
11
  import { type SlasherConfig, SlasherConfigSchema } from './slasher.js';
@@ -54,11 +55,21 @@ export interface AztecNodeAdmin {
54
55
  export type AztecNodeAdminConfig = ValidatorClientFullConfig &
55
56
  SequencerConfig &
56
57
  ProverConfig &
57
- SlasherConfig & { maxTxPoolSize: number };
58
+ SlasherConfig &
59
+ Pick<ArchiverSpecificConfig, 'archiverPollingIntervalMS' | 'skipValidateBlockAttestations' | 'archiverBatchSize'> & {
60
+ maxTxPoolSize: number;
61
+ };
58
62
 
59
63
  export const AztecNodeAdminConfigSchema = SequencerConfigSchema.merge(ProverConfigSchema)
60
64
  .merge(SlasherConfigSchema)
61
65
  .merge(ValidatorClientConfigSchema)
66
+ .merge(
67
+ ArchiverSpecificConfigSchema.pick({
68
+ archiverPollingIntervalMS: true,
69
+ skipValidateBlockAttestations: true,
70
+ archiverBatchSize: true,
71
+ }),
72
+ )
62
73
  .merge(z.object({ maxTxPoolSize: z.number() }));
63
74
 
64
75
  export const AztecNodeAdminApiSchema: ApiSchemaFor<AztecNodeAdmin> = {
@@ -98,6 +98,10 @@ export class BlockAttestation extends Gossipable {
98
98
  return new BlockAttestation(0, ConsensusPayload.empty(), Signature.empty());
99
99
  }
100
100
 
101
+ static random(): BlockAttestation {
102
+ return new BlockAttestation(Math.floor(Math.random() * 1000) + 1, ConsensusPayload.random(), Signature.random());
103
+ }
104
+
101
105
  getSize(): number {
102
106
  return 4 /* blockNumber */ + this.payload.getSize() + this.signature.getSize();
103
107
  }
@@ -5,7 +5,7 @@ import { Signature } from '@aztec/foundation/eth-signature';
5
5
  import { Fr } from '@aztec/foundation/fields';
6
6
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
7
7
 
8
- import type { BlockInfo } from '../block/l2_block.js';
8
+ import type { L2BlockInfo } from '../block/l2_block_info.js';
9
9
  import { TxHash } from '../tx/index.js';
10
10
  import { Tx } from '../tx/tx.js';
11
11
  import type { UInt32 } from '../types/index.js';
@@ -71,11 +71,13 @@ export class BlockProposal extends Gossipable {
71
71
  return this.payload.header.slotNumber;
72
72
  }
73
73
 
74
- toBlockInfo(): BlockInfo {
74
+ toBlockInfo(): L2BlockInfo {
75
75
  return {
76
76
  blockNumber: this.blockNumber,
77
77
  slotNumber: this.slotNumber.toNumber(),
78
- archive: this.archive.toString(),
78
+ lastArchive: this.payload.header.lastArchiveRoot,
79
+ timestamp: this.payload.header.timestamp,
80
+ archive: this.archive,
79
81
  txCount: this.txHashes.length,
80
82
  };
81
83
  }
@@ -60,18 +60,17 @@ export class ConsensusPayload implements Signable {
60
60
  }
61
61
 
62
62
  toBuffer(): Buffer {
63
- const buffer = serializeToBuffer([this.header, this.archive, this.stateReference]);
64
- this.size = buffer.length;
65
- return buffer;
63
+ return serializeToBuffer([this.header, this.archive, this.stateReference]);
66
64
  }
67
65
 
68
66
  static fromBuffer(buf: Buffer | BufferReader): ConsensusPayload {
69
67
  const reader = BufferReader.asReader(buf);
70
- return new ConsensusPayload(
68
+ const payload = new ConsensusPayload(
71
69
  reader.readObject(ProposedBlockHeader),
72
70
  reader.readObject(Fr),
73
71
  reader.readObject(StateReference),
74
72
  );
73
+ return payload;
75
74
  }
76
75
 
77
76
  static fromFields(fields: FieldsOf<ConsensusPayload>): ConsensusPayload {
@@ -86,6 +85,10 @@ export class ConsensusPayload implements Signable {
86
85
  return new ConsensusPayload(ProposedBlockHeader.empty(), Fr.ZERO, StateReference.empty());
87
86
  }
88
87
 
88
+ static random(): ConsensusPayload {
89
+ return new ConsensusPayload(ProposedBlockHeader.random(), Fr.random(), StateReference.random());
90
+ }
91
+
89
92
  /**
90
93
  * Get the size of the consensus payload in bytes.
91
94
  * @returns The size of the consensus payload.
@@ -6,10 +6,10 @@ import { Fr } from '@aztec/foundation/fields';
6
6
 
7
7
  import type { ContractArtifact } from '../abi/abi.js';
8
8
  import { AztecAddress } from '../aztec-address/index.js';
9
- import { CommitteeAttestation } from '../block/index.js';
9
+ import { CommitteeAttestation, L1PublishedData } from '../block/index.js';
10
10
  import { L2Block } from '../block/l2_block.js';
11
11
  import type { CommitteeAttestationsAndSigners } from '../block/proposal/attestations_and_signers.js';
12
- import type { PublishedL2Block } from '../block/published_l2_block.js';
12
+ import { PublishedL2Block } from '../block/published_l2_block.js';
13
13
  import { computeContractAddressFromInstance } from '../contract/contract_address.js';
14
14
  import { getContractClassFromArtifact } from '../contract/contract_class.js';
15
15
  import { SerializableContractInstance } from '../contract/contract_instance.js';
@@ -318,16 +318,16 @@ export async function randomPublishedL2Block(
318
318
  opts: { signers?: Secp256k1Signer[] } = {},
319
319
  ): Promise<PublishedL2Block> {
320
320
  const block = await L2Block.random(l2BlockNumber);
321
- const l1 = {
321
+ const l1 = L1PublishedData.fromFields({
322
322
  blockNumber: BigInt(block.number),
323
323
  timestamp: block.header.globalVariables.timestamp,
324
324
  blockHash: Buffer32.random().toString(),
325
- };
325
+ });
326
326
 
327
327
  const signers = opts.signers ?? times(3, () => Secp256k1Signer.random());
328
328
  const atts = await Promise.all(signers.map(signer => makeBlockAttestationFromBlock(block, signer)));
329
329
  const attestations = atts.map(
330
330
  (attestation, i) => new CommitteeAttestation(signers[i].address, attestation.signature),
331
331
  );
332
- return { block, l1, attestations };
332
+ return new PublishedL2Block(block, l1, attestations);
333
333
  }
@@ -75,6 +75,10 @@ export class ContentCommitment {
75
75
  return new ContentCommitment(reader.readField(), reader.readField(), reader.readField());
76
76
  }
77
77
 
78
+ static random(): ContentCommitment {
79
+ return new ContentCommitment(Fr.random(), Fr.random(), Fr.random());
80
+ }
81
+
78
82
  static empty(): ContentCommitment {
79
83
  return new ContentCommitment(Fr.zero(), Fr.zero(), Fr.zero());
80
84
  }
@@ -64,6 +64,14 @@ export class PartialStateReference {
64
64
  );
65
65
  }
66
66
 
67
+ static random(): PartialStateReference {
68
+ return new PartialStateReference(
69
+ AppendOnlyTreeSnapshot.random(),
70
+ AppendOnlyTreeSnapshot.random(),
71
+ AppendOnlyTreeSnapshot.random(),
72
+ );
73
+ }
74
+
67
75
  toViem(): ViemPartialStateReference {
68
76
  return {
69
77
  noteHashTree: this.noteHashTree.toViem(),
@@ -116,6 +116,19 @@ export class ProposedBlockHeader {
116
116
  });
117
117
  }
118
118
 
119
+ static random(): ProposedBlockHeader {
120
+ return new ProposedBlockHeader(
121
+ Fr.random(),
122
+ ContentCommitment.random(),
123
+ new Fr(BigInt(Math.floor(Math.random() * 1000) + 1)),
124
+ BigInt(Math.floor(Date.now() / 1000)),
125
+ EthAddress.random(),
126
+ new AztecAddress(Fr.random()),
127
+ GasFees.random(),
128
+ new Fr(BigInt(Math.floor(Math.random() * 1000000))),
129
+ );
130
+ }
131
+
119
132
  isEmpty(): boolean {
120
133
  return (
121
134
  this.lastArchiveRoot.isZero() &&
@@ -78,6 +78,10 @@ export class StateReference {
78
78
  return new StateReference(AppendOnlyTreeSnapshot.empty(), PartialStateReference.empty());
79
79
  }
80
80
 
81
+ static random(): StateReference {
82
+ return new StateReference(AppendOnlyTreeSnapshot.random(), PartialStateReference.random());
83
+ }
84
+
81
85
  toViem(): ViemStateReference {
82
86
  return {
83
87
  l1ToL2MessageTree: this.l1ToL2MessageTree.toViem(),
@@ -43,7 +43,7 @@ export class UpdateChecker extends EventEmitter<EventMap> {
43
43
  private rollupVersion: bigint,
44
44
  private fetch: typeof globalThis.fetch,
45
45
  private getLatestRollupVersion: () => Promise<bigint>,
46
- private checkIntervalMs = 60_000, // every minute
46
+ private checkIntervalMs = 10 * 60_000, // every 10 mins
47
47
  private log = createLogger('foundation:update-check'),
48
48
  ) {
49
49
  super();