@aztec/aztec-node 0.0.1-commit.3895657bc → 0.0.1-commit.3a4ae741b
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.
- package/dest/aztec-node/server.d.ts +17 -18
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +171 -101
- package/dest/sentinel/sentinel.js +8 -8
- package/package.json +26 -27
- package/src/aztec-node/server.ts +171 -97
- package/src/sentinel/sentinel.ts +8 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/aztec-node",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.3a4ae741b",
|
|
4
4
|
"main": "dest/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -65,32 +65,31 @@
|
|
|
65
65
|
]
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@aztec/archiver": "0.0.1-commit.
|
|
69
|
-
"@aztec/bb-prover": "0.0.1-commit.
|
|
70
|
-
"@aztec/blob-client": "0.0.1-commit.
|
|
71
|
-
"@aztec/blob-lib": "0.0.1-commit.
|
|
72
|
-
"@aztec/constants": "0.0.1-commit.
|
|
73
|
-
"@aztec/epoch-cache": "0.0.1-commit.
|
|
74
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
75
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
76
|
-
"@aztec/kv-store": "0.0.1-commit.
|
|
77
|
-
"@aztec/l1-artifacts": "0.0.1-commit.
|
|
78
|
-
"@aztec/
|
|
79
|
-
"@aztec/node-
|
|
80
|
-
"@aztec/
|
|
81
|
-
"@aztec/
|
|
82
|
-
"@aztec/
|
|
83
|
-
"@aztec/
|
|
84
|
-
"@aztec/prover-
|
|
85
|
-
"@aztec/
|
|
86
|
-
"@aztec/
|
|
87
|
-
"@aztec/
|
|
88
|
-
"@aztec/
|
|
89
|
-
"@aztec/
|
|
90
|
-
"@aztec/
|
|
91
|
-
"@aztec/validator-
|
|
92
|
-
"@aztec/
|
|
93
|
-
"@aztec/world-state": "0.0.1-commit.3895657bc",
|
|
68
|
+
"@aztec/archiver": "0.0.1-commit.3a4ae741b",
|
|
69
|
+
"@aztec/bb-prover": "0.0.1-commit.3a4ae741b",
|
|
70
|
+
"@aztec/blob-client": "0.0.1-commit.3a4ae741b",
|
|
71
|
+
"@aztec/blob-lib": "0.0.1-commit.3a4ae741b",
|
|
72
|
+
"@aztec/constants": "0.0.1-commit.3a4ae741b",
|
|
73
|
+
"@aztec/epoch-cache": "0.0.1-commit.3a4ae741b",
|
|
74
|
+
"@aztec/ethereum": "0.0.1-commit.3a4ae741b",
|
|
75
|
+
"@aztec/foundation": "0.0.1-commit.3a4ae741b",
|
|
76
|
+
"@aztec/kv-store": "0.0.1-commit.3a4ae741b",
|
|
77
|
+
"@aztec/l1-artifacts": "0.0.1-commit.3a4ae741b",
|
|
78
|
+
"@aztec/node-keystore": "0.0.1-commit.3a4ae741b",
|
|
79
|
+
"@aztec/node-lib": "0.0.1-commit.3a4ae741b",
|
|
80
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.3a4ae741b",
|
|
81
|
+
"@aztec/p2p": "0.0.1-commit.3a4ae741b",
|
|
82
|
+
"@aztec/protocol-contracts": "0.0.1-commit.3a4ae741b",
|
|
83
|
+
"@aztec/prover-client": "0.0.1-commit.3a4ae741b",
|
|
84
|
+
"@aztec/prover-node": "0.0.1-commit.3a4ae741b",
|
|
85
|
+
"@aztec/sequencer-client": "0.0.1-commit.3a4ae741b",
|
|
86
|
+
"@aztec/simulator": "0.0.1-commit.3a4ae741b",
|
|
87
|
+
"@aztec/slasher": "0.0.1-commit.3a4ae741b",
|
|
88
|
+
"@aztec/stdlib": "0.0.1-commit.3a4ae741b",
|
|
89
|
+
"@aztec/telemetry-client": "0.0.1-commit.3a4ae741b",
|
|
90
|
+
"@aztec/validator-client": "0.0.1-commit.3a4ae741b",
|
|
91
|
+
"@aztec/validator-ha-signer": "0.0.1-commit.3a4ae741b",
|
|
92
|
+
"@aztec/world-state": "0.0.1-commit.3a4ae741b",
|
|
94
93
|
"koa": "^2.16.1",
|
|
95
94
|
"koa-router": "^13.1.1",
|
|
96
95
|
"tslib": "^2.4.0",
|
package/src/aztec-node/server.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { Archiver, createArchiver } from '@aztec/archiver';
|
|
2
|
-
import { BBCircuitVerifier,
|
|
2
|
+
import { BBCircuitVerifier, BatchChonkVerifier, QueuedIVCVerifier } from '@aztec/bb-prover';
|
|
3
|
+
import { TestCircuitVerifier } from '@aztec/bb-prover/test';
|
|
3
4
|
import { type BlobClientInterface, createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
4
5
|
import { Blob } from '@aztec/blob-lib';
|
|
5
6
|
import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
|
|
6
7
|
import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
|
|
7
8
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
8
|
-
import { getPublicClient } from '@aztec/ethereum/client';
|
|
9
|
+
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
9
10
|
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
10
11
|
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
12
|
+
import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
|
|
11
13
|
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
12
|
-
import { compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
14
|
+
import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
13
15
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
14
16
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
15
17
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
@@ -111,9 +113,10 @@ import {
|
|
|
111
113
|
createBlockProposalHandler,
|
|
112
114
|
createValidatorClient,
|
|
113
115
|
} from '@aztec/validator-client';
|
|
116
|
+
import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
|
|
114
117
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
115
118
|
|
|
116
|
-
import { createPublicClient
|
|
119
|
+
import { createPublicClient } from 'viem';
|
|
117
120
|
|
|
118
121
|
import { createSentinel } from '../sentinel/factory.js';
|
|
119
122
|
import { Sentinel } from '../sentinel/sentinel.js';
|
|
@@ -150,7 +153,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
150
153
|
protected readonly globalVariableBuilder: GlobalVariableBuilderInterface,
|
|
151
154
|
protected readonly epochCache: EpochCacheInterface,
|
|
152
155
|
protected readonly packageVersion: string,
|
|
153
|
-
private
|
|
156
|
+
private peerProofVerifier: ClientProtocolCircuitVerifier,
|
|
157
|
+
private rpcProofVerifier: ClientProtocolCircuitVerifier,
|
|
154
158
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
155
159
|
private log = createLogger('node'),
|
|
156
160
|
private blobClient?: BlobClientInterface,
|
|
@@ -172,6 +176,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
172
176
|
}
|
|
173
177
|
}
|
|
174
178
|
|
|
179
|
+
/** @internal Exposed for testing — returns the RPC proof verifier. */
|
|
180
|
+
public getProofVerifier(): ClientProtocolCircuitVerifier {
|
|
181
|
+
return this.rpcProofVerifier;
|
|
182
|
+
}
|
|
183
|
+
|
|
175
184
|
public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
|
|
176
185
|
const status = await this.worldStateSynchronizer.status();
|
|
177
186
|
return status.syncSummary;
|
|
@@ -195,6 +204,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
195
204
|
dateProvider?: DateProvider;
|
|
196
205
|
p2pClientDeps?: P2PClientDeps;
|
|
197
206
|
proverNodeDeps?: Partial<ProverNodeDeps>;
|
|
207
|
+
slashingProtectionDb?: SlashingProtectionDatabase;
|
|
198
208
|
} = {},
|
|
199
209
|
options: {
|
|
200
210
|
prefilledPublicData?: PublicDataTreeLeaf[];
|
|
@@ -257,7 +267,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
257
267
|
|
|
258
268
|
const publicClient = createPublicClient({
|
|
259
269
|
chain: ethereumChain.chainInfo,
|
|
260
|
-
transport:
|
|
270
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
|
|
261
271
|
pollingInterval: config.viemPollingIntervalMS,
|
|
262
272
|
});
|
|
263
273
|
|
|
@@ -306,10 +316,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
306
316
|
options.prefilledPublicData,
|
|
307
317
|
telemetry,
|
|
308
318
|
);
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
319
|
+
const useRealVerifiers = config.realProofs || config.debugForceTxProofVerification;
|
|
320
|
+
let peerProofVerifier: ClientProtocolCircuitVerifier;
|
|
321
|
+
let rpcProofVerifier: ClientProtocolCircuitVerifier;
|
|
322
|
+
if (useRealVerifiers) {
|
|
323
|
+
peerProofVerifier = await BatchChonkVerifier.new(config, config.bbChonkVerifyMaxBatch, 'peer');
|
|
324
|
+
const rpcVerifier = await BBCircuitVerifier.new(config);
|
|
325
|
+
rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, config.numConcurrentIVCVerifiers);
|
|
326
|
+
} else {
|
|
327
|
+
peerProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
328
|
+
rpcProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
329
|
+
}
|
|
313
330
|
|
|
314
331
|
let debugLogStore: DebugLogStore;
|
|
315
332
|
if (!config.realProofs) {
|
|
@@ -323,8 +340,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
323
340
|
debugLogStore = new NullDebugLogStore();
|
|
324
341
|
}
|
|
325
342
|
|
|
326
|
-
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
327
|
-
|
|
328
343
|
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
329
344
|
if (proverOnly) {
|
|
330
345
|
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
@@ -334,7 +349,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
334
349
|
const p2pClient = await createP2PClient(
|
|
335
350
|
config,
|
|
336
351
|
archiver,
|
|
337
|
-
|
|
352
|
+
peerProofVerifier,
|
|
338
353
|
worldStateSynchronizer,
|
|
339
354
|
epochCache,
|
|
340
355
|
packageVersion,
|
|
@@ -377,6 +392,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
377
392
|
l1ToL2MessageSource: archiver,
|
|
378
393
|
keyStoreManager,
|
|
379
394
|
blobClient,
|
|
395
|
+
slashingProtectionDb: deps.slashingProtectionDb,
|
|
380
396
|
});
|
|
381
397
|
|
|
382
398
|
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
@@ -455,6 +471,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
455
471
|
})
|
|
456
472
|
.catch(err => log.error('Failed to start p2p services after archiver sync', err));
|
|
457
473
|
|
|
474
|
+
const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, {
|
|
475
|
+
l1Contracts: config.l1Contracts,
|
|
476
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
477
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
478
|
+
l1GenesisTime,
|
|
479
|
+
slotDuration: Number(slotDuration),
|
|
480
|
+
});
|
|
481
|
+
|
|
458
482
|
// Validator enabled, create/start relevant service
|
|
459
483
|
let sequencer: SequencerClient | undefined;
|
|
460
484
|
let slasherClient: SlasherClientInterface | undefined;
|
|
@@ -492,6 +516,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
492
516
|
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
493
517
|
);
|
|
494
518
|
|
|
519
|
+
// Create a funder L1TxUtils from the keystore funding account (if configured)
|
|
520
|
+
const fundingSigner = keyStoreManager?.createFundingSigner();
|
|
521
|
+
let funderL1TxUtils: L1TxUtils | undefined;
|
|
522
|
+
if (fundingSigner) {
|
|
523
|
+
const [funder] = await createL1TxUtilsFromSigners(
|
|
524
|
+
publicClient,
|
|
525
|
+
[fundingSigner],
|
|
526
|
+
{ ...config, scope: 'sequencer' },
|
|
527
|
+
{ telemetry, logger: log.createChild('l1-tx-utils:funder'), dateProvider },
|
|
528
|
+
);
|
|
529
|
+
funderL1TxUtils = funder;
|
|
530
|
+
}
|
|
531
|
+
|
|
495
532
|
// Create and start the sequencer client
|
|
496
533
|
const checkpointsBuilder = new CheckpointsBuilder(
|
|
497
534
|
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
|
|
@@ -506,6 +543,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
506
543
|
...deps,
|
|
507
544
|
epochCache,
|
|
508
545
|
l1TxUtils,
|
|
546
|
+
funderL1TxUtils,
|
|
509
547
|
validatorClient,
|
|
510
548
|
p2pClient,
|
|
511
549
|
worldStateSynchronizer,
|
|
@@ -517,6 +555,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
517
555
|
dateProvider,
|
|
518
556
|
blobClient,
|
|
519
557
|
nodeKeyStore: keyStoreManager!,
|
|
558
|
+
globalVariableBuilder,
|
|
520
559
|
});
|
|
521
560
|
}
|
|
522
561
|
|
|
@@ -550,13 +589,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
550
589
|
}
|
|
551
590
|
}
|
|
552
591
|
|
|
553
|
-
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
554
|
-
...config,
|
|
555
|
-
rollupVersion: BigInt(config.rollupVersion),
|
|
556
|
-
l1GenesisTime,
|
|
557
|
-
slotDuration: Number(slotDuration),
|
|
558
|
-
});
|
|
559
|
-
|
|
560
592
|
const node = new AztecNodeService(
|
|
561
593
|
config,
|
|
562
594
|
p2pClient,
|
|
@@ -575,7 +607,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
575
607
|
globalVariableBuilder,
|
|
576
608
|
epochCache,
|
|
577
609
|
packageVersion,
|
|
578
|
-
|
|
610
|
+
peerProofVerifier,
|
|
611
|
+
rpcProofVerifier,
|
|
579
612
|
telemetry,
|
|
580
613
|
log,
|
|
581
614
|
blobClient,
|
|
@@ -720,6 +753,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
720
753
|
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
721
754
|
}
|
|
722
755
|
|
|
756
|
+
public getCheckpointsDataForEpoch(epochNumber: EpochNumber) {
|
|
757
|
+
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
758
|
+
}
|
|
759
|
+
|
|
723
760
|
/**
|
|
724
761
|
* Method to fetch the current min L2 fees.
|
|
725
762
|
* @returns The current min L2 fees.
|
|
@@ -793,18 +830,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
793
830
|
page?: number,
|
|
794
831
|
referenceBlock?: BlockHash,
|
|
795
832
|
): Promise<TxScopedL2Log[][]> {
|
|
833
|
+
let upToBlockNumber: BlockNumber | undefined;
|
|
796
834
|
if (referenceBlock) {
|
|
797
835
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
798
|
-
if (
|
|
836
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
837
|
+
upToBlockNumber = BlockNumber(0);
|
|
838
|
+
} else {
|
|
799
839
|
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
800
840
|
if (!header) {
|
|
801
841
|
throw new Error(
|
|
802
842
|
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
803
843
|
);
|
|
804
844
|
}
|
|
845
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
805
846
|
}
|
|
806
847
|
}
|
|
807
|
-
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
848
|
+
return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
808
849
|
}
|
|
809
850
|
|
|
810
851
|
public async getPublicLogsByTagsFromContract(
|
|
@@ -813,18 +854,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
813
854
|
page?: number,
|
|
814
855
|
referenceBlock?: BlockHash,
|
|
815
856
|
): Promise<TxScopedL2Log[][]> {
|
|
857
|
+
let upToBlockNumber: BlockNumber | undefined;
|
|
816
858
|
if (referenceBlock) {
|
|
817
859
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
818
|
-
if (
|
|
860
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
861
|
+
upToBlockNumber = BlockNumber(0);
|
|
862
|
+
} else {
|
|
819
863
|
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
820
864
|
if (!header) {
|
|
821
865
|
throw new Error(
|
|
822
866
|
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
823
867
|
);
|
|
824
868
|
}
|
|
869
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
825
870
|
}
|
|
826
871
|
}
|
|
827
|
-
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
872
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
828
873
|
}
|
|
829
874
|
|
|
830
875
|
/**
|
|
@@ -910,7 +955,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
910
955
|
await tryStop(this.validatorsSentinel);
|
|
911
956
|
await tryStop(this.epochPruneWatcher);
|
|
912
957
|
await tryStop(this.slasherClient);
|
|
913
|
-
await tryStop(this.
|
|
958
|
+
await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
|
|
914
959
|
await tryStop(this.sequencer);
|
|
915
960
|
await tryStop(this.proverNode);
|
|
916
961
|
await tryStop(this.p2pClient);
|
|
@@ -966,58 +1011,64 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
966
1011
|
treeId: MerkleTreeId,
|
|
967
1012
|
leafValues: Fr[],
|
|
968
1013
|
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
969
|
-
const committedDb = await this
|
|
1014
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
970
1015
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
971
1016
|
treeId,
|
|
972
1017
|
leafValues.map(x => x.toBuffer()),
|
|
973
1018
|
);
|
|
974
|
-
//
|
|
975
|
-
const
|
|
1019
|
+
// Filter out undefined values to query block numbers only for found leaves
|
|
1020
|
+
const definedIndices = maybeIndices.filter(x => x !== undefined);
|
|
976
1021
|
|
|
977
|
-
// Now we find the block numbers for the indices
|
|
978
|
-
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId,
|
|
1022
|
+
// Now we find the block numbers for the defined indices
|
|
1023
|
+
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
|
|
979
1024
|
|
|
980
|
-
//
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
1025
|
+
// Build a map from leaf index to block number
|
|
1026
|
+
const indexToBlockNumber = new Map<bigint, BlockNumber>();
|
|
1027
|
+
for (let i = 0; i < definedIndices.length; i++) {
|
|
1028
|
+
const blockNumber = blockNumbers[i];
|
|
1029
|
+
if (blockNumber === undefined) {
|
|
1030
|
+
throw new Error(
|
|
1031
|
+
`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`,
|
|
1032
|
+
);
|
|
984
1033
|
}
|
|
1034
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
985
1035
|
}
|
|
986
1036
|
|
|
987
1037
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
988
|
-
const uniqueBlockNumbers = [...new Set(
|
|
1038
|
+
const uniqueBlockNumbers = [...new Set(indexToBlockNumber.values())];
|
|
989
1039
|
|
|
990
|
-
// Now we obtain the block hashes from the archive tree
|
|
991
|
-
// (note that block number corresponds to the leaf index in the archive tree).
|
|
1040
|
+
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
992
1041
|
const blockHashes = await Promise.all(
|
|
993
1042
|
uniqueBlockNumbers.map(blockNumber => {
|
|
994
1043
|
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
995
1044
|
}),
|
|
996
1045
|
);
|
|
997
1046
|
|
|
998
|
-
//
|
|
1047
|
+
// Build a map from block number to block hash
|
|
1048
|
+
const blockNumberToHash = new Map<BlockNumber, Fr>();
|
|
999
1049
|
for (let i = 0; i < uniqueBlockNumbers.length; i++) {
|
|
1000
|
-
|
|
1050
|
+
const blockHash = blockHashes[i];
|
|
1051
|
+
if (blockHash === undefined) {
|
|
1001
1052
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
1002
1053
|
}
|
|
1054
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
1003
1055
|
}
|
|
1004
1056
|
|
|
1005
1057
|
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
1006
|
-
return maybeIndices.map(
|
|
1058
|
+
return maybeIndices.map(index => {
|
|
1007
1059
|
if (index === undefined) {
|
|
1008
1060
|
return undefined;
|
|
1009
1061
|
}
|
|
1010
|
-
const blockNumber =
|
|
1062
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
1011
1063
|
if (blockNumber === undefined) {
|
|
1012
|
-
|
|
1064
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
1013
1065
|
}
|
|
1014
|
-
const
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
return undefined;
|
|
1066
|
+
const blockHash = blockNumberToHash.get(blockNumber);
|
|
1067
|
+
if (blockHash === undefined) {
|
|
1068
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
1018
1069
|
}
|
|
1019
1070
|
return {
|
|
1020
|
-
l2BlockNumber:
|
|
1071
|
+
l2BlockNumber: blockNumber,
|
|
1021
1072
|
l2BlockHash: new BlockHash(blockHash),
|
|
1022
1073
|
data: index,
|
|
1023
1074
|
};
|
|
@@ -1028,7 +1079,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1028
1079
|
referenceBlock: BlockParameter,
|
|
1029
1080
|
blockHash: BlockHash,
|
|
1030
1081
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
1031
|
-
|
|
1082
|
+
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
1083
|
+
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1084
|
+
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1085
|
+
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1086
|
+
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
1032
1087
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
1033
1088
|
return pathAndIndex === undefined
|
|
1034
1089
|
? undefined
|
|
@@ -1039,7 +1094,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1039
1094
|
referenceBlock: BlockParameter,
|
|
1040
1095
|
noteHash: Fr,
|
|
1041
1096
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
1042
|
-
const committedDb = await this
|
|
1097
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1043
1098
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
1044
1099
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
1045
1100
|
[noteHash],
|
|
@@ -1053,7 +1108,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1053
1108
|
referenceBlock: BlockParameter,
|
|
1054
1109
|
l1ToL2Message: Fr,
|
|
1055
1110
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
1056
|
-
const db = await this
|
|
1111
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1057
1112
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
1058
1113
|
if (!witness) {
|
|
1059
1114
|
return undefined;
|
|
@@ -1086,19 +1141,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1086
1141
|
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
1087
1142
|
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1088
1143
|
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1089
|
-
const blocksInCheckpoints
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
for (const checkpointedBlock of checkpointedBlocks) {
|
|
1093
|
-
const block = checkpointedBlock.block;
|
|
1094
|
-
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1095
|
-
if (slotNumber !== previousSlotNumber) {
|
|
1096
|
-
checkpointIndex++;
|
|
1097
|
-
blocksInCheckpoints.push([]);
|
|
1098
|
-
previousSlotNumber = slotNumber;
|
|
1099
|
-
}
|
|
1100
|
-
blocksInCheckpoints[checkpointIndex].push(block);
|
|
1101
|
-
}
|
|
1144
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, cb => cb.block.header.globalVariables.slotNumber).map(
|
|
1145
|
+
group => group.map(cb => cb.block),
|
|
1146
|
+
);
|
|
1102
1147
|
return blocksInCheckpoints.map(blocks =>
|
|
1103
1148
|
blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
1104
1149
|
);
|
|
@@ -1108,7 +1153,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1108
1153
|
referenceBlock: BlockParameter,
|
|
1109
1154
|
nullifier: Fr,
|
|
1110
1155
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1111
|
-
const db = await this
|
|
1156
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1112
1157
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
1113
1158
|
if (!witness) {
|
|
1114
1159
|
return undefined;
|
|
@@ -1123,33 +1168,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1123
1168
|
return new NullifierMembershipWitness(index, leafPreimage as NullifierLeafPreimage, path);
|
|
1124
1169
|
}
|
|
1125
1170
|
|
|
1126
|
-
/**
|
|
1127
|
-
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1128
|
-
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
|
|
1129
|
-
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
|
|
1130
|
-
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1131
|
-
* @returns The low nullifier membership witness (if found).
|
|
1132
|
-
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
1133
|
-
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
1134
|
-
* we are trying to prove non-inclusion for.
|
|
1135
|
-
*
|
|
1136
|
-
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
|
|
1137
|
-
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
1138
|
-
* index of the nullifier itself when it already exists in the tree.
|
|
1139
|
-
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1140
|
-
*/
|
|
1141
1171
|
public async getLowNullifierMembershipWitness(
|
|
1142
1172
|
referenceBlock: BlockParameter,
|
|
1143
1173
|
nullifier: Fr,
|
|
1144
1174
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1145
|
-
const committedDb = await this
|
|
1175
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1146
1176
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1147
1177
|
if (!findResult) {
|
|
1148
1178
|
return undefined;
|
|
1149
1179
|
}
|
|
1150
1180
|
const { index, alreadyPresent } = findResult;
|
|
1151
1181
|
if (alreadyPresent) {
|
|
1152
|
-
|
|
1182
|
+
throw new Error(
|
|
1183
|
+
`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`,
|
|
1184
|
+
);
|
|
1153
1185
|
}
|
|
1154
1186
|
const preimageData = (await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index))!;
|
|
1155
1187
|
|
|
@@ -1158,7 +1190,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1158
1190
|
}
|
|
1159
1191
|
|
|
1160
1192
|
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1161
|
-
const committedDb = await this
|
|
1193
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1162
1194
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1163
1195
|
if (!lowLeafResult) {
|
|
1164
1196
|
return undefined;
|
|
@@ -1173,7 +1205,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1173
1205
|
}
|
|
1174
1206
|
|
|
1175
1207
|
public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1176
|
-
const committedDb = await this
|
|
1208
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1177
1209
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1178
1210
|
|
|
1179
1211
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1313,11 +1345,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1313
1345
|
{ isSimulation, skipFeeEnforcement }: { isSimulation?: boolean; skipFeeEnforcement?: boolean } = {},
|
|
1314
1346
|
): Promise<TxValidationResult> {
|
|
1315
1347
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1316
|
-
const verifier = isSimulation ? undefined : this.
|
|
1348
|
+
const verifier = isSimulation ? undefined : this.rpcProofVerifier;
|
|
1317
1349
|
|
|
1318
1350
|
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1319
1351
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1320
1352
|
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1353
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1321
1354
|
const validator = createTxValidatorForAcceptingTxsOverRPC(
|
|
1322
1355
|
db,
|
|
1323
1356
|
this.contractDataSource,
|
|
@@ -1334,6 +1367,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1334
1367
|
gasFees: await this.getCurrentMinFees(),
|
|
1335
1368
|
skipFeeEnforcement,
|
|
1336
1369
|
txsPermitted: !this.config.disableTransactions,
|
|
1370
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1371
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1372
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas,
|
|
1337
1373
|
},
|
|
1338
1374
|
this.log.getBindings(),
|
|
1339
1375
|
);
|
|
@@ -1358,7 +1394,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1358
1394
|
archiver.updateConfig(config);
|
|
1359
1395
|
}
|
|
1360
1396
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
1361
|
-
|
|
1397
|
+
await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
|
|
1398
|
+
if (newConfig.realProofs) {
|
|
1399
|
+
this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
|
|
1400
|
+
const rpcVerifier = await BBCircuitVerifier.new(newConfig);
|
|
1401
|
+
this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
|
|
1402
|
+
} else {
|
|
1403
|
+
this.peerProofVerifier = new TestCircuitVerifier();
|
|
1404
|
+
this.rpcProofVerifier = new TestCircuitVerifier();
|
|
1405
|
+
}
|
|
1362
1406
|
}
|
|
1363
1407
|
|
|
1364
1408
|
this.config = newConfig;
|
|
@@ -1600,7 +1644,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1600
1644
|
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1601
1645
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1602
1646
|
*/
|
|
1603
|
-
async
|
|
1647
|
+
protected async getWorldState(block: BlockParameter) {
|
|
1604
1648
|
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1605
1649
|
try {
|
|
1606
1650
|
// Attempt to sync the world state if necessary
|
|
@@ -1614,6 +1658,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1614
1658
|
return this.worldStateSynchronizer.getCommitted();
|
|
1615
1659
|
}
|
|
1616
1660
|
|
|
1661
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1662
|
+
let blockNumber: BlockNumber;
|
|
1617
1663
|
if (BlockHash.isBlockHash(block)) {
|
|
1618
1664
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1619
1665
|
if (block.equals(initialBlockHash)) {
|
|
@@ -1627,22 +1673,50 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1627
1673
|
`Block hash ${block.toString()} not found when querying world state. If the node API has been queried with anchor block hash possibly a reorg has occurred.`,
|
|
1628
1674
|
);
|
|
1629
1675
|
}
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1676
|
+
|
|
1677
|
+
blockNumber = header.getBlockNumber();
|
|
1678
|
+
} else {
|
|
1679
|
+
blockNumber = block as BlockNumber;
|
|
1633
1680
|
}
|
|
1634
1681
|
|
|
1635
|
-
//
|
|
1636
|
-
{
|
|
1637
|
-
|
|
1682
|
+
// Check it's within world state sync range
|
|
1683
|
+
if (blockNumber > blockSyncedTo) {
|
|
1684
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1685
|
+
}
|
|
1686
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1687
|
+
|
|
1688
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1638
1689
|
|
|
1639
|
-
|
|
1640
|
-
|
|
1690
|
+
// Double-check world-state synced to the same block hash as was requested
|
|
1691
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1692
|
+
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1693
|
+
if (!blockHash || !new BlockHash(blockHash).equals(block)) {
|
|
1694
|
+
throw new Error(
|
|
1695
|
+
`Block hash ${block.toString()} not found in world state at block number ${blockNumber}. If the node API has been queried with anchor block hash possibly a reorg has occurred.`,
|
|
1696
|
+
);
|
|
1641
1697
|
}
|
|
1698
|
+
}
|
|
1642
1699
|
|
|
1643
|
-
|
|
1644
|
-
|
|
1700
|
+
return snapshot;
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
/** Resolves a block parameter to a block number. */
|
|
1704
|
+
protected async resolveBlockNumber(block: BlockParameter): Promise<BlockNumber> {
|
|
1705
|
+
if (block === 'latest') {
|
|
1706
|
+
return BlockNumber(await this.blockSource.getBlockNumber());
|
|
1707
|
+
}
|
|
1708
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1709
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1710
|
+
if (block.equals(initialBlockHash)) {
|
|
1711
|
+
return BlockNumber.ZERO;
|
|
1712
|
+
}
|
|
1713
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1714
|
+
if (!header) {
|
|
1715
|
+
throw new Error(`Block hash ${block.toString()} not found.`);
|
|
1716
|
+
}
|
|
1717
|
+
return header.getBlockNumber();
|
|
1645
1718
|
}
|
|
1719
|
+
return block as BlockNumber;
|
|
1646
1720
|
}
|
|
1647
1721
|
|
|
1648
1722
|
/**
|