@aztec/world-state 0.87.2 → 0.87.3-nightly.20250528

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.
@@ -0,0 +1,23 @@
1
+ import { MerkleTreeId } from '@aztec/stdlib/trees';
2
+ export declare enum InsertionType {
3
+ BATCH = 0,
4
+ SEQUENTIAL = 1
5
+ }
6
+ export declare enum DataRetrievalType {
7
+ SIBLING_PATH = 0,
8
+ LEAF_PREIMAGE = 1,
9
+ LEAF_VALUE = 2,
10
+ LEAF_INDICES = 3,
11
+ LOW_LEAF = 4
12
+ }
13
+ export declare class NativeBenchMetics {
14
+ private blockSyncMetrics;
15
+ private insertionMetrics;
16
+ private dataRetrievalMetrics;
17
+ toPrettyString(): string;
18
+ addBlockSyncMetric(numTxs: number, numLeaves: number, value: number): void;
19
+ addInsertionMetric(treeId: MerkleTreeId, insertionType: InsertionType, numLeaves: number, value: number): void;
20
+ addDataRetrievalMetric(retrievalType: DataRetrievalType, value: number): void;
21
+ toGithubActionBenchmarkJSON(indent?: number): string;
22
+ }
23
+ //# sourceMappingURL=bench_metrics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bench_metrics.d.ts","sourceRoot":"","sources":["../../src/native/bench_metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAQnD,oBAAY,aAAa;IACvB,KAAK,IAAA;IACL,UAAU,IAAA;CACX;AASD,oBAAY,iBAAiB;IAC3B,YAAY,IAAA;IACZ,aAAa,IAAA;IACb,UAAU,IAAA;IACV,YAAY,IAAA;IACZ,QAAQ,IAAA;CACT;AAOD,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,gBAAgB,CAA0B;IAClD,OAAO,CAAC,gBAAgB,CAA0B;IAClD,OAAO,CAAC,oBAAoB,CAA8B;IAEnD,cAAc;IAiBd,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAGnE,kBAAkB,CAAC,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAGvG,sBAAsB,CAAC,aAAa,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM;IAItE,2BAA2B,CAAC,MAAM,SAAI;CAyB9C"}
@@ -0,0 +1,81 @@
1
+ import { MerkleTreeId } from '@aztec/stdlib/trees';
2
+ export var InsertionType = /*#__PURE__*/ function(InsertionType) {
3
+ InsertionType[InsertionType["BATCH"] = 0] = "BATCH";
4
+ InsertionType[InsertionType["SEQUENTIAL"] = 1] = "SEQUENTIAL";
5
+ return InsertionType;
6
+ }({});
7
+ export var DataRetrievalType = /*#__PURE__*/ function(DataRetrievalType) {
8
+ DataRetrievalType[DataRetrievalType["SIBLING_PATH"] = 0] = "SIBLING_PATH";
9
+ DataRetrievalType[DataRetrievalType["LEAF_PREIMAGE"] = 1] = "LEAF_PREIMAGE";
10
+ DataRetrievalType[DataRetrievalType["LEAF_VALUE"] = 2] = "LEAF_VALUE";
11
+ DataRetrievalType[DataRetrievalType["LEAF_INDICES"] = 3] = "LEAF_INDICES";
12
+ DataRetrievalType[DataRetrievalType["LOW_LEAF"] = 4] = "LOW_LEAF";
13
+ return DataRetrievalType;
14
+ }({});
15
+ export class NativeBenchMetics {
16
+ blockSyncMetrics = [];
17
+ insertionMetrics = [];
18
+ dataRetrievalMetrics = [];
19
+ toPrettyString() {
20
+ let pretty = '';
21
+ pretty += `Block sync metrics:\n`;
22
+ for (const metric of this.blockSyncMetrics){
23
+ pretty += ` ${metric.numTxs} txs, ${metric.numLeaves} leaves: ${metric.value} ms\n`;
24
+ }
25
+ pretty += `Insertion metrics:\n`;
26
+ for (const metric of this.insertionMetrics){
27
+ pretty += ` ${MerkleTreeId[metric.treeType]}: ${InsertionType[metric.insertionType]} (${metric.numLeaves} leaves): ${metric.value} ms\n`;
28
+ }
29
+ pretty += `Data retrieval metrics:\n`;
30
+ for (const metric of this.dataRetrievalMetrics){
31
+ pretty += ` ${DataRetrievalType[metric.retrievalType]}: ${metric.value} us\n`;
32
+ }
33
+ return pretty;
34
+ }
35
+ addBlockSyncMetric(numTxs, numLeaves, value) {
36
+ this.blockSyncMetrics.push({
37
+ numTxs,
38
+ numLeaves,
39
+ value
40
+ });
41
+ }
42
+ addInsertionMetric(treeId, insertionType, numLeaves, value) {
43
+ this.insertionMetrics.push({
44
+ treeType: treeId,
45
+ insertionType,
46
+ numLeaves,
47
+ value
48
+ });
49
+ }
50
+ addDataRetrievalMetric(retrievalType, value) {
51
+ this.dataRetrievalMetrics.push({
52
+ retrievalType,
53
+ value: value
54
+ });
55
+ }
56
+ toGithubActionBenchmarkJSON(indent = 2) {
57
+ const data = [];
58
+ for (const blockSync of this.blockSyncMetrics){
59
+ data.push({
60
+ name: `blockSync/${blockSync.numTxs}/${blockSync.numLeaves}`,
61
+ value: blockSync.value,
62
+ unit: 'ms'
63
+ });
64
+ }
65
+ for (const insertion of this.insertionMetrics){
66
+ data.push({
67
+ name: `${MerkleTreeId[insertion.treeType]}/${InsertionType[insertion.insertionType]}/${insertion.numLeaves}`,
68
+ value: insertion.value,
69
+ unit: 'ms'
70
+ });
71
+ }
72
+ for (const retrieval of this.dataRetrievalMetrics){
73
+ data.push({
74
+ name: `dataRetrieval/${DataRetrievalType[retrieval.retrievalType]}`,
75
+ value: retrieval.value,
76
+ unit: 'us'
77
+ });
78
+ }
79
+ return JSON.stringify(data, null, indent);
80
+ }
81
+ }
@@ -2,7 +2,7 @@ import { Fr } from '@aztec/foundation/fields';
2
2
  import { L2Block } from '@aztec/stdlib/block';
