@aztec/validator-client 0.0.1-commit.c2eed6949 → 0.0.1-commit.c52d6e7
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 +12 -11
- package/dest/checkpoint_builder.d.ts +17 -7
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +26 -9
- package/dest/config.d.ts +9 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +23 -10
- package/dest/duties/validation_service.d.ts +12 -13
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +32 -38
- package/dest/factory.d.ts +8 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +18 -6
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/key_store/web3signer_key_store.d.ts +10 -2
- package/dest/key_store/web3signer_key_store.d.ts.map +1 -1
- package/dest/key_store/web3signer_key_store.js +32 -41
- package/dest/metrics.d.ts +6 -2
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +15 -1
- package/dest/proposal_handler.d.ts +166 -0
- package/dest/proposal_handler.d.ts.map +1 -0
- package/dest/proposal_handler.js +1303 -0
- package/dest/validator.d.ts +35 -21
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +228 -250
- package/package.json +19 -19
- package/src/checkpoint_builder.ts +28 -10
- package/src/config.ts +31 -12
- package/src/duties/validation_service.ts +51 -47
- package/src/factory.ts +25 -4
- package/src/index.ts +1 -1
- package/src/key_store/web3signer_key_store.ts +43 -59
- package/src/metrics.ts +21 -1
- package/src/proposal_handler.ts +1409 -0
- package/src/validator.ts +296 -281
- package/dest/block_proposal_handler.d.ts +0 -64
- package/dest/block_proposal_handler.d.ts.map +0 -1
- package/dest/block_proposal_handler.js +0 -614
- package/src/block_proposal_handler.ts +0 -632
package/src/validator.ts
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
1
|
import type { BlobClientInterface } from '@aztec/blob-client/client';
|
|
2
2
|
import { type Blob, getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
3
3
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
BlockNumber,
|
|
7
|
-
CheckpointNumber,
|
|
8
|
-
EpochNumber,
|
|
9
|
-
IndexWithinCheckpoint,
|
|
10
|
-
SlotNumber,
|
|
11
|
-
} from '@aztec/foundation/branded-types';
|
|
4
|
+
import { CheckpointNumber, EpochNumber, IndexWithinCheckpoint, SlotNumber } from '@aztec/foundation/branded-types';
|
|
12
5
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
13
|
-
import { TimeoutError } from '@aztec/foundation/error';
|
|
14
6
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
15
|
-
import
|
|
7
|
+
import { Signature } from '@aztec/foundation/eth-signature';
|
|
8
|
+
import { FifoSet } from '@aztec/foundation/fifo-set';
|
|
16
9
|
import { type LogData, type Logger, createLogger } from '@aztec/foundation/log';
|
|
17
|
-
import { retryUntil } from '@aztec/foundation/retry';
|
|
18
10
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
19
11
|
import { sleep } from '@aztec/foundation/sleep';
|
|
20
12
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
21
13
|
import type { KeystoreManager } from '@aztec/node-keystore';
|
|
22
|
-
import type { DuplicateAttestationInfo, DuplicateProposalInfo, P2P, PeerId } from '@aztec/p2p';
|
|
14
|
+
import type { DuplicateAttestationInfo, DuplicateProposalInfo, OversizedProposalInfo, P2P, PeerId } from '@aztec/p2p';
|
|
23
15
|
import { AuthRequest, AuthResponse, BlockProposalValidator, ReqRespSubProtocol } from '@aztec/p2p';
|
|
24
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
OffenseType,
|
|
18
|
+
WANT_TO_CLEAR_SLASH_EVENT,
|
|
19
|
+
WANT_TO_SLASH_EVENT,
|
|
20
|
+
type Watcher,
|
|
21
|
+
type WatcherEmitter,
|
|
22
|
+
getOffenseTypeName,
|
|
23
|
+
} from '@aztec/slasher';
|
|
25
24
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
26
|
-
import type { CommitteeAttestationsAndSigners,
|
|
27
|
-
import {
|
|
28
|
-
import { getEpochAtSlot
|
|
25
|
+
import type { CommitteeAttestationsAndSigners, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
|
|
26
|
+
import type { CheckpointReexecutionTracker } from '@aztec/stdlib/checkpoint';
|
|
27
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
29
28
|
import type {
|
|
30
|
-
CreateCheckpointProposalLastBlockData,
|
|
31
29
|
ITxProvider,
|
|
32
30
|
Validator,
|
|
33
31
|
ValidatorClientFullConfig,
|
|
34
32
|
WorldStateSynchronizer,
|
|
35
33
|
} from '@aztec/stdlib/interfaces/server';
|
|
36
|
-
import {
|
|
34
|
+
import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
37
35
|
import {
|
|
38
36
|
type BlockProposal,
|
|
39
37
|
type BlockProposalOptions,
|
|
40
|
-
|
|
38
|
+
CheckpointAttestation,
|
|
41
39
|
CheckpointProposal,
|
|
42
40
|
type CheckpointProposalCore,
|
|
43
41
|
type CheckpointProposalOptions,
|
|
42
|
+
type CoordinationSignatureContext,
|
|
44
43
|
} from '@aztec/stdlib/p2p';
|
|
45
44
|
import type { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
46
|
-
import
|
|
45
|
+
import { ConsensusTimetable } from '@aztec/stdlib/timetable';
|
|
46
|
+
import type { BlockHeader, Tx } from '@aztec/stdlib/tx';
|
|
47
47
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
48
48
|
import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
|
|
49
49
|
import {
|
|
@@ -57,23 +57,26 @@ import type { ValidatorHASigner } from '@aztec/validator-ha-signer/validator-ha-
|
|
|
57
57
|
import { EventEmitter } from 'events';
|
|
58
58
|
import type { TypedDataDefinition } from 'viem';
|
|
59
59
|
|
|
60
|
-
import { BlockProposalHandler, type BlockProposalValidationFailureReason } from './block_proposal_handler.js';
|
|
61
60
|
import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
|
|
61
|
+
import { DEFAULT_MAX_GOSSIP_CLOCK_DISPARITY_MS } from './config.js';
|
|
62
62
|
import { ValidationService } from './duties/validation_service.js';
|
|
63
63
|
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
64
64
|
import type { ExtendedValidatorKeyStore } from './key_store/interface.js';
|
|
65
65
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
66
66
|
import { ValidatorMetrics } from './metrics.js';
|
|
67
|
+
import {
|
|
68
|
+
type BlockProposalValidationFailureReason,
|
|
69
|
+
type CheckpointProposalValidationFailureResult,
|
|
70
|
+
ProposalHandler,
|
|
71
|
+
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT,
|
|
72
|
+
SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT,
|
|
73
|
+
} from './proposal_handler.js';
|
|
67
74
|
|
|
68
75
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
69
76
|
// Just cap the set to avoid unbounded growth.
|
|
70
77
|
const MAX_PROPOSERS_OF_INVALID_BLOCKS = 1000;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT: BlockProposalValidationFailureReason[] = [
|
|
74
|
-
'state_mismatch',
|
|
75
|
-
'failed_txs',
|
|
76
|
-
];
|
|
78
|
+
const MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS = 1000;
|
|
79
|
+
const MAX_TRACKED_BAD_ATTESTATIONS = 10_000;
|
|
77
80
|
|
|
78
81
|
/**
|
|
79
82
|
* Validator Client
|
|
@@ -97,7 +100,10 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
97
100
|
/** Tracks the last epoch in which each attester successfully submitted at least one attestation. */
|
|
98
101
|
private lastAttestedEpochByAttester: Map<string, EpochNumber> = new Map();
|
|
99
102
|
|
|
100
|
-
private proposersOfInvalidBlocks
|
|
103
|
+
private proposersOfInvalidBlocks = FifoSet.withLimit<string>(MAX_PROPOSERS_OF_INVALID_BLOCKS);
|
|
104
|
+
private invalidCheckpointProposalOffenseKeys = FifoSet.withLimit<string>(MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS);
|
|
105
|
+
private oversizedProposalOffenseKeys = FifoSet.withLimit<string>(MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS);
|
|
106
|
+
private badAttestationOffenseKeys = FifoSet.withLimit<string>(MAX_TRACKED_BAD_ATTESTATIONS);
|
|
101
107
|
|
|
102
108
|
/** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */
|
|
103
109
|
private lastAttestedProposal?: CheckpointProposalCore;
|
|
@@ -106,7 +112,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
106
112
|
private keyStore: ExtendedValidatorKeyStore,
|
|
107
113
|
private epochCache: EpochCache,
|
|
108
114
|
private p2pClient: P2P,
|
|
109
|
-
private
|
|
115
|
+
private proposalHandler: ProposalHandler,
|
|
110
116
|
private blockSource: L2BlockSource,
|
|
111
117
|
private checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
112
118
|
private worldState: WorldStateSynchronizer,
|
|
@@ -126,11 +132,17 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
126
132
|
this.tracer = telemetry.getTracer('Validator');
|
|
127
133
|
this.metrics = new ValidatorMetrics(telemetry);
|
|
128
134
|
|
|
129
|
-
this.validationService = new ValidationService(
|
|
135
|
+
this.validationService = new ValidationService(
|
|
136
|
+
keyStore,
|
|
137
|
+
this.getSignatureContext(),
|
|
138
|
+
this.log.createChild('validation-service'),
|
|
139
|
+
);
|
|
140
|
+
this.proposalHandler.setCheckpointProposalValidationFailureCallback((proposal, result, proposalInfo) =>
|
|
141
|
+
this.handleInvalidCheckpointProposal(proposal, result, proposalInfo),
|
|
142
|
+
);
|
|
130
143
|
|
|
131
144
|
// Refresh epoch cache every second to trigger alert if participation in committee changes
|
|
132
145
|
this.epochCacheUpdateLoop = new RunningPromise(this.handleEpochCommitteeUpdate.bind(this), this.log, 1000);
|
|
133
|
-
|
|
134
146
|
const myAddresses = this.getValidatorAddresses();
|
|
135
147
|
this.log.verbose(`Initialized validator with addresses: ${myAddresses.map(a => a.toString()).join(', ')}`);
|
|
136
148
|
}
|
|
@@ -199,16 +211,28 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
199
211
|
txProvider: ITxProvider,
|
|
200
212
|
keyStoreManager: KeystoreManager,
|
|
201
213
|
blobClient: BlobClientInterface,
|
|
214
|
+
reexecutionTracker: CheckpointReexecutionTracker,
|
|
202
215
|
dateProvider: DateProvider = new DateProvider(),
|
|
203
216
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
204
217
|
slashingProtectionDb?: SlashingProtectionDatabase,
|
|
205
218
|
) {
|
|
206
219
|
const metrics = new ValidatorMetrics(telemetry);
|
|
207
|
-
const
|
|
220
|
+
const consensusTimetable = new ConsensusTimetable({
|
|
221
|
+
l1Constants: epochCache.getL1Constants(),
|
|
222
|
+
blockDuration: config.blockDurationMs / 1000,
|
|
223
|
+
});
|
|
224
|
+
const blockProposalValidator = new BlockProposalValidator(epochCache, consensusTimetable, {
|
|
208
225
|
txsPermitted: !config.disableTransactions,
|
|
209
226
|
maxTxsPerBlock: config.validateMaxTxsPerBlock,
|
|
227
|
+
maxBlocksPerCheckpoint: config.maxBlocksPerCheckpoint,
|
|
228
|
+
skipSlotValidation: config.skipProposalSlotValidation,
|
|
229
|
+
signatureContext: {
|
|
230
|
+
chainId: config.l1ChainId,
|
|
231
|
+
rollupAddress: config.rollupAddress,
|
|
232
|
+
},
|
|
233
|
+
clockDisparityMs: config.maxGossipClockDisparityMs ?? DEFAULT_MAX_GOSSIP_CLOCK_DISPARITY_MS,
|
|
210
234
|
});
|
|
211
|
-
const
|
|
235
|
+
const proposalHandler = new ProposalHandler(
|
|
212
236
|
checkpointsBuilder,
|
|
213
237
|
worldState,
|
|
214
238
|
blockSource,
|
|
@@ -216,10 +240,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
216
240
|
txProvider,
|
|
217
241
|
blockProposalValidator,
|
|
218
242
|
epochCache,
|
|
243
|
+
consensusTimetable,
|
|
219
244
|
config,
|
|
245
|
+
blobClient,
|
|
246
|
+
reexecutionTracker,
|
|
220
247
|
metrics,
|
|
221
248
|
dateProvider,
|
|
222
249
|
telemetry,
|
|
250
|
+
undefined,
|
|
223
251
|
);
|
|
224
252
|
|
|
225
253
|
const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
@@ -255,7 +283,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
255
283
|
validatorKeyStore,
|
|
256
284
|
epochCache,
|
|
257
285
|
p2pClient,
|
|
258
|
-
|
|
286
|
+
proposalHandler,
|
|
259
287
|
blockSource,
|
|
260
288
|
checkpointsBuilder,
|
|
261
289
|
worldState,
|
|
@@ -276,14 +304,21 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
276
304
|
.filter(addr => !this.config.disabledValidators.some(disabled => disabled.equals(addr)));
|
|
277
305
|
}
|
|
278
306
|
|
|
279
|
-
public
|
|
280
|
-
return this.
|
|
307
|
+
public getProposalHandler() {
|
|
308
|
+
return this.proposalHandler;
|
|
281
309
|
}
|
|
282
310
|
|
|
283
311
|
public signWithAddress(addr: EthAddress, msg: TypedDataDefinition, context: SigningContext) {
|
|
284
312
|
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
285
313
|
}
|
|
286
314
|
|
|
315
|
+
private getSignatureContext(): CoordinationSignatureContext {
|
|
316
|
+
return {
|
|
317
|
+
chainId: this.config.l1ChainId,
|
|
318
|
+
rollupAddress: this.config.rollupAddress,
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
|
|
287
322
|
public getCoinbaseForAttestor(attestor: EthAddress): EthAddress {
|
|
288
323
|
return this.keyStore.getCoinbaseAddress(attestor);
|
|
289
324
|
}
|
|
@@ -296,14 +331,27 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
296
331
|
return this.config;
|
|
297
332
|
}
|
|
298
333
|
|
|
334
|
+
public hasProposalEquivocation(slotNumber: SlotNumber): boolean {
|
|
335
|
+
return this.proposalHandler.hasProposalEquivocation(slotNumber);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
public hasInvalidProposals(slotNumber: SlotNumber): boolean {
|
|
339
|
+
return this.proposalHandler.hasInvalidProposals(slotNumber);
|
|
340
|
+
}
|
|
341
|
+
|
|
299
342
|
public updateConfig(config: Partial<ValidatorClientFullConfig>) {
|
|
300
343
|
this.config = { ...this.config, ...config };
|
|
344
|
+
this.proposalHandler.updateConfig(config);
|
|
301
345
|
}
|
|
302
346
|
|
|
303
347
|
public reloadKeystore(newManager: KeystoreManager): void {
|
|
304
348
|
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
305
349
|
this.keyStore = new HAKeyStore(newAdapter, this.slashingProtectionSigner);
|
|
306
|
-
this.validationService = new ValidationService(
|
|
350
|
+
this.validationService = new ValidationService(
|
|
351
|
+
this.keyStore,
|
|
352
|
+
this.getSignatureContext(),
|
|
353
|
+
this.log.createChild('validation-service'),
|
|
354
|
+
);
|
|
307
355
|
}
|
|
308
356
|
|
|
309
357
|
public async start() {
|
|
@@ -350,18 +398,27 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
350
398
|
checkpoint: CheckpointProposalCore,
|
|
351
399
|
proposalSender: PeerId,
|
|
352
400
|
): Promise<CheckpointAttestation[] | undefined> => this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
353
|
-
this.p2pClient.
|
|
401
|
+
this.p2pClient.registerValidatorCheckpointProposalHandler(checkpointHandler);
|
|
354
402
|
|
|
355
403
|
// Duplicate proposal handler - triggers slashing for equivocation
|
|
356
404
|
this.p2pClient.registerDuplicateProposalCallback((info: DuplicateProposalInfo) => {
|
|
357
405
|
this.handleDuplicateProposal(info);
|
|
358
406
|
});
|
|
359
407
|
|
|
408
|
+
// Oversized proposal handler - triggers slashing for proposals beyond the per-checkpoint block limit
|
|
409
|
+
this.p2pClient.registerOversizedProposalCallback((info: OversizedProposalInfo) => {
|
|
410
|
+
this.handleOversizedProposal(info);
|
|
411
|
+
});
|
|
412
|
+
|
|
360
413
|
// Duplicate attestation handler - triggers slashing for attestation equivocation
|
|
361
414
|
this.p2pClient.registerDuplicateAttestationCallback((info: DuplicateAttestationInfo) => {
|
|
362
415
|
this.handleDuplicateAttestation(info);
|
|
363
416
|
});
|
|
364
417
|
|
|
418
|
+
this.p2pClient.registerCheckpointAttestationCallback((attestation: CheckpointAttestation) => {
|
|
419
|
+
this.handleCheckpointAttestation(attestation);
|
|
420
|
+
});
|
|
421
|
+
|
|
365
422
|
const myAddresses = this.getValidatorAddresses();
|
|
366
423
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
367
424
|
|
|
@@ -408,22 +465,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
408
465
|
fishermanMode: this.config.fishermanMode || false,
|
|
409
466
|
});
|
|
410
467
|
|
|
411
|
-
// Reexecute
|
|
412
|
-
|
|
413
|
-
const { validatorReexecute, slashBroadcastedInvalidBlockPenalty, alwaysReexecuteBlockProposals, fishermanMode } =
|
|
414
|
-
this.config;
|
|
415
|
-
const shouldReexecute =
|
|
416
|
-
fishermanMode ||
|
|
417
|
-
(slashBroadcastedInvalidBlockPenalty > 0n && validatorReexecute) ||
|
|
418
|
-
(partOfCommittee && validatorReexecute) ||
|
|
419
|
-
alwaysReexecuteBlockProposals ||
|
|
420
|
-
this.blobClient.canUpload();
|
|
421
|
-
|
|
422
|
-
const validationResult = await this.blockProposalHandler.handleBlockProposal(
|
|
423
|
-
proposal,
|
|
424
|
-
proposalSender,
|
|
425
|
-
!!shouldReexecute && !escapeHatchOpen,
|
|
426
|
-
);
|
|
468
|
+
// Reexecute outside the escape hatch so slashing observers can detect invalid proposals even when penalties are 0.
|
|
469
|
+
const validationResult = await this.proposalHandler.handleBlockProposal(proposal, proposalSender, !escapeHatchOpen);
|
|
427
470
|
|
|
428
471
|
if (!validationResult.isValid) {
|
|
429
472
|
const reason = validationResult.reason || 'unknown';
|
|
@@ -437,6 +480,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
437
480
|
'failed_txs',
|
|
438
481
|
'in_hash_mismatch',
|
|
439
482
|
'parent_block_wrong_slot',
|
|
483
|
+
'duplicate_txs',
|
|
484
|
+
'invalid_embedded_txs',
|
|
440
485
|
];
|
|
441
486
|
|
|
442
487
|
if (badProposalReasons.includes(reason as BlockProposalValidationFailureReason)) {
|
|
@@ -446,15 +491,18 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
446
491
|
this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
|
|
447
492
|
}
|
|
448
493
|
|
|
449
|
-
// Slash invalid block proposals (can happen even when not in committee)
|
|
450
494
|
if (
|
|
451
495
|
!escapeHatchOpen &&
|
|
452
496
|
validationResult.reason &&
|
|
453
|
-
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason)
|
|
454
|
-
slashBroadcastedInvalidBlockPenalty > 0n
|
|
497
|
+
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason)
|
|
455
498
|
) {
|
|
456
|
-
this.log.
|
|
499
|
+
this.log.info(`Detected invalid block proposal offense`, {
|
|
500
|
+
...proposalInfo,
|
|
501
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
502
|
+
offenseType: getOffenseTypeName(OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL),
|
|
503
|
+
});
|
|
457
504
|
this.slashInvalidBlock(proposal);
|
|
505
|
+
this.markInvalidProposalSlot(proposal.slotNumber);
|
|
458
506
|
}
|
|
459
507
|
return false;
|
|
460
508
|
}
|
|
@@ -493,29 +541,20 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
493
541
|
return undefined;
|
|
494
542
|
}
|
|
495
543
|
|
|
496
|
-
//
|
|
497
|
-
if (!
|
|
498
|
-
this.log.warn(`Received checkpoint proposal with invalid signature for proposal slot ${proposalSlotNumber}`);
|
|
544
|
+
// Early-out for equivocation: refuses if we've already attested to a higher slot.
|
|
545
|
+
if (!this.shouldAttestToSlot(proposalSlotNumber)) {
|
|
499
546
|
return undefined;
|
|
500
547
|
}
|
|
501
548
|
|
|
502
549
|
// Ignore proposals from ourselves (may happen in HA setups)
|
|
503
|
-
if (this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
504
|
-
this.log.debug(`
|
|
550
|
+
if (proposer && this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
551
|
+
this.log.debug(`Not attesting to block proposal from self for slot ${proposalSlotNumber}`, {
|
|
505
552
|
proposer: proposer.toString(),
|
|
506
553
|
proposalSlotNumber,
|
|
507
554
|
});
|
|
508
555
|
return undefined;
|
|
509
556
|
}
|
|
510
557
|
|
|
511
|
-
// Validate fee asset price modifier is within allowed range
|
|
512
|
-
if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
|
|
513
|
-
this.log.warn(
|
|
514
|
-
`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${proposalSlotNumber}`,
|
|
515
|
-
);
|
|
516
|
-
return undefined;
|
|
517
|
-
}
|
|
518
|
-
|
|
519
558
|
// Check that I have any address in the committee where this checkpoint will land before attesting
|
|
520
559
|
const inCommittee = await this.epochCache.filterInCommittee(proposalSlotNumber, this.getValidatorAddresses());
|
|
521
560
|
const partOfCommittee = inCommittee.length > 0;
|
|
@@ -523,27 +562,26 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
523
562
|
const proposalInfo = {
|
|
524
563
|
proposalSlotNumber,
|
|
525
564
|
archive: proposal.archive.toString(),
|
|
526
|
-
proposer: proposer
|
|
565
|
+
proposer: proposer?.toString(),
|
|
527
566
|
};
|
|
528
567
|
this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
529
568
|
...proposalInfo,
|
|
530
569
|
fishermanMode: this.config.fishermanMode || false,
|
|
531
570
|
});
|
|
532
571
|
|
|
533
|
-
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
|
|
572
|
+
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set).
|
|
573
|
+
// Uses the cached result from the all-nodes callback if available (avoids double validation).
|
|
574
|
+
let checkpointNumber: CheckpointNumber;
|
|
534
575
|
if (this.config.skipCheckpointProposalValidation) {
|
|
535
576
|
this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
|
|
577
|
+
checkpointNumber = CheckpointNumber(0);
|
|
536
578
|
} else {
|
|
537
|
-
const validationResult = await this.
|
|
579
|
+
const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
|
|
538
580
|
if (!validationResult.isValid) {
|
|
539
581
|
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
540
582
|
return undefined;
|
|
541
583
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
// Upload blobs to filestore if we can (fire and forget)
|
|
545
|
-
if (this.blobClient.canUpload()) {
|
|
546
|
-
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
584
|
+
checkpointNumber = validationResult.checkpointNumber;
|
|
547
585
|
}
|
|
548
586
|
|
|
549
587
|
// Check that I have any address in current committee before attesting
|
|
@@ -601,7 +639,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
601
639
|
return undefined;
|
|
602
640
|
}
|
|
603
641
|
|
|
604
|
-
return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
642
|
+
return await this.createCheckpointAttestationsFromProposal(proposal, attestors, checkpointNumber);
|
|
605
643
|
}
|
|
606
644
|
|
|
607
645
|
/**
|
|
@@ -628,13 +666,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
628
666
|
private async createCheckpointAttestationsFromProposal(
|
|
629
667
|
proposal: CheckpointProposalCore,
|
|
630
668
|
attestors: EthAddress[] = [],
|
|
669
|
+
checkpointNumber: CheckpointNumber,
|
|
631
670
|
): Promise<CheckpointAttestation[] | undefined> {
|
|
632
671
|
// Equivocation check: must happen right before signing to minimize the race window
|
|
633
672
|
if (!this.shouldAttestToSlot(proposal.slotNumber)) {
|
|
634
673
|
return undefined;
|
|
635
674
|
}
|
|
636
675
|
|
|
637
|
-
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
676
|
+
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors, checkpointNumber);
|
|
638
677
|
|
|
639
678
|
// Track the proposal we attested to (to prevent equivocation)
|
|
640
679
|
this.lastAttestedProposal = proposal;
|
|
@@ -643,178 +682,12 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
643
682
|
return attestations;
|
|
644
683
|
}
|
|
645
684
|
|
|
646
|
-
/**
|
|
647
|
-
* Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
|
|
648
|
-
* @returns Validation result with isValid flag and reason if invalid.
|
|
649
|
-
*/
|
|
650
|
-
private async validateCheckpointProposal(
|
|
651
|
-
proposal: CheckpointProposalCore,
|
|
652
|
-
proposalInfo: LogData,
|
|
653
|
-
): Promise<{ isValid: true } | { isValid: false; reason: string }> {
|
|
654
|
-
const slot = proposal.slotNumber;
|
|
655
|
-
|
|
656
|
-
// Timeout block syncing at the start of the next slot
|
|
657
|
-
const config = this.checkpointsBuilder.getConfig();
|
|
658
|
-
const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
|
|
659
|
-
const timeoutSeconds = Math.max(1, nextSlotTimestampSeconds - Math.floor(this.dateProvider.now() / 1000));
|
|
660
|
-
|
|
661
|
-
// Wait for last block to sync by archive
|
|
662
|
-
let lastBlockHeader: BlockHeader | undefined;
|
|
663
|
-
try {
|
|
664
|
-
lastBlockHeader = await retryUntil(
|
|
665
|
-
async () => {
|
|
666
|
-
await this.blockSource.syncImmediate();
|
|
667
|
-
return this.blockSource.getBlockHeaderByArchive(proposal.archive);
|
|
668
|
-
},
|
|
669
|
-
`waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`,
|
|
670
|
-
timeoutSeconds,
|
|
671
|
-
0.5,
|
|
672
|
-
);
|
|
673
|
-
} catch (err) {
|
|
674
|
-
if (err instanceof TimeoutError) {
|
|
675
|
-
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
676
|
-
return { isValid: false, reason: 'last_block_not_found' };
|
|
677
|
-
}
|
|
678
|
-
this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
|
|
679
|
-
return { isValid: false, reason: 'block_fetch_error' };
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
if (!lastBlockHeader) {
|
|
683
|
-
this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
|
|
684
|
-
return { isValid: false, reason: 'last_block_not_found' };
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
// Get all full blocks for the slot and checkpoint
|
|
688
|
-
const blocks = await this.blockSource.getBlocksForSlot(slot);
|
|
689
|
-
if (blocks.length === 0) {
|
|
690
|
-
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
691
|
-
return { isValid: false, reason: 'no_blocks_for_slot' };
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
// Ensure the last block for this slot matches the archive in the checkpoint proposal
|
|
695
|
-
if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
|
|
696
|
-
this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
|
|
697
|
-
return { isValid: false, reason: 'last_block_archive_mismatch' };
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
701
|
-
...proposalInfo,
|
|
702
|
-
blockNumbers: blocks.map(b => b.number),
|
|
703
|
-
});
|
|
704
|
-
|
|
705
|
-
// Get checkpoint constants from first block
|
|
706
|
-
const firstBlock = blocks[0];
|
|
707
|
-
const constants = this.extractCheckpointConstants(firstBlock);
|
|
708
|
-
const checkpointNumber = firstBlock.checkpointNumber;
|
|
709
|
-
|
|
710
|
-
// Get L1-to-L2 messages for this checkpoint
|
|
711
|
-
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
712
|
-
|
|
713
|
-
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
714
|
-
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
715
|
-
const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch))
|
|
716
|
-
.filter(c => c.checkpointNumber < checkpointNumber)
|
|
717
|
-
.map(c => c.checkpointOutHash);
|
|
718
|
-
|
|
719
|
-
// Fork world state at the block before the first block
|
|
720
|
-
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
721
|
-
const fork = await this.worldState.fork(parentBlockNumber);
|
|
722
|
-
|
|
723
|
-
try {
|
|
724
|
-
// Create checkpoint builder with all existing blocks
|
|
725
|
-
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(
|
|
726
|
-
checkpointNumber,
|
|
727
|
-
constants,
|
|
728
|
-
proposal.feeAssetPriceModifier,
|
|
729
|
-
l1ToL2Messages,
|
|
730
|
-
previousCheckpointOutHashes,
|
|
731
|
-
fork,
|
|
732
|
-
blocks,
|
|
733
|
-
this.log.getBindings(),
|
|
734
|
-
);
|
|
735
|
-
|
|
736
|
-
// Complete the checkpoint to get computed values
|
|
737
|
-
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
738
|
-
|
|
739
|
-
// Compare checkpoint header with proposal
|
|
740
|
-
if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
|
|
741
|
-
this.log.warn(`Checkpoint header mismatch`, {
|
|
742
|
-
...proposalInfo,
|
|
743
|
-
computed: computedCheckpoint.header.toInspect(),
|
|
744
|
-
proposal: proposal.checkpointHeader.toInspect(),
|
|
745
|
-
});
|
|
746
|
-
return { isValid: false, reason: 'checkpoint_header_mismatch' };
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
// Compare archive root with proposal
|
|
750
|
-
if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
|
|
751
|
-
this.log.warn(`Archive root mismatch`, {
|
|
752
|
-
...proposalInfo,
|
|
753
|
-
computed: computedCheckpoint.archive.root.toString(),
|
|
754
|
-
proposal: proposal.archive.toString(),
|
|
755
|
-
});
|
|
756
|
-
return { isValid: false, reason: 'archive_mismatch' };
|
|
757
|
-
}
|
|
758
|
-
|
|
759
|
-
// Check that the accumulated epoch out hash matches the value in the proposal.
|
|
760
|
-
// The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
|
|
761
|
-
const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
|
|
762
|
-
const computedEpochOutHash = accumulateCheckpointOutHashes([...previousCheckpointOutHashes, checkpointOutHash]);
|
|
763
|
-
const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
|
|
764
|
-
if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
|
|
765
|
-
this.log.warn(`Epoch out hash mismatch`, {
|
|
766
|
-
proposalEpochOutHash: proposalEpochOutHash.toString(),
|
|
767
|
-
computedEpochOutHash: computedEpochOutHash.toString(),
|
|
768
|
-
checkpointOutHash: checkpointOutHash.toString(),
|
|
769
|
-
previousCheckpointOutHashes: previousCheckpointOutHashes.map(h => h.toString()),
|
|
770
|
-
...proposalInfo,
|
|
771
|
-
});
|
|
772
|
-
return { isValid: false, reason: 'out_hash_mismatch' };
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
// Final round of validations on the checkpoint, just in case.
|
|
776
|
-
try {
|
|
777
|
-
validateCheckpoint(computedCheckpoint, {
|
|
778
|
-
rollupManaLimit: this.checkpointsBuilder.getConfig().rollupManaLimit,
|
|
779
|
-
maxDABlockGas: this.config.validateMaxDABlockGas,
|
|
780
|
-
maxL2BlockGas: this.config.validateMaxL2BlockGas,
|
|
781
|
-
maxTxsPerBlock: this.config.validateMaxTxsPerBlock,
|
|
782
|
-
maxTxsPerCheckpoint: this.config.validateMaxTxsPerCheckpoint,
|
|
783
|
-
});
|
|
784
|
-
} catch (err) {
|
|
785
|
-
this.log.warn(`Checkpoint validation failed: ${err}`, proposalInfo);
|
|
786
|
-
return { isValid: false, reason: 'checkpoint_validation_failed' };
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
790
|
-
return { isValid: true };
|
|
791
|
-
} finally {
|
|
792
|
-
await fork.close();
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
/**
|
|
797
|
-
* Extract checkpoint global variables from a block.
|
|
798
|
-
*/
|
|
799
|
-
private extractCheckpointConstants(block: L2Block): CheckpointGlobalVariables {
|
|
800
|
-
const gv = block.header.globalVariables;
|
|
801
|
-
return {
|
|
802
|
-
chainId: gv.chainId,
|
|
803
|
-
version: gv.version,
|
|
804
|
-
slotNumber: gv.slotNumber,
|
|
805
|
-
timestamp: gv.timestamp,
|
|
806
|
-
coinbase: gv.coinbase,
|
|
807
|
-
feeRecipient: gv.feeRecipient,
|
|
808
|
-
gasFees: gv.gasFees,
|
|
809
|
-
};
|
|
810
|
-
}
|
|
811
|
-
|
|
812
685
|
/**
|
|
813
686
|
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
814
687
|
*/
|
|
815
688
|
protected async uploadBlobsForCheckpoint(proposal: CheckpointProposalCore, proposalInfo: LogData): Promise<void> {
|
|
816
689
|
try {
|
|
817
|
-
const lastBlockHeader = await this.blockSource.
|
|
690
|
+
const lastBlockHeader = (await this.blockSource.getBlockData({ archive: proposal.archive }))?.header;
|
|
818
691
|
if (!lastBlockHeader) {
|
|
819
692
|
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
820
693
|
return;
|
|
@@ -847,12 +720,6 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
847
720
|
return;
|
|
848
721
|
}
|
|
849
722
|
|
|
850
|
-
// Trim the set if it's too big.
|
|
851
|
-
if (this.proposersOfInvalidBlocks.size > MAX_PROPOSERS_OF_INVALID_BLOCKS) {
|
|
852
|
-
// remove oldest proposer. `values` is guaranteed to be in insertion order.
|
|
853
|
-
this.proposersOfInvalidBlocks.delete(this.proposersOfInvalidBlocks.values().next().value!);
|
|
854
|
-
}
|
|
855
|
-
|
|
856
723
|
this.proposersOfInvalidBlocks.add(proposer.toString());
|
|
857
724
|
|
|
858
725
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
@@ -865,20 +732,148 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
865
732
|
]);
|
|
866
733
|
}
|
|
867
734
|
|
|
735
|
+
private handleInvalidCheckpointProposal(
|
|
736
|
+
proposal: CheckpointProposalCore,
|
|
737
|
+
result: CheckpointProposalValidationFailureResult,
|
|
738
|
+
proposalInfo: LogData,
|
|
739
|
+
): void {
|
|
740
|
+
if (!SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT[result.reason]) {
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
// The slot is already marked invalid by the all-nodes checkpoint handler that invokes this callback,
|
|
745
|
+
// so we only emit the proposer slash event here.
|
|
746
|
+
if (this.slashInvalidCheckpointProposal(proposal)) {
|
|
747
|
+
this.log.info(`Detected invalid checkpoint proposal offense`, {
|
|
748
|
+
...proposalInfo,
|
|
749
|
+
reason: result.reason,
|
|
750
|
+
amount: this.config.slashBroadcastedInvalidCheckpointProposalPenalty,
|
|
751
|
+
offenseType: getOffenseTypeName(OffenseType.BROADCASTED_INVALID_CHECKPOINT_PROPOSAL),
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
private slashInvalidCheckpointProposal(proposal: CheckpointProposalCore): boolean {
|
|
757
|
+
const proposer = proposal.getSender();
|
|
758
|
+
if (!proposer) {
|
|
759
|
+
this.log.warn(`Cannot slash checkpoint proposal with invalid signature`, {
|
|
760
|
+
slotNumber: proposal.slotNumber,
|
|
761
|
+
archive: proposal.archive.toString(),
|
|
762
|
+
});
|
|
763
|
+
return false;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
const offenseType = OffenseType.BROADCASTED_INVALID_CHECKPOINT_PROPOSAL;
|
|
767
|
+
const offenseKey = `${proposer.toString()}:${offenseType}:${proposal.slotNumber}`;
|
|
768
|
+
if (!this.invalidCheckpointProposalOffenseKeys.addIfAbsent(offenseKey)) {
|
|
769
|
+
return false;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
773
|
+
{
|
|
774
|
+
validator: proposer,
|
|
775
|
+
amount: this.config.slashBroadcastedInvalidCheckpointProposalPenalty,
|
|
776
|
+
offenseType,
|
|
777
|
+
epochOrSlot: BigInt(proposal.slotNumber),
|
|
778
|
+
},
|
|
779
|
+
]);
|
|
780
|
+
return true;
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
private markInvalidProposalSlot(slotNumber: SlotNumber): void {
|
|
784
|
+
this.proposalHandler.markInvalidProposalSlot(slotNumber);
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
private handleCheckpointAttestation(attestation: CheckpointAttestation): void {
|
|
788
|
+
const slotNumber = attestation.slotNumber;
|
|
789
|
+
if (
|
|
790
|
+
!this.proposalHandler.hasInvalidProposals(slotNumber) ||
|
|
791
|
+
this.proposalHandler.hasProposalEquivocation(slotNumber)
|
|
792
|
+
) {
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
const attester = attestation.getSender();
|
|
797
|
+
if (!attester) {
|
|
798
|
+
this.log.warn(`Cannot slash checkpoint attestation with invalid signature`, {
|
|
799
|
+
slotNumber,
|
|
800
|
+
archive: attestation.archive.toString(),
|
|
801
|
+
});
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
this.slashAttestedToInvalidCheckpointProposal(slotNumber, attester);
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
private slashAttestedToInvalidCheckpointProposal(slotNumber: SlotNumber, attester: EthAddress): void {
|
|
809
|
+
const offenseKey = `${attester.toString()}:${OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL}:${slotNumber}`;
|
|
810
|
+
if (!this.badAttestationOffenseKeys.addIfAbsent(offenseKey)) {
|
|
811
|
+
return;
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
this.log.info(`Detected attestation to invalid checkpoint proposal offense`, {
|
|
815
|
+
attester: attester.toString(),
|
|
816
|
+
slotNumber,
|
|
817
|
+
amount: this.config.slashAttestInvalidCheckpointProposalPenalty,
|
|
818
|
+
offenseType: getOffenseTypeName(OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL),
|
|
819
|
+
});
|
|
820
|
+
|
|
821
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
822
|
+
{
|
|
823
|
+
validator: attester,
|
|
824
|
+
amount: this.config.slashAttestInvalidCheckpointProposalPenalty,
|
|
825
|
+
offenseType: OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL,
|
|
826
|
+
epochOrSlot: BigInt(slotNumber),
|
|
827
|
+
},
|
|
828
|
+
]);
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
/**
|
|
832
|
+
* Handle detection of an oversized block proposal: one whose index within its checkpoint lands at or
|
|
833
|
+
* beyond the consensus per-checkpoint block limit. A single signed proposal at an illegal index is
|
|
834
|
+
* self-contained evidence, so emit an invalid-block-proposal slash event for the proposer, deduped per
|
|
835
|
+
* (proposer, slot) since the p2p layer reports every oversized proposal it stores.
|
|
836
|
+
*/
|
|
837
|
+
private handleOversizedProposal(info: OversizedProposalInfo): void {
|
|
838
|
+
const { slot, proposer } = info;
|
|
839
|
+
const offenseType = OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL;
|
|
840
|
+
if (!this.oversizedProposalOffenseKeys.addIfAbsent(`${proposer.toString()}:${offenseType}:${slot}`)) {
|
|
841
|
+
return;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
this.log.info(`Detected oversized block proposal offense from ${proposer.toString()} at slot ${slot}`, {
|
|
845
|
+
proposer: proposer.toString(),
|
|
846
|
+
slot,
|
|
847
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
848
|
+
offenseType: getOffenseTypeName(offenseType),
|
|
849
|
+
});
|
|
850
|
+
|
|
851
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
852
|
+
{
|
|
853
|
+
validator: proposer,
|
|
854
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
855
|
+
offenseType,
|
|
856
|
+
epochOrSlot: BigInt(slot),
|
|
857
|
+
},
|
|
858
|
+
]);
|
|
859
|
+
}
|
|
860
|
+
|
|
868
861
|
/**
|
|
869
862
|
* Handle detection of a duplicate proposal (equivocation).
|
|
870
863
|
* Emits a slash event when a proposer sends multiple proposals for the same position.
|
|
871
864
|
*/
|
|
872
865
|
private handleDuplicateProposal(info: DuplicateProposalInfo): void {
|
|
873
866
|
const { slot, proposer, type } = info;
|
|
867
|
+
this.proposalHandler.markProposalEquivocation(slot);
|
|
874
868
|
|
|
875
|
-
this.log.
|
|
869
|
+
this.log.info(`Detected duplicate ${type} proposal offense from ${proposer.toString()} at slot ${slot}`, {
|
|
876
870
|
proposer: proposer.toString(),
|
|
877
871
|
slot,
|
|
878
872
|
type,
|
|
873
|
+
amount: this.config.slashDuplicateProposalPenalty,
|
|
874
|
+
offenseType: getOffenseTypeName(OffenseType.DUPLICATE_PROPOSAL),
|
|
879
875
|
});
|
|
880
876
|
|
|
881
|
-
// Emit slash event
|
|
882
877
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
883
878
|
{
|
|
884
879
|
validator: proposer,
|
|
@@ -887,6 +882,13 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
887
882
|
epochOrSlot: BigInt(slot),
|
|
888
883
|
},
|
|
889
884
|
]);
|
|
885
|
+
|
|
886
|
+
this.emit(WANT_TO_CLEAR_SLASH_EVENT, [
|
|
887
|
+
{
|
|
888
|
+
offenseType: OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL,
|
|
889
|
+
epochOrSlot: BigInt(slot),
|
|
890
|
+
},
|
|
891
|
+
]);
|
|
890
892
|
}
|
|
891
893
|
|
|
892
894
|
/**
|
|
@@ -896,9 +898,11 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
896
898
|
private handleDuplicateAttestation(info: DuplicateAttestationInfo): void {
|
|
897
899
|
const { slot, attester } = info;
|
|
898
900
|
|
|
899
|
-
this.log.
|
|
901
|
+
this.log.info(`Detected duplicate attestation offense from ${attester.toString()} at slot ${slot}`, {
|
|
900
902
|
attester: attester.toString(),
|
|
901
903
|
slot,
|
|
904
|
+
amount: this.config.slashDuplicateAttestationPenalty,
|
|
905
|
+
offenseType: getOffenseTypeName(OffenseType.DUPLICATE_ATTESTATION),
|
|
902
906
|
});
|
|
903
907
|
|
|
904
908
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
@@ -913,6 +917,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
913
917
|
|
|
914
918
|
async createBlockProposal(
|
|
915
919
|
blockHeader: BlockHeader,
|
|
920
|
+
checkpointNumber: CheckpointNumber,
|
|
916
921
|
indexWithinCheckpoint: IndexWithinCheckpoint,
|
|
917
922
|
inHash: Fr,
|
|
918
923
|
archive: Fr,
|
|
@@ -939,6 +944,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
939
944
|
);
|
|
940
945
|
const newProposal = await this.validationService.createBlockProposal(
|
|
941
946
|
blockHeader,
|
|
947
|
+
checkpointNumber,
|
|
942
948
|
indexWithinCheckpoint,
|
|
943
949
|
inHash,
|
|
944
950
|
archive,
|
|
@@ -946,7 +952,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
946
952
|
proposerAddress,
|
|
947
953
|
{
|
|
948
954
|
...options,
|
|
949
|
-
broadcastInvalidBlockProposal:
|
|
955
|
+
broadcastInvalidBlockProposal:
|
|
956
|
+
options.broadcastInvalidBlockProposal || this.config.broadcastInvalidBlockProposal,
|
|
950
957
|
},
|
|
951
958
|
);
|
|
952
959
|
this.lastProposedBlock = newProposal;
|
|
@@ -956,8 +963,9 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
956
963
|
async createCheckpointProposal(
|
|
957
964
|
checkpointHeader: CheckpointHeader,
|
|
958
965
|
archive: Fr,
|
|
966
|
+
checkpointNumber: CheckpointNumber,
|
|
959
967
|
feeAssetPriceModifier: bigint,
|
|
960
|
-
|
|
968
|
+
lastBlockProposal: BlockProposal | undefined,
|
|
961
969
|
proposerAddress: EthAddress | undefined,
|
|
962
970
|
options: CheckpointProposalOptions = {},
|
|
963
971
|
): Promise<CheckpointProposal> {
|
|
@@ -978,12 +986,20 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
978
986
|
const newProposal = await this.validationService.createCheckpointProposal(
|
|
979
987
|
checkpointHeader,
|
|
980
988
|
archive,
|
|
989
|
+
checkpointNumber,
|
|
981
990
|
feeAssetPriceModifier,
|
|
982
|
-
|
|
991
|
+
lastBlockProposal,
|
|
983
992
|
proposerAddress,
|
|
984
993
|
options,
|
|
985
994
|
);
|
|
986
995
|
this.lastProposedCheckpoint = newProposal;
|
|
996
|
+
// Self-record this slot's outcome on the re-execution tracker. Proposers don't run their
|
|
997
|
+
// own proposals through `handleCheckpointProposal`, so without this call the proposer's
|
|
998
|
+
// sentinel would see no outcome for slots it proposed and would mis-attribute itself as
|
|
999
|
+
// inactive. We pass the locally-computed `archive` (not `newProposal.archive`, which may
|
|
1000
|
+
// be intentionally corrupted under test-only flags); from the proposer's local-view
|
|
1001
|
+
// perspective the work it just completed is valid by definition.
|
|
1002
|
+
this.proposalHandler.recordOwnCheckpointProposalAsValid(checkpointHeader.slotNumber, archive, checkpointNumber);
|
|
987
1003
|
return newProposal;
|
|
988
1004
|
}
|
|
989
1005
|
|
|
@@ -995,16 +1011,24 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
995
1011
|
attestationsAndSigners: CommitteeAttestationsAndSigners,
|
|
996
1012
|
proposer: EthAddress,
|
|
997
1013
|
slot: SlotNumber,
|
|
998
|
-
|
|
1014
|
+
checkpointNumber: CheckpointNumber,
|
|
999
1015
|
): Promise<Signature> {
|
|
1000
|
-
return await this.validationService.signAttestationsAndSigners(
|
|
1016
|
+
return await this.validationService.signAttestationsAndSigners(
|
|
1017
|
+
attestationsAndSigners,
|
|
1018
|
+
proposer,
|
|
1019
|
+
slot,
|
|
1020
|
+
checkpointNumber,
|
|
1021
|
+
);
|
|
1001
1022
|
}
|
|
1002
1023
|
|
|
1003
|
-
async collectOwnAttestations(
|
|
1024
|
+
async collectOwnAttestations(
|
|
1025
|
+
proposal: CheckpointProposal,
|
|
1026
|
+
checkpointNumber: CheckpointNumber,
|
|
1027
|
+
): Promise<CheckpointAttestation[]> {
|
|
1004
1028
|
const slot = proposal.slotNumber;
|
|
1005
1029
|
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
1006
1030
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, { inCommittee });
|
|
1007
|
-
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
1031
|
+
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee, checkpointNumber);
|
|
1008
1032
|
|
|
1009
1033
|
if (!attestations) {
|
|
1010
1034
|
return [];
|
|
@@ -1023,6 +1047,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
1023
1047
|
proposal: CheckpointProposal,
|
|
1024
1048
|
required: number,
|
|
1025
1049
|
deadline: Date,
|
|
1050
|
+
checkpointNumber: CheckpointNumber,
|
|
1026
1051
|
): Promise<CheckpointAttestation[]> {
|
|
1027
1052
|
// Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
|
|
1028
1053
|
const slot = proposal.slotNumber;
|
|
@@ -1035,33 +1060,23 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
1035
1060
|
throw new AttestationTimeoutError(0, required, slot);
|
|
1036
1061
|
}
|
|
1037
1062
|
|
|
1038
|
-
await this.collectOwnAttestations(proposal);
|
|
1063
|
+
await this.collectOwnAttestations(proposal, checkpointNumber);
|
|
1039
1064
|
|
|
1040
|
-
const
|
|
1065
|
+
const proposalPayloadHash = proposal.getPayloadHash();
|
|
1041
1066
|
const myAddresses = this.getValidatorAddresses();
|
|
1042
1067
|
|
|
1043
1068
|
let attestations: CheckpointAttestation[] = [];
|
|
1044
1069
|
while (true) {
|
|
1045
|
-
//
|
|
1046
|
-
//
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
if (!attestation.archive.equals(proposal.archive)) {
|
|
1050
|
-
this.log.warn(
|
|
1051
|
-
`Received attestation for slot ${slot} with mismatched archive from ${attestation.getSender()?.toString()}`,
|
|
1052
|
-
{ attestationArchive: attestation.archive.toString(), proposalArchive: proposal.archive.toString() },
|
|
1053
|
-
);
|
|
1054
|
-
return false;
|
|
1055
|
-
}
|
|
1056
|
-
return true;
|
|
1057
|
-
},
|
|
1058
|
-
);
|
|
1070
|
+
// The pool already filters by proposal payload hash; if any attestation slips through with a
|
|
1071
|
+
// mismatched payload hash, drop it defensively. Equivocations are emitted as separate slash
|
|
1072
|
+
// events from libp2p_service.
|
|
1073
|
+
const collectedAttestations = await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalPayloadHash);
|
|
1059
1074
|
|
|
1060
1075
|
// Log new attestations we collected
|
|
1061
1076
|
const oldSenders = attestations.map(attestation => attestation.getSender());
|
|
1062
1077
|
for (const collected of collectedAttestations) {
|
|
1063
1078
|
const collectedSender = collected.getSender();
|
|
1064
|
-
// Skip attestations with invalid signatures
|
|
1079
|
+
// Skip attestations with invalid signatures. Should not happen as we don't add invalid attestations to our pool.
|
|
1065
1080
|
if (!collectedSender) {
|
|
1066
1081
|
this.log.warn(`Skipping attestation with invalid signature for slot ${slot}`);
|
|
1067
1082
|
continue;
|