@aztec/validator-client 0.0.1-commit.7d4e6cd → 0.0.1-commit.858058eac
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/README.md +53 -24
- package/dest/block_proposal_handler.d.ts +8 -8
- package/dest/block_proposal_handler.d.ts.map +1 -1
- package/dest/block_proposal_handler.js +27 -32
- package/dest/checkpoint_builder.d.ts +21 -25
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +50 -32
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +12 -14
- package/dest/duties/validation_service.d.ts +19 -6
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +72 -19
- package/dest/factory.d.ts +2 -2
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +1 -1
- package/dest/key_store/ha_key_store.d.ts +99 -0
- package/dest/key_store/ha_key_store.d.ts.map +1 -0
- package/dest/key_store/ha_key_store.js +208 -0
- package/dest/key_store/index.d.ts +2 -1
- package/dest/key_store/index.d.ts.map +1 -1
- package/dest/key_store/index.js +1 -0
- package/dest/key_store/interface.d.ts +36 -6
- package/dest/key_store/interface.d.ts.map +1 -1
- package/dest/key_store/local_key_store.d.ts +10 -5
- package/dest/key_store/local_key_store.d.ts.map +1 -1
- package/dest/key_store/local_key_store.js +8 -4
- package/dest/key_store/node_keystore_adapter.d.ts +18 -5
- package/dest/key_store/node_keystore_adapter.d.ts.map +1 -1
- package/dest/key_store/node_keystore_adapter.js +18 -4
- package/dest/key_store/web3signer_key_store.d.ts +10 -5
- package/dest/key_store/web3signer_key_store.d.ts.map +1 -1
- package/dest/key_store/web3signer_key_store.js +8 -4
- package/dest/metrics.d.ts +4 -3
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +34 -5
- package/dest/tx_validator/tx_validator_factory.d.ts +4 -3
- package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -1
- package/dest/tx_validator/tx_validator_factory.js +17 -16
- package/dest/validator.d.ts +35 -16
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +194 -91
- package/package.json +21 -17
- package/src/block_proposal_handler.ts +41 -42
- package/src/checkpoint_builder.ts +85 -38
- package/src/config.ts +11 -13
- package/src/duties/validation_service.ts +91 -23
- package/src/factory.ts +1 -0
- package/src/key_store/ha_key_store.ts +269 -0
- package/src/key_store/index.ts +1 -0
- package/src/key_store/interface.ts +44 -5
- package/src/key_store/local_key_store.ts +13 -4
- package/src/key_store/node_keystore_adapter.ts +27 -4
- package/src/key_store/web3signer_key_store.ts +17 -4
- package/src/metrics.ts +45 -6
- package/src/tx_validator/tx_validator_factory.ts +52 -31
- package/src/validator.ts +253 -111
package/dest/validator.js
CHANGED
|
@@ -8,11 +8,16 @@ import { sleep } from '@aztec/foundation/sleep';
|
|
|
8
8
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
9
9
|
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
10
10
|
import { OffenseType, WANT_TO_SLASH_EVENT } from '@aztec/slasher';
|
|
11
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
12
|
+
import { accumulateCheckpointOutHashes } from '@aztec/stdlib/messaging';
|
|
11
13
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
12
14
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
15
|
+
import { createHASigner } from '@aztec/validator-ha-signer/factory';
|
|
16
|
+
import { DutyType } from '@aztec/validator-ha-signer/types';
|
|
13
17
|
import { EventEmitter } from 'events';
|
|
14
18
|
import { BlockProposalHandler } from './block_proposal_handler.js';
|
|
15
19
|
import { ValidationService } from './duties/validation_service.js';
|
|
20
|
+
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
16
21
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
17
22
|
import { ValidatorMetrics } from './metrics.js';
|
|
18
23
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
@@ -43,17 +48,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
43
48
|
log;
|
|
44
49
|
// Whether it has already registered handlers on the p2p client
|
|
45
50
|
hasRegisteredHandlers;
|
|
46
|
-
|
|
47
|
-
|
|
51
|
+
/** Tracks the last block proposal we created, to detect duplicate proposal attempts. */ lastProposedBlock;
|
|
52
|
+
/** Tracks the last checkpoint proposal we created. */ lastProposedCheckpoint;
|
|
48
53
|
lastEpochForCommitteeUpdateLoop;
|
|
49
54
|
epochCacheUpdateLoop;
|
|
50
55
|
proposersOfInvalidBlocks;
|
|
51
|
-
|
|
52
|
-
// Tracks slots for which we have successfully validated a block proposal, so we can attest to checkpoint proposals for those slots.
|
|
53
|
-
// eslint-disable-next-line aztec-custom/no-non-primitive-in-collections
|
|
54
|
-
validatedBlockSlots;
|
|
56
|
+
/** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */ lastAttestedProposal;
|
|
55
57
|
constructor(keyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator')){
|
|
56
|
-
super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.blockProposalHandler = blockProposalHandler, this.blockSource = blockSource, this.checkpointsBuilder = checkpointsBuilder, this.worldState = worldState, this.l1ToL2MessageSource = l1ToL2MessageSource, this.config = config, this.blobClient = blobClient, this.dateProvider = dateProvider, this.hasRegisteredHandlers = false, this.proposersOfInvalidBlocks = new Set()
|
|
58
|
+
super(), this.keyStore = keyStore, this.epochCache = epochCache, this.p2pClient = p2pClient, this.blockProposalHandler = blockProposalHandler, this.blockSource = blockSource, this.checkpointsBuilder = checkpointsBuilder, this.worldState = worldState, this.l1ToL2MessageSource = l1ToL2MessageSource, this.config = config, this.blobClient = blobClient, this.dateProvider = dateProvider, this.hasRegisteredHandlers = false, this.proposersOfInvalidBlocks = new Set();
|
|
57
59
|
// Create child logger with fisherman prefix if in fisherman mode
|
|
58
60
|
this.log = config.fishermanMode ? log.createChild('[FISHERMAN]') : log;
|
|
59
61
|
this.tracer = telemetry.getTracer('Validator');
|
|
@@ -107,13 +109,23 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
107
109
|
this.log.error(`Error updating epoch committee`, err);
|
|
108
110
|
}
|
|
109
111
|
}
|
|
110
|
-
static new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
|
|
112
|
+
static async new(config, checkpointsBuilder, worldState, epochCache, p2pClient, blockSource, l1ToL2MessageSource, txProvider, keyStoreManager, blobClient, dateProvider = new DateProvider(), telemetry = getTelemetryClient()) {
|
|
111
113
|
const metrics = new ValidatorMetrics(telemetry);
|
|
112
114
|
const blockProposalValidator = new BlockProposalValidator(epochCache, {
|
|
113
115
|
txsPermitted: !config.disableTransactions
|
|
114
116
|
});
|
|
115
|
-
const blockProposalHandler = new BlockProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, config, metrics, dateProvider, telemetry);
|
|
116
|
-
|
|
117
|
+
const blockProposalHandler = new BlockProposalHandler(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, config, metrics, dateProvider, telemetry);
|
|
118
|
+
let validatorKeyStore = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
119
|
+
if (config.haSigningEnabled) {
|
|
120
|
+
// If maxStuckDutiesAgeMs is not explicitly set, compute it from Aztec slot duration
|
|
121
|
+
const haConfig = {
|
|
122
|
+
...config,
|
|
123
|
+
maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs ?? epochCache.getL1Constants().slotDuration * 2 * 1000
|
|
124
|
+
};
|
|
125
|
+
const { signer } = await createHASigner(haConfig);
|
|
126
|
+
validatorKeyStore = new HAKeyStore(validatorKeyStore, signer);
|
|
127
|
+
}
|
|
128
|
+
const validator = new ValidatorClient(validatorKeyStore, epochCache, p2pClient, blockProposalHandler, blockSource, checkpointsBuilder, worldState, l1ToL2MessageSource, config, blobClient, dateProvider, telemetry);
|
|
117
129
|
return validator;
|
|
118
130
|
}
|
|
119
131
|
getValidatorAddresses() {
|
|
@@ -122,8 +134,8 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
122
134
|
getBlockProposalHandler() {
|
|
123
135
|
return this.blockProposalHandler;
|
|
124
136
|
}
|
|
125
|
-
signWithAddress(addr, msg) {
|
|
126
|
-
return this.keyStore.signTypedDataWithAddress(addr, msg);
|
|
137
|
+
signWithAddress(addr, msg, context) {
|
|
138
|
+
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
127
139
|
}
|
|
128
140
|
getCoinbaseForAttestor(attestor) {
|
|
129
141
|
return this.keyStore.getCoinbaseAddress(attestor);
|
|
@@ -145,6 +157,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
145
157
|
this.log.warn(`Validator client already started`);
|
|
146
158
|
return;
|
|
147
159
|
}
|
|
160
|
+
await this.keyStore.start();
|
|
148
161
|
await this.registerHandlers();
|
|
149
162
|
const myAddresses = this.getValidatorAddresses();
|
|
150
163
|
const inCommittee = await this.epochCache.filterInCommittee('now', myAddresses);
|
|
@@ -157,6 +170,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
157
170
|
}
|
|
158
171
|
async stop() {
|
|
159
172
|
await this.epochCacheUpdateLoop.stop();
|
|
173
|
+
await this.keyStore.stop();
|
|
160
174
|
}
|
|
161
175
|
/** Register handlers on the p2p client */ async registerHandlers() {
|
|
162
176
|
if (!this.hasRegisteredHandlers) {
|
|
@@ -170,6 +184,14 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
170
184
|
// and processed separately via the block handler above.
|
|
171
185
|
const checkpointHandler = (checkpoint, proposalSender)=>this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
172
186
|
this.p2pClient.registerCheckpointProposalHandler(checkpointHandler);
|
|
187
|
+
// Duplicate proposal handler - triggers slashing for equivocation
|
|
188
|
+
this.p2pClient.registerDuplicateProposalCallback((info)=>{
|
|
189
|
+
this.handleDuplicateProposal(info);
|
|
190
|
+
});
|
|
191
|
+
// Duplicate attestation handler - triggers slashing for attestation equivocation
|
|
192
|
+
this.p2pClient.registerDuplicateAttestationCallback((info)=>{
|
|
193
|
+
this.handleDuplicateAttestation(info);
|
|
194
|
+
});
|
|
173
195
|
const myAddresses = this.getValidatorAddresses();
|
|
174
196
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
175
197
|
await this.p2pClient.addReqRespSubProtocol(ReqRespSubProtocol.AUTH, this.handleAuthRequest.bind(this));
|
|
@@ -181,12 +203,23 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
181
203
|
* @returns true if the proposal is valid, false otherwise
|
|
182
204
|
*/ async validateBlockProposal(proposal, proposalSender) {
|
|
183
205
|
const slotNumber = proposal.slotNumber;
|
|
206
|
+
// Note: During escape hatch, we still want to "validate" proposals for observability,
|
|
207
|
+
// but we intentionally reject them and disable slashing invalid block and attestation flow.
|
|
208
|
+
const escapeHatchOpen = await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber);
|
|
184
209
|
const proposer = proposal.getSender();
|
|
185
210
|
// Reject proposals with invalid signatures
|
|
186
211
|
if (!proposer) {
|
|
187
212
|
this.log.warn(`Received block proposal with invalid signature for slot ${slotNumber}`);
|
|
188
213
|
return false;
|
|
189
214
|
}
|
|
215
|
+
// Ignore proposals from ourselves (may happen in HA setups)
|
|
216
|
+
if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
217
|
+
this.log.warn(`Ignoring block proposal from self for slot ${slotNumber}`, {
|
|
218
|
+
proposer: proposer.toString(),
|
|
219
|
+
slotNumber
|
|
220
|
+
});
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
190
223
|
// Check if we're in the committee (for metrics purposes)
|
|
191
224
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
192
225
|
const partOfCommittee = inCommittee.length > 0;
|
|
@@ -203,7 +236,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
203
236
|
// In fisherman mode, we always reexecute to validate proposals.
|
|
204
237
|
const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } = this.config;
|
|
205
238
|
const shouldReexecute = fishermanMode || slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute || partOfCommittee && validatorReexecute || alwaysReexecuteBlockProposals || this.blobClient.canUpload();
|
|
206
|
-
const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute);
|
|
239
|
+
const validationResult = await this.blockProposalHandler.handleBlockProposal(proposal, proposalSender, !!shouldReexecute && !escapeHatchOpen);
|
|
207
240
|
if (!validationResult.isValid) {
|
|
208
241
|
this.log.warn(`Block proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
209
242
|
const reason = validationResult.reason || 'unknown';
|
|
@@ -222,7 +255,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
222
255
|
this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
|
|
223
256
|
}
|
|
224
257
|
// Slash invalid block proposals (can happen even when not in committee)
|
|
225
|
-
if (validationResult.reason && SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) && slashBroadcastedInvalidBlockPenalty > 0n) {
|
|
258
|
+
if (!escapeHatchOpen && validationResult.reason && SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason) && slashBroadcastedInvalidBlockPenalty > 0n) {
|
|
226
259
|
this.log.warn(`Slashing proposer for invalid block proposal`, proposalInfo);
|
|
227
260
|
this.slashInvalidBlock(proposal);
|
|
228
261
|
}
|
|
@@ -231,11 +264,13 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
231
264
|
this.log.info(`Validated block proposal for slot ${slotNumber}`, {
|
|
232
265
|
...proposalInfo,
|
|
233
266
|
inCommittee: partOfCommittee,
|
|
234
|
-
fishermanMode: this.config.fishermanMode || false
|
|
267
|
+
fishermanMode: this.config.fishermanMode || false,
|
|
268
|
+
escapeHatchOpen
|
|
235
269
|
});
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
270
|
+
if (escapeHatchOpen) {
|
|
271
|
+
this.log.warn(`Escape hatch open for slot ${slotNumber}, rejecting block proposal`, proposalInfo);
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
239
274
|
return true;
|
|
240
275
|
}
|
|
241
276
|
/**
|
|
@@ -246,11 +281,24 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
246
281
|
*/ async attestToCheckpointProposal(proposal, _proposalSender) {
|
|
247
282
|
const slotNumber = proposal.slotNumber;
|
|
248
283
|
const proposer = proposal.getSender();
|
|
284
|
+
// If escape hatch is open for this slot's epoch, do not attest.
|
|
285
|
+
if (await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber)) {
|
|
286
|
+
this.log.warn(`Escape hatch open for slot ${slotNumber}, skipping checkpoint attestation handling`);
|
|
287
|
+
return undefined;
|
|
288
|
+
}
|
|
249
289
|
// Reject proposals with invalid signatures
|
|
250
290
|
if (!proposer) {
|
|
251
291
|
this.log.warn(`Received checkpoint proposal with invalid signature for slot ${slotNumber}`);
|
|
252
292
|
return undefined;
|
|
253
293
|
}
|
|
294
|
+
// Ignore proposals from ourselves (may happen in HA setups)
|
|
295
|
+
if (this.getValidatorAddresses().some((addr)=>addr.equals(proposer))) {
|
|
296
|
+
this.log.warn(`Ignoring block proposal from self for slot ${slotNumber}`, {
|
|
297
|
+
proposer: proposer.toString(),
|
|
298
|
+
slotNumber
|
|
299
|
+
});
|
|
300
|
+
return undefined;
|
|
301
|
+
}
|
|
254
302
|
// Check that I have any address in current committee before attesting
|
|
255
303
|
const inCommittee = await this.epochCache.filterInCommittee(slotNumber, this.getValidatorAddresses());
|
|
256
304
|
const partOfCommittee = inCommittee.length > 0;
|
|
@@ -265,16 +313,9 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
265
313
|
txHashes: proposal.txHashes.map((t)=>t.toString()),
|
|
266
314
|
fishermanMode: this.config.fishermanMode || false
|
|
267
315
|
});
|
|
268
|
-
// TODO(palla/mbps): Remove this once checkpoint validation is stable.
|
|
269
|
-
// Check that we have successfully validated a block for this slot before attesting to the checkpoint.
|
|
270
|
-
if (!this.validatedBlockSlots.has(slotNumber)) {
|
|
271
|
-
this.log.warn(`No validated block found for slot ${slotNumber}, refusing to attest to checkpoint`, proposalInfo);
|
|
272
|
-
return undefined;
|
|
273
|
-
}
|
|
274
316
|
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
this.log.verbose(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
|
|
317
|
+
if (this.config.skipCheckpointProposalValidation) {
|
|
318
|
+
this.log.warn(`Skipping checkpoint proposal validation for slot ${slotNumber}`, proposalInfo);
|
|
278
319
|
} else {
|
|
279
320
|
const validationResult = await this.validateCheckpointProposal(proposal, proposalInfo);
|
|
280
321
|
if (!validationResult.isValid) {
|
|
@@ -321,11 +362,32 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
321
362
|
});
|
|
322
363
|
return undefined;
|
|
323
364
|
}
|
|
324
|
-
return this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
365
|
+
return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Checks if we should attest to a slot based on equivocation prevention rules.
|
|
369
|
+
* @returns true if we should attest, false if we should skip
|
|
370
|
+
*/ shouldAttestToSlot(slotNumber) {
|
|
371
|
+
// If attestToEquivocatedProposals is true, always allow
|
|
372
|
+
if (this.config.attestToEquivocatedProposals) {
|
|
373
|
+
return true;
|
|
374
|
+
}
|
|
375
|
+
// Check if incoming slot is strictly greater than last attested
|
|
376
|
+
if (this.lastAttestedProposal && slotNumber <= this.lastAttestedProposal.slotNumber) {
|
|
377
|
+
this.log.warn(`Refusing to process a proposal for slot ${slotNumber} given we already attested to a proposal for slot ${this.lastAttestedProposal.slotNumber}`);
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
380
|
+
return true;
|
|
325
381
|
}
|
|
326
382
|
async createCheckpointAttestationsFromProposal(proposal, attestors = []) {
|
|
383
|
+
// Equivocation check: must happen right before signing to minimize the race window
|
|
384
|
+
if (!this.shouldAttestToSlot(proposal.slotNumber)) {
|
|
385
|
+
return undefined;
|
|
386
|
+
}
|
|
327
387
|
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
328
|
-
|
|
388
|
+
// Track the proposal we attested to (to prevent equivocation)
|
|
389
|
+
this.lastAttestedProposal = proposal;
|
|
390
|
+
await this.p2pClient.addOwnCheckpointAttestations(attestations);
|
|
329
391
|
return attestations;
|
|
330
392
|
}
|
|
331
393
|
/**
|
|
@@ -333,7 +395,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
333
395
|
* @returns Validation result with isValid flag and reason if invalid.
|
|
334
396
|
*/ async validateCheckpointProposal(proposal, proposalInfo) {
|
|
335
397
|
const slot = proposal.slotNumber;
|
|
336
|
-
const timeoutSeconds = 10;
|
|
398
|
+
const timeoutSeconds = 10; // TODO(palla/mbps): This should map to the timetable settings
|
|
337
399
|
// Wait for last block to sync by archive
|
|
338
400
|
let lastBlockHeader;
|
|
339
401
|
try {
|
|
@@ -362,18 +424,8 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
362
424
|
reason: 'last_block_not_found'
|
|
363
425
|
};
|
|
364
426
|
}
|
|
365
|
-
// Get the last full block to determine checkpoint number
|
|
366
|
-
const lastBlock = await this.blockSource.getL2BlockNew(lastBlockHeader.getBlockNumber());
|
|
367
|
-
if (!lastBlock) {
|
|
368
|
-
this.log.warn(`Last block ${lastBlockHeader.getBlockNumber()} not found`, proposalInfo);
|
|
369
|
-
return {
|
|
370
|
-
isValid: false,
|
|
371
|
-
reason: 'last_block_not_found'
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
const checkpointNumber = lastBlock.checkpointNumber;
|
|
375
427
|
// Get all full blocks for the slot and checkpoint
|
|
376
|
-
const blocks = await this.getBlocksForSlot(slot
|
|
428
|
+
const blocks = await this.blockSource.getBlocksForSlot(slot);
|
|
377
429
|
if (blocks.length === 0) {
|
|
378
430
|
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
379
431
|
return {
|
|
@@ -388,14 +440,21 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
388
440
|
// Get checkpoint constants from first block
|
|
389
441
|
const firstBlock = blocks[0];
|
|
390
442
|
const constants = this.extractCheckpointConstants(firstBlock);
|
|
443
|
+
const checkpointNumber = firstBlock.checkpointNumber;
|
|
391
444
|
// Get L1-to-L2 messages for this checkpoint
|
|
392
445
|
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
446
|
+
// Compute the previous checkpoint out hashes for the epoch.
|
|
447
|
+
// TODO: There can be a more efficient way to get the previous checkpoint out hashes without having to fetch the
|
|
448
|
+
// actual checkpoints and the blocks/txs in them.
|
|
449
|
+
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
450
|
+
const previousCheckpoints = (await this.blockSource.getCheckpointsForEpoch(epoch)).filter((b)=>b.number < checkpointNumber).sort((a, b)=>a.number - b.number);
|
|
451
|
+
const previousCheckpointOutHashes = previousCheckpoints.map((c)=>c.getCheckpointOutHash());
|
|
393
452
|
// Fork world state at the block before the first block
|
|
394
453
|
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
395
454
|
const fork = await this.worldState.fork(parentBlockNumber);
|
|
396
455
|
try {
|
|
397
456
|
// Create checkpoint builder with all existing blocks
|
|
398
|
-
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, l1ToL2Messages, fork, blocks);
|
|
457
|
+
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, l1ToL2Messages, previousCheckpointOutHashes, fork, blocks, this.log.getBindings());
|
|
399
458
|
// Complete the checkpoint to get computed values
|
|
400
459
|
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
401
460
|
// Compare checkpoint header with proposal
|
|
@@ -422,6 +481,27 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
422
481
|
reason: 'archive_mismatch'
|
|
423
482
|
};
|
|
424
483
|
}
|
|
484
|
+
// Check that the accumulated epoch out hash matches the value in the proposal.
|
|
485
|
+
// The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
|
|
486
|
+
const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
|
|
487
|
+
const computedEpochOutHash = accumulateCheckpointOutHashes([
|
|
488
|
+
...previousCheckpointOutHashes,
|
|
489
|
+
checkpointOutHash
|
|
490
|
+
]);
|
|
491
|
+
const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
|
|
492
|
+
if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
|
|
493
|
+
this.log.warn(`Epoch out hash mismatch`, {
|
|
494
|
+
proposalEpochOutHash: proposalEpochOutHash.toString(),
|
|
495
|
+
computedEpochOutHash: computedEpochOutHash.toString(),
|
|
496
|
+
checkpointOutHash: checkpointOutHash.toString(),
|
|
497
|
+
previousCheckpointOutHashes: previousCheckpointOutHashes.map((h)=>h.toString()),
|
|
498
|
+
...proposalInfo
|
|
499
|
+
});
|
|
500
|
+
return {
|
|
501
|
+
isValid: false,
|
|
502
|
+
reason: 'out_hash_mismatch'
|
|
503
|
+
};
|
|
504
|
+
}
|
|
425
505
|
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
426
506
|
return {
|
|
427
507
|
isValid: true
|
|
@@ -431,36 +511,6 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
431
511
|
}
|
|
432
512
|
}
|
|
433
513
|
/**
|
|
434
|
-
* Get all full blocks for a given slot and checkpoint by walking backwards from the last block.
|
|
435
|
-
* Returns blocks in ascending order (earliest to latest).
|
|
436
|
-
* TODO(palla/mbps): Add getL2BlocksForSlot() to L2BlockSource interface for efficiency.
|
|
437
|
-
*/ async getBlocksForSlot(slot, lastBlockHeader, checkpointNumber) {
|
|
438
|
-
const blocks = [];
|
|
439
|
-
let currentHeader = lastBlockHeader;
|
|
440
|
-
const { genesisArchiveRoot } = await this.blockSource.getGenesisValues();
|
|
441
|
-
while(currentHeader.getSlot() === slot){
|
|
442
|
-
const block = await this.blockSource.getL2BlockNew(currentHeader.getBlockNumber());
|
|
443
|
-
if (!block) {
|
|
444
|
-
this.log.warn(`Block ${currentHeader.getBlockNumber()} not found while getting blocks for slot ${slot}`);
|
|
445
|
-
break;
|
|
446
|
-
}
|
|
447
|
-
if (block.checkpointNumber !== checkpointNumber) {
|
|
448
|
-
break;
|
|
449
|
-
}
|
|
450
|
-
blocks.unshift(block);
|
|
451
|
-
const prevArchive = currentHeader.lastArchive.root;
|
|
452
|
-
if (prevArchive.equals(genesisArchiveRoot)) {
|
|
453
|
-
break;
|
|
454
|
-
}
|
|
455
|
-
const prevHeader = await this.blockSource.getBlockHeaderByArchive(prevArchive);
|
|
456
|
-
if (!prevHeader || prevHeader.getSlot() !== slot) {
|
|
457
|
-
break;
|
|
458
|
-
}
|
|
459
|
-
currentHeader = prevHeader;
|
|
460
|
-
}
|
|
461
|
-
return blocks;
|
|
462
|
-
}
|
|
463
|
-
/**
|
|
464
514
|
* Extract checkpoint global variables from a block.
|
|
465
515
|
*/ extractCheckpointConstants(block) {
|
|
466
516
|
const gv = block.header.globalVariables;
|
|
@@ -482,13 +532,7 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
482
532
|
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
483
533
|
return;
|
|
484
534
|
}
|
|
485
|
-
|
|
486
|
-
const lastBlock = await this.blockSource.getL2BlockNew(lastBlockHeader.getBlockNumber());
|
|
487
|
-
if (!lastBlock) {
|
|
488
|
-
this.log.warn(`Failed to get last block for blob upload`, proposalInfo);
|
|
489
|
-
return;
|
|
490
|
-
}
|
|
491
|
-
const blocks = await this.getBlocksForSlot(proposal.slotNumber, lastBlockHeader, lastBlock.checkpointNumber);
|
|
535
|
+
const blocks = await this.blockSource.getBlocksForSlot(proposal.slotNumber);
|
|
492
536
|
if (blocks.length === 0) {
|
|
493
537
|
this.log.warn(`No blocks found for blob upload`, proposalInfo);
|
|
494
538
|
return;
|
|
@@ -526,29 +570,81 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
526
570
|
}
|
|
527
571
|
]);
|
|
528
572
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
573
|
+
/**
|
|
574
|
+
* Handle detection of a duplicate proposal (equivocation).
|
|
575
|
+
* Emits a slash event when a proposer sends multiple proposals for the same position.
|
|
576
|
+
*/ handleDuplicateProposal(info) {
|
|
577
|
+
const { slot, proposer, type } = info;
|
|
578
|
+
this.log.warn(`Triggering slash event for duplicate ${type} proposal from ${proposer.toString()} at slot ${slot}`, {
|
|
579
|
+
proposer: proposer.toString(),
|
|
580
|
+
slot,
|
|
581
|
+
type
|
|
582
|
+
});
|
|
583
|
+
// Emit slash event
|
|
584
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
585
|
+
{
|
|
586
|
+
validator: proposer,
|
|
587
|
+
amount: this.config.slashDuplicateProposalPenalty,
|
|
588
|
+
offenseType: OffenseType.DUPLICATE_PROPOSAL,
|
|
589
|
+
epochOrSlot: BigInt(slot)
|
|
590
|
+
}
|
|
591
|
+
]);
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Handle detection of a duplicate attestation (equivocation).
|
|
595
|
+
* Emits a slash event when an attester signs attestations for different proposals at the same slot.
|
|
596
|
+
*/ handleDuplicateAttestation(info) {
|
|
597
|
+
const { slot, attester } = info;
|
|
598
|
+
this.log.warn(`Triggering slash event for duplicate attestation from ${attester.toString()} at slot ${slot}`, {
|
|
599
|
+
attester: attester.toString(),
|
|
600
|
+
slot
|
|
601
|
+
});
|
|
602
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
603
|
+
{
|
|
604
|
+
validator: attester,
|
|
605
|
+
amount: this.config.slashDuplicateAttestationPenalty,
|
|
606
|
+
offenseType: OffenseType.DUPLICATE_ATTESTATION,
|
|
607
|
+
epochOrSlot: BigInt(slot)
|
|
608
|
+
}
|
|
609
|
+
]);
|
|
610
|
+
}
|
|
611
|
+
async createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, options = {}) {
|
|
612
|
+
// Validate that we're not creating a proposal for an older or equal position
|
|
613
|
+
if (this.lastProposedBlock) {
|
|
614
|
+
const lastSlot = this.lastProposedBlock.slotNumber;
|
|
615
|
+
const lastIndex = this.lastProposedBlock.indexWithinCheckpoint;
|
|
616
|
+
const newSlot = blockHeader.globalVariables.slotNumber;
|
|
617
|
+
if (newSlot < lastSlot || newSlot === lastSlot && indexWithinCheckpoint <= lastIndex) {
|
|
618
|
+
throw new Error(`Cannot create block proposal for slot ${newSlot} index ${indexWithinCheckpoint}: ` + `already proposed block for slot ${lastSlot} index ${lastIndex}`);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
535
621
|
this.log.info(`Assembling block proposal for block ${blockHeader.globalVariables.blockNumber} slot ${blockHeader.globalVariables.slotNumber}`);
|
|
536
622
|
const newProposal = await this.validationService.createBlockProposal(blockHeader, indexWithinCheckpoint, inHash, archive, txs, proposerAddress, {
|
|
537
623
|
...options,
|
|
538
624
|
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal
|
|
539
625
|
});
|
|
540
|
-
this.
|
|
626
|
+
this.lastProposedBlock = newProposal;
|
|
541
627
|
return newProposal;
|
|
542
628
|
}
|
|
543
|
-
async createCheckpointProposal(checkpointHeader, archive, lastBlockInfo, proposerAddress, options) {
|
|
629
|
+
async createCheckpointProposal(checkpointHeader, archive, lastBlockInfo, proposerAddress, options = {}) {
|
|
630
|
+
// Validate that we're not creating a proposal for an older or equal slot
|
|
631
|
+
if (this.lastProposedCheckpoint) {
|
|
632
|
+
const lastSlot = this.lastProposedCheckpoint.slotNumber;
|
|
633
|
+
const newSlot = checkpointHeader.slotNumber;
|
|
634
|
+
if (newSlot <= lastSlot) {
|
|
635
|
+
throw new Error(`Cannot create checkpoint proposal for slot ${newSlot}: ` + `already proposed checkpoint for slot ${lastSlot}`);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
544
638
|
this.log.info(`Assembling checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
|
|
545
|
-
|
|
639
|
+
const newProposal = await this.validationService.createCheckpointProposal(checkpointHeader, archive, lastBlockInfo, proposerAddress, options);
|
|
640
|
+
this.lastProposedCheckpoint = newProposal;
|
|
641
|
+
return newProposal;
|
|
546
642
|
}
|
|
547
643
|
async broadcastBlockProposal(proposal) {
|
|
548
644
|
await this.p2pClient.broadcastProposal(proposal);
|
|
549
645
|
}
|
|
550
|
-
async signAttestationsAndSigners(attestationsAndSigners, proposer) {
|
|
551
|
-
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer);
|
|
646
|
+
async signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber) {
|
|
647
|
+
return await this.validationService.signAttestationsAndSigners(attestationsAndSigners, proposer, slot, blockNumber);
|
|
552
648
|
}
|
|
553
649
|
async collectOwnAttestations(proposal) {
|
|
554
650
|
const slot = proposal.slotNumber;
|
|
@@ -557,6 +653,9 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
557
653
|
inCommittee
|
|
558
654
|
});
|
|
559
655
|
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
656
|
+
if (!attestations) {
|
|
657
|
+
return [];
|
|
658
|
+
}
|
|
560
659
|
// We broadcast our own attestations to our peers so, in case our block does not get mined on L1,
|
|
561
660
|
// other nodes can see that our validators did attest to this block proposal, and do not slash us
|
|
562
661
|
// due to inactivity for missed attestations.
|
|
@@ -630,7 +729,11 @@ const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
|
630
729
|
return Buffer.alloc(0);
|
|
631
730
|
}
|
|
632
731
|
const payloadToSign = authRequest.getPayloadToSign();
|
|
633
|
-
|
|
732
|
+
// AUTH_REQUEST doesn't require HA protection - multiple signatures are safe
|
|
733
|
+
const context = {
|
|
734
|
+
dutyType: DutyType.AUTH_REQUEST
|
|
735
|
+
};
|
|
736
|
+
const signature = await this.keyStore.signMessageWithAddress(addressToUse, payloadToSign, context);
|
|
634
737
|
const authResponse = new AuthResponse(statusMessage, signature);
|
|
635
738
|
return authResponse.toBuffer();
|
|
636
739
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/validator-client",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.858058eac",
|
|
4
4
|
"main": "dest/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -64,31 +64,35 @@
|
|
|
64
64
|
]
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@aztec/blob-client": "0.0.1-commit.
|
|
68
|
-
"@aztec/blob-lib": "0.0.1-commit.
|
|
69
|
-
"@aztec/constants": "0.0.1-commit.
|
|
70
|
-
"@aztec/epoch-cache": "0.0.1-commit.
|
|
71
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
72
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
73
|
-
"@aztec/node-keystore": "0.0.1-commit.
|
|
74
|
-
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.
|
|
75
|
-
"@aztec/p2p": "0.0.1-commit.
|
|
76
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
77
|
-
"@aztec/prover-client": "0.0.1-commit.
|
|
78
|
-
"@aztec/simulator": "0.0.1-commit.
|
|
79
|
-
"@aztec/slasher": "0.0.1-commit.
|
|
80
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
81
|
-
"@aztec/telemetry-client": "0.0.1-commit.
|
|
67
|
+
"@aztec/blob-client": "0.0.1-commit.858058eac",
|
|
68
|
+
"@aztec/blob-lib": "0.0.1-commit.858058eac",
|
|
69
|
+
"@aztec/constants": "0.0.1-commit.858058eac",
|
|
70
|
+
"@aztec/epoch-cache": "0.0.1-commit.858058eac",
|
|
71
|
+
"@aztec/ethereum": "0.0.1-commit.858058eac",
|
|
72
|
+
"@aztec/foundation": "0.0.1-commit.858058eac",
|
|
73
|
+
"@aztec/node-keystore": "0.0.1-commit.858058eac",
|
|
74
|
+
"@aztec/noir-protocol-circuits-types": "0.0.1-commit.858058eac",
|
|
75
|
+
"@aztec/p2p": "0.0.1-commit.858058eac",
|
|
76
|
+
"@aztec/protocol-contracts": "0.0.1-commit.858058eac",
|
|
77
|
+
"@aztec/prover-client": "0.0.1-commit.858058eac",
|
|
78
|
+
"@aztec/simulator": "0.0.1-commit.858058eac",
|
|
79
|
+
"@aztec/slasher": "0.0.1-commit.858058eac",
|
|
80
|
+
"@aztec/stdlib": "0.0.1-commit.858058eac",
|
|
81
|
+
"@aztec/telemetry-client": "0.0.1-commit.858058eac",
|
|
82
|
+
"@aztec/validator-ha-signer": "0.0.1-commit.858058eac",
|
|
82
83
|
"koa": "^2.16.1",
|
|
83
84
|
"koa-router": "^13.1.1",
|
|
84
85
|
"tslib": "^2.4.0",
|
|
85
86
|
"viem": "npm:@aztec/viem@2.38.2"
|
|
86
87
|
},
|
|
87
88
|
"devDependencies": {
|
|
89
|
+
"@aztec/archiver": "0.0.1-commit.858058eac",
|
|
90
|
+
"@aztec/world-state": "0.0.1-commit.858058eac",
|
|
91
|
+
"@electric-sql/pglite": "^0.3.14",
|
|
88
92
|
"@jest/globals": "^30.0.0",
|
|
89
93
|
"@types/jest": "^30.0.0",
|
|
90
94
|
"@types/node": "^22.15.17",
|
|
91
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
95
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
92
96
|
"jest": "^30.0.0",
|
|
93
97
|
"jest-mock-extended": "^4.0.0",
|
|
94
98
|
"ts-node": "^10.9.1",
|