3
3
  import type { MerkleTreeReadOperations, MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
4
4
  import type { NativeWorldStateService } from '../native/native_world_state.js';
5
- export declare function mockBlock(blockNum: number, size: number, fork: MerkleTreeWriteOperations): Promise<{
5
+ export declare function mockBlock(blockNum: number, size: number, fork: MerkleTreeWriteOperations, maxEffects?: number | undefined): Promise<{
6
6
  block: L2Block;
7
7
  messages: Fr[];
8
8
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/test/utils.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,KAAK,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAG3G,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAE/E,wBAAsB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,yBAAyB;;;GA+C9F;AAED,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,yBAAyB;;;GAiDrF;AAED,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,uBAAuB;;;GAchH;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,wBAAwB,EAAE,KAAK,EAAE,wBAAwB,iBAQrG;AAED,wBAAsB,aAAa,CAAC,IAAI,EAAE,wBAAwB,EAAE,KAAK,EAAE,wBAAwB,iBAYlG"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/test/utils.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,KAAK,EAEV,wBAAwB,EACxB,yBAAyB,EAC1B,MAAM,iCAAiC,CAAC;AAGzC,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAE/E,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,yBAAyB,EAC/B,UAAU,GAAE,MAAM,GAAG,SAAqB;;;GAsD3C;AAED,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,yBAAyB;;;GAiDrF;AAED,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,uBAAuB;;;GAchH;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,wBAAwB,EAAE,KAAK,EAAE,wBAAwB,iBAQrG;AAED,wBAAsB,aAAa,CAAC,IAAI,EAAE,wBAAwB,EAAE,KAAK,EAAE,wBAAwB,iBAYlG"}
@@ -3,24 +3,27 @@ import { padArrayEnd } from '@aztec/foundation/collection';
3
3
  import { Fr } from '@aztec/foundation/fields';
4
4
  import { L2Block } from '@aztec/stdlib/block';
5
5
  import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
6
- export async function mockBlock(blockNum, size, fork) {
7
- const l2Block = await L2Block.random(blockNum, size);
6
+ export async function mockBlock(blockNum, size, fork, maxEffects = undefined) {
7
+ const l2Block = await L2Block.random(blockNum, size, maxEffects);
8
8
  const l1ToL2Messages = Array(16).fill(0).map(Fr.random);
9
- // Sync the append only trees
10
9
  {
10
+ const insertData = async (treeId, data, subTreeHeight, fork)=>{
11
+ for (const dataBatch of data){
12
+ await fork.batchInsert(treeId, dataBatch, subTreeHeight);
13
+ }
14
+ };
15
+ const publicDataInsert = insertData(MerkleTreeId.PUBLIC_DATA_TREE, l2Block.body.txEffects.map((txEffect)=>txEffect.publicDataWrites.map((write)=>write.toBuffer())), 0, fork);
16
+ const nullifierInsert = insertData(MerkleTreeId.NULLIFIER_TREE, l2Block.body.txEffects.map((txEffect)=>padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX).map((nullifier)=>nullifier.toBuffer())), NULLIFIER_SUBTREE_HEIGHT, fork);
11
17
  const noteHashesPadded = l2Block.body.txEffects.flatMap((txEffect)=>padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX));
12
- await fork.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashesPadded);
13
18
  const l1ToL2MessagesPadded = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
14
- await fork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
15
- }
16
- // Sync the indexed trees
17
- {
18
- // We insert the public data tree leaves with one batch per tx to avoid updating the same key twice
19
- for (const txEffect of l2Block.body.txEffects){
20
- await fork.batchInsert(MerkleTreeId.PUBLIC_DATA_TREE, txEffect.publicDataWrites.map((write)=>write.toBuffer()), 0);
21
- const nullifiersPadded = padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX);
22
- await fork.batchInsert(MerkleTreeId.NULLIFIER_TREE, nullifiersPadded.map((nullifier)=>nullifier.toBuffer()), NULLIFIER_SUBTREE_HEIGHT);
23
- }
19
+ const noteHashInsert = fork.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashesPadded);
20
+ const messageInsert = fork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
21
+ await Promise.all([
22
+ publicDataInsert,
23
+ nullifierInsert,
24
+ noteHashInsert,
25
+ messageInsert
26
+ ]);
24
27
  }
