@aztec/validator-client 4.0.0-nightly.20250907 → 4.0.0-nightly.20260108

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 (43) hide show
  1. package/dest/block_proposal_handler.d.ts +53 -0
  2. package/dest/block_proposal_handler.d.ts.map +1 -0
  3. package/dest/block_proposal_handler.js +290 -0
  4. package/dest/config.d.ts +1 -1
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +10 -0
  7. package/dest/duties/validation_service.d.ts +11 -6
  8. package/dest/duties/validation_service.d.ts.map +1 -1
  9. package/dest/duties/validation_service.js +19 -7
  10. package/dest/factory.d.ts +16 -5
  11. package/dest/factory.d.ts.map +1 -1
  12. package/dest/factory.js +11 -1
  13. package/dest/index.d.ts +2 -1
  14. package/dest/index.d.ts.map +1 -1
  15. package/dest/index.js +1 -0
  16. package/dest/key_store/index.d.ts +1 -1
  17. package/dest/key_store/interface.d.ts +1 -1
  18. package/dest/key_store/local_key_store.d.ts +1 -1
  19. package/dest/key_store/local_key_store.d.ts.map +1 -1
  20. package/dest/key_store/local_key_store.js +1 -1
  21. package/dest/key_store/node_keystore_adapter.d.ts +1 -1
  22. package/dest/key_store/node_keystore_adapter.d.ts.map +1 -1
  23. package/dest/key_store/node_keystore_adapter.js +2 -4
  24. package/dest/key_store/web3signer_key_store.d.ts +1 -7
  25. package/dest/key_store/web3signer_key_store.d.ts.map +1 -1
  26. package/dest/key_store/web3signer_key_store.js +7 -8
  27. package/dest/metrics.d.ts +7 -5
  28. package/dest/metrics.d.ts.map +1 -1
  29. package/dest/metrics.js +25 -12
  30. package/dest/validator.d.ts +28 -27
  31. package/dest/validator.d.ts.map +1 -1
  32. package/dest/validator.js +579 -198
  33. package/package.json +17 -15
  34. package/src/block_proposal_handler.ts +346 -0
  35. package/src/config.ts +12 -0
  36. package/src/duties/validation_service.ts +30 -12
  37. package/src/factory.ts +37 -4
  38. package/src/index.ts +1 -0
  39. package/src/key_store/local_key_store.ts +1 -1
  40. package/src/key_store/node_keystore_adapter.ts +3 -4
  41. package/src/key_store/web3signer_key_store.ts +7 -10
  42. package/src/metrics.ts +34 -13
  43. package/src/validator.ts +281 -271
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/validator-client",
3
- "version": "4.0.0-nightly.20250907",
3
+ "version": "4.0.0-nightly.20260108",
4
4
  "main": "dest/index.js",
5
5
  "type": "module",
6
6
  "exports": {
@@ -18,8 +18,8 @@
18
18
  },
19
19
  "scripts": {
20
20
  "start": "node --no-warnings ./dest/bin",
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,25 +64,27 @@
64
64
  ]
65
65
  },
66
66
  "dependencies": {
67
- "@aztec/constants": "4.0.0-nightly.20250907",
68
- "@aztec/epoch-cache": "4.0.0-nightly.20250907",
69
- "@aztec/ethereum": "4.0.0-nightly.20250907",
70
- "@aztec/foundation": "4.0.0-nightly.20250907",
71
- "@aztec/node-keystore": "4.0.0-nightly.20250907",
72
- "@aztec/p2p": "4.0.0-nightly.20250907",
73
- "@aztec/prover-client": "4.0.0-nightly.20250907",
74
- "@aztec/slasher": "4.0.0-nightly.20250907",
75
- "@aztec/stdlib": "4.0.0-nightly.20250907",
76
- "@aztec/telemetry-client": "4.0.0-nightly.20250907",
67
+ "@aztec/blob-client": "4.0.0-nightly.20260108",
68
+ "@aztec/blob-lib": "4.0.0-nightly.20260108",
69
+ "@aztec/constants": "4.0.0-nightly.20260108",
70
+ "@aztec/epoch-cache": "4.0.0-nightly.20260108",
71
+ "@aztec/ethereum": "4.0.0-nightly.20260108",
72
+ "@aztec/foundation": "4.0.0-nightly.20260108",
73
+ "@aztec/node-keystore": "4.0.0-nightly.20260108",
74
+ "@aztec/p2p": "4.0.0-nightly.20260108",
75
+ "@aztec/slasher": "4.0.0-nightly.20260108",
76
+ "@aztec/stdlib": "4.0.0-nightly.20260108",
77
+ "@aztec/telemetry-client": "4.0.0-nightly.20260108",
77
78
  "koa": "^2.16.1",
78
- "koa-router": "^12.0.0",
79
+ "koa-router": "^13.1.1",
79
80
  "tslib": "^2.4.0",
80
- "viem": "2.23.7"
81
+ "viem": "npm:@aztec/viem@2.38.2"
81
82
  },
