@aztec/stdlib 0.80.0 → 0.81.0

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 (109) hide show
  1. package/dest/abi/contract_artifact.d.ts.map +1 -1
  2. package/dest/abi/contract_artifact.js +11 -0
  3. package/dest/avm/avm.d.ts +173 -405
  4. package/dest/avm/avm.d.ts.map +1 -1
  5. package/dest/avm/avm.js +34 -27
  6. package/dest/avm/avm_proving_request.d.ts +84 -186
  7. package/dest/avm/avm_proving_request.d.ts.map +1 -1
  8. package/dest/avm/public_data_write.d.ts +1 -0
  9. package/dest/avm/public_data_write.d.ts.map +1 -1
  10. package/dest/avm/public_data_write.js +3 -0
  11. package/dest/block/body.d.ts +1 -0
  12. package/dest/block/body.d.ts.map +1 -1
  13. package/dest/block/body.js +3 -0
  14. package/dest/block/index.d.ts +1 -0
  15. package/dest/block/index.d.ts.map +1 -1
  16. package/dest/block/index.js +1 -0
  17. package/dest/block/l2_block.d.ts +2 -1
  18. package/dest/block/l2_block.d.ts.map +1 -1
  19. package/dest/block/l2_block.js +3 -0
  20. package/dest/block/l2_block_downloader/l2_block_stream.d.ts +3 -3
  21. package/dest/block/l2_block_downloader/l2_block_stream.d.ts.map +1 -1
  22. package/dest/block/l2_block_downloader/l2_block_stream.js +2 -2
  23. package/dest/block/l2_block_source.d.ts +3 -0
  24. package/dest/block/l2_block_source.d.ts.map +1 -1
  25. package/dest/block/published_l2_block.d.ts +89 -0
  26. package/dest/block/published_l2_block.d.ts.map +1 -0
  27. package/dest/block/published_l2_block.js +32 -0
  28. package/dest/contract/interfaces/contract_data_source.d.ts +3 -9
  29. package/dest/contract/interfaces/contract_data_source.d.ts.map +1 -1
  30. package/dest/database-version/version_manager.js +1 -1
  31. package/dest/interfaces/archiver.d.ts.map +1 -1
  32. package/dest/interfaces/archiver.js +4 -3
  33. package/dest/interfaces/aztec-node.d.ts +1 -1
  34. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  35. package/dest/interfaces/aztec-node.js +2 -0
  36. package/dest/interfaces/proving-job.d.ts +106 -208
  37. package/dest/interfaces/proving-job.d.ts.map +1 -1
  38. package/dest/logs/contract_class_log.d.ts +1 -0
  39. package/dest/logs/contract_class_log.d.ts.map +1 -1
  40. package/dest/logs/contract_class_log.js +3 -0
  41. package/dest/logs/l1_payload/index.d.ts +1 -1
  42. package/dest/logs/l1_payload/index.d.ts.map +1 -1
  43. package/dest/logs/l1_payload/index.js +1 -1
  44. package/dest/logs/private_log.d.ts +2 -1
  45. package/dest/logs/private_log.d.ts.map +1 -1
  46. package/dest/logs/private_log.js +14 -3
  47. package/dest/logs/public_log.d.ts.map +1 -1
  48. package/dest/logs/public_log.js +4 -1
  49. package/dest/logs/tx_scoped_l2_log.d.ts +16 -28
  50. package/dest/logs/tx_scoped_l2_log.d.ts.map +1 -1
  51. package/dest/logs/tx_scoped_l2_log.js +28 -19
  52. package/dest/note/extended_note.d.ts +10 -21
  53. package/dest/note/extended_note.d.ts.map +1 -1
  54. package/dest/note/extended_note.js +19 -28
  55. package/dest/note/notes_filter.d.ts +2 -2
  56. package/dest/note/notes_filter.d.ts.map +1 -1
  57. package/dest/note/notes_filter.js +1 -1
  58. package/dest/p2p/consensus_payload.d.ts +3 -1
  59. package/dest/p2p/consensus_payload.d.ts.map +1 -1
  60. package/dest/p2p/consensus_payload.js +3 -0
  61. package/dest/proofs/proof.d.ts +0 -1
  62. package/dest/proofs/proof.d.ts.map +1 -1
  63. package/dest/proofs/proof.js +2 -7
  64. package/dest/rollup/block_root_rollup.d.ts +1 -1
  65. package/dest/tests/factories.d.ts +3 -2
  66. package/dest/tests/factories.d.ts.map +1 -1
  67. package/dest/tests/factories.js +14 -8
  68. package/dest/tests/mocks.d.ts +2 -2
  69. package/dest/tests/mocks.d.ts.map +1 -1
  70. package/dest/tests/mocks.js +4 -5
  71. package/dest/trees/nullifier_membership_witness.d.ts +7 -7
  72. package/dest/trees/public_data_witness.d.ts +7 -7
  73. package/dest/tx/capsule.d.ts +2 -0
  74. package/dest/tx/capsule.d.ts.map +1 -1
  75. package/dest/tx/capsule.js +2 -0
  76. package/dest/tx/tx_effect.d.ts +1 -0
  77. package/dest/tx/tx_effect.d.ts.map +1 -1
  78. package/dest/tx/tx_effect.js +4 -1
  79. package/package.json +6 -6
  80. package/src/abi/contract_artifact.ts +11 -0
  81. package/src/avm/avm.ts +42 -39
  82. package/src/avm/public_data_write.ts +4 -0
  83. package/src/block/body.ts +6 -0
  84. package/src/block/index.ts +1 -0
  85. package/src/block/l2_block.ts +4 -0
  86. package/src/block/l2_block_downloader/l2_block_stream.ts +5 -5
  87. package/src/block/l2_block_source.ts +4 -0
  88. package/src/block/published_l2_block.ts +45 -0
  89. package/src/contract/interfaces/contract_data_source.ts +3 -10
  90. package/src/database-version/version_manager.ts +1 -1
  91. package/src/interfaces/archiver.ts +9 -6
  92. package/src/interfaces/aztec-node.ts +4 -1
  93. package/src/logs/contract_class_log.ts +8 -0
  94. package/src/logs/l1_payload/index.ts +1 -1
  95. package/src/logs/private_log.ts +13 -3
  96. package/src/logs/public_log.ts +11 -1
  97. package/src/logs/tx_scoped_l2_log.ts +28 -25
  98. package/src/note/extended_note.ts +17 -36
  99. package/src/note/notes_filter.ts +3 -3
  100. package/src/p2p/consensus_payload.ts +9 -0
  101. package/src/proofs/proof.ts +2 -8
  102. package/src/tests/factories.ts +15 -14
  103. package/src/tests/mocks.ts +4 -9
  104. package/src/tx/capsule.ts +2 -0
  105. package/src/tx/tx_effect.ts +23 -1
  106. package/dest/logs/l1_payload/l1_note_payload.d.ts +0 -82
  107. package/dest/logs/l1_payload/l1_note_payload.d.ts.map +0 -1
  108. package/dest/logs/l1_payload/l1_note_payload.js +0 -129
  109. package/src/logs/l1_payload/l1_note_payload.ts +0 -182
