@aztec/validator-client 0.0.0-test.1 → 0.0.1-commit.017a351

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 (66) hide show
  1. package/README.md +325 -0
  2. package/dest/checkpoint_builder.d.ts +79 -0
  3. package/dest/checkpoint_builder.d.ts.map +1 -0
  4. package/dest/checkpoint_builder.js +251 -0
  5. package/dest/config.d.ts +3 -14
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +75 -12
  8. package/dest/duties/validation_service.d.ts +49 -13
  9. package/dest/duties/validation_service.d.ts.map +1 -1
  10. package/dest/duties/validation_service.js +112 -18
  11. package/dest/factory.d.ts +34 -6
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +19 -6
  14. package/dest/index.d.ts +5 -2
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +4 -1
  17. package/dest/key_store/ha_key_store.d.ts +99 -0
  18. package/dest/key_store/ha_key_store.d.ts.map +1 -0
  19. package/dest/key_store/ha_key_store.js +208 -0
  20. package/dest/key_store/index.d.ts +4 -1
  21. package/dest/key_store/index.d.ts.map +1 -1
  22. package/dest/key_store/index.js +3 -0
  23. package/dest/key_store/interface.d.ts +85 -6
  24. package/dest/key_store/interface.d.ts.map +1 -1
  25. package/dest/key_store/interface.js +3 -3
  26. package/dest/key_store/local_key_store.d.ts +46 -11
  27. package/dest/key_store/local_key_store.d.ts.map +1 -1
  28. package/dest/key_store/local_key_store.js +68 -17
  29. package/dest/key_store/node_keystore_adapter.d.ts +151 -0
  30. package/dest/key_store/node_keystore_adapter.d.ts.map +1 -0
  31. package/dest/key_store/node_keystore_adapter.js +330 -0
  32. package/dest/key_store/web3signer_key_store.d.ts +66 -0
  33. package/dest/key_store/web3signer_key_store.d.ts.map +1 -0
  34. package/dest/key_store/web3signer_key_store.js +156 -0
  35. package/dest/metrics.d.ts +25 -5
  36. package/dest/metrics.d.ts.map +1 -1
  37. package/dest/metrics.js +86 -21
  38. package/dest/proposal_handler.d.ts +134 -0
  39. package/dest/proposal_handler.d.ts.map +1 -0
  40. package/dest/proposal_handler.js +1072 -0
  41. package/dest/validator.d.ts +109 -59
  42. package/dest/validator.d.ts.map +1 -1
  43. package/dest/validator.js +698 -171
  44. package/package.json +37 -21
  45. package/src/checkpoint_builder.ts +417 -0
  46. package/src/config.ts +87 -26
  47. package/src/duties/validation_service.ts +200 -21
  48. package/src/factory.ts +82 -11
  49. package/src/index.ts +4 -1
  50. package/src/key_store/ha_key_store.ts +269 -0
  51. package/src/key_store/index.ts +3 -0
  52. package/src/key_store/interface.ts +100 -5
  53. package/src/key_store/local_key_store.ts +77 -18
  54. package/src/key_store/node_keystore_adapter.ts +398 -0
  55. package/src/key_store/web3signer_key_store.ts +205 -0
  56. package/src/metrics.ts +121 -22
  57. package/src/proposal_handler.ts +1161 -0
  58. package/src/validator.ts +975 -222
  59. package/dest/errors/index.d.ts +0 -2
  60. package/dest/errors/index.d.ts.map +0 -1
  61. package/dest/errors/index.js +0 -1
  62. package/dest/errors/validator.error.d.ts +0 -29
  63. package/dest/errors/validator.error.d.ts.map +0 -1
  64. package/dest/errors/validator.error.js +0 -45
  65. package/src/errors/index.ts +0 -1
  66. package/src/errors/validator.error.ts +0 -55