82
83
  "devDependencies": {
83
84
  "@jest/globals": "^30.0.0",
84
85
  "@types/jest": "^30.0.0",
85
86
  "@types/node": "^22.15.17",
87
+ "@typescript/native-preview": "7.0.0-dev.20251126.1",
86
88
  "jest": "^30.0.0",
87
89
  "jest-mock-extended": "^4.0.0",
88
90
  "ts-node": "^10.9.1",
@@ -0,0 +1,346 @@
1
+ import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
2
+ import { BlockNumber, CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
4
+ import { TimeoutError } from '@aztec/foundation/error';
5
+ import { createLogger } from '@aztec/foundation/log';
6
+ import { retryUntil } from '@aztec/foundation/retry';
7
+ import { DateProvider, Timer } from '@aztec/foundation/timer';
8
+ import type { P2P, PeerId } from '@aztec/p2p';
9
+ import { TxProvider } from '@aztec/p2p';
10
+ import { BlockProposalValidator } from '@aztec/p2p/msg_validators';
11
+ import type { L2Block, L2BlockSource } from '@aztec/stdlib/block';
12
+ import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
13
+ import type { IFullNodeBlockBuilder, ValidatorClientFullConfig } from '@aztec/stdlib/interfaces/server';
14
+ import { type L1ToL2MessageSource, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
15
+ import { type BlockProposal, ConsensusPayload } from '@aztec/stdlib/p2p';
16
+ import { BlockHeader, type FailedTx, GlobalVariables, type Tx } from '@aztec/stdlib/tx';
17
+ import {
18
+ ReExFailedTxsError,
19
+ ReExStateMismatchError,
20
+ ReExTimeoutError,
21
+ TransactionsNotAvailableError,
22
+ } from '@aztec/stdlib/validators';
23
+ import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
24
+
25
+ import type { ValidatorMetrics } from './metrics.js';
26
+
27
+ export type BlockProposalValidationFailureReason =
28
+ | 'invalid_proposal'
29
+ | 'parent_block_not_found'
30
+ | 'parent_block_wrong_slot'
31
+ | 'in_hash_mismatch'
32
+ | 'block_number_already_exists'
33
+ | 'txs_not_available'
34
+ | 'state_mismatch'
35
+ | 'failed_txs'
36
+ | 'timeout'
37
+ | 'unknown_error';
38
+
39
+ type ReexecuteTransactionsResult = {
40
+ block: L2Block;
41
+ failedTxs: FailedTx[];
42
+ reexecutionTimeMs: number;
43
+ totalManaUsed: number;
44
+ };
45
+
46
+ export type BlockProposalValidationSuccessResult = {
47
+ isValid: true;
48
+ blockNumber: BlockNumber;
49
+ reexecutionResult?: ReexecuteTransactionsResult;
50
+ };
51
+
52
+ export type BlockProposalValidationFailureResult = {
53
+ isValid: false;
54
+ reason: BlockProposalValidationFailureReason;
55
+ blockNumber?: BlockNumber;
56
+ reexecutionResult?: ReexecuteTransactionsResult;
57
+ };
58
+
59
+ export type BlockProposalValidationResult = BlockProposalValidationSuccessResult | BlockProposalValidationFailureResult;
60
+
61
+ export class BlockProposalHandler {
62
+ public readonly tracer: Tracer;
63
+
64
+ constructor(
65
+ private blockBuilder: IFullNodeBlockBuilder,
66
+ private blockSource: L2BlockSource,
67
+ private l1ToL2MessageSource: L1ToL2MessageSource,
68
+ private txProvider: TxProvider,
69
+ private blockProposalValidator: BlockProposalValidator,
70
+ private config: ValidatorClientFullConfig,
71
+ private metrics?: ValidatorMetrics,
72
+ private dateProvider: DateProvider = new DateProvider(),
73
+ telemetry: TelemetryClient = getTelemetryClient(),
74
+ private log = createLogger('validator:block-proposal-handler'),
75
+ ) {
76
+ if (config.fishermanMode) {
77
+ this.log = this.log.createChild('[FISHERMAN]');
78
+ }
79
+ this.tracer = telemetry.getTracer('BlockProposalHandler');
80
+ }
81
+
82
+ registerForReexecution(p2pClient: P2P): BlockProposalHandler {
83
+ const handler = async (proposal: BlockProposal, proposalSender: PeerId) => {
84
+ try {
85
+ const result = await this.handleBlockProposal(proposal, proposalSender, true);
86
+ if (result.isValid) {
87
+ this.log.info(`Non-validator reexecution completed for slot ${proposal.slotNumber}`, {
88
+ blockNumber: result.blockNumber,
89
+ reexecutionTimeMs: result.reexecutionResult?.reexecutionTimeMs,
90
+ totalManaUsed: result.reexecutionResult?.totalManaUsed,
91
+ numTxs: result.reexecutionResult?.block?.body?.txEffects?.length ?? 0,
92
+ });
93
+ } else {
94
+ this.log.warn(`Non-validator reexecution failed for slot ${proposal.slotNumber}`, {
95
+ blockNumber: result.blockNumber,
96
+ reason: result.reason,
97
+ });
98
+ }
99
+ } catch (error) {
100
+ this.log.error('Error processing block proposal in non-validator handler', error);
101
+ }
102
+ return undefined; // Non-validator nodes don't return attestations
103
+ };
104
+
105
+ p2pClient.registerBlockProposalHandler(handler);
106
+ return this;
107
+ }
108
+
109
+ async handleBlockProposal(
110
+ proposal: BlockProposal,
111
+ proposalSender: PeerId,
112
+ shouldReexecute: boolean,
113
+ ): Promise<BlockProposalValidationResult> {
114
+ const slotNumber = proposal.slotNumber;
115
+ const proposer = proposal.getSender();
116
+ const config = this.blockBuilder.getConfig();
117
+
118
+ // Reject proposals with invalid signatures
119
+ if (!proposer) {
120
+ this.log.warn(`Received proposal with invalid signature for slot ${slotNumber}`);
121
+ return { isValid: false, reason: 'invalid_proposal' };
122
+ }
123
+
124
+ const proposalInfo = { ...proposal.toBlockInfo(), proposer: proposer.toString() };
125
+ this.log.info(`Processing proposal for slot ${slotNumber}`, {
126
+ ...proposalInfo,
127
+ txHashes: proposal.txHashes.map(t => t.toString()),
128
+ });
129
+
130
+ // Check that the proposal is from the current proposer, or the next proposer
131
+ // This should have been handled by the p2p layer, but we double check here out of caution
132
+ const invalidProposal = await this.blockProposalValidator.validate(proposal);
133
+ if (invalidProposal) {
134
+ this.log.warn(`Proposal is not valid, skipping processing`, proposalInfo);
135
+ return { isValid: false, reason: 'invalid_proposal' };
136
+ }
137
+
138
+ // Check that the parent proposal is a block we know, otherwise reexecution would fail
139
+ const parentBlockHeader = await this.getParentBlock(proposal);
140
+ if (parentBlockHeader === undefined) {
141
+ this.log.warn(`Parent block for proposal not found, skipping processing`, proposalInfo);
142
+ return { isValid: false, reason: 'parent_block_not_found' };
143
+ }
144
+
145
+ // Check that the parent block's slot is less than the proposal's slot (should not happen, but we check anyway)
146
+ if (parentBlockHeader !== 'genesis' && parentBlockHeader.getSlot() >= slotNumber) {
147
+ this.log.warn(`Parent block slot is greater than or equal to proposal slot, skipping processing`, {
148
+ parentBlockSlot: parentBlockHeader.getSlot().toString(),
149
+ proposalSlot: slotNumber.toString(),
150
+ ...proposalInfo,
151
+ });
152
+ return { isValid: false, reason: 'parent_block_wrong_slot' };
153
+ }
154
+
155
+ // Compute the block number based on the parent block
156
+ const blockNumber =
157
+ parentBlockHeader === 'genesis'
158
+ ? BlockNumber(INITIAL_L2_BLOCK_NUM)
159
+ : BlockNumber(parentBlockHeader.getBlockNumber() + 1);
160
+
161
+ // Check that this block number does not exist already
162
+ const existingBlock = await this.blockSource.getBlockHeader(blockNumber);
163
+ if (existingBlock) {
164
+ this.log.warn(`Block number ${blockNumber} already exists, skipping processing`, proposalInfo);
165
+ return { isValid: false, blockNumber, reason: 'block_number_already_exists' };
166
+ }
167
+
168
+ // Collect txs from the proposal. We start doing this as early as possible,
169
+ // and we do it even if we don't plan to re-execute the txs, so that we have them if another node needs them.
170
+ const { txs, missingTxs } = await this.txProvider.getTxsForBlockProposal(proposal, blockNumber, {
171
+ pinnedPeer: proposalSender,
172
+ deadline: this.getReexecutionDeadline(slotNumber, config),
173
+ });
174
+
175
+ // Check that I have the same set of l1ToL2Messages as the proposal
176
+ const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(
177
+ CheckpointNumber.fromBlockNumber(blockNumber),
178
+ );
179
+ const computedInHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
180
+ const proposalInHash = proposal.payload.header.contentCommitment.inHash;
181
+ if (!computedInHash.equals(proposalInHash)) {
182
+ this.log.warn(`L1 to L2 messages in hash mismatch, skipping processing`, {
183
+ proposalInHash: proposalInHash.toString(),
184
+ computedInHash: computedInHash.toString(),
185
+ ...proposalInfo,
186
+ });
187
+ return { isValid: false, blockNumber, reason: 'in_hash_mismatch' };
188
+ }
189
+
190
+ // Check that all of the transactions in the proposal are available
191
+ if (missingTxs.length > 0) {
192
+ this.log.warn(`Missing ${missingTxs.length} txs to process proposal`, { ...proposalInfo, missingTxs });
193
+ return { isValid: false, blockNumber, reason: 'txs_not_available' };
194
+ }
195
+
196
+ // Try re-executing the transactions in the proposal if needed
197
+ let reexecutionResult;
198
+ if (shouldReexecute) {
199
+ try {
200
+ this.log.verbose(`Re-executing transactions in the proposal`, proposalInfo);
201
+ reexecutionResult = await this.reexecuteTransactions(proposal, blockNumber, txs, l1ToL2Messages);
202
+ } catch (error) {
203
+ this.log.error(`Error reexecuting txs while processing block proposal`, error, proposalInfo);
204
+ const reason = this.getReexecuteFailureReason(error);
205
+ return { isValid: false, blockNumber, reason, reexecutionResult };
206
+ }
207
+ }
208
+
209
+ this.log.info(`Successfully processed proposal for slot ${slotNumber}`, proposalInfo);
210
+ return { isValid: true, blockNumber, reexecutionResult };
211
+ }
212
+
213
+ private async getParentBlock(proposal: BlockProposal): Promise<'genesis' | BlockHeader | undefined> {
214
+ const parentArchive = proposal.payload.header.lastArchiveRoot;
215
+ const slot = proposal.slotNumber;
216
+ const config = this.blockBuilder.getConfig();
217
+ const { genesisArchiveRoot } = await this.blockSource.getGenesisValues();
218
+
219
+ if (parentArchive.equals(genesisArchiveRoot)) {
220
+ return 'genesis';
221
+ }
222
+
223
+ const deadline = this.getReexecutionDeadline(slot, config);
224
+ const currentTime = this.dateProvider.now();
225
+ const timeoutDurationMs = deadline.getTime() - currentTime;
226
+
227
+ try {
228
+ return (
229
+ (await this.blockSource.getBlockHeaderByArchive(parentArchive)) ??
230
+ (timeoutDurationMs <= 0
231
+ ? undefined
232
+ : await retryUntil(
233
+ () =>
234
+ this.blockSource.syncImmediate().then(() => this.blockSource.getBlockHeaderByArchive(parentArchive)),
235
+ 'force archiver sync',
236
+ timeoutDurationMs / 1000,
237
+ 0.5,
238
+ ))
239
+ );
240
+ } catch (err) {
241
+ if (err instanceof TimeoutError) {
242
+ this.log.debug(`Timed out getting parent block by archive root`, { parentArchive });
243
+ } else {
244
+ this.log.error('Error getting parent block by archive root', err, { parentArchive });
245
+ }
246
+ return undefined;
247
+ }
248
+ }
249
+
250
+ private getReexecutionDeadline(slot: SlotNumber, config: { l1GenesisTime: bigint; slotDuration: number }): Date {
251
+ const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
252
+ const msNeededForPropagationAndPublishing = this.config.validatorReexecuteDeadlineMs;
253
+ return new Date(nextSlotTimestampSeconds * 1000 - msNeededForPropagationAndPublishing);
254
+ }
255
+
256
+ private getReexecuteFailureReason(err: any) {
257
+ if (err instanceof ReExStateMismatchError) {
258
+ return 'state_mismatch';
259
+ } else if (err instanceof ReExFailedTxsError) {
260
+ return 'failed_txs';
261
+ } else if (err instanceof ReExTimeoutError) {
262
+ return 'timeout';
263
+ } else {
264
+ return 'unknown_error';
265
+ }
266
+ }
267
+
268
+ async reexecuteTransactions(
269
+ proposal: BlockProposal,
270
+ blockNumber: BlockNumber,
271
+ txs: Tx[],
272
+ l1ToL2Messages: Fr[],
273
+ ): Promise<ReexecuteTransactionsResult> {
274
+ const { header } = proposal.payload;
275
+ const { txHashes } = proposal;
276
+
277
+ // If we do not have all of the transactions, then we should fail
278
+ if (txs.length !== txHashes.length) {
279
+ const foundTxHashes = txs.map(tx => tx.getTxHash());
280
+ const missingTxHashes = txHashes.filter(txHash => !foundTxHashes.includes(txHash));
281
+ throw new TransactionsNotAvailableError(missingTxHashes);
282
+ }
283
+
284
+ // Use the sequencer's block building logic to re-execute the transactions
285
+ const timer = new Timer();
286
+ const config = this.blockBuilder.getConfig();
287
+
288
+ // We source most global variables from the proposal
289
+ const globalVariables = GlobalVariables.from({
290
+ slotNumber: proposal.payload.header.slotNumber, // checked in the block proposal validator
291
+ coinbase: proposal.payload.header.coinbase, // set arbitrarily by the proposer
292
+ feeRecipient: proposal.payload.header.feeRecipient, // set arbitrarily by the proposer
293
+ gasFees: proposal.payload.header.gasFees, // validated by the rollup contract
294
+ blockNumber, // computed from the parent block and checked it does not exist in archiver
295
+ timestamp: header.timestamp, // checked in the rollup contract against the slot number
296
+ chainId: new Fr(config.l1ChainId),
297
+ version: new Fr(config.rollupVersion),
298
+ });
299
+
300
+ const { block, failedTxs } = await this.blockBuilder.buildBlock(txs, l1ToL2Messages, globalVariables, {
301
+ deadline: this.getReexecutionDeadline(proposal.payload.header.slotNumber, config),
302
+ });
303
+
304
+ const numFailedTxs = failedTxs.length;
305
+ const slot = proposal.slotNumber;
306
+ this.log.verbose(`Transaction re-execution complete for slot ${slot}`, {
307
+ numFailedTxs,
308
+ numProposalTxs: txHashes.length,
309
+ numProcessedTxs: block.body.txEffects.length,
310
+ slot,
311
+ });
312
+
313
+ if (numFailedTxs > 0) {
314
+ this.metrics?.recordFailedReexecution(proposal);
315
+ throw new ReExFailedTxsError(numFailedTxs);
316
+ }
317
+
318
+ if (block.body.txEffects.length !== txHashes.length) {
319
+ this.metrics?.recordFailedReexecution(proposal);
320
+ throw new ReExTimeoutError();
321
+ }
322
+
323
+ // Throw a ReExStateMismatchError error if state updates do not match
324
+ const blockPayload = ConsensusPayload.fromBlock(block);
325
+ if (!blockPayload.equals(proposal.payload)) {
326
+ this.log.warn(`Re-execution state mismatch for slot ${slot}`, {
327
+ expected: blockPayload.toInspect(),
328
+ actual: proposal.payload.toInspect(),
329
+ });
330
+ this.metrics?.recordFailedReexecution(proposal);
331
+ throw new ReExStateMismatchError(proposal.archive, block.archive.root);
332
+ }
333
+
334
+ const reexecutionTimeMs = timer.ms();
335
+ const totalManaUsed = block.header.totalManaUsed.toNumber() / 1e6;
336
+
337
+ this.metrics?.recordReex(reexecutionTimeMs, txs.length, totalManaUsed);
338
+
339
+ return {
340
+ block,
341
+ failedTxs,
342
+ reexecutionTimeMs,
343
+ totalManaUsed,
344
+ };
345
+ }
346
+ }
package/src/config.ts CHANGED
@@ -58,6 +58,18 @@ export const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientCo
58
58
  description: 'Will re-execute until this many milliseconds are left in the slot',
59
59
  ...numberConfigHelper(6000),
60
60
  },
61
+ alwaysReexecuteBlockProposals: {
62
+ env: 'ALWAYS_REEXECUTE_BLOCK_PROPOSALS',
63
+ description:
64
+ 'Whether to always reexecute block proposals, even for non-validator nodes (useful for monitoring network status).',
65
+ ...booleanConfigHelper(false),
66
+ },
67
+ fishermanMode: {
68
+ env: 'FISHERMAN_MODE',
69
+ description:
70
+ 'Whether to run in fisherman mode: validates all proposals and attestations but does not broadcast attestations or participate in consensus.',
71
+ ...booleanConfigHelper(false),
72
+ },
61
73
  };
62
74
 
63
75
  /**
@@ -1,8 +1,10 @@
1
1
  import { Buffer32 } from '@aztec/foundation/buffer';
2
- import { keccak256 } from '@aztec/foundation/crypto';
2
+ import { keccak256 } from '@aztec/foundation/crypto/keccak';
3
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
4
  import type { EthAddress } from '@aztec/foundation/eth-address';
4
5
  import type { Signature } from '@aztec/foundation/eth-signature';
5
- import type { Fr } from '@aztec/foundation/fields';
6
+ import { createLogger } from '@aztec/foundation/log';
7
+ import type { CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
6
8
  import {
7
9
  BlockAttestation,
8
10
  BlockProposal,
@@ -10,28 +12,30 @@ import {
10
12
  ConsensusPayload,
11
13
  SignatureDomainSeparator,
12
14
  } from '@aztec/stdlib/p2p';
13
- import type { ProposedBlockHeader, StateReference, Tx } from '@aztec/stdlib/tx';
15
+ import type { CheckpointHeader } from '@aztec/stdlib/rollup';
16
+ import type { Tx } from '@aztec/stdlib/tx';
14
17
 
15
18
  import type { ValidatorKeyStore } from '../key_store/interface.js';
16
19
 
17
20
  export class ValidationService {
18
- constructor(private keyStore: ValidatorKeyStore) {}
21
+ constructor(
22
+ private keyStore: ValidatorKeyStore,
23
+ private log = createLogger('validator:validation-service'),
24
+ ) {}
19
25
 
20
26
  /**
21
27
  * Create a block proposal with the given header, archive, and transactions
22
28
  *
23
- * @param blockNumber - The block number this proposal is for
24
29
  * @param header - The block header
25
30
  * @param archive - The archive of the current block
26
31
  * @param txs - TxHash[] ordered list of transactions
32
+ * @param options - Block proposal options (including broadcastInvalidBlockProposal for testing)
27
33
  *
28
34
  * @returns A block proposal signing the above information (not the current implementation!!!)
29
35
  */
30
36
  async createBlockProposal(
31
- blockNumber: number,
32
- header: ProposedBlockHeader,
37
+ header: CheckpointHeader,
33
38
  archive: Fr,
34
- stateReference: StateReference,
35
39
  txs: Tx[],
36
40
  proposerAttesterAddress: EthAddress | undefined,
37
41
  options: BlockProposalOptions,
@@ -47,9 +51,14 @@ export class ValidationService {
47
51
  // TODO: check if this is calculated earlier / can not be recomputed
48
52
  const txHashes = await Promise.all(txs.map(tx => tx.getTxHash()));
49
53
 
54
+ // For testing: change the new archive to trigger state_mismatch validation failure
55
+ if (options.broadcastInvalidBlockProposal) {
56
+ archive = Fr.random();
57
+ this.log.warn(`Creating INVALID block proposal for slot ${header.slotNumber}`);
58
+ }
59
+
50
60
  return BlockProposal.createProposalFromSigner(
51
- blockNumber,
52
- new ConsensusPayload(header, archive, stateReference),
61
+ new ConsensusPayload(header, archive),
53
62
  txHashes,
54
63
  options.publishFullTxs ? txs : undefined,
55
64
  payloadSigner,
@@ -73,7 +82,16 @@ export class ValidationService {
73
82
  const signatures = await Promise.all(
74
83
  attestors.map(attestor => this.keyStore.signMessageWithAddress(attestor, buf)),
75
84
  );
76
- //await this.keyStore.signMessage(buf);
77
- return signatures.map(sig => new BlockAttestation(proposal.blockNumber, proposal.payload, sig));
85
+ return signatures.map(sig => new BlockAttestation(proposal.payload, sig, proposal.signature));
86
+ }
87
+
88
+ async signAttestationsAndSigners(
89
+ attestationsAndSigners: CommitteeAttestationsAndSigners,
90
+ proposer: EthAddress,
91
+ ): Promise<Signature> {
92
+ const buf = Buffer32.fromBuffer(
93
+ keccak256(attestationsAndSigners.getPayloadToSign(SignatureDomainSeparator.attestationsAndSigners)),
94
+ );
95
+ return await this.keyStore.signMessageWithAddress(proposer, buf);
78
96
  }
79
97
  }
package/src/factory.ts CHANGED
@@ -1,17 +1,48 @@
1
+ import type { BlobClientInterface } from '@aztec/blob-client/client';
1
2
  import type { EpochCache } from '@aztec/epoch-cache';
2
3
  import type { DateProvider } from '@aztec/foundation/timer';
3
4
  import type { KeystoreManager } from '@aztec/node-keystore';
4
- import type { P2PClient } from '@aztec/p2p';
5
+ import { BlockProposalValidator, type P2PClient } from '@aztec/p2p';
5
6
  import type { L2BlockSource } from '@aztec/stdlib/block';
6
- import type { IFullNodeBlockBuilder, SlasherConfig } from '@aztec/stdlib/interfaces/server';
7
+ import type { IFullNodeBlockBuilder, ValidatorClientFullConfig } from '@aztec/stdlib/interfaces/server';
7
8
  import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
8
9
  import type { TelemetryClient } from '@aztec/telemetry-client';
9
10
 
10
- import type { ValidatorClientConfig } from './config.js';
11
+ import { BlockProposalHandler } from './block_proposal_handler.js';
12
+ import { ValidatorMetrics } from './metrics.js';
11
13
  import { ValidatorClient } from './validator.js';
12
14
 
15
+ export function createBlockProposalHandler(
16
+ config: ValidatorClientFullConfig,
17
+ deps: {
18
+ blockBuilder: IFullNodeBlockBuilder;
19
+ blockSource: L2BlockSource;
20
+ l1ToL2MessageSource: L1ToL2MessageSource;
21
+ p2pClient: P2PClient;
22
+ epochCache: EpochCache;
23
+ dateProvider: DateProvider;
24
+ telemetry: TelemetryClient;
25
+ },
26
+ ) {
27
+ const metrics = new ValidatorMetrics(deps.telemetry);
28
+ const blockProposalValidator = new BlockProposalValidator(deps.epochCache, {
29
+ txsPermitted: !config.disableTransactions,
30
+ });
31
+ return new BlockProposalHandler(
32
+ deps.blockBuilder,
33
+ deps.blockSource,
34
+ deps.l1ToL2MessageSource,
35
+ deps.p2pClient.getTxProvider(),
36
+ blockProposalValidator,
37
+ config,
38
+ metrics,
39
+ deps.dateProvider,
40
+ deps.telemetry,
41
+ );
42
+ }
43
+
13
44
  export function createValidatorClient(
14
- config: ValidatorClientConfig & Pick<SlasherConfig, 'slashBroadcastedInvalidBlockPenalty'>,
45
+ config: ValidatorClientFullConfig,
15
46
  deps: {
16
47
  blockBuilder: IFullNodeBlockBuilder;
17
48
  p2pClient: P2PClient;
@@ -21,6 +52,7 @@ export function createValidatorClient(
21
52
  dateProvider: DateProvider;
22
53
  epochCache: EpochCache;
23
54
  keyStoreManager: KeystoreManager | undefined;
55
+ blobClient: BlobClientInterface;
24
56
  },
25
57
  ) {
26
58
  if (config.disableValidator || !deps.keyStoreManager) {
@@ -37,6 +69,7 @@ export function createValidatorClient(
37
69
  deps.l1ToL2MessageSource,
38
70
  txProvider,
39
71
  deps.keyStoreManager,
72
+ deps.blobClient,
40
73
  deps.dateProvider,
41
74
  deps.telemetry,
42
75
  );
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './block_proposal_handler.js';
1
2
  export * from './config.js';
2
3
  export * from './factory.js';
3
4
  export * from './validator.js';
@@ -1,5 +1,5 @@
1
1
  import { Buffer32 } from '@aztec/foundation/buffer';
2
- import { Secp256k1Signer } from '@aztec/foundation/crypto';
2
+ import { Secp256k1Signer } from '@aztec/foundation/crypto/secp256k1-signer';
3
3
  import type { EthAddress } from '@aztec/foundation/eth-address';
4
4
  import type { Signature } from '@aztec/foundation/eth-signature';
5
5
 
@@ -1,4 +1,4 @@
1
- import type { EthSigner } from '@aztec/ethereum';
1
+ import type { EthSigner } from '@aztec/ethereum/eth-signer';
2
2
  import type { Buffer32 } from '@aztec/foundation/buffer';
3
3
  import { EthAddress } from '@aztec/foundation/eth-address';
4
4
  import type { Signature } from '@aztec/foundation/eth-signature';
@@ -324,7 +324,7 @@ export class NodeKeystoreAdapter implements ExtendedValidatorKeyStore {
324
324
  */
325
325
  getCoinbaseAddress(attesterAddress: EthAddress): EthAddress {
326
326
  const validatorIndex = this.findValidatorIndexForAttester(attesterAddress);
327
- return this.keystoreManager.getCoinbaseAddress(validatorIndex);
327
+ return this.keystoreManager.getCoinbaseAddress(validatorIndex, attesterAddress);
328
328
  }
329
329
 
330
330
  /**
@@ -358,8 +358,7 @@ export class NodeKeystoreAdapter implements ExtendedValidatorKeyStore {
358
358
  */
359
359
  getFeeRecipient(attesterAddress: EthAddress): AztecAddress {
360
360
  const validatorIndex = this.findValidatorIndexForAttester(attesterAddress);
361
- const feeRecipientHex = this.keystoreManager.getFeeRecipient(validatorIndex);
362
- return AztecAddress.fromString(feeRecipientHex);
361
+ return this.keystoreManager.getFeeRecipient(validatorIndex);
363
362
  }
364
363
 
365
364
  /**
@@ -1,4 +1,5 @@
1
1
  import type { Buffer32 } from '@aztec/foundation/buffer';
2
+ import { normalizeSignature } from '@aztec/foundation/crypto/secp256k1-signer';
2
3
  import { EthAddress } from '@aztec/foundation/eth-address';
3
4
  import { Signature } from '@aztec/foundation/eth-signature';
4
5
 
@@ -45,11 +46,8 @@ export class Web3SignerKeyStore implements ValidatorKeyStore {
45
46
  * @param typedData - The complete EIP-712 typed data structure (domain, types, primaryType, message)
46
47
  * @return signatures
47
48
  */
48
- public async signTypedData(typedData: TypedDataDefinition): Promise<Signature[]> {
49
- const signatures = await Promise.all(
50
- this.addresses.map(address => this.makeJsonRpcSignTypedDataRequest(address, typedData)),
51
- );
52
- return signatures;
49
+ public signTypedData(typedData: TypedDataDefinition): Promise<Signature[]> {
50
+ return Promise.all(this.addresses.map(address => this.makeJsonRpcSignTypedDataRequest(address, typedData)));
53
51
  }
54
52
 
55
53
  /**
@@ -73,9 +71,8 @@ export class Web3SignerKeyStore implements ValidatorKeyStore {
73
71
  * @param message - The message to sign
74
72
  * @return signatures
75
73
  */
76
- public async signMessage(message: Buffer32): Promise<Signature[]> {
77
- const signatures = await Promise.all(this.addresses.map(address => this.makeJsonRpcSignRequest(address, message)));
78
- return signatures;
74
+ public signMessage(message: Buffer32): Promise<Signature[]> {
75
+ return Promise.all(this.addresses.map(address => this.makeJsonRpcSignRequest(address, message)));
79
76
  }
80
77
 
81
78
  /**
@@ -144,7 +141,7 @@ export class Web3SignerKeyStore implements ValidatorKeyStore {
144
141
  }
145
142
 
146
143
  // Parse the signature from the hex string
147
- return Signature.fromString(signatureHex as `0x${string}`);
144
+ return normalizeSignature(Signature.fromString(signatureHex as `0x${string}`));
148
145
  }
149
146
 
150
147
  private async makeJsonRpcSignTypedDataRequest(
@@ -190,6 +187,6 @@ export class Web3SignerKeyStore implements ValidatorKeyStore {
190
187
  signatureHex = '0x' + signatureHex;
191
188
  }
192
189
 
193
- return Signature.fromString(signatureHex as `0x${string}`);
190
+ return normalizeSignature(Signature.fromString(signatureHex as `0x${string}`));
194
191
  }
195
192
  }