25
28
  const state = await fork.getStateReference();
26
29
  l2Block.header.state = state;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/world-state",
3
- "version": "0.87.2",
3
+ "version": "0.87.3-nightly.20250528",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./dest/index.js",
@@ -60,19 +60,19 @@
60
60
  ]
61
61
  },
62
62
  "dependencies": {
63
- "@aztec/constants": "0.87.2",
64
- "@aztec/foundation": "0.87.2",
65
- "@aztec/kv-store": "0.87.2",
66
- "@aztec/merkle-tree": "0.87.2",
67
- "@aztec/native": "0.87.2",
68
- "@aztec/protocol-contracts": "0.87.2",
69
- "@aztec/stdlib": "0.87.2",
70
- "@aztec/telemetry-client": "0.87.2",
63
+ "@aztec/constants": "0.87.3-nightly.20250528",
64
+ "@aztec/foundation": "0.87.3-nightly.20250528",
65
+ "@aztec/kv-store": "0.87.3-nightly.20250528",
66
+ "@aztec/merkle-tree": "0.87.3-nightly.20250528",
67
+ "@aztec/native": "0.87.3-nightly.20250528",
68
+ "@aztec/protocol-contracts": "0.87.3-nightly.20250528",
69
+ "@aztec/stdlib": "0.87.3-nightly.20250528",
70
+ "@aztec/telemetry-client": "0.87.3-nightly.20250528",
71
71
  "tslib": "^2.4.0",
72
72
  "zod": "^3.23.8"
73
73
  },
