@aztec/world-state 0.0.1-commit.b655e406 → 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 (50) hide show
  1. package/dest/index.d.ts +1 -1
  2. package/dest/instrumentation/instrumentation.d.ts +1 -1
  3. package/dest/instrumentation/instrumentation.d.ts.map +1 -1
  4. package/dest/native/bench_metrics.d.ts +1 -1
  5. package/dest/native/bench_metrics.d.ts.map +1 -1
  6. package/dest/native/fork_checkpoint.d.ts +1 -1
  7. package/dest/native/fork_checkpoint.d.ts.map +1 -1
  8. package/dest/native/index.d.ts +1 -1
  9. package/dest/native/merkle_trees_facade.d.ts +5 -4
  10. package/dest/native/merkle_trees_facade.d.ts.map +1 -1
  11. package/dest/native/merkle_trees_facade.js +4 -2
  12. package/dest/native/message.d.ts +11 -10
  13. package/dest/native/message.d.ts.map +1 -1
  14. package/dest/native/message.js +13 -12
  15. package/dest/native/native_world_state.d.ts +9 -8
  16. package/dest/native/native_world_state.d.ts.map +1 -1
  17. package/dest/native/native_world_state.js +11 -8
  18. package/dest/native/native_world_state_instance.d.ts +10 -1
  19. package/dest/native/native_world_state_instance.d.ts.map +1 -1
  20. package/dest/native/native_world_state_instance.js +21 -0
  21. package/dest/native/world_state_ops_queue.d.ts +1 -1
  22. package/dest/native/world_state_ops_queue.d.ts.map +1 -1
  23. package/dest/synchronizer/config.d.ts +1 -1
  24. package/dest/synchronizer/errors.d.ts +1 -1
  25. package/dest/synchronizer/errors.d.ts.map +1 -1
  26. package/dest/synchronizer/factory.d.ts +1 -1
  27. package/dest/synchronizer/index.d.ts +1 -1
  28. package/dest/synchronizer/server_world_state_synchronizer.d.ts +7 -25
  29. package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
  30. package/dest/synchronizer/server_world_state_synchronizer.js +35 -52
  31. package/dest/synchronizer/utils.d.ts +11 -0
  32. package/dest/synchronizer/utils.d.ts.map +1 -0
  33. package/dest/synchronizer/utils.js +59 -0
  34. package/dest/test/index.d.ts +1 -1
  35. package/dest/test/utils.d.ts +21 -8
  36. package/dest/test/utils.d.ts.map +1 -1
  37. package/dest/test/utils.js +51 -10
  38. package/dest/testing.d.ts +1 -1
  39. package/dest/world-state-db/index.d.ts +1 -1
  40. package/dest/world-state-db/merkle_tree_db.d.ts +9 -8
  41. package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
  42. package/package.json +13 -12
  43. package/src/native/merkle_trees_facade.ts +6 -5
  44. package/src/native/message.ts +22 -21
  45. package/src/native/native_world_state.ts +28 -17
  46. package/src/native/native_world_state_instance.ts +28 -0
  47. package/src/synchronizer/server_world_state_synchronizer.ts +58 -75
  48. package/src/synchronizer/utils.ts +83 -0
  49. package/src/test/utils.ts +66 -13
  50. package/src/world-state-db/merkle_tree_db.ts +12 -7
@@ -1,6 +1,7 @@
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
1
2
  import type { Fr } from '@aztec/foundation/fields';
2
3
  import type { IndexedTreeSnapshot, TreeSnapshot } from '@aztec/merkle-tree';
