@aztec/stdlib 0.0.1-commit.9b94fc1 → 0.0.1-commit.d3ec352c

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 (160) hide show
  1. package/dest/avm/avm.d.ts +187 -24
  2. package/dest/avm/avm.d.ts.map +1 -1
  3. package/dest/avm/avm.js +174 -20
  4. package/dest/avm/avm_circuit_public_inputs.d.ts +5 -3
  5. package/dest/avm/avm_circuit_public_inputs.d.ts.map +1 -1
  6. package/dest/avm/avm_proving_request.d.ts +9 -5
  7. package/dest/avm/avm_proving_request.d.ts.map +1 -1
  8. package/dest/block/block_parameter.d.ts +5 -0
  9. package/dest/block/block_parameter.d.ts.map +1 -0
  10. package/dest/block/block_parameter.js +6 -0
  11. package/dest/block/in_block.d.ts +12 -9
  12. package/dest/block/in_block.d.ts.map +1 -1
  13. package/dest/block/in_block.js +3 -3
  14. package/dest/block/index.d.ts +1 -1
  15. package/dest/block/index.js +1 -1
  16. package/dest/block/l2_block.d.ts +5 -5
  17. package/dest/block/l2_block.d.ts.map +1 -1
  18. package/dest/block/l2_block.js +3 -2
  19. package/dest/block/l2_block_code_to_purge.js +3 -3
  20. package/dest/block/l2_block_header.d.ts +3 -3
  21. package/dest/block/l2_block_header.d.ts.map +1 -1
  22. package/dest/block/l2_block_info.d.ts +15 -10
  23. package/dest/block/l2_block_info.d.ts.map +1 -1
  24. package/dest/block/l2_block_info.js +7 -6
  25. package/dest/block/l2_block_new.d.ts +6 -4
  26. package/dest/block/l2_block_new.d.ts.map +1 -1
  27. package/dest/block/l2_block_new.js +4 -1
  28. package/dest/block/l2_block_source.d.ts +63 -97
  29. package/dest/block/l2_block_source.d.ts.map +1 -1
  30. package/dest/block/l2_block_source.js +5 -11
  31. package/dest/block/l2_block_stream/l2_block_stream.d.ts +1 -1
  32. package/dest/block/l2_block_stream/l2_block_stream.d.ts.map +1 -1
  33. package/dest/block/l2_block_stream/l2_block_stream.js +4 -3
  34. package/dest/block/l2_block_stream/l2_tips_memory_store.d.ts +3 -2
  35. package/dest/block/l2_block_stream/l2_tips_memory_store.d.ts.map +1 -1
  36. package/dest/block/l2_block_stream/l2_tips_memory_store.js +4 -2
  37. package/dest/block/test/l2_tips_store_test_suite.d.ts +1 -1
  38. package/dest/block/test/l2_tips_store_test_suite.d.ts.map +1 -1
  39. package/dest/block/test/l2_tips_store_test_suite.js +6 -4
  40. package/dest/checkpoint/checkpoint.d.ts +14 -11
  41. package/dest/checkpoint/checkpoint.d.ts.map +1 -1
  42. package/dest/checkpoint/checkpoint.js +5 -5
  43. package/dest/checkpoint/published_checkpoint.d.ts +5 -3
  44. package/dest/checkpoint/published_checkpoint.d.ts.map +1 -1
  45. package/dest/contract/interfaces/contract_data_source.d.ts +3 -2
  46. package/dest/contract/interfaces/contract_data_source.d.ts.map +1 -1
  47. package/dest/interfaces/archiver.d.ts +1 -1
  48. package/dest/interfaces/archiver.d.ts.map +1 -1
  49. package/dest/interfaces/archiver.js +15 -9
  50. package/dest/interfaces/aztec-node.d.ts +29 -24
  51. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  52. package/dest/interfaces/aztec-node.js +25 -23
  53. package/dest/interfaces/block-builder.d.ts +3 -2
  54. package/dest/interfaces/block-builder.d.ts.map +1 -1
  55. package/dest/interfaces/epoch-prover.d.ts +4 -4
  56. package/dest/interfaces/epoch-prover.d.ts.map +1 -1
  57. package/dest/interfaces/get_logs_response.d.ts +5 -3
  58. package/dest/interfaces/get_logs_response.d.ts.map +1 -1
  59. package/dest/interfaces/l2_logs_source.d.ts +4 -3
  60. package/dest/interfaces/l2_logs_source.d.ts.map +1 -1
  61. package/dest/interfaces/merkle_tree_operations.d.ts +3 -2
  62. package/dest/interfaces/merkle_tree_operations.d.ts.map +1 -1
  63. package/dest/interfaces/proving-job.d.ts +9 -5
  64. package/dest/interfaces/proving-job.d.ts.map +1 -1
  65. package/dest/interfaces/tx_provider.d.ts +3 -3
  66. package/dest/interfaces/tx_provider.d.ts.map +1 -1
  67. package/dest/interfaces/world_state.d.ts +9 -26
  68. package/dest/interfaces/world_state.d.ts.map +1 -1
  69. package/dest/interfaces/world_state.js +4 -3
  70. package/dest/logs/extended_public_log.d.ts +5 -3
  71. package/dest/logs/extended_public_log.d.ts.map +1 -1
  72. package/dest/logs/log_id.d.ts +8 -5
  73. package/dest/logs/log_id.d.ts.map +1 -1
  74. package/dest/logs/log_id.js +5 -4
  75. package/dest/logs/tx_scoped_l2_log.d.ts +10 -7
  76. package/dest/logs/tx_scoped_l2_log.d.ts.map +1 -1
  77. package/dest/logs/tx_scoped_l2_log.js +4 -3
  78. package/dest/messaging/l1_to_l2_message_source.d.ts +10 -3
  79. package/dest/messaging/l1_to_l2_message_source.d.ts.map +1 -1
  80. package/dest/messaging/l2_to_l1_membership.d.ts +4 -3
  81. package/dest/messaging/l2_to_l1_membership.d.ts.map +1 -1
  82. package/dest/note/note_dao.d.ts +9 -5
  83. package/dest/note/note_dao.d.ts.map +1 -1
  84. package/dest/note/note_dao.js +12 -7
  85. package/dest/note/notes_filter.d.ts +3 -1
  86. package/dest/note/notes_filter.d.ts.map +1 -1
  87. package/dest/note/notes_filter.js +1 -0
  88. package/dest/rollup/checkpoint_header.d.ts +2 -2
  89. package/dest/rollup/checkpoint_header.d.ts.map +1 -1
  90. package/dest/rollup/checkpoint_header.js +1 -1
  91. package/dest/tests/factories.js +5 -5
  92. package/dest/tests/mocks.d.ts +1 -1
  93. package/dest/tests/mocks.d.ts.map +1 -1
  94. package/dest/tests/mocks.js +2 -1
  95. package/dest/tx/block_header.d.ts +4 -4
  96. package/dest/tx/block_header.d.ts.map +1 -1
  97. package/dest/tx/content_commitment.d.ts +3 -2
  98. package/dest/tx/content_commitment.d.ts.map +1 -1
  99. package/dest/tx/content_commitment.js +10 -2
  100. package/dest/tx/global_variables.d.ts +13 -11
  101. package/dest/tx/global_variables.d.ts.map +1 -1
  102. package/dest/tx/global_variables.js +6 -6
  103. package/dest/tx/indexed_tx_effect.d.ts +8 -5
  104. package/dest/tx/indexed_tx_effect.d.ts.map +1 -1
  105. package/dest/tx/indexed_tx_effect.js +2 -1
  106. package/dest/tx/private_execution_result.d.ts +3 -3
  107. package/dest/tx/private_execution_result.d.ts.map +1 -1
  108. package/dest/tx/processed_tx.d.ts +2 -2
  109. package/dest/tx/processed_tx.d.ts.map +1 -1
  110. package/dest/tx/processed_tx.js +4 -1
  111. package/dest/tx/tx.d.ts +2 -2
  112. package/dest/tx/tx.d.ts.map +1 -1
  113. package/dest/tx/tx.js +1 -0
  114. package/dest/tx/tx_receipt.d.ts +4 -3
  115. package/dest/tx/tx_receipt.d.ts.map +1 -1
  116. package/dest/tx/tx_receipt.js +2 -1
  117. package/package.json +9 -9
  118. package/src/avm/avm.ts +238 -23
  119. package/src/block/block_parameter.ts +8 -0
  120. package/src/block/in_block.ts +13 -9
  121. package/src/block/index.ts +1 -1
  122. package/src/block/l2_block.ts +10 -5
  123. package/src/block/l2_block_code_to_purge.ts +3 -3
  124. package/src/block/l2_block_info.ts +10 -9
  125. package/src/block/l2_block_new.ts +8 -3
  126. package/src/block/l2_block_source.ts +40 -22
  127. package/src/block/l2_block_stream/l2_block_stream.ts +10 -5
  128. package/src/block/l2_block_stream/l2_tips_memory_store.ts +5 -2
  129. package/src/block/test/l2_tips_store_test_suite.ts +8 -3
  130. package/src/checkpoint/checkpoint.ts +7 -7
  131. package/src/contract/interfaces/contract_data_source.ts +2 -1
  132. package/src/interfaces/archiver.ts +18 -9
  133. package/src/interfaces/aztec-node.ts +61 -46
  134. package/src/interfaces/block-builder.ts +2 -1
  135. package/src/interfaces/epoch-prover.ts +3 -3
  136. package/src/interfaces/l2_logs_source.ts +3 -2
  137. package/src/interfaces/merkle_tree_operations.ts +2 -1
  138. package/src/interfaces/tx_provider.ts +2 -2
  139. package/src/interfaces/world_state.ts +12 -11
  140. package/src/logs/log_id.ts +6 -5
  141. package/src/logs/tx_scoped_l2_log.ts +5 -4
  142. package/src/messaging/l1_to_l2_message_source.ts +10 -2
  143. package/src/messaging/l2_to_l1_membership.ts +3 -2
  144. package/src/note/note_dao.ts +15 -5
  145. package/src/note/notes_filter.ts +3 -0
  146. package/src/rollup/checkpoint_header.ts +4 -2
  147. package/src/tests/factories.ts +4 -4
  148. package/src/tests/mocks.ts +2 -1
  149. package/src/tx/block_header.ts +2 -2
  150. package/src/tx/content_commitment.ts +11 -2
  151. package/src/tx/global_variables.ts +8 -8
  152. package/src/tx/indexed_tx_effect.ts +4 -3
  153. package/src/tx/private_execution_result.ts +2 -2
  154. package/src/tx/processed_tx.ts +8 -2
  155. package/src/tx/tx.ts +2 -1
  156. package/src/tx/tx_receipt.ts +3 -2
  157. package/dest/block/l2_block_number.d.ts +0 -5
  158. package/dest/block/l2_block_number.d.ts.map +0 -1
  159. package/dest/block/l2_block_number.js +0 -6
  160. package/src/block/l2_block_number.ts +0 -8