@@ -0,0 +1,251 @@
1
+ import { NUM_CHECKPOINT_END_MARKER_FIELDS, getNumBlockEndBlobFields } from '@aztec/blob-lib/encoding';
2
+ import { BLOBS_PER_CHECKPOINT, FIELDS_PER_BLOB, MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT } from '@aztec/constants';
3
+ import { merge, pick, sum } from '@aztec/foundation/collection';
4
+ import { createLogger } from '@aztec/foundation/log';
5
+ import { bufferToHex } from '@aztec/foundation/string';
6
+ import { elapsed } from '@aztec/foundation/timer';
7
+ import { createTxValidatorForBlockBuilding, getDefaultAllowedSetupFunctions } from '@aztec/p2p/msg_validators';
8
+ import { LightweightCheckpointBuilder } from '@aztec/prover-client/light';
9
+ import { GuardedMerkleTreeOperations, PublicContractsDB, PublicProcessor, createPublicTxSimulatorForBlockBuilding } from '@aztec/simulator/server';
10
+ import { Gas } from '@aztec/stdlib/gas';
11
+ import { FullNodeBlockBuilderConfigKeys, InsufficientValidTxsError } from '@aztec/stdlib/interfaces/server';
12
+ import { NullDebugLogStore } from '@aztec/stdlib/logs';
13
+ import { MerkleTreeId } from '@aztec/stdlib/trees';
14
+ import { GlobalVariables } from '@aztec/stdlib/tx';
15
+ import { getTelemetryClient } from '@aztec/telemetry-client';
16
+ import { ForkCheckpoint } from '@aztec/world-state';
17
+ /**
18
+ * Builder for a single checkpoint. Handles building blocks within the checkpoint
19
+ * and completing it.
20
+ */ export class CheckpointBuilder {
21
+ checkpointBuilder;
22
+ fork;
23
+ config;
24
+ contractDataSource;
25
+ dateProvider;
26
+ telemetryClient;
27
+ debugLogStore;
28
+ log;
29
+ /** Persistent contracts DB shared across all blocks in this checkpoint. */ contractsDB;
30
+ constructor(checkpointBuilder, fork, config, contractDataSource, dateProvider, telemetryClient, bindings, debugLogStore = new NullDebugLogStore()){
31
+ this.checkpointBuilder = checkpointBuilder;
32
+ this.fork = fork;
33
+ this.config = config;
34
+ this.contractDataSource = contractDataSource;
35
+ this.dateProvider = dateProvider;
36
+ this.telemetryClient = telemetryClient;
37
+ this.debugLogStore = debugLogStore;
38
+ this.log = createLogger('checkpoint-builder', {
39
+ ...bindings,
40
+ instanceId: `checkpoint-${checkpointBuilder.checkpointNumber}`
41
+ });
42
+ this.contractsDB = new PublicContractsDB(this.contractDataSource, this.log.getBindings());
43
+ }
44
+ getConstantData() {
45
+ return this.checkpointBuilder.constants;
46
+ }
47
+ /**
48
+ * Builds a single block within this checkpoint.
49
+ * Automatically caps gas and blob field limits based on checkpoint-level budgets and prior blocks.
50
+ */ async buildBlock(pendingTxs, blockNumber, timestamp, opts) {
51
+ const slot = this.checkpointBuilder.constants.slotNumber;
52
+ this.log.verbose(`Building block ${blockNumber} for slot ${slot} within checkpoint`, {
53
+ slot,
54
+ blockNumber,
55
+ ...opts,
56
+ currentTime: new Date(this.dateProvider.now())
57
+ });
58
+ const constants = this.checkpointBuilder.constants;
59
+ const globalVariables = GlobalVariables.from({
60
+ chainId: constants.chainId,
61
+ version: constants.version,
62
+ blockNumber,
63
+ slotNumber: constants.slotNumber,
64
+ timestamp,
65
+ coinbase: constants.coinbase,
66
+ feeRecipient: constants.feeRecipient,
67
+ gasFees: constants.gasFees
68
+ });
69
+ const { processor, validator } = await this.makeBlockBuilderDeps(globalVariables, this.fork);
70
+ // Cap gas limits amd available blob fields by remaining checkpoint-level budgets
71
+ const cappedOpts = {
72
+ ...opts,
73
+ ...this.capLimitsByCheckpointBudgets(opts)
74
+ };
75
+ // Create a block-level checkpoint on the contracts DB so we can roll back on failure
76
+ this.contractsDB.createCheckpoint();
77
+ // We execute all merkle tree operations on a world state fork checkpoint
78
+ // This enables us to discard all modifications in the event that we fail to successfully process sufficient transactions
79
+ const forkCheckpoint = await ForkCheckpoint.new(this.fork);
80
+ try {
81
+ const [publicProcessorDuration, [processedTxs, failedTxs, usedTxs]] = await elapsed(()=>processor.process(pendingTxs, cappedOpts, validator));
82
+ // Throw before updating state if we don't have enough valid txs
83
+ const minValidTxs = opts.minValidTxs ?? 0;
84
+ if (processedTxs.length < minValidTxs) {
85
+ throw new InsufficientValidTxsError(processedTxs.length, minValidTxs, failedTxs);
86
+ }
87
+ // Commit the fork checkpoint
88
+ await forkCheckpoint.commit();
89
+ // Add block to checkpoint
90
+ const { block } = await this.checkpointBuilder.addBlock(globalVariables, processedTxs, {
91
+ expectedEndState: opts.expectedEndState
92
+ });
93
+ this.contractsDB.commitCheckpoint();
94
+ this.log.debug('Built block within checkpoint', {
95
+ header: block.header.toInspect(),
96
+ processedTxs: processedTxs.map((tx)=>tx.hash.toString()),
97
+ failedTxs: failedTxs.map((tx)=>tx.tx.txHash.toString())
98
+ });
99
+ return {
100
+ block,
101
+ publicProcessorDuration,
102
+ numTxs: processedTxs.length,
103
+ failedTxs,
104
+ usedTxs
105
+ };
106
+ } catch (err) {
107
+ // Revert all changes to contracts db
108
+ this.contractsDB.revertCheckpoint();
109
+ // If we reached the point of committing the checkpoint, this does nothing
110
+ // Otherwise it reverts any changes made to the fork for this failed block
111
+ await forkCheckpoint.revert();
112
+ throw err;
113
+ }
114
+ }
115
+ /** Completes the checkpoint and returns it. */ async completeCheckpoint() {
116
+ const checkpoint = await this.checkpointBuilder.completeCheckpoint();
117
+ this.log.verbose(`Completed checkpoint ${checkpoint.number}`, {
118
+ checkpointNumber: checkpoint.number,
119
+ numBlocks: checkpoint.blocks.length,
120
+ archiveRoot: checkpoint.archive.root.toString()
121
+ });
122
+ return checkpoint;
123
+ }
124
+ /** Gets the checkpoint currently in progress. */ getCheckpoint() {
125
+ return this.checkpointBuilder.clone().completeCheckpoint();
126
+ }
127
+ /**
128
+ * Caps per-block gas and blob field limits by remaining checkpoint-level budgets.
129
+ * When building a proposal (isBuildingProposal=true), computes a fair share of remaining budget
130
+ * across remaining blocks scaled by the multiplier. When validating, only caps by per-block limit
131
+ * and remaining checkpoint budget (no redistribution or multiplier).
132
+ */ capLimitsByCheckpointBudgets(opts) {
133
+ const existingBlocks = this.checkpointBuilder.getBlocks();
134
+ // Remaining L2 gas (mana)
135
+ // IMPORTANT: This assumes mana is computed solely based on L2 gas used in transactions.
136
+ // This may change in the future.
137
+ const usedMana = sum(existingBlocks.map((b)=>b.header.totalManaUsed.toNumber()));
138
+ const remainingMana = this.config.rollupManaLimit - usedMana;
139
+ // Remaining DA gas
140
+ const usedDAGas = sum(existingBlocks.map((b)=>b.computeDAGasUsed())) ?? 0;
141
+ const remainingDAGas = MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT - usedDAGas;
142
+ // Remaining blob fields (block blob fields include both tx data and block-end overhead)
143
+ const usedBlobFields = sum(existingBlocks.map((b)=>b.toBlobFields().length));
144
+ const totalBlobCapacity = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB - NUM_CHECKPOINT_END_MARKER_FIELDS;
145
+ const isFirstBlock = existingBlocks.length === 0;
146
+ const blockEndOverhead = getNumBlockEndBlobFields(isFirstBlock);
147
+ const maxBlobFieldsForTxs = totalBlobCapacity - usedBlobFields - blockEndOverhead;
148
+ // Remaining txs
149
+ const usedTxs = sum(existingBlocks.map((b)=>b.body.txEffects.length));
150
+ const remainingTxs = Math.max(0, (this.config.maxTxsPerCheckpoint ?? Infinity) - usedTxs);
151
+ // Cap by per-block limit + remaining checkpoint budget
152
+ let cappedL2Gas = Math.min(opts.maxBlockGas?.l2Gas ?? Infinity, remainingMana);
153
+ let cappedDAGas = Math.min(opts.maxBlockGas?.daGas ?? Infinity, remainingDAGas);
154
+ let cappedBlobFields = Math.min(opts.maxBlobFields ?? Infinity, maxBlobFieldsForTxs);
155
+ let cappedMaxTransactions = Math.min(opts.maxTransactions ?? Infinity, remainingTxs);
156
+ // Proposer mode: further cap by fair share of remaining budget across remaining blocks
157
+ if (opts.isBuildingProposal) {
158
+ const remainingBlocks = Math.max(1, opts.maxBlocksPerCheckpoint - existingBlocks.length);
159
+ const multiplier = opts.perBlockAllocationMultiplier;
160
+ cappedL2Gas = Math.min(cappedL2Gas, Math.ceil(remainingMana / remainingBlocks * multiplier));
161
+ cappedDAGas = Math.min(cappedDAGas, Math.ceil(remainingDAGas / remainingBlocks * multiplier));
162
+ cappedBlobFields = Math.min(cappedBlobFields, Math.ceil(maxBlobFieldsForTxs / remainingBlocks * multiplier));
163
+ cappedMaxTransactions = Math.min(cappedMaxTransactions, Math.ceil(remainingTxs / remainingBlocks * multiplier));
164
+ }
165
+ return {
166
+ maxBlockGas: new Gas(cappedDAGas, cappedL2Gas),
167
+ maxBlobFields: cappedBlobFields,
168
+ maxTransactions: Number.isFinite(cappedMaxTransactions) ? cappedMaxTransactions : undefined
169
+ };
170
+ }
171
+ async makeBlockBuilderDeps(globalVariables, fork) {
172
+ const txPublicSetupAllowList = [
173
+ ...await getDefaultAllowedSetupFunctions(),
174
+ ...this.config.txPublicSetupAllowListExtend ?? []
175
+ ];
176
+ const contractsDB = this.contractsDB;
177
+ const guardedFork = new GuardedMerkleTreeOperations(fork);
178
+ const collectDebugLogs = this.debugLogStore.isEnabled;
179
+ const bindings = this.log.getBindings();
180
+ const publicTxSimulator = createPublicTxSimulatorForBlockBuilding(guardedFork, contractsDB, globalVariables, this.telemetryClient, bindings, collectDebugLogs);
181
+ const processor = new PublicProcessor(globalVariables, guardedFork, contractsDB, publicTxSimulator, this.dateProvider, this.telemetryClient, createLogger('simulator:public-processor', bindings), this.config, this.debugLogStore);
182
+ const validator = createTxValidatorForBlockBuilding(fork, this.contractDataSource, globalVariables, txPublicSetupAllowList, this.log.getBindings());
183
+ return {
184
+ processor,
185
+ validator
186
+ };
187
+ }
188
+ }
189
+ /** Factory for creating checkpoint builders. */ export class FullNodeCheckpointsBuilder {
190
+ config;
191
+ worldState;
192
+ contractDataSource;
193
+ dateProvider;
194
+ telemetryClient;
195
+ debugLogStore;
196
+ log;
197
+ constructor(config, worldState, contractDataSource, dateProvider, telemetryClient = getTelemetryClient(), debugLogStore = new NullDebugLogStore()){
198
+ this.config = config;
199
+ this.worldState = worldState;
200
+ this.contractDataSource = contractDataSource;
201
+ this.dateProvider = dateProvider;
202
+ this.telemetryClient = telemetryClient;
203
+ this.debugLogStore = debugLogStore;
204
+ this.log = createLogger('checkpoint-builder');
205
+ }
206
+ getConfig() {
207
+ return this.config;
208
+ }
209
+ updateConfig(config) {
210
+ this.config = merge(this.config, pick(config, ...FullNodeBlockBuilderConfigKeys));
211
+ }
212
+ /**
213
+ * Starts a new checkpoint and returns a CheckpointBuilder to build blocks within it.
214
+ */ async startCheckpoint(checkpointNumber, constants, feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, bindings) {
215
+ const stateReference = await fork.getStateReference();
216
+ const archiveTree = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
217
+ this.log.verbose(`Building new checkpoint ${checkpointNumber}`, {
218
+ checkpointNumber,
219
+ msgCount: l1ToL2Messages.length,
220
+ initialStateReference: stateReference.toInspect(),
221
+ initialArchiveRoot: bufferToHex(archiveTree.root),
222
+ constants,
223
+ feeAssetPriceModifier
224
+ });
225
+ const lightweightBuilder = await LightweightCheckpointBuilder.startNewCheckpoint(checkpointNumber, constants, l1ToL2Messages, previousCheckpointOutHashes, fork, bindings, feeAssetPriceModifier);
226
+ return new CheckpointBuilder(lightweightBuilder, fork, this.config, this.contractDataSource, this.dateProvider, this.telemetryClient, bindings, this.debugLogStore);
227
+ }
228
+ /**
229
+ * Opens a checkpoint, either starting fresh or resuming from existing blocks.
230
+ */ async openCheckpoint(checkpointNumber, constants, feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, existingBlocks = [], bindings) {
231
+ const stateReference = await fork.getStateReference();
232
+ const archiveTree = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
233
+ if (existingBlocks.length === 0) {
234
+ return this.startCheckpoint(checkpointNumber, constants, feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, bindings);
235
+ }
236
+ this.log.verbose(`Resuming checkpoint ${checkpointNumber} with ${existingBlocks.length} existing blocks`, {
237
+ checkpointNumber,
238
+ msgCount: l1ToL2Messages.length,
239
+ existingBlockCount: existingBlocks.length,
240
+ initialStateReference: stateReference.toInspect(),
241
+ initialArchiveRoot: bufferToHex(archiveTree.root),
242
+ constants,
243
+ feeAssetPriceModifier
244
+ });
245
+ const lightweightBuilder = await LightweightCheckpointBuilder.resumeCheckpoint(checkpointNumber, constants, feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, existingBlocks, bindings);
246
+ return new CheckpointBuilder(lightweightBuilder, fork, this.config, this.contractDataSource, this.dateProvider, this.telemetryClient, bindings, this.debugLogStore);
247
+ }
248
+ /** Returns a fork of the world state at the given block number. */ getFork(blockNumber) {
249
+ return this.worldState.fork(blockNumber);
250
+ }
251
+ }
package/dest/config.d.ts CHANGED
@@ -1,17 +1,6 @@
1
1
  import { type ConfigMappingsType } from '@aztec/foundation/config';