3
- import type { L2Block } from '@aztec/stdlib/block';
4
+ import type { L2BlockNew } from '@aztec/stdlib/block';
4
5
  import type { ForkMerkleTreeOperations, MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
5
6
  import type { MerkleTreeId } from '@aztec/stdlib/trees';
6
7
  import type { WorldStateStatusFull, WorldStateStatusSummary } from '../native/message.js';
@@ -33,10 +34,10 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
33
34
  * Handles a single L2 block (i.e. Inserts the new note hashes into the merkle tree).
34
35
  * @param block - The L2 block to handle.
35
36
  * @param l1ToL2Messages - The L1 to L2 messages for the block.
36
- * @param isFirstBlock - Whether the block is the first block in a checkpoint. Temporary hack to only insert l1 to l2
37
- * messages for the first block in a checkpoint. TODO(#17027) Remove this.
37
+ * @param isFirstBlock - Whether the block is the first block in a checkpoint. The messages are padded and inserted
38
+ * to the tree for the first block in a checkpoint.
38
39
  */
39
- handleL2BlockAndMessages(block: L2Block, l1ToL2Messages: Fr[], isFirstBlock?: boolean): Promise<WorldStateStatusFull>;
40
+ handleL2BlockAndMessages(block: L2BlockNew, l1ToL2Messages: Fr[], isFirstBlock: boolean): Promise<WorldStateStatusFull>;
40
41
  /**
41
42
  * Gets a handle that allows reading the latest committed state
42
43
  */
@@ -46,19 +47,19 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
46
47
  * @param toBlockNumber The block number of the new oldest historical block
47
48
  * @returns The new WorldStateStatus
48
49
  */
49
- removeHistoricalBlocks(toBlockNumber: bigint): Promise<WorldStateStatusFull>;
50
+ removeHistoricalBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
50
51
  /**
51
52
  * Removes all pending blocks down to but not including the given block number
52
53
  * @param toBlockNumber The block number of the new tip of the pending chain,
53
54
  * @returns The new WorldStateStatus
54
55
  */
55
- unwindBlocks(toBlockNumber: bigint): Promise<WorldStateStatusFull>;
56
+ unwindBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
56
57
  /**
57
58
  * Advances the finalized block number to be the number provided
58
59
  * @param toBlockNumber The block number that is now the tip of the finalized chain
59
60
  * @returns The new WorldStateStatus
60
61
  */
61
- setFinalized(toBlockNumber: bigint): Promise<WorldStateStatusSummary>;
62
+ setFinalized(toBlockNumber: BlockNumber): Promise<WorldStateStatusSummary>;
62
63
  /**
63
64
  * Gets the current status summary of the database.
64
65
  * @returns The current WorldStateStatus.
@@ -69,4 +70,4 @@ export interface MerkleTreeAdminDatabase extends ForkMerkleTreeOperations {
69
70
  /** Deletes the db. */
70
71
  clear(): Promise<void>;
71
72
  }
72
- //# sourceMappingURL=merkle_tree_db.d.ts.map
73
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVya2xlX3RyZWVfZGIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3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AY,CAAC,OAAO,CAAC,EAAE,YAAY,CAAC,EAAE,CAAC,CAAC;CAC1C,CAAC;AAEF,MAAM,WAAW,uBAAwB,SAAQ,wBAAwB;IACvE;;;;;;OAMG;IACH,wBAAwB,CACtB,KAAK,EAAE,UAAU,EACjB,cAAc,EAAE,EAAE,EAAE,EACpB,YAAY,EAAE,OAAO,GACpB,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAEjC;;OAEG;IACH,YAAY,IAAI,wBAAwB,CAAC;IAEzC;;;;OAIG;IACH,sBAAsB,CAAC,aAAa,EAAE,WAAW,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAElF;;;;OAIG;IACH,YAAY,CAAC,aAAa,EAAE,WAAW,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAExE;;;;OAIG;IACH,YAAY,CAAC,aAAa,EAAE,WAAW,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAE3E;;;OAGG;IACH,gBAAgB,IAAI,OAAO,CAAC,uBAAuB,CAAC,CAAC;IAErD,yBAAyB;IACzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB,sBAAsB;IACtB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/world-state",
3
- "version": "0.0.1-commit.b655e406",
3
+ "version": "0.0.1-commit.d3ec352c",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
@@ -18,8 +18,8 @@
18
18
  "tsconfig": "./tsconfig.json"
19
19
  },
20
20
  "scripts": {
21
- "build": "yarn clean && tsc -b",
22
- "build:dev": "tsc -b --watch",
21
+ "build": "yarn clean && ../scripts/tsc.sh",
22
+ "build:dev": "../scripts/tsc.sh --watch",
23
23
  "clean": "rm -rf ./dest .tsbuildinfo",
24
24
  "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
25
25
  },
@@ -64,22 +64,23 @@
64
64
  ]
65
65
  },