package/src/avm/avm.ts CHANGED
@@ -12,25 +12,33 @@ import { AvmCircuitPublicInputs } from './avm_circuit_public_inputs.js';
12
12
  import { serializeWithMessagePack } from './message_pack.js';
13
13
 
14
14
  export class AvmEnqueuedCallHint {
15
- constructor(public readonly contractAddress: AztecAddress, public readonly calldata: Fr[]) {}
15
+ constructor(
16
+ public readonly msgSender: AztecAddress,
17
+ public readonly contractAddress: AztecAddress,
18
+ public readonly calldata: Fr[],
19
+ public isStaticCall: boolean,
20
+ ) {}
16
21
 
17
22
  static get schema() {
18
23
  return z
19
24
  .object({
25
+ msgSender: AztecAddress.schema,
20
26
  contractAddress: AztecAddress.schema,
21
27
  calldata: schemas.Fr.array(),
28
+ isStaticCall: z.boolean(),
22
29
  })
23
- .transform(({ contractAddress, calldata }) => new AvmEnqueuedCallHint(contractAddress, calldata));
30
+ .transform(
31
+ ({ msgSender, contractAddress, calldata, isStaticCall }) =>
32
+ new AvmEnqueuedCallHint(msgSender, contractAddress, calldata, isStaticCall),
33
+ );
24
34
  }
25
35
  }
26
36
 
27
37
  export class AvmContractClassHint {
28
38
  constructor(
29
39
  public readonly classId: Fr,
30
- public readonly exists: boolean,
31
40
  public readonly artifactHash: Fr,
32
41
  public readonly privateFunctionsRoot: Fr,
33
- public readonly publicBytecodeCommitment: Fr,
34
42
  public readonly packedBytecode: Buffer,
35
43
  ) {}
36
44
 
@@ -38,79 +46,70 @@ export class AvmContractClassHint {
38
46
  return z
39
47
  .object({
40
48
  classId: schemas.Fr,
41
- exists: z.boolean(),
42
49
  artifactHash: schemas.Fr,
43
50
  privateFunctionsRoot: schemas.Fr,
44
- publicBytecodeCommitment: schemas.Fr,
45
51
  packedBytecode: schemas.Buffer,
46
52
  })
47
53
  .transform(
48
- ({ classId, exists, artifactHash, privateFunctionsRoot, publicBytecodeCommitment, packedBytecode }) =>
49
- new AvmContractClassHint(
50
- classId,
51
- exists,
52
- artifactHash,
53
- privateFunctionsRoot,
54
- publicBytecodeCommitment,
55
- packedBytecode,
56
- ),
54
+ ({ classId, artifactHash, privateFunctionsRoot, packedBytecode }) =>
55
+ new AvmContractClassHint(classId, artifactHash, privateFunctionsRoot, packedBytecode),
57
56
  );
58
57
  }
59
58
  }