2
- /**
3
- * The Validator Configuration
4
- */
5
- export interface ValidatorClientConfig {
6
- /** The private key of the validator participating in attestation duties */
7
- validatorPrivateKey?: string;
8
- /** Do not run the validator */
9
- disableValidator: boolean;
10
- /** Interval between polling for new attestations from peers */
11
- attestationPollingIntervalMs: number;
12
- /** Re-execute transactions before attesting */
13
- validatorReexecute: boolean;
14
- }
2
+ import type { ValidatorClientConfig } from '@aztec/stdlib/interfaces/server';
3
+ export type { ValidatorClientConfig };
15
4
  export declare const validatorClientConfigMappings: ConfigMappingsType<ValidatorClientConfig>;
16
5
  /**
17
6
  * Returns the prover configuration from the environment variables.
@@ -19,4 +8,4 @@ export declare const validatorClientConfigMappings: ConfigMappingsType<Validator
19
8
  * @returns The validator configuration.
20
9
  */
21
10
  export declare function getProverEnvVars(): ValidatorClientConfig;
22
- //# sourceMappingURL=config.d.ts.map
11
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uZmlnLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvY29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFDTCxLQUFLLGtCQUFrQixFQU14QixNQUFNLDBCQUEwQixDQUFDO0FBR2xDLE9BQU8sS0FBSyxFQUFFLHFCQUFxQixFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFFN0UsWUFBWSxFQUFFLHFCQUFxQixFQUFFLENBQUM7QUFFdEMsZUFBTyxNQUFNLDZCQUE2QixFQUFFLGtCQUFrQixDQUFDLHFCQUFxQixDQTZGbkYsQ0FBQztBQUVGOzs7O0dBSUc7QUFDSCx3QkFBZ0IsZ0JBQWdCLElBQUkscUJBQXFCLENBRXhEIn0=
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,kBAAkB,EAIxB,MAAM,0BAA0B,CAAC;AAElC;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,2EAA2E;IAC3E,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B,+BAA+B;IAC/B,gBAAgB,EAAE,OAAO,CAAC;IAE1B,+DAA+D;IAC/D,4BAA4B,EAAE,MAAM,CAAC;IAErC,+CAA+C;IAC/C,kBAAkB,EAAE,OAAO,CAAC;CAC7B;AAED,eAAO,MAAM,6BAA6B,EAAE,kBAAkB,CAAC,qBAAqB,CAqBnF,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,qBAAqB,CAExD"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EAMxB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAE7E,YAAY,EAAE,qBAAqB,EAAE,CAAC;AAEtC,eAAO,MAAM,6BAA6B,EAAE,kBAAkB,CAAC,qBAAqB,CA6FnF,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,qBAAqB,CAExD"}
package/dest/config.js CHANGED
@@ -1,26 +1,89 @@
1
- import { NULL_KEY } from '@aztec/ethereum';
2
- import { booleanConfigHelper, getConfigFromMappings, numberConfigHelper } from '@aztec/foundation/config';
1
+ import { booleanConfigHelper, getConfigFromMappings, numberConfigHelper, optionalNumberConfigHelper, secretValueConfigHelper } from '@aztec/foundation/config';
2
+ import { EthAddress } from '@aztec/foundation/eth-address';
3
+ import { localSignerConfigMappings, validatorHASignerConfigMappings } from '@aztec/stdlib/ha-signing';
3
4
  export const validatorClientConfigMappings = {
4
- validatorPrivateKey: {
5
- env: 'VALIDATOR_PRIVATE_KEY',
6
- parseEnv: (val)=>val ? `0x${val.replace('0x', '')}` : NULL_KEY,
7
- description: 'The private key of the validator participating in attestation duties'
5
+ validatorPrivateKeys: {
6
+ env: 'VALIDATOR_PRIVATE_KEYS',
7
+ description: 'List of private keys of the validators participating in attestation duties',
8
+ ...secretValueConfigHelper((val)=>val ? val.split(',').map((key)=>`0x${key.replace('0x', '')}`) : []),
9
+ fallback: [
10
+ 'VALIDATOR_PRIVATE_KEY'
11
+ ]
12
+ },
13
+ validatorAddresses: {
14
+ env: 'VALIDATOR_ADDRESSES',
15
+ description: 'List of addresses of the validators to use with remote signers',
16
+ parseEnv: (val)=>val.split(',').filter((address)=>address && address.trim().length > 0).map((address)=>EthAddress.fromString(address.trim())),
17
+ defaultValue: []
18
+ },
19
+ l1ChainId: {
20
+ env: 'L1_CHAIN_ID',
21
+ description: 'The chain ID of the ethereum host.',
22
+ parseEnv: (val)=>+val,
23
+ defaultValue: 31337
8
24
  },
9
25
  disableValidator: {
10
26
  env: 'VALIDATOR_DISABLED',
11
27
  description: 'Do not run the validator',
12
- ...booleanConfigHelper()
28
+ ...booleanConfigHelper(false)
29
+ },
30
+ disabledValidators: {
31
+ description: 'Temporarily disable these specific validator addresses',
32
+ parseEnv: (val)=>val.split(',').filter((address)=>address && address.trim().length > 0).map((address)=>EthAddress.fromString(address.trim())),
33
+ defaultValue: []
13
34
  },
14
35
  attestationPollingIntervalMs: {
15
36
  env: 'VALIDATOR_ATTESTATIONS_POLLING_INTERVAL_MS',
16
37
  description: 'Interval between polling for new attestations',
17
38
  ...numberConfigHelper(200)
18
39
  },
19
- validatorReexecute: {
20
- env: 'VALIDATOR_REEXECUTE',
21
- description: 'Re-execute transactions before attesting',
22
- ...booleanConfigHelper(true)
23
- }
40
+ alwaysReexecuteBlockProposals: {
41
+ description: 'Whether to always reexecute block proposals, even for non-validator nodes (useful for monitoring network status).',
42
+ defaultValue: true
43
+ },
44
+ fishermanMode: {
45
+ env: 'FISHERMAN_MODE',
46
+ description: 'Whether to run in fisherman mode: validates all proposals and attestations but does not broadcast attestations or participate in consensus.',
47
+ ...booleanConfigHelper(false)
48
+ },
49
+ skipCheckpointProposalValidation: {
50
+ description: 'Skip checkpoint proposal validation and always attest (default: false)',
51
+ defaultValue: false
52
+ },
53
+ skipPushProposedBlocksToArchiver: {
54
+ description: 'Skip pushing re-executed blocks to archiver (default: false)',
55
+ defaultValue: false
56
+ },
57
+ attestToEquivocatedProposals: {
58
+ description: 'Agree to attest to equivocated checkpoint proposals (for testing purposes only)',
59
+ ...booleanConfigHelper(false)
60
+ },
61
+ skipProposalSlotValidation: {
62
+ description: 'Accept proposal validation regardless of slot timing (for testing only)',
63
+ ...booleanConfigHelper(false)
64
+ },
65
+ validateMaxL2BlockGas: {
66
+ env: 'VALIDATOR_MAX_L2_BLOCK_GAS',
67
+ description: 'Maximum L2 block gas for validation. Proposals exceeding this limit are rejected.',
68
+ ...optionalNumberConfigHelper()
69
+ },
70
+ validateMaxDABlockGas: {
71
+ env: 'VALIDATOR_MAX_DA_BLOCK_GAS',
72
+ description: 'Maximum DA block gas for validation. Proposals exceeding this limit are rejected.',
73
+ ...optionalNumberConfigHelper()
74
+ },
75
+ validateMaxTxsPerBlock: {
76
+ env: 'VALIDATOR_MAX_TX_PER_BLOCK',
77
+ description: 'Maximum transactions per block for validation. Proposals exceeding this limit are rejected.',
78
+ ...optionalNumberConfigHelper()
79
+ },
80
+ validateMaxTxsPerCheckpoint: {
81
+ env: 'VALIDATOR_MAX_TX_PER_CHECKPOINT',
82
+ description: 'Maximum transactions per checkpoint for validation. Proposals exceeding this limit are rejected.',
83
+ ...optionalNumberConfigHelper()
84
+ },
85
+ ...localSignerConfigMappings,
86
+ ...validatorHASignerConfigMappings
24
87
  };
25
88
  /**
26
89
  * Returns the prover configuration from the environment variables.
@@ -1,29 +1,65 @@
1
- import type { Fr } from '@aztec/foundation/fields';
2
- import { BlockAttestation, BlockProposal } from '@aztec/stdlib/p2p';
3
- import type { BlockHeader, TxHash } from '@aztec/stdlib/tx';
1
+ import { type CheckpointNumber, IndexWithinCheckpoint, type SlotNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
+ import type { EthAddress } from '@aztec/foundation/eth-address';
4
+ import type { Signature } from '@aztec/foundation/eth-signature';
5
+ import { CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
6
+ import { BlockProposal, type BlockProposalOptions, CheckpointAttestation, CheckpointProposal, type CheckpointProposalCore, type CheckpointProposalOptions, type CoordinationSignatureContext } from '@aztec/stdlib/p2p';
7
+ import { CheckpointHeader } from '@aztec/stdlib/rollup';
8
+ import type { BlockHeader, Tx } from '@aztec/stdlib/tx';
4
9
  import type { ValidatorKeyStore } from '../key_store/interface.js';
5
10
  export declare class ValidationService {
6
11
  private keyStore;
7
- constructor(keyStore: ValidatorKeyStore);
12
+ private signatureContext;
13
+ private log;
14
+ constructor(keyStore: ValidatorKeyStore, signatureContext: CoordinationSignatureContext, log?: import("@aztec/foundation/log").Logger);
8
15
  /**
9
16
  * Create a block proposal with the given header, archive, and transactions
10
17
  *
11
- * @param header - The block header
18
+ * @param blockHeader - The block header
19
+ * @param blockIndexWithinCheckpoint - The block index within checkpoint for HA signing context
20
+ * @param inHash - Hash of L1 to L2 messages for this checkpoint
12
21
  * @param archive - The archive of the current block
13
- * @param txs - TxHash[] ordered list of transactions
22
+ * @param txs - Ordered list of transactions (Tx[])
23
+ * @param proposerAttesterAddress - The address of the proposer/attester, or undefined
24
+ * @param options - Block proposal options (including broadcastInvalidBlockProposal for testing)
14
25
  *
15
- * @returns A block proposal signing the above information (not the current implementation!!!)
26
+ * @returns A block proposal signing the above information
27
+ * @throws DutyAlreadySignedError if HA signer indicates duty already signed by another node
28
+ * @throws SlashingProtectionError if attempting to sign different data for same slot
16
29
  */
17
- createBlockProposal(header: BlockHeader, archive: Fr, txs: TxHash[]): Promise<BlockProposal>;
30
+ createBlockProposal(blockHeader: BlockHeader, checkpointNumber: CheckpointNumber, blockIndexWithinCheckpoint: IndexWithinCheckpoint, inHash: Fr, archive: Fr, txs: Tx[], proposerAttesterAddress: EthAddress | undefined, options: BlockProposalOptions): Promise<BlockProposal>;
18
31
  /**
19
- * Attest to the given block proposal constructed by the current sequencer
32
+ * Create a checkpoint proposal with the last block header and checkpoint header
33
+ *
34
+ * @param checkpointHeader - The checkpoint header containing aggregated data
35
+ * @param archive - The archive of the checkpoint
36
+ * @param lastBlockProposal - Signed block proposal for the last block in the checkpoint, or undefined
37
+ * @param proposerAttesterAddress - The address of the proposer
38
+ * @param options - Checkpoint proposal options
39
+ *
40
+ * @returns A checkpoint proposal signing the above information
41
+ */
42
+ createCheckpointProposal(checkpointHeader: CheckpointHeader, archive: Fr, checkpointNumber: CheckpointNumber, feeAssetPriceModifier: bigint, lastBlockProposal: BlockProposal | undefined, proposerAttesterAddress: EthAddress | undefined, options: CheckpointProposalOptions): Promise<CheckpointProposal>;
43
+ /**
44
+ * Attest with selection of validators to the given checkpoint proposal
20
45
  *
21
46
  * NOTE: This is just a blind signing.
22
47
  * We assume that the proposal is valid and DA guarantees have been checked previously.
23
48
  *
24
- * @param proposal - The proposal to attest to
25
- * @returns attestation
49
+ * @param proposal - The checkpoint proposal (core version without lastBlock) to attest to
50
+ * @param attestors - The validators to attest with
51
+ * @returns checkpoint attestations
52
+ */
53
+ attestToCheckpointProposal(proposal: CheckpointProposalCore, attestors: EthAddress[], checkpointNumber: CheckpointNumber): Promise<CheckpointAttestation[]>;
54
+ /**
55
+ * Sign attestations and signers payload
56
+ * @param attestationsAndSigners - The attestations and signers to sign
57
+ * @param proposer - The proposer address to sign with
58
+ * @param slot - The slot number for HA signing context
59
+ * @returns signature
60
+ * @throws DutyAlreadySignedError if already signed by another HA node
61
+ * @throws SlashingProtectionError if attempting to sign different data for same slot
26
62
  */
27
- attestToProposal(proposal: BlockProposal): Promise<BlockAttestation>;
63
+ signAttestationsAndSigners(attestationsAndSigners: CommitteeAttestationsAndSigners, proposer: EthAddress, slot: SlotNumber, checkpointNumber: CheckpointNumber): Promise<Signature>;
28
64
  }