74
74
  "devDependencies": {
75
- "@aztec/archiver": "0.87.2",
75
+ "@aztec/archiver": "0.87.3-nightly.20250528",
76
76
  "@jest/globals": "^29.5.0",
77
77
  "@types/jest": "^29.5.0",
78
78
  "@types/node": "^22.15.17",
@@ -0,0 +1,91 @@
1
+ import { MerkleTreeId } from '@aztec/stdlib/trees';
2
+
3
+ type BlockSyncMetrics = {
4
+ numTxs: number;
5
+ numLeaves: number;
6
+ value: number;
7
+ };
8
+
9
+ export enum InsertionType {
10
+ BATCH,
11
+ SEQUENTIAL,
12
+ }
13
+
14
+ type InsertionMetrics = {
15
+ treeType: MerkleTreeId;
16
+ insertionType: InsertionType;
17
+ numLeaves: number;
18
+ value: number;
19
+ };
20
+
21
+ export enum DataRetrievalType {
22
+ SIBLING_PATH,
23
+ LEAF_PREIMAGE,
24
+ LEAF_VALUE,
25
+ LEAF_INDICES,
26
+ LOW_LEAF,
27
+ }
28
+
29
+ type DataRetrievalMetrics = {
30
+ retrievalType: DataRetrievalType;
31
+ value: number;
32
+ };
33
+
34
+ export class NativeBenchMetics {
35
+ private blockSyncMetrics: BlockSyncMetrics[] = [];
36
+ private insertionMetrics: InsertionMetrics[] = [];
37
+ private dataRetrievalMetrics: DataRetrievalMetrics[] = [];
38
+
39
+ public toPrettyString() {
40
+ let pretty = '';
41
+ pretty += `Block sync metrics:\n`;
42
+ for (const metric of this.blockSyncMetrics) {
43
+ pretty += ` ${metric.numTxs} txs, ${metric.numLeaves} leaves: ${metric.value} ms\n`;
44
+ }
45
+ pretty += `Insertion metrics:\n`;
46
+ for (const metric of this.insertionMetrics) {
47
+ pretty += ` ${MerkleTreeId[metric.treeType]}: ${InsertionType[metric.insertionType]} (${metric.numLeaves} leaves): ${metric.value} ms\n`;
48
+ }
49
+ pretty += `Data retrieval metrics:\n`;
50
+ for (const metric of this.dataRetrievalMetrics) {
51
+ pretty += ` ${DataRetrievalType[metric.retrievalType]}: ${metric.value} us\n`;
52
+ }
53
+ return pretty;
54
+ }
55
+
56
+ public addBlockSyncMetric(numTxs: number, numLeaves: number, value: number) {
57
+ this.blockSyncMetrics.push({ numTxs, numLeaves, value });
58
+ }
59
+ public addInsertionMetric(treeId: MerkleTreeId, insertionType: InsertionType, numLeaves: number, value: number) {
60
+ this.insertionMetrics.push({ treeType: treeId, insertionType, numLeaves, value });
61
+ }
62
+ public addDataRetrievalMetric(retrievalType: DataRetrievalType, value: number) {
63
+ this.dataRetrievalMetrics.push({ retrievalType, value: value });
64
+ }
65
+
66
+ public toGithubActionBenchmarkJSON(indent = 2) {
67
+ const data = [];
68
+ for (const blockSync of this.blockSyncMetrics) {
69
+ data.push({
70
+ name: `blockSync/${blockSync.numTxs}/${blockSync.numLeaves}`,
71
+ value: blockSync.value,
72
+ unit: 'ms',
73
+ });
74
+ }
75
+ for (const insertion of this.insertionMetrics) {
76
+ data.push({
77
+ name: `${MerkleTreeId[insertion.treeType]}/${InsertionType[insertion.insertionType]}/${insertion.numLeaves}`,
78
+ value: insertion.value,
79
+ unit: 'ms',
80
+ });
81
+ }
82
+ for (const retrieval of this.dataRetrievalMetrics) {
83
+ data.push({
84
+ name: `dataRetrieval/${DataRetrievalType[retrieval.retrievalType]}`,
85
+ value: retrieval.value,
86
+ unit: 'us',
87
+ });
88
+ }
89
+ return JSON.stringify(data, null, indent);
90
+ }
91
+ }
package/src/test/utils.ts CHANGED
@@ -7,44 +7,59 @@ import {
7
7
  import { padArrayEnd } from '@aztec/foundation/collection';
8
8
  import { Fr } from '@aztec/foundation/fields';
9
9
  import { L2Block } from '@aztec/stdlib/block';
10
- import type { MerkleTreeReadOperations, MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
10
+ import type {
11
+ IndexedTreeId,
12
+ MerkleTreeReadOperations,
13
+ MerkleTreeWriteOperations,
14
+ } from '@aztec/stdlib/interfaces/server';
11
15
  import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
12
16
 
13
17
  import type { NativeWorldStateService } from '../native/native_world_state.js';
14
18
 
15
- export async function mockBlock(blockNum: number, size: number, fork: MerkleTreeWriteOperations) {
16
- const l2Block = await L2Block.random(blockNum, size);
19
+ export async function mockBlock(
20
+ blockNum: number,
21
+ size: number,
22
+ fork: MerkleTreeWriteOperations,
23
+ maxEffects: number | undefined = undefined,
24
+ ) {
25
+ const l2Block = await L2Block.random(blockNum, size, maxEffects);
17
26
  const l1ToL2Messages = Array(16).fill(0).map(Fr.random);
18
27
 
19
- // Sync the append only trees
20
28
  {
29
+ const insertData = async (
30
+ treeId: IndexedTreeId,
31
+ data: Buffer[][],
32
+ subTreeHeight: number,
33
+ fork: MerkleTreeWriteOperations,
34
+ ) => {
35
+ for (const dataBatch of data) {
36
+ await fork.batchInsert(treeId, dataBatch, subTreeHeight);
37
+ }
38
+ };
39
+
40
+ const publicDataInsert = insertData(
41
+ MerkleTreeId.PUBLIC_DATA_TREE,
42
+ l2Block.body.txEffects.map(txEffect => txEffect.publicDataWrites.map(write => write.toBuffer())),
43
+ 0,
44
+ fork,
45
+ );
46
+ const nullifierInsert = insertData(
47
+ MerkleTreeId.NULLIFIER_TREE,
48
+ l2Block.body.txEffects.map(txEffect =>
49
+ padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX).map(nullifier => nullifier.toBuffer()),
50
+ ),
51
+ NULLIFIER_SUBTREE_HEIGHT,
52
+ fork,
53
+ );
21
54
  const noteHashesPadded = l2Block.body.txEffects.flatMap(txEffect =>
22
55
  padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX),
23
56
  );
24
- await fork.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashesPadded);
25
57
 
26
58
  const l1ToL2MessagesPadded = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
27
- await fork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
28
- }
29
-
30
- // Sync the indexed trees
31
- {
32
- // We insert the public data tree leaves with one batch per tx to avoid updating the same key twice
33
- for (const txEffect of l2Block.body.txEffects) {
34
- await fork.batchInsert(
35
- MerkleTreeId.PUBLIC_DATA_TREE,
36
- txEffect.publicDataWrites.map(write => write.toBuffer()),
37
- 0,
38
- );
39
-
40
- const nullifiersPadded = padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX);
41
59
 
42
- await fork.batchInsert(
43
- MerkleTreeId.NULLIFIER_TREE,
44
- nullifiersPadded.map(nullifier => nullifier.toBuffer()),
45
- NULLIFIER_SUBTREE_HEIGHT,
46
- );
47
- }
60
+ const noteHashInsert = fork.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, noteHashesPadded);
61
+ const messageInsert = fork.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2MessagesPadded);
62
+ await Promise.all([publicDataInsert, nullifierInsert, noteHashInsert, messageInsert]);
48
63
  }
49
64
 
50
65
  const state = await fork.getStateReference();