66
66
  "dependencies": {
67
- "@aztec/constants": "0.0.1-commit.b655e406",
68
- "@aztec/foundation": "0.0.1-commit.b655e406",
69
- "@aztec/kv-store": "0.0.1-commit.b655e406",
70
- "@aztec/merkle-tree": "0.0.1-commit.b655e406",
71
- "@aztec/native": "0.0.1-commit.b655e406",
72
- "@aztec/protocol-contracts": "0.0.1-commit.b655e406",
73
- "@aztec/stdlib": "0.0.1-commit.b655e406",
74
- "@aztec/telemetry-client": "0.0.1-commit.b655e406",
67
+ "@aztec/constants": "0.0.1-commit.d3ec352c",
68
+ "@aztec/foundation": "0.0.1-commit.d3ec352c",
69
+ "@aztec/kv-store": "0.0.1-commit.d3ec352c",
70
+ "@aztec/merkle-tree": "0.0.1-commit.d3ec352c",
71
+ "@aztec/native": "0.0.1-commit.d3ec352c",
72
+ "@aztec/protocol-contracts": "0.0.1-commit.d3ec352c",
73
+ "@aztec/stdlib": "0.0.1-commit.d3ec352c",
74
+ "@aztec/telemetry-client": "0.0.1-commit.d3ec352c",
75
75
  "tslib": "^2.4.0",
76
76
  "zod": "^3.23.8"
77
77
  },