60
59
 
60
+ export class AvmBytecodeCommitmentHint {
61
+ constructor(public readonly classId: Fr, public readonly commitment: Fr) {}
62
+
63
+ static get schema() {
64
+ return z
65
+ .object({
66
+ classId: schemas.Fr,
67
+ commitment: schemas.Fr,
68
+ })
69
+ .transform(({ classId, commitment }) => new AvmBytecodeCommitmentHint(classId, commitment));
70
+ }
71
+ }
72
+
61
73
  export class AvmContractInstanceHint {
62
74
  constructor(
63
75
  public readonly address: AztecAddress,
64
- public readonly exists: boolean,
65
76
  public readonly salt: Fr,
66
77
  public readonly deployer: AztecAddress,
67
78
  public readonly currentContractClassId: Fr,
68
79
  public readonly originalContractClassId: Fr,
69
80
  public readonly initializationHash: Fr,
70
81
  public readonly publicKeys: PublicKeys,
71
- // public readonly updateMembershipHint: AvmPublicDataReadTreeHint = AvmPublicDataReadTreeHint.empty(),
72
- public readonly updateMembershipHint: AvmPublicDataReadTreeHint,
73
- public readonly updatePreimage: Fr[] = [],
74
82
  ) {}
75
83
 
76
84
  static get schema() {
77
85
  return z
78
86
  .object({
79
87
  address: AztecAddress.schema,
80
- exists: z.boolean(),
81
88
  salt: schemas.Fr,
82
89
  deployer: AztecAddress.schema,
83
90
  currentContractClassId: schemas.Fr,
84
91
  originalContractClassId: schemas.Fr,
85
92
  initializationHash: schemas.Fr,
86
93
  publicKeys: PublicKeys.schema,
87
- updateMembershipHint: AvmPublicDataReadTreeHint.schema,
88
- updatePreimage: schemas.Fr.array(),
89
94
  })
90
95
  .transform(
91
96
  ({
92
97
  address,
93
- exists,
94
98
  salt,
95
99
  deployer,
96
100
  currentContractClassId,
97
101
  originalContractClassId,
98
102
  initializationHash,
99
103
  publicKeys,
100
- updateMembershipHint,
101
- updatePreimage,
102
104
  }) =>
103
105
  new AvmContractInstanceHint(
104
106
  address,
105
- exists,
106
107
  salt,
107
108
  deployer,
108
109
  currentContractClassId,
109
110
  originalContractClassId,
110
111
  initializationHash,
111
112
  publicKeys,
112
- updateMembershipHint,
113
- updatePreimage,
114
113
  ),
115
114
  );
116
115
  }
@@ -213,20 +212,21 @@ export class AvmPublicDataWriteTreeHint {
213
212
 
214
213
  export class AvmExecutionHints {
215
214
  constructor(
216
- public readonly enqueuedCalls: AvmEnqueuedCallHint[],
217
- public readonly contractInstances: AvmContractInstanceHint[],
218
- public readonly contractClasses: AvmContractClassHint[],
219
- public readonly publicDataReads: AvmPublicDataReadTreeHint[],
220
- public readonly publicDataWrites: AvmPublicDataWriteTreeHint[],
221
- public readonly nullifierReads: AvmNullifierReadTreeHint[],
222
- public readonly nullifierWrites: AvmNullifierWriteTreeHint[],
223
- public readonly noteHashReads: AvmAppendTreeHint[],
224
- public readonly noteHashWrites: AvmAppendTreeHint[],
225
- public readonly l1ToL2MessageReads: AvmAppendTreeHint[],
215
+ public readonly enqueuedCalls: AvmEnqueuedCallHint[] = [],
216
+ public readonly contractInstances: AvmContractInstanceHint[] = [],
217
+ public readonly contractClasses: AvmContractClassHint[] = [],
218
+ public readonly bytecodeCommitments: AvmBytecodeCommitmentHint[] = [],
219
+ public readonly publicDataReads: AvmPublicDataReadTreeHint[] = [],
220
+ public readonly publicDataWrites: AvmPublicDataWriteTreeHint[] = [],
221
+ public readonly nullifierReads: AvmNullifierReadTreeHint[] = [],
222
+ public readonly nullifierWrites: AvmNullifierWriteTreeHint[] = [],
223
+ public readonly noteHashReads: AvmAppendTreeHint[] = [],
224
+ public readonly noteHashWrites: AvmAppendTreeHint[] = [],
225
+ public readonly l1ToL2MessageReads: AvmAppendTreeHint[] = [],
226
226
  ) {}
227
227
 
228
228
  static empty() {
229
- return new AvmExecutionHints([], [], [], [], [], [], [], [], [], []);
229
+ return new AvmExecutionHints();
230
230
  }
231
231
 
232
232
  static get schema() {
@@ -235,6 +235,7 @@ export class AvmExecutionHints {
235
235
  enqueuedCalls: AvmEnqueuedCallHint.schema.array(),
236
236
  contractInstances: AvmContractInstanceHint.schema.array(),
237
237
  contractClasses: AvmContractClassHint.schema.array(),
238
+ bytecodeCommitments: AvmBytecodeCommitmentHint.schema.array(),
238
239
  publicDataReads: AvmPublicDataReadTreeHint.schema.array(),
239
240
  publicDataWrites: AvmPublicDataWriteTreeHint.schema.array(),
240
241
  nullifierReads: AvmNullifierReadTreeHint.schema.array(),
@@ -248,6 +249,7 @@ export class AvmExecutionHints {
248
249
  enqueuedCalls,
249
250
  contractInstances,
250
251
  contractClasses,
252
+ bytecodeCommitments,
251
253
  publicDataReads,
252
254
  publicDataWrites,
253
255
  nullifierReads,
@@ -260,6 +262,7 @@ export class AvmExecutionHints {
260
262
  enqueuedCalls,
261
263
  contractInstances,
262
264
  contractClasses,
265
+ bytecodeCommitments,
263
266
  publicDataReads,
264
267
  publicDataWrites,
265
268
  nullifierReads,
@@ -77,4 +77,8 @@ export class PublicDataWrite {
77
77
  isEmpty() {
78
78
  return this.leafSlot.isZero() && this.value.isZero();
79
79
  }
80
+
81
+ equals(other: PublicDataWrite): boolean {
82
+ return this.leafSlot.equals(other.leafSlot) && this.value.equals(other.value);
83
+ }
80
84
  }
package/src/block/body.ts CHANGED
@@ -18,6 +18,12 @@ export class Body {
18
18
  });
19
19
  }
20
20
 
21
+ equals(other: Body) {
22
+ return (
23
+ this.txEffects.length === other.txEffects.length && this.txEffects.every((te, i) => te.equals(other.txEffects[i]))
24
+ );
25
+ }
26
+
21
27
  static get schema(): ZodFor<Body> {
22
28
  return z
23
29
  .object({
@@ -6,3 +6,4 @@ export * from './body.js';
6
6
  export * from './l2_block_number.js';
7
7
  export * from './l2_block_source.js';
8
8
  export * from './block_hash.js';
9
+ export * from './published_l2_block.js';
@@ -202,4 +202,8 @@ export class L2Block {
202
202
  ...logsStats,
203
203
  };
204
204
  }
205
+
206
+ equals(other: L2Block) {
207
+ return this.archive.equals(other.archive) && this.header.equals(other.header) && this.body.equals(other.body);
208
+ }
205
209
  }
@@ -2,8 +2,8 @@ import { AbortError } from '@aztec/foundation/error';
2
2
  import { createLogger } from '@aztec/foundation/log';
3
3
  import { RunningPromise } from '@aztec/foundation/running-promise';
4
4
 
5
- import type { L2Block } from '../l2_block.js';
6
5
  import type { L2BlockId, L2BlockSource, L2Tips } from '../l2_block_source.js';
6
+ import type { PublishedL2Block } from '../published_l2_block.js';
7
7
 
8
8
  /** Creates a stream of events for new blocks, chain tips updates, and reorgs, out of polling an archiver or a node. */
9
9
  export class L2BlockStream {
@@ -11,7 +11,7 @@ export class L2BlockStream {
11
11
  private isSyncing = false;
12
12
 
13
13
  constructor(
14
- private l2BlockSource: Pick<L2BlockSource, 'getBlocks' | 'getBlockHeader' | 'getL2Tips'>,
14
+ private l2BlockSource: Pick<L2BlockSource, 'getPublishedBlocks' | 'getBlockHeader' | 'getL2Tips'>,
15
15
  private localData: L2BlockStreamLocalDataProvider,
16
16
  private handler: L2BlockStreamEventHandler,
17
17
  private readonly log = createLogger('types:block_stream'),
@@ -84,12 +84,12 @@ export class L2BlockStream {
84
84
  const from = latestBlockNumber + 1;
85
85
  const limit = Math.min(this.opts.batchSize ?? 20, sourceTips.latest.number - from + 1);
86
86
  this.log.trace(`Requesting blocks from ${from} limit ${limit} proven=${this.opts.proven}`);
87
- const blocks = await this.l2BlockSource.getBlocks(from, limit, this.opts.proven);
87
+ const blocks = await this.l2BlockSource.getPublishedBlocks(from, limit, this.opts.proven);
88
88
  if (blocks.length === 0) {
89
89
  break;
90
90
  }
91
91
  await this.emitEvent({ type: 'blocks-added', blocks });
92
- latestBlockNumber = blocks.at(-1)!.number;
92
+ latestBlockNumber = blocks.at(-1)!.block.number;
93
93
  }
94
94
 
95
95
  // Update the proven and finalized tips.
@@ -160,7 +160,7 @@ export type L2BlockStreamEvent =
160
160
  | {
161
161
  type: 'blocks-added';
162
162
  /** New blocks added to the chain. */
163
- blocks: L2Block[];
163
+ blocks: PublishedL2Block[];
164
164
  }
165
165
  | {
166
166
  type: 'chain-pruned';
@@ -10,6 +10,7 @@ import type { TxHash } from '../tx/tx_hash.js';
10
10
  import type { TxReceipt } from '../tx/tx_receipt.js';
11
11
  import type { InBlock } from './in_block.js';
12
12
  import type { L2Block } from './l2_block.js';
13
+ import type { PublishedL2Block } from './published_l2_block.js';
13
14
 
14
15
  /**
15
16
  * Interface of classes allowing for the retrieval of L2 blocks.
@@ -62,6 +63,9 @@ export interface L2BlockSource {
62
63
  */
63
64
  getBlocks(from: number, limit: number, proven?: boolean): Promise<L2Block[]>;
64
65
 
66
+ /** Equivalent to getBlocks but includes publish data. */
67
+ getPublishedBlocks(from: number, limit: number, proven?: boolean): Promise<PublishedL2Block[]>;
68
+
65
69
  /**
66
70
  * Gets a tx effect.
67
71
  * @param txHash - The hash of a transaction which resulted in the returned tx effect.
@@ -0,0 +1,45 @@
1
+ import { Buffer32 } from '@aztec/foundation/buffer';
2
+ import { times } from '@aztec/foundation/collection';
3
+ import { Secp256k1Signer } from '@aztec/foundation/crypto';
4
+ import { Signature } from '@aztec/foundation/eth-signature';
5
+ import { schemas } from '@aztec/foundation/schemas';
6
+ import { L2Block } from '@aztec/stdlib/block';
7
+
8
+ import { z } from 'zod';
9
+
10
+ export type L1PublishedData = {
11
+ blockNumber: bigint;
12
+ timestamp: bigint;
13
+ blockHash: string;
14
+ };
15
+
16
+ export type PublishedL2Block = {
17
+ block: L2Block;
18
+ l1: L1PublishedData;
19
+ signatures: Signature[];
20
+ };
21
+
22
+ export const PublishedL2BlockSchema = z.object({
23
+ block: L2Block.schema,
24
+ l1: z.object({
25
+ blockNumber: schemas.BigInt,
26
+ timestamp: schemas.BigInt,
27
+ blockHash: z.string(),
28
+ }),
29
+ signatures: z.array(Signature.schema),
30
+ });
31
+
32
+ export async function randomPublishedL2Block(l2BlockNumber: number): Promise<PublishedL2Block> {
33
+ const block = await L2Block.random(l2BlockNumber);
34
+ const l1 = {
35
+ blockNumber: BigInt(block.number),
36
+ timestamp: block.header.globalVariables.timestamp.toBigInt(),
37
+ blockHash: Buffer32.random().toString(),
38
+ };
39
+ // Create valid signatures
40
+ const signers = times(3, () => Secp256k1Signer.random());
41
+ const signatures = await Promise.all(
42
+ times(3, async i => signers[i].signMessage(Buffer32.fromField(await block.hash()))),
43
+ );
44
+ return { block, l1, signatures };
45
+ }
@@ -2,18 +2,10 @@ import type { Fr } from '@aztec/foundation/fields';
2
2
 
3
3
  import { FunctionSelector } from '../../abi/index.js';
4
4
  import type { AztecAddress } from '../../aztec-address/index.js';
5
- import type { ContractClassPublic, PublicFunction } from './contract_class.js';
5
+ import type { ContractClassPublic } from './contract_class.js';
6
6
  import type { ContractInstanceWithAddress } from './contract_instance.js';
7
7
 
8
8
  export interface ContractDataSource {
9
- /**
10
- * Returns a contract's encoded public function, given its function selector.
11
- * @param address - The contract aztec address.
12
- * @param selector - The function's selector.
13
- * @returns The function's data.
14
- */
15
- getPublicFunction(address: AztecAddress, selector: FunctionSelector): Promise<PublicFunction | undefined>;
16
-
17
9
  /**
18
10
  * Gets the number of the latest L2 block processed by the implementation.
19
11
  * @returns The number of the latest L2 block processed by the implementation.
@@ -37,8 +29,9 @@ export interface ContractDataSource {
37
29
  /**
38
30
  * Returns a publicly deployed contract instance given its address.
39
31
  * @param address - Address of the deployed contract.
32
+ * @param blockNumber - Block number at which to retrieve the contract instance. If not provided, the latest block should be used.
40
33
  */
41
- getContract(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined>;
34
+ getContract(address: AztecAddress, blockNumber?: number): Promise<ContractInstanceWithAddress | undefined>;
42
35
 
43
36
  /**
44
37
  * Returns the list of all class ids known.
@@ -148,7 +148,7 @@ export class DatabaseVersionManager<T> {
148
148
  }
149
149
  } else if (cmp !== 0) {
150
150
  this.log.info(
151
- `Can't upgrade from version ${storedVersion.schemaVersion} to ${this.currentVersion}. Resetting database at ${this.dataDirectory}`,
151
+ `Can't upgrade from version ${storedVersion.schemaVersion} to ${this.currentVersion.schemaVersion}. Resetting database at ${this.dataDirectory}`,
152
152
  );
153
153
  needsReset = true;
154
154
  }
@@ -6,11 +6,11 @@ import { inBlockSchemaFor } from '../block/in_block.js';
6
6
  import { L2Block } from '../block/l2_block.js';
7
7
  import { type L2BlockSource, L2TipsSchema } from '../block/l2_block_source.js';
8
8
  import type { NullifierWithBlockSource } from '../block/nullifier_with_block_source.js';
9
+ import { PublishedL2BlockSchema } from '../block/published_l2_block.js';
9
10
  import {
10
11
  ContractClassPublicSchema,
11
12
  type ContractDataSource,
12
13
  ContractInstanceWithAddressSchema,
13
- PublicFunctionSchema,
14
14
  } from '../contract/index.js';
15
15
  import { L1RollupConstantsSchema } from '../epoch-helpers/index.js';
16
16
  import { LogFilterSchema } from '../logs/log_filter.js';
@@ -44,6 +44,10 @@ export const ArchiverApiSchema: ApiSchemaFor<ArchiverApi> = {
44
44
  .function()
45
45
  .args(schemas.Integer, schemas.Integer, optional(z.boolean()))
46
46
  .returns(z.array(L2Block.schema)),
47
+ getPublishedBlocks: z
48
+ .function()
49
+ .args(schemas.Integer, schemas.Integer, optional(z.boolean()))
50
+ .returns(z.array(PublishedL2BlockSchema)),
47
51
  getTxEffect: z.function().args(TxHash.schema).returns(inBlockSchemaFor(TxEffect.schema).optional()),
48
52
  getSettledTxReceipt: z.function().args(TxHash.schema).returns(TxReceipt.schema.optional()),
49
53
  getL2SlotNumber: z.function().args().returns(schemas.BigInt),
@@ -62,13 +66,12 @@ export const ArchiverApiSchema: ApiSchemaFor<ArchiverApi> = {
62
66
  .returns(z.array(optional(inBlockSchemaFor(schemas.BigInt)))),
63
67
  getPublicLogs: z.function().args(LogFilterSchema).returns(GetPublicLogsResponseSchema),
64
68
  getContractClassLogs: z.function().args(LogFilterSchema).returns(GetContractClassLogsResponseSchema),
65
- getPublicFunction: z
66
- .function()
67
- .args(schemas.AztecAddress, schemas.FunctionSelector)
68
- .returns(PublicFunctionSchema.optional()),
69
69
  getContractClass: z.function().args(schemas.Fr).returns(ContractClassPublicSchema.optional()),
70
70
  getBytecodeCommitment: z.function().args(schemas.Fr).returns(schemas.Fr),
71
- getContract: z.function().args(schemas.AztecAddress).returns(ContractInstanceWithAddressSchema.optional()),
71
+ getContract: z
72
+ .function()
73
+ .args(schemas.AztecAddress, optional(schemas.Integer))
74
+ .returns(ContractInstanceWithAddressSchema.optional()),
72
75
  getContractClassIds: z.function().args().returns(z.array(schemas.Fr)),
73
76
  registerContractFunctionSignatures: z.function().args(schemas.AztecAddress, z.array(z.string())).returns(z.void()),
74
77
  getL1ToL2Messages: z.function().args(schemas.BigInt).returns(z.array(schemas.Fr)),
@@ -17,6 +17,7 @@ import { type InBlock, inBlockSchemaFor } from '../block/in_block.js';
17
17
  import { L2Block } from '../block/l2_block.js';
18
18
  import { type L2BlockNumber, L2BlockNumberSchema } from '../block/l2_block_number.js';
19
19
  import { type L2BlockSource, type L2Tips, L2TipsSchema } from '../block/l2_block_source.js';
20
+ import { PublishedL2BlockSchema } from '../block/published_l2_block.js';
20
21
  import {
21
22
  type ContractClassPublic,
22
23
  ContractClassPublicSchema,
@@ -63,7 +64,7 @@ import { type WorldStateSyncStatus, WorldStateSyncStatusSchema } from './world_s
63
64
  */
64
65
  export interface AztecNode
65
66
  extends ProverCoordination,
66
- Pick<L2BlockSource, 'getBlocks' | 'getBlockHeader' | 'getL2Tips'> {
67
+ Pick<L2BlockSource, 'getBlocks' | 'getPublishedBlocks' | 'getBlockHeader' | 'getL2Tips'> {
67
68
  /**
68
69
  * Returns the tips of the L2 chain.
69
70
  */
@@ -534,6 +535,8 @@ export const AztecNodeApiSchema: ApiSchemaFor<AztecNode> = {
534
535
 
535
536
  getBlocks: z.function().args(z.number(), z.number()).returns(z.array(L2Block.schema)),
536
537
 
538
+ getPublishedBlocks: z.function().args(z.number(), z.number()).returns(z.array(PublishedL2BlockSchema)),
539
+
537
540
  getCurrentBaseFees: z.function().returns(GasFees.schema),
538
541
 
539
542
  getNodeVersion: z.function().returns(z.string()),
@@ -28,6 +28,14 @@ export class ContractClassLog {
28
28
  return [this.contractAddress.toField(), ...this.fields];
29
29
  }
30
30
 
31
+ equals(other: ContractClassLog) {
32
+ return (
33
+ this.contractAddress.equals(other.contractAddress) &&
34
+ this.fields.length === other.fields.length &&
35
+ this.fields.every((f, i) => f.equals(other.fields[i]))
36
+ );
37
+ }
38
+
31
39
  static fromFields(fields: Fr[] | FieldReader) {
32
40
  const reader = FieldReader.asReader(fields);
33
41
  // Below line gives error 'Type instantiation is excessively deep and possibly infinite. ts(2589)'
@@ -1,2 +1,2 @@
1
1
  export * from './encrypted_log_payload.js';
2
- export * from './l1_note_payload.js';
2
+ export * from './shared_secret_derivation.js';
@@ -1,4 +1,4 @@
1
- import { PRIVATE_LOG_SIZE_IN_FIELDS } from '@aztec/constants';
1
+ import { PRIVATE_LOG_SIZE_IN_FIELDS, PUBLIC_LOG_DATA_SIZE_IN_FIELDS } from '@aztec/constants';
2
2
  import { makeTuple } from '@aztec/foundation/array';
3
3
  import { Fr } from '@aztec/foundation/fields';
4
4
  import { schemas } from '@aztec/foundation/schemas';
@@ -38,8 +38,8 @@ export class PrivateLog {
38
38
  return new PrivateLog(reader.readArray(PRIVATE_LOG_SIZE_IN_FIELDS, Fr));
39
39
  }
40
40
 
41
- static random() {
42
- return new PrivateLog(makeTuple(PRIVATE_LOG_SIZE_IN_FIELDS, Fr.random));
41
+ static random(tag = Fr.random()) {
42
+ return PrivateLog.fromFields([tag, ...Array.from({ length: PRIVATE_LOG_SIZE_IN_FIELDS - 1 }, () => Fr.random())]);
43
43
  }
44
44
 
45
45
  getEmittedLength() {
@@ -54,6 +54,12 @@ export class PrivateLog {
54
54
  }
55
55
 
56
56
  static get schema() {
57
+ if (PUBLIC_LOG_DATA_SIZE_IN_FIELDS + 1 == PRIVATE_LOG_SIZE_IN_FIELDS) {
58
+ throw new Error(
59
+ 'Constants got updated and schema for PublicLog matches that of PrivateLog. This needs to be updated now as Zod is no longer able to differentiate the 2 in TxScopedL2Log.',
60
+ );
61
+ }
62
+
57
63
  return z
58
64
  .object({
59
65
  fields: z.array(schemas.Fr),
@@ -61,6 +67,10 @@ export class PrivateLog {
61
67
  .transform(({ fields }) => PrivateLog.fromFields(fields));
62
68
  }
63
69
 
70
+ equals(other: PrivateLog) {
71
+ return this.fields.every((field, i) => field.equals(other.fields[i]));
72
+ }
73
+
64
74
  [inspect.custom](): string {
65
75
  return `PrivateLog {
66
76
  fields: [${this.fields.map(x => inspect(x)).join(', ')}],
@@ -1,4 +1,8 @@
1
- import { PUBLIC_LOG_DATA_SIZE_IN_FIELDS, PUBLIC_LOG_SIZE_IN_FIELDS } from '@aztec/constants';
1
+ import {
2
+ PRIVATE_LOG_SIZE_IN_FIELDS,
3
+ PUBLIC_LOG_DATA_SIZE_IN_FIELDS,
4
+ PUBLIC_LOG_SIZE_IN_FIELDS,
5
+ } from '@aztec/constants';
2
6
  import { type FieldsOf, makeTuple } from '@aztec/foundation/array';
3
7
  import { Fr } from '@aztec/foundation/fields';
4
8
  import { type ZodFor, schemas } from '@aztec/foundation/schemas';
@@ -78,6 +82,12 @@ export class PublicLog {
78
82
  }
79
83
 
80
84
  static get schema(): ZodFor<PublicLog> {
85
+ if (PUBLIC_LOG_DATA_SIZE_IN_FIELDS + 1 == PRIVATE_LOG_SIZE_IN_FIELDS) {
86
+ throw new Error(
87
+ 'Constants got updated and schema for PrivateLog matches that of PublicLog. This needs to be updated now as Zod is no longer able to differentiate the 2 in TxScopedL2Log.',
88
+ );
89
+ }
90
+
81
91
  return z
82
92
  .object({
83
93
  contractAddress: AztecAddress.schema,
@@ -1,10 +1,10 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
1
  import { BufferReader, boolToBuffer, numToUInt32BE } from '@aztec/foundation/serialize';
3
2
 
4
3
  import { z } from 'zod';
5
4
 
6
- import { schemas } from '../schemas/schemas.js';
7
5
  import { TxHash } from '../tx/tx_hash.js';
6
+ import { PrivateLog } from './private_log.js';
7
+ import { PublicLog } from './public_log.js';
8
8
 
9
9
  export class TxScopedL2Log {
10
10
  constructor(
@@ -22,53 +22,55 @@ export class TxScopedL2Log {
22
22
  */
23
23
  public blockNumber: number,
24
24
  /*
25
- * Indicates if the log comes from the public logs stream (partial note)
25
+ * The log data as either a PrivateLog or PublicLog
26
26
  */
27
- public isFromPublic: boolean,
28
- /*
29
- * The log data
30
- */
31
- public logData: Buffer,
27
+ public log: PrivateLog | PublicLog,
32
28
  ) {}
33
29
 
30
+ get isFromPublic() {
31
+ return this.log instanceof PublicLog;
32
+ }
33
+
34
34
  static get schema() {
35
35
  return z
36
36
  .object({
37
37
  txHash: TxHash.schema,
38
38
  dataStartIndexForTx: z.number(),
39
39
  blockNumber: z.number(),
40
- isFromPublic: z.boolean(),
41
- logData: schemas.Buffer,
40
+ log: z.union([PrivateLog.schema, PublicLog.schema]),
42
41
  })
43
42
  .transform(
44
- ({ txHash, dataStartIndexForTx, blockNumber, isFromPublic, logData }) =>
45
- new TxScopedL2Log(txHash, dataStartIndexForTx, blockNumber, isFromPublic, logData),
43
+ ({ txHash, dataStartIndexForTx, blockNumber, log }) =>
44
+ new TxScopedL2Log(txHash, dataStartIndexForTx, blockNumber, log),
46
45
  );
47
46
  }
48
47
 
49
48
  toBuffer() {
49
+ const isFromPublic = this.log instanceof PublicLog;
50
50
  return Buffer.concat([
51
51
  this.txHash.toBuffer(),
52
52
  numToUInt32BE(this.dataStartIndexForTx),
53
53
  numToUInt32BE(this.blockNumber),
54
- boolToBuffer(this.isFromPublic),
55
- this.logData,
54
+ boolToBuffer(isFromPublic),
55
+ this.log.toBuffer(),
56
56
  ]);
57
57
  }
58
58
 
59
59
  static fromBuffer(buffer: Buffer) {
60
60
  const reader = BufferReader.asReader(buffer);
61
- return new TxScopedL2Log(
62
- reader.readObject(TxHash),
63
- reader.readNumber(),
64
- reader.readNumber(),
65
- reader.readBoolean(),
66
- reader.readToEnd(),
67
- );
61
+ const txHash = reader.readObject(TxHash);
62
+ const dataStartIndexForTx = reader.readNumber();
63
+ const blockNumber = reader.readNumber();
64
+ const isFromPublic = reader.readBoolean();
65
+ const log = isFromPublic ? PublicLog.fromBuffer(reader) : PrivateLog.fromBuffer(reader);
66
+
67
+ return new TxScopedL2Log(txHash, dataStartIndexForTx, blockNumber, log);
68
68
  }
69
69
 
70
- static random() {
71
- return new TxScopedL2Log(TxHash.random(), 1, 1, false, Fr.random().toBuffer());
70
+ static async random() {
71
+ const isFromPublic = Math.random() < 0.5;
72
+ const log = isFromPublic ? await PublicLog.random() : PrivateLog.random();
73
+ return new TxScopedL2Log(TxHash.random(), 1, 1, log);
72
74
  }
73
75
 
74
76
  equals(other: TxScopedL2Log) {
@@ -76,8 +78,9 @@ export class TxScopedL2Log {
76
78
  this.txHash.equals(other.txHash) &&
77
79
  this.dataStartIndexForTx === other.dataStartIndexForTx &&
78
80
  this.blockNumber === other.blockNumber &&
79
- this.isFromPublic === other.isFromPublic &&
80
- this.logData.equals(other.logData)
81
+ ((this.log instanceof PublicLog && other.log instanceof PublicLog) ||
82
+ (this.log instanceof PrivateLog && other.log instanceof PrivateLog)) &&
83
+ this.log.equals(other.log as any)
81
84
  );
82
85
  }
83
86
  }