@@ -1,10 +1,18 @@
1
- import type { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
1
+ import {
2
+ BlockNumber,
3
+ BlockNumberSchema,
4
+ type CheckpointNumber,
5
+ type EpochNumber,
6
+ type SlotNumber,
7
+ } from '@aztec/foundation/branded-types';
2
8
  import type { EthAddress } from '@aztec/foundation/eth-address';
3
9
  import type { Fr } from '@aztec/foundation/fields';
4
10
  import type { TypedEventEmitter } from '@aztec/foundation/types';
5
11
 
6
12
  import { z } from 'zod';
7
13
 
14
+ import type { Checkpoint } from '../checkpoint/checkpoint.js';
15
+ import type { PublishedCheckpoint } from '../checkpoint/published_checkpoint.js';
8
16
  import type { L1RollupConstants } from '../epoch-helpers/index.js';
9
17
  import type { BlockHeader } from '../tx/block_header.js';
10
18
  import type { IndexedTxEffect } from '../tx/indexed_tx_effect.js';
@@ -34,27 +42,27 @@ export interface L2BlockSource {
34
42
  * Gets the number of the latest L2 block processed by the block source implementation.
35
43
  * @returns The number of the latest L2 block processed by the block source implementation.
36
44
  */
37
- getBlockNumber(): Promise<number>;
45
+ getBlockNumber(): Promise<BlockNumber>;
38
46
 
39
47
  /**
40
48
  * Gets the number of the latest L2 block proven seen by the block source implementation.
41
49
  * @returns The number of the latest L2 block proven seen by the block source implementation.
42
50
  */
43
- getProvenBlockNumber(): Promise<number>;
51
+ getProvenBlockNumber(): Promise<BlockNumber>;
44
52
 
45
53
  /**
46
54
  * Gets an l2 block. If a negative number is passed, the block returned is the most recent.
47
55
  * @param number - The block number to return (inclusive).
48
56
  * @returns The requested L2 block.
49
57
  */
50
- getBlock(number: number): Promise<L2Block | undefined>;
58
+ getBlock(number: BlockNumber): Promise<L2Block | undefined>;
51
59
 
52
60
  /**
53
61
  * Gets an l2 block header.
54
62
  * @param number - The block number to return or 'latest' for the most recent one.
55
63
  * @returns The requested L2 block header.
56
64
  */
57
- getBlockHeader(number: number | 'latest'): Promise<BlockHeader | undefined>;
65
+ getBlockHeader(number: BlockNumber | 'latest'): Promise<BlockHeader | undefined>;
58
66
 
59
67
  /**
60
68
  * Gets up to `limit` amount of L2 blocks starting from `from`.
@@ -63,10 +71,20 @@ export interface L2BlockSource {
63
71
  * @param proven - If true, only return blocks that have been proven.
64
72
  * @returns The requested L2 blocks.
65
73
  */
66
- getBlocks(from: number, limit: number, proven?: boolean): Promise<L2Block[]>;
74
+ getBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<L2Block[]>;
75
+
76
+ getPublishedCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]>;
77
+
78
+ /**
79
+ * Gets a checkpoint by the archive root, which should be the root of the archive tree after the requested checkpoint
80
+ * is applied.
81
+ * @param archive - The new archive root of the checkpoint.
82
+ * @returns The requested checkpoint (or undefined if not found).
83
+ */
84
+ getCheckpointByArchive(archive: Fr): Promise<Checkpoint | undefined>;
67
85
 
68
86
  /** Equivalent to getBlocks but includes publish data. */
69
- getPublishedBlocks(from: number, limit: number, proven?: boolean): Promise<PublishedL2Block[]>;
87
+ getPublishedBlocks(from: BlockNumber, limit: number, proven?: boolean): Promise<PublishedL2Block[]>;
70
88
 
71
89
  /**
72
90
  * Gets a published block by its hash.
@@ -120,6 +138,13 @@ export interface L2BlockSource {
120
138
  */
121
139
  getL2EpochNumber(): Promise<EpochNumber | undefined>;
122
140
 
141
+ /**
142
+ * Returns all checkpoints for a given epoch.
143
+ * @dev Use this method only with recent epochs, since it walks the checkpoint list backwards.
144
+ * @param epochNumber - The epoch number to return checkpoints for.
145
+ */
146
+ getCheckpointsForEpoch(epochNumber: EpochNumber): Promise<Checkpoint[]>;
147
+
123
148
  /**
124
149
  * Returns all blocks for a given epoch.
125
150
  * @dev Use this method only with recent epochs, since it walks the block list backwards.
@@ -195,33 +220,26 @@ export type L2BlockTag = 'latest' | 'proven' | 'finalized';
195
220
  export type L2Tips = Record<L2BlockTag, L2BlockId>;
196
221
 
197
222
  /** Identifies a block by number and hash. */
198
- export type L2BlockId = z.infer<typeof L2BlockIdSchema>;
223
+ export type L2BlockId = { number: BlockNumber; hash: string };
199
224
 
200
225
  /** Creates an L2 block id */
201
- export function makeL2BlockId(number: number, hash?: string): L2BlockId {
226
+ export function makeL2BlockId(number: BlockNumber, hash?: string): L2BlockId {
202
227
  if (number !== 0 && !hash) {
203
228
  throw new Error(`Hash is required for non-genesis blocks (got block number ${number})`);
204
229
  }
205
230
  return { number, hash: hash! };
206
231
  }
207
232
 
208
- // TODO(palla/schemas): This package should know what is the block hash of the genesis block 0.
209
- const L2BlockIdSchema = z.union([
210
- z.object({
211
- number: z.literal(0),
212
- hash: z.undefined(),
213
- }),
214
- z.object({
215
- number: z.number(),
216
- hash: z.string(),
217
- }),
218
- ]);
233
+ const L2BlockIdSchema = z.object({
234
+ number: BlockNumberSchema,
235
+ hash: z.string(),
236
+ });
219
237
 
220
238
  export const L2TipsSchema = z.object({
221
239
  latest: L2BlockIdSchema,
222
240
  proven: L2BlockIdSchema,
223
241
  finalized: L2BlockIdSchema,
224
- }) satisfies z.ZodType<L2Tips>;
242
+ });
225
243
 