78
78
  "devDependencies": {
79
- "@aztec/archiver": "0.0.1-commit.b655e406",
79
+ "@aztec/archiver": "0.0.1-commit.d3ec352c",
80
80
  "@jest/globals": "^30.0.0",
81
81
  "@types/jest": "^30.0.0",
82
82
  "@types/node": "^22.15.17",
83
+ "@typescript/native-preview": "7.0.0-dev.20251126.1",
83
84
  "jest": "^30.0.0",
84
85
  "jest-mock-extended": "^4.0.0",
85
86
  "ts-node": "^10.9.1",
@@ -1,3 +1,4 @@
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
1
2
  import { Fr } from '@aztec/foundation/fields';
2
3
  import { serializeToBuffer } from '@aztec/foundation/serialize';
3
4
  import { type IndexedTreeLeafPreimage, SiblingPath } from '@aztec/foundation/trees';
@@ -18,7 +19,7 @@ import {
18
19
  PublicDataTreeLeafPreimage,
19
20
  } from '@aztec/stdlib/trees';
20
21
  import { type BlockHeader, PartialStateReference, StateReference } from '@aztec/stdlib/tx';
21
- import type { WorldStateRevision } from '@aztec/stdlib/world-state';
22
+ import { type WorldStateRevision, WorldStateRevisionWithHandle } from '@aztec/stdlib/world-state';
22
23
 
23
24
  import assert from 'assert';
24
25
 
@@ -42,8 +43,8 @@ export class MerkleTreesFacade implements MerkleTreeReadOperations {
42
43
  return this.initialHeader;
43
44
  }
44
45
 
45
- getRevision(): WorldStateRevision {
46
- return this.revision;
46
+ getRevision(): WorldStateRevisionWithHandle {
47
+ return WorldStateRevisionWithHandle.fromWorldStateRevision(this.revision, this.instance.getHandle());
47
48
  }
48
49
 
49
50
  findLeafIndices(treeId: MerkleTreeId, values: MerkleTreeLeafType<MerkleTreeId>[]): Promise<(bigint | undefined)[]> {
@@ -191,14 +192,14 @@ export class MerkleTreesFacade implements MerkleTreeReadOperations {
191
192
  async getBlockNumbersForLeafIndices<ID extends MerkleTreeId>(
192
193
  treeId: ID,
193
194
  leafIndices: bigint[],
194
- ): Promise<(bigint | undefined)[]> {
195
+ ): Promise<(BlockNumber | undefined)[]> {
195
196
  const response = await this.instance.call(WorldStateMessageType.GET_BLOCK_NUMBERS_FOR_LEAF_INDICES, {
196
197
  treeId,
197
198
  revision: this.revision,
198
199
  leafIndices,
199
200
  });
200
201
 
201
- return response.blockNumbers.map(x => (x === undefined || x === null ? undefined : BigInt(x)));
202
+ return response.blockNumbers.map(x => (x === undefined || x === null ? undefined : BlockNumber(Number(x))));
202
203
  }
203
204
  }
204
205
 
@@ -1,3 +1,4 @@
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
1
2
  import { Fr } from '@aztec/foundation/fields';
2
3
  import type { Tuple } from '@aztec/foundation/serialize';
3
4
  import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
@@ -56,11 +57,11 @@ interface WithTreeId {
56
57
 
57
58
  export interface WorldStateStatusSummary {
58
59
  /** Last block number that can still be unwound. */
59
- unfinalizedBlockNumber: bigint;
60
+ unfinalizedBlockNumber: BlockNumber;
60
61
  /** Last block number that is finalized and cannot be unwound. */
61
- finalizedBlockNumber: bigint;
62
+ finalizedBlockNumber: BlockNumber;
62
63
  /** Oldest block still available for historical queries and forks. */
63
- oldestHistoricalBlock: bigint;
64
+ oldestHistoricalBlock: BlockNumber;
64
65
  /** Whether the trees are in sync with each other */
65
66
  treesAreSynched: boolean;
66
67
  }
@@ -81,11 +82,11 @@ export interface TreeMeta {
81
82
  /** The tree's initial root value */
82
83
  initialRoot: Fr;
83
84
  /** The current oldest historical block number of the tree */
84
- oldestHistoricBlock: bigint;
85
+ oldestHistoricBlock: BlockNumber;
85
86
  /** The current unfinalized block number of the tree */
86
- unfinalizedBlockHeight: bigint;
87
+ unfinalizedBlockHeight: BlockNumber;
87
88
  /** The current finalized block number of the tree */
88
- finalizedBlockHeight: bigint;
89
+ finalizedBlockHeight: BlockNumber;
89
90
  }
90
91
 
91
92
  export interface DBStats {
@@ -173,9 +174,9 @@ export function buildEmptyTreeMeta() {
173
174
  depth: 0,
174
175
  size: 0n,
175
176
  committedSize: 0n,
176
- unfinalizedBlockHeight: 0n,
177
- finalizedBlockHeight: 0n,
178
- oldestHistoricBlock: 0n,
177
+ unfinalizedBlockHeight: BlockNumber.ZERO,
178
+ finalizedBlockHeight: BlockNumber.ZERO,
179
+ oldestHistoricBlock: BlockNumber.ZERO,
179
180
  root: Fr.ZERO,
180
181
  initialRoot: Fr.ZERO,
181
182
  initialSize: 0n,
@@ -204,9 +205,9 @@ export function buildEmptyWorldStateDBStats() {
204
205
 
205
206
  export function buildEmptyWorldStateSummary() {
206
207
  return {
207
- unfinalizedBlockNumber: 0n,
208
- finalizedBlockNumber: 0n,
209
- oldestHistoricalBlock: 0n,
208
+ unfinalizedBlockNumber: BlockNumber.ZERO,
209
+ finalizedBlockNumber: BlockNumber.ZERO,
210
+ oldestHistoricalBlock: BlockNumber.ZERO,
210
211
  treesAreSynched: true,
211
212
  } as WorldStateStatusSummary;
212
213
  }
@@ -220,9 +221,9 @@ export function buildEmptyWorldStateStatusFull() {
220
221
  }
221
222
 
222
223
  export function sanitizeSummary(summary: WorldStateStatusSummary) {
223
- summary.finalizedBlockNumber = BigInt(summary.finalizedBlockNumber);
224
- summary.unfinalizedBlockNumber = BigInt(summary.unfinalizedBlockNumber);
225
- summary.oldestHistoricalBlock = BigInt(summary.oldestHistoricalBlock);
224
+ summary.finalizedBlockNumber = BlockNumber.fromBigInt(BigInt(summary.finalizedBlockNumber));
225
+ summary.unfinalizedBlockNumber = BlockNumber.fromBigInt(BigInt(summary.unfinalizedBlockNumber));
226
+ summary.oldestHistoricalBlock = BlockNumber.fromBigInt(BigInt(summary.oldestHistoricalBlock));
226
227
  return summary;
227
228
  }
228
229
 
@@ -234,11 +235,11 @@ export function sanitizeDBStats(stats: DBStats) {
234
235
 
235
236
  export function sanitizeMeta(meta: TreeMeta) {
236
237
  meta.committedSize = BigInt(meta.committedSize);
237
- meta.finalizedBlockHeight = BigInt(meta.finalizedBlockHeight);
238
+ meta.finalizedBlockHeight = BlockNumber.fromBigInt(BigInt(meta.finalizedBlockHeight));
238
239
  meta.initialSize = BigInt(meta.initialSize);
239
- meta.oldestHistoricBlock = BigInt(meta.oldestHistoricBlock);
240
+ meta.oldestHistoricBlock = BlockNumber.fromBigInt(BigInt(meta.oldestHistoricBlock));
240
241
  meta.size = BigInt(meta.size);
241
- meta.unfinalizedBlockHeight = BigInt(meta.unfinalizedBlockHeight);
242
+ meta.unfinalizedBlockHeight = BlockNumber.fromBigInt(BigInt(meta.unfinalizedBlockHeight));
242
243
  return meta;
243
244
  }
244
245
 
@@ -310,7 +311,7 @@ interface WithLeafValues {
310
311
  }
311
312
 
312
313
  interface BlockShiftRequest extends WithCanonicalForkId {
313
- toBlockNumber: bigint;
314
+ toBlockNumber: BlockNumber;
314
315
  }
315
316
 
316
317
  interface WithLeaves {
@@ -409,7 +410,7 @@ interface UpdateArchiveRequest extends WithForkId {
409
410
  }
410
411
 
411
412
  interface SyncBlockRequest extends WithCanonicalForkId {
412
- blockNumber: number;
413
+ blockNumber: BlockNumber;
413
414
  blockStateRef: BlockStateReference;
414
415
  blockHeaderHash: Fr;
415
416
  paddedNoteHashes: readonly SerializedLeafValue[];
@@ -420,7 +421,7 @@ interface SyncBlockRequest extends WithCanonicalForkId {
420
421
 
421
422
  interface CreateForkRequest extends WithCanonicalForkId {
422
423
  latest: boolean;
423
- blockNumber: number;
424
+ blockNumber: BlockNumber;
424
425
  }
425
426
 
426
427
  interface CreateForkResponse {
@@ -1,10 +1,11 @@
1
1
  import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
3
  import { fromEntries, padArrayEnd } from '@aztec/foundation/collection';
3
4
  import { EthAddress } from '@aztec/foundation/eth-address';
4
5
  import { Fr } from '@aztec/foundation/fields';
5
6
  import { tryRmDir } from '@aztec/foundation/fs';
6
7
  import { type Logger, createLogger } from '@aztec/foundation/log';
7
- import type { L2Block } from '@aztec/stdlib/block';
8
+ import type { L2BlockNew } from '@aztec/stdlib/block';
8
9
  import { DatabaseVersionManager } from '@aztec/stdlib/database-version';
9
10
  import type {
10
11
  IndexedTreeId,
@@ -150,7 +151,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
150
151
  return new MerkleTreesFacade(this.instance, this.initialHeader!, WorldStateRevision.empty());
151
152
  }
152
153
 
153
- public getSnapshot(blockNumber: number): MerkleTreeReadOperations {
154
+ public getSnapshot(blockNumber: BlockNumber): MerkleTreeReadOperations {
154
155
  return new MerkleTreesFacade(
155
156
  this.instance,
156
157
  this.initialHeader!,
@@ -158,16 +159,20 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
158
159
  );
159
160
  }
160
161
 
161
- public async fork(blockNumber?: number): Promise<MerkleTreeWriteOperations> {
162
+ public async fork(blockNumber?: BlockNumber): Promise<MerkleTreeWriteOperations> {
162
163
  const resp = await this.instance.call(WorldStateMessageType.CREATE_FORK, {
163
164
  latest: blockNumber === undefined,
164
- blockNumber: blockNumber ?? 0,
165
+ blockNumber: blockNumber ?? BlockNumber.ZERO,
165
166
  canonical: true,
166
167
  });
167
168
  return new MerkleTreesForkFacade(
168
169
  this.instance,
169
170
  this.initialHeader!,
170
- new WorldStateRevision(/*forkId=*/ resp.forkId, /* blockNumber=*/ 0, /* includeUncommitted=*/ true),
171
+ new WorldStateRevision(
172
+ /*forkId=*/ resp.forkId,
173
+ /* blockNumber=*/ BlockNumber.ZERO,
174
+ /* includeUncommitted=*/ true,
175
+ ),
171
176
  );
172
177
  }
173
178
 
@@ -176,20 +181,26 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
176
181
  }
177
182
 
178
183
  public async handleL2BlockAndMessages(
179
- l2Block: L2Block,
184
+ l2Block: L2BlockNew,
180
185
  l1ToL2Messages: Fr[],
181
- // TODO(#17027)
182
- // Temporary hack to only insert l1 to l2 messages for the first block in a checkpoint.
183
- isFirstBlock = true,
186
+ isFirstBlock: boolean,
184
187
  ): Promise<WorldStateStatusFull> {
185
- // We have to pad both the values within tx effects because that's how the trees are built by circuits.
186
- const paddedNoteHashes = l2Block.body.txEffects.flatMap(txEffect =>
187
- padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX),
188
- );
188
+ if (!isFirstBlock && l1ToL2Messages.length > 0) {
189
+ throw new Error(
190
+ `L1 to L2 messages must be empty for non-first blocks, but got ${l1ToL2Messages.length} messages for block ${l2Block.number}.`,
191
+ );
192
+ }
193
+
194
+ // We have to pad the given l1 to l2 messages, and the note hashes and nullifiers within tx effects, because that's
195
+ // how the trees are built by circuits.
189
196
  const paddedL1ToL2Messages = isFirstBlock
190
197
  ? padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP)
191
198
  : [];
192
199
 
200
+ const paddedNoteHashes = l2Block.body.txEffects.flatMap(txEffect =>
201
+ padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX),
202
+ );
203
+
193
204
  const paddedNullifiers = l2Block.body.txEffects
194
205
  .flatMap(txEffect => padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX))
195
206
  .map(nullifier => new NullifierLeaf(nullifier));
@@ -208,7 +219,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
208
219
  WorldStateMessageType.SYNC_BLOCK,
209
220
  {
210
221
  blockNumber: l2Block.number,
211
- blockHeaderHash: await l2Block.getBlockHeader().hash(),
222
+ blockHeaderHash: await l2Block.hash(),
212
223
  paddedL1ToL2Messages: paddedL1ToL2Messages.map(serializeLeaf),
213
224
  paddedNoteHashes: paddedNoteHashes.map(serializeLeaf),
214
225
  paddedNullifiers: paddedNullifiers.map(serializeLeaf),
@@ -256,7 +267,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
256
267
  * @param toBlockNumber The block number that is now the tip of the finalized chain
257
268
  * @returns The new WorldStateStatus
258
269
  */
259
- public async setFinalized(toBlockNumber: bigint) {
270
+ public async setFinalized(toBlockNumber: BlockNumber) {
260
271
  try {
261
272
  await this.instance.call(
262
273
  WorldStateMessageType.FINALIZE_BLOCKS,
@@ -279,7 +290,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
279
290
  * @param toBlockNumber The block number of the new oldest historical block
280
291
  * @returns The new WorldStateStatus
281
292
  */
282
- public async removeHistoricalBlocks(toBlockNumber: bigint) {
293
+ public async removeHistoricalBlocks(toBlockNumber: BlockNumber) {
283
294
  try {
284
295
  return await this.instance.call(
285
296
  WorldStateMessageType.REMOVE_HISTORICAL_BLOCKS,
@@ -301,7 +312,7 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
301
312
  * @param toBlockNumber The block number of the new tip of the pending chain,
302
313
  * @returns The new WorldStateStatus
303
314
  */
304
- public async unwindBlocks(toBlockNumber: bigint) {
315
+ public async unwindBlocks(toBlockNumber: BlockNumber) {
305
316
  try {
306
317
  return await this.instance.call(
307
318
  WorldStateMessageType.UNWIND_BLOCKS,
@@ -36,6 +36,8 @@ export interface NativeWorldStateInstance {
36
36
  messageType: T,
37
37
  body: WorldStateRequest[T] & WorldStateRequestCategories,
38
38
  ): Promise<WorldStateResponse[T]>;
39
+ // TODO(dbanks12): this returns any type, but we should strongly type it
40
+ getHandle(): any;
39
41
  }
40
42
 
41
43
  /**
@@ -107,6 +109,32 @@ export class NativeWorldState implements NativeWorldStateInstance {
107
109
  );
108
110
  }
109
111
 
112
+ /**
113
+ * Gets the native WorldState handle from the underlying native instance.
114
+ * We call the getHandle() method on the native WorldState to get a NAPI External
115
+ * that wraps the underlying C++ WorldState pointer.
116
+ * @returns The NAPI External handle to the native WorldState instance,since
117
+ * the NAPI external type is opaque, we return any (we could also use an opaque symbol type)
118
+ */
119
+ public getHandle(): any {
120
+ const worldStateWrapper = (this.instance as any).dest;
121
+
122
+ if (!worldStateWrapper) {
123
+ throw new Error('No WorldStateWrapper found');
124
+ }
125
+
126
+ if (typeof worldStateWrapper.getHandle !== 'function') {
127
+ throw new Error('WorldStateWrapper does not have getHandle method');
128
+ }
129
+
130
+ // Call getHandle() to get the NAPI External
131
+ try {
132
+ return worldStateWrapper.getHandle();
133
+ } catch (error) {
134
+ this.log.error('Failed to get native WorldState handle', error);
135
+ }
136
+ }
137
+
110
138
  /**
111
139
  * Sends a message to the native instance and returns the response.
112
140
  * @param messageType - The type of message to send