29
- //# sourceMappingURL=validation_service.d.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BUUc7SUFDSCwwQkFBMEIsQ0FDeEIsc0JBQXNCLEVBQUUsK0JBQStCLEVBQ3ZELFFBQVEsRUFBRSxVQUFVLEVBQ3BCLElBQUksRUFBRSxVQUFVLEVBQ2hCLGdCQUFnQixFQUFFLGdCQUFnQixHQUNqQyxPQUFPLENBQUMsU0FBUyxDQUFDLENBU3BCO0NBQ0YifQ==
@@ -1 +1 @@
1
- {"version":3,"file":"validation_service.d.ts","sourceRoot":"","sources":["../../src/duties/validation_service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAA8C,MAAM,mBAAmB,CAAC;AAChH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAEnE,qBAAa,iBAAiB;IAChB,OAAO,CAAC,QAAQ;gBAAR,QAAQ,EAAE,iBAAiB;IAE/C;;;;;;;;OAQG;IACH,mBAAmB,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IAM5F;;;;;;;;OAQG;IACG,gBAAgB,CAAC,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAS3E"}
1
+ {"version":3,"file":"validation_service.d.ts","sourceRoot":"","sources":["../../src/duties/validation_service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAE,qBAAqB,EAAE,KAAK,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAChH,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;A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AE,sBAAsB,EAChC,SAAS,EAAE,UAAU,EAAE,EACvB,gBAAgB,EAAE,gBAAgB,GACjC,OAAO,CAAC,qBAAqB,EAAE,CAAC,CA2ClC;IAED;;;;;;;;OAQG;IACH,0BAA0B,CACxB,sBAAsB,EAAE,+BAA+B,EACvD,QAAQ,EAAE,UAAU,EACpB,IAAI,EAAE,UAAU,EAChB,gBAAgB,EAAE,gBAAgB,GACjC,OAAO,CAAC,SAAS,CAAC,CASpB;CACF"}
@@ -1,35 +1,129 @@
1
- import { Buffer32 } from '@aztec/foundation/buffer';
2
- import { keccak256 } from '@aztec/foundation/crypto';
3
- import { BlockAttestation, BlockProposal, ConsensusPayload, SignatureDomainSeparator } from '@aztec/stdlib/p2p';
1
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
+ import { createLogger } from '@aztec/foundation/log';
3
+ import { BlockProposal, CheckpointAttestation, CheckpointProposal, ConsensusPayload, getCoordinationSignatureTypedData } from '@aztec/stdlib/p2p';
4
+ import { CheckpointHeader } from '@aztec/stdlib/rollup';
5
+ import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validator-ha-signer/errors';
6
+ import { DutyType } from '@aztec/validator-ha-signer/types';
4
7
  export class ValidationService {
5
8
  keyStore;
6
- constructor(keyStore){
9
+ signatureContext;
10
+ log;
11
+ constructor(keyStore, signatureContext, log = createLogger('validator:validation-service')){
7
12
  this.keyStore = keyStore;
13
+ this.signatureContext = signatureContext;
14
+ this.log = log;
8
15
  }
9
16
  /**
10
17
  * Create a block proposal with the given header, archive, and transactions
11
18
  *
12
- * @param header - The block header
19
+ * @param blockHeader - The block header
20
+ * @param blockIndexWithinCheckpoint - The block index within checkpoint for HA signing context
21
+ * @param inHash - Hash of L1 to L2 messages for this checkpoint
13
22
  * @param archive - The archive of the current block
14
- * @param txs - TxHash[] ordered list of transactions
23
+ * @param txs - Ordered list of transactions (Tx[])
24
+ * @param proposerAttesterAddress - The address of the proposer/attester, or undefined
25
+ * @param options - Block proposal options (including broadcastInvalidBlockProposal for testing)
15
26
  *
16
- * @returns A block proposal signing the above information (not the current implementation!!!)
17
- */ createBlockProposal(header, archive, txs) {
18
- const payloadSigner = (payload)=>this.keyStore.signMessage(payload);
19
- return BlockProposal.createProposalFromSigner(new ConsensusPayload(header, archive, txs), payloadSigner);
27
+ * @returns A block proposal signing the above information
28
+ * @throws DutyAlreadySignedError if HA signer indicates duty already signed by another node
29
+ * @throws SlashingProtectionError if attempting to sign different data for same slot
30
+ */ createBlockProposal(blockHeader, checkpointNumber, blockIndexWithinCheckpoint, inHash, archive, txs, proposerAttesterAddress, options) {
31
+ // For testing: change the new archive to trigger state_mismatch validation failure
32
+ if (options.broadcastInvalidBlockProposal) {
33
+ archive = Fr.random();
34
+ this.log.warn(`Creating INVALID block proposal for slot ${blockHeader.globalVariables.slotNumber}`);
35
+ }
36
+ // Create a signer that uses the appropriate address
37
+ const address = proposerAttesterAddress ?? this.keyStore.getAddress(0);
38
+ const payloadSigner = (typedData, context)=>this.keyStore.signTypedDataWithAddress(address, typedData, context);
39
+ const txsSigner = (typedData, context)=>this.keyStore.signTypedDataWithAddress(address, typedData, context);
40
+ return BlockProposal.createProposalFromSigner(blockHeader, checkpointNumber, blockIndexWithinCheckpoint, inHash, archive, txs.map((tx)=>tx.getTxHash()), options.publishFullTxs ? txs : undefined, this.signatureContext, payloadSigner, txsSigner);
20
41
  }
21
42
  /**
22
- * Attest to the given block proposal constructed by the current sequencer
43
+ * Create a checkpoint proposal with the last block header and checkpoint header
44
+ *
45
+ * @param checkpointHeader - The checkpoint header containing aggregated data
46
+ * @param archive - The archive of the checkpoint
47
+ * @param lastBlockProposal - Signed block proposal for the last block in the checkpoint, or undefined
48
+ * @param proposerAttesterAddress - The address of the proposer
49
+ * @param options - Checkpoint proposal options
50
+ *
51
+ * @returns A checkpoint proposal signing the above information
52
+ */ createCheckpointProposal(checkpointHeader, archive, checkpointNumber, feeAssetPriceModifier, lastBlockProposal, proposerAttesterAddress, options) {
53
+ // For testing: corrupt the checkpoint so observers' checkpoint validation fails.
54
+ //
55
+ // Keep `archive` aligned with `lastBlockProposal.archiveRoot` so the archive-based lookup
56
+ // in `validateCheckpointProposal` (`getBlockData({ archive })`) still succeeds
57
+ if (options.broadcastInvalidCheckpointProposal) {
58
+ archive = lastBlockProposal?.archiveRoot ?? Fr.random();
59
+ checkpointHeader = CheckpointHeader.from({
60
+ ...checkpointHeader,
61
+ epochOutHash: Fr.random()
62
+ });
63
+ this.log.warn(`Creating INVALID checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
64
+ }
65
+ // Create a signer that takes payload and context, and uses the appropriate address
66
+ const payloadSigner = (typedData, context)=>{
67
+ const address = proposerAttesterAddress ?? this.keyStore.getAddress(0);
68
+ return this.keyStore.signTypedDataWithAddress(address, typedData, context);
69
+ };
70
+ return CheckpointProposal.createProposalFromSigner(checkpointHeader, archive, checkpointNumber, feeAssetPriceModifier, lastBlockProposal, this.signatureContext, payloadSigner);
71
+ }
72
+ /**
73
+ * Attest with selection of validators to the given checkpoint proposal
23
74
  *
24
75
  * NOTE: This is just a blind signing.
25
76
  * We assume that the proposal is valid and DA guarantees have been checked previously.
26
77
  *
27
- * @param proposal - The proposal to attest to
28
- * @returns attestation
29
- */ async attestToProposal(proposal) {
30
- // TODO(https://github.com/AztecProtocol/aztec-packages/issues/7961): check that the current validator is correct
31
- const buf = Buffer32.fromBuffer(keccak256(await proposal.payload.getPayloadToSign(SignatureDomainSeparator.blockAttestation)));
32
- const sig = await this.keyStore.signMessage(buf);
33
- return new BlockAttestation(proposal.payload, sig);
78
+ * @param proposal - The checkpoint proposal (core version without lastBlock) to attest to
79
+ * @param attestors - The validators to attest with
80
+ * @returns checkpoint attestations
81
+ */ async attestToCheckpointProposal(proposal, attestors, checkpointNumber) {
82
+ // Create the attestation payload from the checkpoint proposal
83
+ const payload = new ConsensusPayload(proposal.checkpointHeader, proposal.archive, proposal.feeAssetPriceModifier, this.signatureContext);
84
+ const typedData = getCoordinationSignatureTypedData(payload);
85
+ const context = {
86
+ slot: proposal.slotNumber,
87
+ checkpointNumber,
88
+ dutyType: DutyType.ATTESTATION
89
+ };
90
+ // Sign each attestor in parallel, catching HA errors per-attestor
91
+ const results = await Promise.allSettled(attestors.map(async (attestor)=>{
92
+ const sig = await this.keyStore.signTypedDataWithAddress(attestor, typedData, context);
93
+ return new CheckpointAttestation(payload, sig, proposal.signature);
94
+ }));
95
+ const attestations = [];
96
+ for(let i = 0; i < results.length; i++){
97
+ const result = results[i];
98
+ if (result.status === 'fulfilled') {
99
+ attestations.push(result.value);
100
+ } else {
101
+ const error = result.reason;
102
+ if (error instanceof DutyAlreadySignedError || error instanceof SlashingProtectionError) {
103
+ this.log.verbose(`Attestation for slot ${proposal.slotNumber} by ${attestors[i]} already signed by another High-Availability node`);
104
+ // Continue with remaining attestors
105
+ } else {
106
+ throw error;
107
+ }
108
+ }
109
+ }
110
+ return attestations;
111
+ }
112
+ /**
113
+ * Sign attestations and signers payload
114
+ * @param attestationsAndSigners - The attestations and signers to sign
115
+ * @param proposer - The proposer address to sign with
116
+ * @param slot - The slot number for HA signing context
117
+ * @returns signature
118
+ * @throws DutyAlreadySignedError if already signed by another HA node
119
+ * @throws SlashingProtectionError if attempting to sign different data for same slot
120
+ */ signAttestationsAndSigners(attestationsAndSigners, proposer, slot, checkpointNumber) {
121
+ const context = {
122
+ slot,
123
+ checkpointNumber,
124
+ dutyType: DutyType.ATTESTATIONS_AND_SIGNERS
125
+ };
126
+ const typedData = getCoordinationSignatureTypedData(attestationsAndSigners);
127
+ return this.keyStore.signTypedDataWithAddress(proposer, typedData, context);
34
128
  }
35
129
  }