@aztec/stdlib 2.0.0-rc.25 → 2.0.0-rc.27

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 (71) 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/interfaces/block-builder.d.ts +5 -6
  28. package/dest/interfaces/block-builder.d.ts.map +1 -1
  29. package/dest/p2p/block_attestation.d.ts +1 -0
  30. package/dest/p2p/block_attestation.d.ts.map +1 -1
  31. package/dest/p2p/block_attestation.js +3 -0
  32. package/dest/p2p/block_proposal.d.ts +2 -2
  33. package/dest/p2p/block_proposal.d.ts.map +1 -1
  34. package/dest/p2p/block_proposal.js +3 -1
  35. package/dest/p2p/consensus_payload.d.ts +1 -0
  36. package/dest/p2p/consensus_payload.d.ts.map +1 -1
  37. package/dest/p2p/consensus_payload.js +6 -4
  38. package/dest/tests/mocks.d.ts +1 -1
  39. package/dest/tests/mocks.d.ts.map +1 -1
  40. package/dest/tests/mocks.js +5 -8
  41. package/dest/tx/content_commitment.d.ts +1 -0
  42. package/dest/tx/content_commitment.d.ts.map +1 -1
  43. package/dest/tx/content_commitment.js +3 -0
  44. package/dest/tx/partial_state_reference.d.ts +1 -0
  45. package/dest/tx/partial_state_reference.d.ts.map +1 -1
  46. package/dest/tx/partial_state_reference.js +3 -0
  47. package/dest/tx/proposed_block_header.d.ts +1 -0
  48. package/dest/tx/proposed_block_header.d.ts.map +1 -1
  49. package/dest/tx/proposed_block_header.js +3 -0
  50. package/dest/tx/state_reference.d.ts +1 -0
  51. package/dest/tx/state_reference.d.ts.map +1 -1
  52. package/dest/tx/state_reference.js +3 -0
  53. package/package.json +8 -8
  54. package/src/block/index.ts +2 -0
  55. package/src/block/l2_block.ts +6 -11
  56. package/src/block/l2_block_info.ts +63 -0
  57. package/src/block/l2_block_source.ts +1 -51
  58. package/src/block/published_l2_block.ts +38 -5
  59. package/src/block/test/l2_tips_store_test_suite.ts +7 -6
  60. package/src/block/validate_block_result.ts +122 -0
  61. package/src/interfaces/archiver.ts +38 -1
  62. package/src/interfaces/aztec-node-admin.ts +12 -1
  63. package/src/interfaces/block-builder.ts +9 -6
  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
@@ -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> = {
@@ -2,6 +2,8 @@ import type { Fr } from '@aztec/foundation/fields';
2
2
  import type { Timer } from '@aztec/foundation/timer';
3
3
 
4
4
  import type { L2Block } from '../block/l2_block.js';
5
+ import type { ChainConfig, SequencerConfig } from '../config/chain-config.js';
6
+ import type { L1RollupConstants } from '../epoch-helpers/index.js';
5
7
  import type { Gas } from '../gas/gas.js';
6
8
  import type { MerkleTreeWriteOperations } from '../trees/index.js';
7
9
  import type { BlockHeader } from '../tx/block_header.js';
@@ -59,13 +61,14 @@ export interface BuildBlockResult {
59
61
  usedTxs: Tx[];
60
62
  }
61
63
 
64
+ export type FullNodeBlockBuilderConfig = Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration'> &
65
+ Pick<ChainConfig, 'l1ChainId' | 'rollupVersion'> &
66
+ Pick<SequencerConfig, 'txPublicSetupAllowList' | 'fakeProcessingDelayPerTxMs'>;
67
+
62
68
  export interface IFullNodeBlockBuilder {
63
- getConfig(): {
64
- l1GenesisTime: bigint;
65
- slotDuration: number;
66
- l1ChainId: number;
67
- rollupVersion: number;
68
- };
69
+ getConfig(): FullNodeBlockBuilderConfig;
70
+
71
+ updateConfig(config: Partial<FullNodeBlockBuilderConfig>): void;
69
72
 
70
73
  buildBlock(
71
74
  txs: Iterable<Tx> | AsyncIterable<Tx>,
@@ -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,9 +6,9 @@ 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
- import type { PublishedL2Block } from '../block/published_l2_block.js';
11
+ import { PublishedL2Block } from '../block/published_l2_block.js';
12
12
  import { computeContractAddressFromInstance } from '../contract/contract_address.js';
13
13
  import { getContractClassFromArtifact } from '../contract/contract_class.js';
14
14
  import { SerializableContractInstance } from '../contract/contract_instance.js';
@@ -306,16 +306,16 @@ export async function randomPublishedL2Block(
306
306
  opts: { signers?: Secp256k1Signer[] } = {},
307
307
  ): Promise<PublishedL2Block> {
308
308
  const block = await L2Block.random(l2BlockNumber);
309
- const l1 = {
309
+ const l1 = L1PublishedData.fromFields({
310
310
  blockNumber: BigInt(block.number),
311
311
  timestamp: block.header.globalVariables.timestamp,
312
312
  blockHash: Buffer32.random().toString(),
313
- };
313
+ });
314
314
 
315
315
  const signers = opts.signers ?? times(3, () => Secp256k1Signer.random());
316
316
  const atts = await Promise.all(signers.map(signer => makeBlockAttestationFromBlock(block, signer)));
317
317
  const attestations = atts.map(
318
318
  (attestation, i) => new CommitteeAttestation(signers[i].address, attestation.signature),
319
319
  );
320
- return { block, l1, attestations };
320
+ return new PublishedL2Block(block, l1, attestations);
321
321
  }
@@ -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(),