226
244
  export enum L2BlockSourceEvents {
227
245
  L2PruneDetected = 'l2PruneDetected',
@@ -231,7 +249,7 @@ export enum L2BlockSourceEvents {
231
249
 
232
250
  export type L2BlockProvenEvent = {
233
251
  type: 'l2BlockProven';
234
- blockNumber: bigint;
252
+ blockNumber: BlockNumber;
235
253
  slotNumber: SlotNumber;
236
254
  epochNumber: EpochNumber;
237
255
  };
@@ -1,3 +1,4 @@
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
1
2
  import { AbortError } from '@aztec/foundation/error';
2
3
  import { createLogger } from '@aztec/foundation/log';
3
4
  import { RunningPromise } from '@aztec/foundation/running-promise';
@@ -74,7 +75,7 @@ export class L2BlockStream {
74
75
  }
75
76
 
76
77
  if (latestBlockNumber < localTips.latest.number) {
77
- latestBlockNumber = Math.min(latestBlockNumber, sourceTips.latest.number); // see #13471
78
+ latestBlockNumber = BlockNumber(Math.min(latestBlockNumber, sourceTips.latest.number)); // see #13471
78
79
  const hash = sourceCache.get(latestBlockNumber) ?? (await this.getBlockHashFromSource(latestBlockNumber));
79
80
  if (latestBlockNumber !== 0 && !hash) {
80
81
  throw new Error(`Block hash not found in block source for block number ${latestBlockNumber}`);
@@ -85,7 +86,7 @@ export class L2BlockStream {
85
86
 
86
87
  // If we are just starting, use the starting block number from the options.
87
88
  if (latestBlockNumber === 0 && this.opts.startingBlock !== undefined) {
88
- latestBlockNumber = Math.max(this.opts.startingBlock - 1, 0);
89
+ latestBlockNumber = BlockNumber(Math.max(this.opts.startingBlock - 1, 0));
89
90
  }
90
91
 
91
92
  // Only log this entry once (for sanity)
@@ -108,7 +109,11 @@ export class L2BlockStream {
108
109
  while (nextBlockNumber <= sourceTips.latest.number) {
109
110
  const limit = Math.min(this.opts.batchSize ?? 50, sourceTips.latest.number - nextBlockNumber + 1);
110
111
  this.log.trace(`Requesting blocks from ${nextBlockNumber} limit ${limit} proven=${this.opts.proven}`);
111
- const blocks = await this.l2BlockSource.getPublishedBlocks(nextBlockNumber, limit, this.opts.proven);
112
+ const blocks = await this.l2BlockSource.getPublishedBlocks(
113
+ BlockNumber(nextBlockNumber),
114
+ limit,
115
+ this.opts.proven,
116
+ );
112
117
  if (blocks.length === 0) {
113
118
  break;
114
119
  }
@@ -139,7 +144,7 @@ export class L2BlockStream {
139
144
  * @param blockNumber - The block number to test.
140
145
  * @param args - A cache of data already requested from source, to avoid re-requesting it.
141
146
  */
142
- private async areBlockHashesEqualAt(blockNumber: number, args: { sourceCache: BlockHashCache }) {
147
+ private async areBlockHashesEqualAt(blockNumber: BlockNumber, args: { sourceCache: BlockHashCache }) {
143
148
  if (blockNumber === 0) {
144
149
  return true;
145
150
  }
@@ -163,7 +168,7 @@ export class L2BlockStream {
163
168
  return localBlockHash === sourceBlockHash;
164
169
  }
165
170
 
166
- private getBlockHashFromSource(blockNumber: number) {
171
+ private getBlockHashFromSource(blockNumber: BlockNumber) {
167
172
  return this.l2BlockSource
168
173
  .getBlockHeader(blockNumber)
169
174
  .then(h => h?.hash())
@@ -1,3 +1,6 @@
1
+ import { GENESIS_BLOCK_HEADER_HASH } from '@aztec/constants';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
3
+
1
4
  import type { L2Block } from '../l2_block.js';
2
5
  import type { L2BlockId, L2BlockTag, L2Tips } from '../l2_block_source.js';
3
6
  import type { L2BlockStreamEvent, L2BlockStreamEventHandler, L2BlockStreamLocalDataProvider } from './interfaces.js';
@@ -7,7 +10,7 @@ import type { L2BlockStreamEvent, L2BlockStreamEventHandler, L2BlockStreamLocalD
7
10
  * @dev tests in kv-store/src/stores/l2_tips_memory_store.test.ts
8
11
  */
9
12
  export class L2TipsMemoryStore implements L2BlockStreamEventHandler, L2BlockStreamLocalDataProvider {
10
- protected readonly l2TipsStore: Map<L2BlockTag, number> = new Map();
13
+ protected readonly l2TipsStore: Map<L2BlockTag, BlockNumber> = new Map();
11
14
  protected readonly l2BlockHashesStore: Map<number, string> = new Map();
12
15
 
13
16
  public getL2BlockHash(number: number): Promise<string | undefined> {
@@ -25,7 +28,7 @@ export class L2TipsMemoryStore implements L2BlockStreamEventHandler, L2BlockStre
25
28
  private getL2Tip(tag: L2BlockTag): L2BlockId {
26
29
  const blockNumber = this.l2TipsStore.get(tag);
27
30
  if (blockNumber === undefined || blockNumber === 0) {
28
- return { number: 0, hash: undefined };
31
+ return { number: BlockNumber.ZERO, hash: GENESIS_BLOCK_HEADER_HASH.toString() };
29
32
  }
30
33
  const blockHash = this.l2BlockHashesStore.get(blockNumber);
31
34
  if (!blockHash) {
@@ -1,3 +1,5 @@
1
+ import { GENESIS_BLOCK_HEADER_HASH } from '@aztec/constants';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
1
3
  import { times } from '@aztec/foundation/collection';
2
4
  import { Fr } from '@aztec/foundation/fields';
3
5
  import { type L2Block, type L2BlockId, PublishedL2Block } from '@aztec/stdlib/block';
@@ -15,17 +17,20 @@ export function testL2TipsStore(makeTipsStore: () => Promise<L2TipsStore>) {
15
17
 
16
18
  const makeBlock = (number: number): PublishedL2Block =>
17
19
  PublishedL2Block.fromFields({
18
- block: { number, hash: () => Promise.resolve(new Fr(number)) } as L2Block,
20
+ block: { number: BlockNumber(number), hash: () => Promise.resolve(new Fr(number)) } as L2Block,
19
21
  l1: { blockNumber: BigInt(number), blockHash: `0x${number}`, timestamp: BigInt(number) },
20
22
  attestations: [],
21
23
  });
22
24
 
23
25
  const makeBlockId = (number: number): L2BlockId => ({
24
- number,
26
+ number: BlockNumber(number),
25
27
  hash: new Fr(number).toString(),
26
28
  });
27
29
 
28
- const makeTip = (number: number) => ({ number, hash: number === 0 ? undefined : new Fr(number).toString() });
30
+ const makeTip = (number: number): L2BlockId => ({
31
+ number: BlockNumber(number),
32
+ hash: number === 0 ? GENESIS_BLOCK_HEADER_HASH.toString() : new Fr(number).toString(),
33
+ });
29
34
 
30
35
  const makeTips = (latest: number, proven: number, finalized: number) => ({
31
36
  latest: makeTip(latest),
@@ -1,6 +1,6 @@
1
1
  import { encodeCheckpointBlobDataFromBlocks } from '@aztec/blob-lib/encoding';
2
+ import { BlockNumber, CheckpointNumber, CheckpointNumberSchema } from '@aztec/foundation/branded-types';
2
3
  import { Fr } from '@aztec/foundation/fields';
3
- import { schemas } from '@aztec/foundation/schemas';
4
4
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
5
5
  import type { FieldsOf } from '@aztec/foundation/types';
6
6
 
@@ -19,7 +19,7 @@ export class Checkpoint {
19
19
  /** L2 blocks in the checkpoint. */
20
20
  public blocks: L2BlockNew[],
21
21
  /** Number of the checkpoint. */
22
- public number: number,
22
+ public number: CheckpointNumber,
23
23
  ) {}
24
24
 
25
25
  static get schema() {
@@ -28,7 +28,7 @@ export class Checkpoint {
28
28
  archive: AppendOnlyTreeSnapshot.schema,
29
29
  header: CheckpointHeader.schema,
30
30
  blocks: z.array(L2BlockNew.schema),
31
- number: schemas.UInt32,
31
+ number: CheckpointNumberSchema,
32
32
  })
33
33
  .transform(({ archive, header, blocks, number }) => new Checkpoint(archive, header, blocks, number));
34
34
  }
@@ -47,7 +47,7 @@ export class Checkpoint {
47
47
  reader.readObject(AppendOnlyTreeSnapshot),
48
48
  reader.readObject(CheckpointHeader),
49
49
  reader.readVector(L2BlockNew),
50
- reader.readNumber(),
50
+ CheckpointNumber(reader.readNumber()),
51
51
  );
52
52
  }
53
53
 
@@ -69,18 +69,18 @@ export class Checkpoint {
69
69
  }
70
70
 
71
71
  static async random(
72
- checkpointNumber = 1,
72
+ checkpointNumber = CheckpointNumber(1),
73
73
  {
74
74
  numBlocks = 1,
75
75
  startBlockNumber = 1,
76
76
  ...options
77
- }: { numBlocks?: number; startBlockNumber?: number } & Partial<FieldsOf<CheckpointHeader>> &
77
+ }: { numBlocks?: number; startBlockNumber?: number } & Partial<Parameters<typeof CheckpointHeader.random>[0]> &
78
78
  Partial<Parameters<typeof L2BlockNew.random>[1]> = {},
79
79
  ) {
80
80
  const header = CheckpointHeader.random(options);
81
81
 
82
82
  const blocks = await Promise.all(
83
- Array.from({ length: numBlocks }, (_, i) => L2BlockNew.random(startBlockNumber + i, options)),
83
+ Array.from({ length: numBlocks }, (_, i) => L2BlockNew.random(BlockNumber(startBlockNumber + i), options)),
84
84
  );
85
85
 
86
86
  return new Checkpoint(AppendOnlyTreeSnapshot.random(), header, blocks, checkpointNumber);
@@ -1,3 +1,4 @@
1
+ import type { BlockNumber } from '@aztec/foundation/branded-types';
1
2
  import type { Fr } from '@aztec/foundation/fields';
2
3
 
3
4
  import type { FunctionSelector } from '../../abi/index.js';
@@ -11,7 +12,7 @@ export interface ContractDataSource {
11
12
  * Gets the number of the latest L2 block processed by the implementation.
12
13
  * @returns The number of the latest L2 block processed by the implementation.
13
14
  */
14
- getBlockNumber(): Promise<number>;
15
+ getBlockNumber(): Promise<BlockNumber>;
15
16
 
16
17
  /**
17
18
  * Returns the contract class for a given contract class id, or undefined if not found.
@@ -1,5 +1,5 @@
1
1
  import type { L1ContractAddresses } from '@aztec/ethereum';
2
- import { EpochNumberSchema } from '@aztec/foundation/branded-types';
2
+ import { BlockNumberSchema, CheckpointNumberSchema, EpochNumberSchema } from '@aztec/foundation/branded-types';
3
3
  import type { ApiSchemaFor } from '@aztec/foundation/schemas';
4
4
 
5
5
  import { z } from 'zod';
@@ -8,6 +8,8 @@ import { L2Block } from '../block/l2_block.js';
8
8
  import { type L2BlockSource, L2TipsSchema } from '../block/l2_block_source.js';
9
9
  import { PublishedL2Block } from '../block/published_l2_block.js';
10
10
  import { ValidateBlockResultSchema } from '../block/validate_block_result.js';
11
+ import { Checkpoint } from '../checkpoint/checkpoint.js';
12
+ import { PublishedCheckpoint } from '../checkpoint/published_checkpoint.js';
11
13
  import {
12
14
  ContractClassPublicSchema,
13
15
  type ContractDataSource,
@@ -73,20 +75,25 @@ export type ArchiverApi = Omit<
73
75
  export const ArchiverApiSchema: ApiSchemaFor<ArchiverApi> = {
74
76
  getRollupAddress: z.function().args().returns(schemas.EthAddress),
75
77
  getRegistryAddress: z.function().args().returns(schemas.EthAddress),
76
- getBlockNumber: z.function().args().returns(schemas.Integer),
77
- getProvenBlockNumber: z.function().args().returns(schemas.Integer),
78
- getBlock: z.function().args(schemas.Integer).returns(L2Block.schema.optional()),
78
+ getBlockNumber: z.function().args().returns(BlockNumberSchema),
79
+ getProvenBlockNumber: z.function().args().returns(BlockNumberSchema),
80
+ getBlock: z.function().args(BlockNumberSchema).returns(L2Block.schema.optional()),
79
81
  getBlockHeader: z
80
82
  .function()
81
- .args(z.union([schemas.Integer, z.literal('latest')]))
83
+ .args(z.union([BlockNumberSchema, z.literal('latest')]))
82
84
  .returns(BlockHeader.schema.optional()),
83
85
  getBlocks: z
84
86
  .function()
85
- .args(schemas.Integer, schemas.Integer, optional(z.boolean()))
87
+ .args(BlockNumberSchema, schemas.Integer, optional(z.boolean()))
86
88
  .returns(z.array(L2Block.schema)),
89
+ getPublishedCheckpoints: z
90
+ .function()
91
+ .args(CheckpointNumberSchema, schemas.Integer)
92
+ .returns(z.array(PublishedCheckpoint.schema)),
93
+ getCheckpointByArchive: z.function().args(schemas.Fr).returns(Checkpoint.schema.optional()),
87
94
  getPublishedBlocks: z
88
95
  .function()
89
- .args(schemas.Integer, schemas.Integer, optional(z.boolean()))
96
+ .args(BlockNumberSchema, schemas.Integer, optional(z.boolean()))
90
97
  .returns(z.array(PublishedL2Block.schema)),
91
98
  getPublishedBlockByHash: z.function().args(schemas.Fr).returns(PublishedL2Block.schema.optional()),
92
99
  getPublishedBlockByArchive: z.function().args(schemas.Fr).returns(PublishedL2Block.schema.optional()),
@@ -96,11 +103,12 @@ export const ArchiverApiSchema: ApiSchemaFor<ArchiverApi> = {
96
103
  getSettledTxReceipt: z.function().args(TxHash.schema).returns(TxReceipt.schema.optional()),
97
104
  getL2SlotNumber: z.function().args().returns(schemas.SlotNumber.optional()),
98
105
  getL2EpochNumber: z.function().args().returns(EpochNumberSchema.optional()),
106
+ getCheckpointsForEpoch: z.function().args(EpochNumberSchema).returns(z.array(Checkpoint.schema)),
99
107
  getBlocksForEpoch: z.function().args(EpochNumberSchema).returns(z.array(L2Block.schema)),
100
108
  getBlockHeadersForEpoch: z.function().args(EpochNumberSchema).returns(z.array(BlockHeader.schema)),
101
109
  isEpochComplete: z.function().args(EpochNumberSchema).returns(z.boolean()),
102
110
  getL2Tips: z.function().args().returns(L2TipsSchema),
103
- getPrivateLogs: z.function().args(z.number(), z.number()).returns(z.array(PrivateLog.schema)),
111
+ getPrivateLogs: z.function().args(BlockNumberSchema, z.number()).returns(z.array(PrivateLog.schema)),
104
112
  getLogsByTags: z
105
113
  .function()
106
114
  .args(z.array(schemas.Fr))
@@ -115,7 +123,8 @@ export const ArchiverApiSchema: ApiSchemaFor<ArchiverApi> = {
115
123
  .returns(ContractInstanceWithAddressSchema.optional()),
116
124
  getContractClassIds: z.function().args().returns(z.array(schemas.Fr)),
117
125
  registerContractFunctionSignatures: z.function().args(z.array(z.string())).returns(z.void()),
118
- getL1ToL2Messages: z.function().args(schemas.Integer).returns(z.array(schemas.Fr)),
126
+ getL1ToL2MessagesForCheckpoint: z.function().args(CheckpointNumberSchema).returns(z.array(schemas.Fr)),
127
+ getL1ToL2Messages: z.function().args(BlockNumberSchema).returns(z.array(schemas.Fr)),
119
128
  getL1ToL2MessageIndex: z.function().args(schemas.Fr).returns(schemas.BigInt.optional()),
120
129
  getDebugFunctionName: z.function().args(schemas.AztecAddress, schemas.FunctionSelector).returns(optional(z.string())),
121
130
  getL1Constants: z.function().args().returns(L1RollupConstantsSchema),