@aztec/validator-client 0.0.1-commit.3fd054f6 → 0.0.1-commit.431c48d
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 +12 -4
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +14 -3
- 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 +9 -5
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +8 -8
- 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 +173 -0
- package/dest/proposal_handler.d.ts.map +1 -0
- package/dest/proposal_handler.js +1302 -0
- package/dest/validator.d.ts +37 -23
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +218 -252
- package/package.json +19 -19
- package/src/checkpoint_builder.ts +16 -5
- package/src/config.ts +31 -12
- package/src/duties/validation_service.ts +51 -47
- package/src/factory.ts +17 -8
- 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 +1418 -0
- package/src/validator.ts +293 -289
- 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,51 @@
|
|
|
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';
|
|
23
|
-
import { AuthRequest, AuthResponse,
|
|
24
|
-
import {
|
|
14
|
+
import type { DuplicateAttestationInfo, DuplicateProposalInfo, OversizedProposalInfo, P2P, PeerId } from '@aztec/p2p';
|
|
15
|
+
import { AuthRequest, AuthResponse, ReqRespSubProtocol } from '@aztec/p2p';
|
|
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,
|
|
43
|
+
type ValidatedBlockProposal,
|
|
44
|
+
type ValidatedCheckpointProposalCore,
|
|
44
45
|
} from '@aztec/stdlib/p2p';
|
|
45
46
|
import type { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
46
|
-
import
|
|
47
|
+
import { ConsensusTimetable } from '@aztec/stdlib/timetable';
|
|
48
|
+
import type { BlockHeader, Tx } from '@aztec/stdlib/tx';
|
|
47
49
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
48
50
|
import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
|
|
49
51
|
import {
|
|
@@ -57,23 +59,25 @@ import type { ValidatorHASigner } from '@aztec/validator-ha-signer/validator-ha-
|
|
|
57
59
|
import { EventEmitter } from 'events';
|
|
58
60
|
import type { TypedDataDefinition } from 'viem';
|
|
59
61
|
|
|
60
|
-
import { BlockProposalHandler, type BlockProposalValidationFailureReason } from './block_proposal_handler.js';
|
|
61
62
|
import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
|
|
62
63
|
import { ValidationService } from './duties/validation_service.js';
|
|
63
64
|
import { HAKeyStore } from './key_store/ha_key_store.js';
|
|
64
65
|
import type { ExtendedValidatorKeyStore } from './key_store/interface.js';
|
|
65
66
|
import { NodeKeystoreAdapter } from './key_store/node_keystore_adapter.js';
|
|
66
67
|
import { ValidatorMetrics } from './metrics.js';
|
|
68
|
+
import {
|
|
69
|
+
type BlockProposalValidationFailureReason,
|
|
70
|
+
type CheckpointProposalValidationFailureResult,
|
|
71
|
+
ProposalHandler,
|
|
72
|
+
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT,
|
|
73
|
+
SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT,
|
|
74
|
+
} from './proposal_handler.js';
|
|
67
75
|
|
|
68
76
|
// We maintain a set of proposers who have proposed invalid blocks.
|
|
69
77
|
// Just cap the set to avoid unbounded growth.
|
|
70
78
|
const MAX_PROPOSERS_OF_INVALID_BLOCKS = 1000;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT: BlockProposalValidationFailureReason[] = [
|
|
74
|
-
'state_mismatch',
|
|
75
|
-
'failed_txs',
|
|
76
|
-
];
|
|
79
|
+
const MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS = 1000;
|
|
80
|
+
const MAX_TRACKED_BAD_ATTESTATIONS = 10_000;
|
|
77
81
|
|
|
78
82
|
/**
|
|
79
83
|
* Validator Client
|
|
@@ -97,7 +101,10 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
97
101
|
/** Tracks the last epoch in which each attester successfully submitted at least one attestation. */
|
|
98
102
|
private lastAttestedEpochByAttester: Map<string, EpochNumber> = new Map();
|
|
99
103
|
|
|
100
|
-
private proposersOfInvalidBlocks
|
|
104
|
+
private proposersOfInvalidBlocks = FifoSet.withLimit<string>(MAX_PROPOSERS_OF_INVALID_BLOCKS);
|
|
105
|
+
private invalidCheckpointProposalOffenseKeys = FifoSet.withLimit<string>(MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS);
|
|
106
|
+
private oversizedProposalOffenseKeys = FifoSet.withLimit<string>(MAX_TRACKED_INVALID_CHECKPOINT_PROPOSALS);
|
|
107
|
+
private badAttestationOffenseKeys = FifoSet.withLimit<string>(MAX_TRACKED_BAD_ATTESTATIONS);
|
|
101
108
|
|
|
102
109
|
/** Tracks the last checkpoint proposal we attested to, to prevent equivocation. */
|
|
103
110
|
private lastAttestedProposal?: CheckpointProposalCore;
|
|
@@ -106,7 +113,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
106
113
|
private keyStore: ExtendedValidatorKeyStore,
|
|
107
114
|
private epochCache: EpochCache,
|
|
108
115
|
private p2pClient: P2P,
|
|
109
|
-
private
|
|
116
|
+
private proposalHandler: ProposalHandler,
|
|
110
117
|
private blockSource: L2BlockSource,
|
|
111
118
|
private checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
112
119
|
private worldState: WorldStateSynchronizer,
|
|
@@ -126,11 +133,17 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
126
133
|
this.tracer = telemetry.getTracer('Validator');
|
|
127
134
|
this.metrics = new ValidatorMetrics(telemetry);
|
|
128
135
|
|
|
129
|
-
this.validationService = new ValidationService(
|
|
136
|
+
this.validationService = new ValidationService(
|
|
137
|
+
keyStore,
|
|
138
|
+
this.getSignatureContext(),
|
|
139
|
+
this.log.createChild('validation-service'),
|
|
140
|
+
);
|
|
141
|
+
this.proposalHandler.setCheckpointProposalValidationFailureCallback((proposal, result, proposalInfo) =>
|
|
142
|
+
this.handleInvalidCheckpointProposal(proposal, result, proposalInfo),
|
|
143
|
+
);
|
|
130
144
|
|
|
131
145
|
// Refresh epoch cache every second to trigger alert if participation in committee changes
|
|
132
146
|
this.epochCacheUpdateLoop = new RunningPromise(this.handleEpochCommitteeUpdate.bind(this), this.log, 1000);
|
|
133
|
-
|
|
134
147
|
const myAddresses = this.getValidatorAddresses();
|
|
135
148
|
this.log.verbose(`Initialized validator with addresses: ${myAddresses.map(a => a.toString()).join(', ')}`);
|
|
136
149
|
}
|
|
@@ -199,27 +212,31 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
199
212
|
txProvider: ITxProvider,
|
|
200
213
|
keyStoreManager: KeystoreManager,
|
|
201
214
|
blobClient: BlobClientInterface,
|
|
215
|
+
reexecutionTracker: CheckpointReexecutionTracker,
|
|
202
216
|
dateProvider: DateProvider = new DateProvider(),
|
|
203
217
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
204
218
|
slashingProtectionDb?: SlashingProtectionDatabase,
|
|
205
219
|
) {
|
|
206
220
|
const metrics = new ValidatorMetrics(telemetry);
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
|
|
221
|
+
const consensusTimetable = new ConsensusTimetable({
|
|
222
|
+
l1Constants: epochCache.getL1Constants(),
|
|
223
|
+
blockDuration: config.blockDurationMs / 1000,
|
|
210
224
|
});
|
|
211
|
-
const
|
|
225
|
+
const proposalHandler = new ProposalHandler(
|
|
212
226
|
checkpointsBuilder,
|
|
213
227
|
worldState,
|
|
214
228
|
blockSource,
|
|
215
229
|
l1ToL2MessageSource,
|
|
216
230
|
txProvider,
|
|
217
|
-
blockProposalValidator,
|
|
218
231
|
epochCache,
|
|
232
|
+
consensusTimetable,
|
|
219
233
|
config,
|
|
234
|
+
blobClient,
|
|
235
|
+
reexecutionTracker,
|
|
220
236
|
metrics,
|
|
221
237
|
dateProvider,
|
|
222
238
|
telemetry,
|
|
239
|
+
undefined,
|
|
223
240
|
);
|
|
224
241
|
|
|
225
242
|
const nodeKeystoreAdapter = NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager);
|
|
@@ -255,7 +272,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
255
272
|
validatorKeyStore,
|
|
256
273
|
epochCache,
|
|
257
274
|
p2pClient,
|
|
258
|
-
|
|
275
|
+
proposalHandler,
|
|
259
276
|
blockSource,
|
|
260
277
|
checkpointsBuilder,
|
|
261
278
|
worldState,
|
|
@@ -276,14 +293,21 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
276
293
|
.filter(addr => !this.config.disabledValidators.some(disabled => disabled.equals(addr)));
|
|
277
294
|
}
|
|
278
295
|
|
|
279
|
-
public
|
|
280
|
-
return this.
|
|
296
|
+
public getProposalHandler() {
|
|
297
|
+
return this.proposalHandler;
|
|
281
298
|
}
|
|
282
299
|
|
|
283
300
|
public signWithAddress(addr: EthAddress, msg: TypedDataDefinition, context: SigningContext) {
|
|
284
301
|
return this.keyStore.signTypedDataWithAddress(addr, msg, context);
|
|
285
302
|
}
|
|
286
303
|
|
|
304
|
+
private getSignatureContext(): CoordinationSignatureContext {
|
|
305
|
+
return {
|
|
306
|
+
chainId: this.config.l1ChainId,
|
|
307
|
+
rollupAddress: this.config.rollupAddress,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
287
311
|
public getCoinbaseForAttestor(attestor: EthAddress): EthAddress {
|
|
288
312
|
return this.keyStore.getCoinbaseAddress(attestor);
|
|
289
313
|
}
|
|
@@ -296,14 +320,27 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
296
320
|
return this.config;
|
|
297
321
|
}
|
|
298
322
|
|
|
323
|
+
public hasProposalEquivocation(slotNumber: SlotNumber): boolean {
|
|
324
|
+
return this.proposalHandler.hasProposalEquivocation(slotNumber);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
public hasInvalidProposals(slotNumber: SlotNumber): boolean {
|
|
328
|
+
return this.proposalHandler.hasInvalidProposals(slotNumber);
|
|
329
|
+
}
|
|
330
|
+
|
|
299
331
|
public updateConfig(config: Partial<ValidatorClientFullConfig>) {
|
|
300
332
|
this.config = { ...this.config, ...config };
|
|
333
|
+
this.proposalHandler.updateConfig(config);
|
|
301
334
|
}
|
|
302
335
|
|
|
303
336
|
public reloadKeystore(newManager: KeystoreManager): void {
|
|
304
337
|
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
305
338
|
this.keyStore = new HAKeyStore(newAdapter, this.slashingProtectionSigner);
|
|
306
|
-
this.validationService = new ValidationService(
|
|
339
|
+
this.validationService = new ValidationService(
|
|
340
|
+
this.keyStore,
|
|
341
|
+
this.getSignatureContext(),
|
|
342
|
+
this.log.createChild('validation-service'),
|
|
343
|
+
);
|
|
307
344
|
}
|
|
308
345
|
|
|
309
346
|
public async start() {
|
|
@@ -339,7 +376,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
339
376
|
this.log.debug(`Registering validator handlers for p2p client`);
|
|
340
377
|
|
|
341
378
|
// Block proposal handler - validates but does NOT attest (validators only attest to checkpoints)
|
|
342
|
-
const blockHandler = (block:
|
|
379
|
+
const blockHandler = (block: ValidatedBlockProposal, proposalSender: PeerId): Promise<boolean> =>
|
|
343
380
|
this.validateBlockProposal(block, proposalSender);
|
|
344
381
|
this.p2pClient.registerBlockProposalHandler(blockHandler);
|
|
345
382
|
|
|
@@ -347,21 +384,30 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
347
384
|
// The checkpoint is received as CheckpointProposalCore since the lastBlock is extracted
|
|
348
385
|
// and processed separately via the block handler above.
|
|
349
386
|
const checkpointHandler = (
|
|
350
|
-
checkpoint:
|
|
387
|
+
checkpoint: ValidatedCheckpointProposalCore,
|
|
351
388
|
proposalSender: PeerId,
|
|
352
389
|
): Promise<CheckpointAttestation[] | undefined> => this.attestToCheckpointProposal(checkpoint, proposalSender);
|
|
353
|
-
this.p2pClient.
|
|
390
|
+
this.p2pClient.registerValidatorCheckpointProposalHandler(checkpointHandler);
|
|
354
391
|
|
|
355
392
|
// Duplicate proposal handler - triggers slashing for equivocation
|
|
356
393
|
this.p2pClient.registerDuplicateProposalCallback((info: DuplicateProposalInfo) => {
|
|
357
394
|
this.handleDuplicateProposal(info);
|
|
358
395
|
});
|
|
359
396
|
|
|
397
|
+
// Oversized proposal handler - triggers slashing for proposals beyond the per-checkpoint block limit
|
|
398
|
+
this.p2pClient.registerOversizedProposalCallback((info: OversizedProposalInfo) => {
|
|
399
|
+
this.handleOversizedProposal(info);
|
|
400
|
+
});
|
|
401
|
+
|
|
360
402
|
// Duplicate attestation handler - triggers slashing for attestation equivocation
|
|
361
403
|
this.p2pClient.registerDuplicateAttestationCallback((info: DuplicateAttestationInfo) => {
|
|
362
404
|
this.handleDuplicateAttestation(info);
|
|
363
405
|
});
|
|
364
406
|
|
|
407
|
+
this.p2pClient.registerCheckpointAttestationCallback((attestation: CheckpointAttestation) => {
|
|
408
|
+
this.handleCheckpointAttestation(attestation);
|
|
409
|
+
});
|
|
410
|
+
|
|
365
411
|
const myAddresses = this.getValidatorAddresses();
|
|
366
412
|
this.p2pClient.registerThisValidatorAddresses(myAddresses);
|
|
367
413
|
|
|
@@ -374,7 +420,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
374
420
|
* Note: Validators do NOT attest to individual blocks - attestations are only for checkpoint proposals.
|
|
375
421
|
* @returns true if the proposal is valid, false otherwise
|
|
376
422
|
*/
|
|
377
|
-
async validateBlockProposal(proposal:
|
|
423
|
+
async validateBlockProposal(proposal: ValidatedBlockProposal, proposalSender: PeerId): Promise<boolean> {
|
|
378
424
|
const slotNumber = proposal.slotNumber;
|
|
379
425
|
|
|
380
426
|
// Note: During escape hatch, we still want to "validate" proposals for observability,
|
|
@@ -408,22 +454,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
408
454
|
fishermanMode: this.config.fishermanMode || false,
|
|
409
455
|
});
|
|
410
456
|
|
|
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
|
-
);
|
|
457
|
+
// Reexecute outside the escape hatch so slashing observers can detect invalid proposals even when penalties are 0.
|
|
458
|
+
const validationResult = await this.proposalHandler.handleBlockProposal(proposal, proposalSender, !escapeHatchOpen);
|
|
427
459
|
|
|
428
460
|
if (!validationResult.isValid) {
|
|
429
461
|
const reason = validationResult.reason || 'unknown';
|
|
@@ -437,6 +469,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
437
469
|
'failed_txs',
|
|
438
470
|
'in_hash_mismatch',
|
|
439
471
|
'parent_block_wrong_slot',
|
|
472
|
+
'duplicate_txs',
|
|
473
|
+
'invalid_embedded_txs',
|
|
440
474
|
];
|
|
441
475
|
|
|
442
476
|
if (badProposalReasons.includes(reason as BlockProposalValidationFailureReason)) {
|
|
@@ -446,15 +480,18 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
446
480
|
this.metrics.incFailedAttestationsNodeIssue(1, reason, partOfCommittee);
|
|
447
481
|
}
|
|
448
482
|
|
|
449
|
-
// Slash invalid block proposals (can happen even when not in committee)
|
|
450
483
|
if (
|
|
451
484
|
!escapeHatchOpen &&
|
|
452
485
|
validationResult.reason &&
|
|
453
|
-
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason)
|
|
454
|
-
slashBroadcastedInvalidBlockPenalty > 0n
|
|
486
|
+
SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(validationResult.reason)
|
|
455
487
|
) {
|
|
456
|
-
this.log.
|
|
488
|
+
this.log.info(`Detected invalid block proposal offense`, {
|
|
489
|
+
...proposalInfo,
|
|
490
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
491
|
+
offenseType: getOffenseTypeName(OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL),
|
|
492
|
+
});
|
|
457
493
|
this.slashInvalidBlock(proposal);
|
|
494
|
+
this.markInvalidProposalSlot(proposal.slotNumber);
|
|
458
495
|
}
|
|
459
496
|
return false;
|
|
460
497
|
}
|
|
@@ -481,7 +518,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
481
518
|
* @returns Checkpoint attestations if valid, undefined otherwise
|
|
482
519
|
*/
|
|
483
520
|
async attestToCheckpointProposal(
|
|
484
|
-
proposal:
|
|
521
|
+
proposal: ValidatedCheckpointProposalCore,
|
|
485
522
|
_proposalSender: PeerId,
|
|
486
523
|
): Promise<CheckpointAttestation[] | undefined> {
|
|
487
524
|
const proposalSlotNumber = proposal.slotNumber;
|
|
@@ -493,29 +530,20 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
493
530
|
return undefined;
|
|
494
531
|
}
|
|
495
532
|
|
|
496
|
-
//
|
|
497
|
-
if (!
|
|
498
|
-
this.log.warn(`Received checkpoint proposal with invalid signature for proposal slot ${proposalSlotNumber}`);
|
|
533
|
+
// Early-out for equivocation: refuses if we've already attested to a higher slot.
|
|
534
|
+
if (!this.shouldAttestToSlot(proposalSlotNumber)) {
|
|
499
535
|
return undefined;
|
|
500
536
|
}
|
|
501
537
|
|
|
502
538
|
// Ignore proposals from ourselves (may happen in HA setups)
|
|
503
|
-
if (this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
504
|
-
this.log.debug(`
|
|
539
|
+
if (proposer && this.getValidatorAddresses().some(addr => addr.equals(proposer))) {
|
|
540
|
+
this.log.debug(`Not attesting to block proposal from self for slot ${proposalSlotNumber}`, {
|
|
505
541
|
proposer: proposer.toString(),
|
|
506
542
|
proposalSlotNumber,
|
|
507
543
|
});
|
|
508
544
|
return undefined;
|
|
509
545
|
}
|
|
510
546
|
|
|
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
547
|
// Check that I have any address in the committee where this checkpoint will land before attesting
|
|
520
548
|
const inCommittee = await this.epochCache.filterInCommittee(proposalSlotNumber, this.getValidatorAddresses());
|
|
521
549
|
const partOfCommittee = inCommittee.length > 0;
|
|
@@ -523,27 +551,26 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
523
551
|
const proposalInfo = {
|
|
524
552
|
proposalSlotNumber,
|
|
525
553
|
archive: proposal.archive.toString(),
|
|
526
|
-
proposer: proposer
|
|
554
|
+
proposer: proposer?.toString(),
|
|
527
555
|
};
|
|
528
556
|
this.log.info(`Received checkpoint proposal for slot ${proposalSlotNumber}`, {
|
|
529
557
|
...proposalInfo,
|
|
530
558
|
fishermanMode: this.config.fishermanMode || false,
|
|
531
559
|
});
|
|
532
560
|
|
|
533
|
-
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set)
|
|
561
|
+
// Validate the checkpoint proposal before attesting (unless skipCheckpointProposalValidation is set).
|
|
562
|
+
// Uses the cached result from the all-nodes callback if available (avoids double validation).
|
|
563
|
+
let checkpointNumber: CheckpointNumber;
|
|
534
564
|
if (this.config.skipCheckpointProposalValidation) {
|
|
535
565
|
this.log.warn(`Skipping checkpoint proposal validation for slot ${proposalSlotNumber}`, proposalInfo);
|
|
566
|
+
checkpointNumber = CheckpointNumber(0);
|
|
536
567
|
} else {
|
|
537
|
-
const validationResult = await this.
|
|
568
|
+
const validationResult = await this.proposalHandler.handleCheckpointProposal(proposal, proposalInfo);
|
|
538
569
|
if (!validationResult.isValid) {
|
|
539
570
|
this.log.warn(`Checkpoint proposal validation failed: ${validationResult.reason}`, proposalInfo);
|
|
540
571
|
return undefined;
|
|
541
572
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
// Upload blobs to filestore if we can (fire and forget)
|
|
545
|
-
if (this.blobClient.canUpload()) {
|
|
546
|
-
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
573
|
+
checkpointNumber = validationResult.checkpointNumber;
|
|
547
574
|
}
|
|
548
575
|
|
|
549
576
|
// Check that I have any address in current committee before attesting
|
|
@@ -601,7 +628,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
601
628
|
return undefined;
|
|
602
629
|
}
|
|
603
630
|
|
|
604
|
-
return await this.createCheckpointAttestationsFromProposal(proposal, attestors);
|
|
631
|
+
return await this.createCheckpointAttestationsFromProposal(proposal, attestors, checkpointNumber);
|
|
605
632
|
}
|
|
606
633
|
|
|
607
634
|
/**
|
|
@@ -628,13 +655,14 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
628
655
|
private async createCheckpointAttestationsFromProposal(
|
|
629
656
|
proposal: CheckpointProposalCore,
|
|
630
657
|
attestors: EthAddress[] = [],
|
|
658
|
+
checkpointNumber: CheckpointNumber,
|
|
631
659
|
): Promise<CheckpointAttestation[] | undefined> {
|
|
632
660
|
// Equivocation check: must happen right before signing to minimize the race window
|
|
633
661
|
if (!this.shouldAttestToSlot(proposal.slotNumber)) {
|
|
634
662
|
return undefined;
|
|
635
663
|
}
|
|
636
664
|
|
|
637
|
-
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors);
|
|
665
|
+
const attestations = await this.validationService.attestToCheckpointProposal(proposal, attestors, checkpointNumber);
|
|
638
666
|
|
|
639
667
|
// Track the proposal we attested to (to prevent equivocation)
|
|
640
668
|
this.lastAttestedProposal = proposal;
|
|
@@ -643,178 +671,12 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
643
671
|
return attestations;
|
|
644
672
|
}
|
|
645
673
|
|
|
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
674
|
/**
|
|
813
675
|
* Uploads blobs for a checkpoint to the filestore (fire and forget).
|
|
814
676
|
*/
|
|
815
677
|
protected async uploadBlobsForCheckpoint(proposal: CheckpointProposalCore, proposalInfo: LogData): Promise<void> {
|
|
816
678
|
try {
|
|
817
|
-
const lastBlockHeader = await this.blockSource.
|
|
679
|
+
const lastBlockHeader = (await this.blockSource.getBlockData({ archive: proposal.archive }))?.header;
|
|
818
680
|
if (!lastBlockHeader) {
|
|
819
681
|
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
820
682
|
return;
|
|
@@ -847,12 +709,6 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
847
709
|
return;
|
|
848
710
|
}
|
|
849
711
|
|
|
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
712
|
this.proposersOfInvalidBlocks.add(proposer.toString());
|
|
857
713
|
|
|
858
714
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
@@ -865,20 +721,148 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
865
721
|
]);
|
|
866
722
|
}
|
|
867
723
|
|
|
724
|
+
private handleInvalidCheckpointProposal(
|
|
725
|
+
proposal: CheckpointProposalCore,
|
|
726
|
+
result: CheckpointProposalValidationFailureResult,
|
|
727
|
+
proposalInfo: LogData,
|
|
728
|
+
): void {
|
|
729
|
+
if (!SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT[result.reason]) {
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
// The slot is already marked invalid by the all-nodes checkpoint handler that invokes this callback,
|
|
734
|
+
// so we only emit the proposer slash event here.
|
|
735
|
+
if (this.slashInvalidCheckpointProposal(proposal)) {
|
|
736
|
+
this.log.info(`Detected invalid checkpoint proposal offense`, {
|
|
737
|
+
...proposalInfo,
|
|
738
|
+
reason: result.reason,
|
|
739
|
+
amount: this.config.slashBroadcastedInvalidCheckpointProposalPenalty,
|
|
740
|
+
offenseType: getOffenseTypeName(OffenseType.BROADCASTED_INVALID_CHECKPOINT_PROPOSAL),
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
private slashInvalidCheckpointProposal(proposal: CheckpointProposalCore): boolean {
|
|
746
|
+
const proposer = proposal.getSender();
|
|
747
|
+
if (!proposer) {
|
|
748
|
+
this.log.warn(`Cannot slash checkpoint proposal with invalid signature`, {
|
|
749
|
+
slotNumber: proposal.slotNumber,
|
|
750
|
+
archive: proposal.archive.toString(),
|
|
751
|
+
});
|
|
752
|
+
return false;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
const offenseType = OffenseType.BROADCASTED_INVALID_CHECKPOINT_PROPOSAL;
|
|
756
|
+
const offenseKey = `${proposer.toString()}:${offenseType}:${proposal.slotNumber}`;
|
|
757
|
+
if (!this.invalidCheckpointProposalOffenseKeys.addIfAbsent(offenseKey)) {
|
|
758
|
+
return false;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
762
|
+
{
|
|
763
|
+
validator: proposer,
|
|
764
|
+
amount: this.config.slashBroadcastedInvalidCheckpointProposalPenalty,
|
|
765
|
+
offenseType,
|
|
766
|
+
epochOrSlot: BigInt(proposal.slotNumber),
|
|
767
|
+
},
|
|
768
|
+
]);
|
|
769
|
+
return true;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
private markInvalidProposalSlot(slotNumber: SlotNumber): void {
|
|
773
|
+
this.proposalHandler.markInvalidProposalSlot(slotNumber);
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
private handleCheckpointAttestation(attestation: CheckpointAttestation): void {
|
|
777
|
+
const slotNumber = attestation.slotNumber;
|
|
778
|
+
if (
|
|
779
|
+
!this.proposalHandler.hasInvalidProposals(slotNumber) ||
|
|
780
|
+
this.proposalHandler.hasProposalEquivocation(slotNumber)
|
|
781
|
+
) {
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
const attester = attestation.getSender();
|
|
786
|
+
if (!attester) {
|
|
787
|
+
this.log.warn(`Cannot slash checkpoint attestation with invalid signature`, {
|
|
788
|
+
slotNumber,
|
|
789
|
+
archive: attestation.archive.toString(),
|
|
790
|
+
});
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
this.slashAttestedToInvalidCheckpointProposal(slotNumber, attester);
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
private slashAttestedToInvalidCheckpointProposal(slotNumber: SlotNumber, attester: EthAddress): void {
|
|
798
|
+
const offenseKey = `${attester.toString()}:${OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL}:${slotNumber}`;
|
|
799
|
+
if (!this.badAttestationOffenseKeys.addIfAbsent(offenseKey)) {
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
this.log.info(`Detected attestation to invalid checkpoint proposal offense`, {
|
|
804
|
+
attester: attester.toString(),
|
|
805
|
+
slotNumber,
|
|
806
|
+
amount: this.config.slashAttestInvalidCheckpointProposalPenalty,
|
|
807
|
+
offenseType: getOffenseTypeName(OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL),
|
|
808
|
+
});
|
|
809
|
+
|
|
810
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
811
|
+
{
|
|
812
|
+
validator: attester,
|
|
813
|
+
amount: this.config.slashAttestInvalidCheckpointProposalPenalty,
|
|
814
|
+
offenseType: OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL,
|
|
815
|
+
epochOrSlot: BigInt(slotNumber),
|
|
816
|
+
},
|
|
817
|
+
]);
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* Handle detection of an oversized block proposal: one whose index within its checkpoint lands at or
|
|
822
|
+
* beyond the consensus per-checkpoint block limit. A single signed proposal at an illegal index is
|
|
823
|
+
* self-contained evidence, so emit an invalid-block-proposal slash event for the proposer, deduped per
|
|
824
|
+
* (proposer, slot) since the p2p layer reports every oversized proposal it stores.
|
|
825
|
+
*/
|
|
826
|
+
private handleOversizedProposal(info: OversizedProposalInfo): void {
|
|
827
|
+
const { slot, proposer } = info;
|
|
828
|
+
const offenseType = OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL;
|
|
829
|
+
if (!this.oversizedProposalOffenseKeys.addIfAbsent(`${proposer.toString()}:${offenseType}:${slot}`)) {
|
|
830
|
+
return;
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
this.log.info(`Detected oversized block proposal offense from ${proposer.toString()} at slot ${slot}`, {
|
|
834
|
+
proposer: proposer.toString(),
|
|
835
|
+
slot,
|
|
836
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
837
|
+
offenseType: getOffenseTypeName(offenseType),
|
|
838
|
+
});
|
|
839
|
+
|
|
840
|
+
this.emit(WANT_TO_SLASH_EVENT, [
|
|
841
|
+
{
|
|
842
|
+
validator: proposer,
|
|
843
|
+
amount: this.config.slashBroadcastedInvalidBlockPenalty,
|
|
844
|
+
offenseType,
|
|
845
|
+
epochOrSlot: BigInt(slot),
|
|
846
|
+
},
|
|
847
|
+
]);
|
|
848
|
+
}
|
|
849
|
+
|
|
868
850
|
/**
|
|
869
851
|
* Handle detection of a duplicate proposal (equivocation).
|
|
870
852
|
* Emits a slash event when a proposer sends multiple proposals for the same position.
|
|
871
853
|
*/
|
|
872
854
|
private handleDuplicateProposal(info: DuplicateProposalInfo): void {
|
|
873
855
|
const { slot, proposer, type } = info;
|
|
856
|
+
this.proposalHandler.markProposalEquivocation(slot);
|
|
874
857
|
|
|
875
|
-
this.log.
|
|
858
|
+
this.log.info(`Detected duplicate ${type} proposal offense from ${proposer.toString()} at slot ${slot}`, {
|
|
876
859
|
proposer: proposer.toString(),
|
|
877
860
|
slot,
|
|
878
861
|
type,
|
|
862
|
+
amount: this.config.slashDuplicateProposalPenalty,
|
|
863
|
+
offenseType: getOffenseTypeName(OffenseType.DUPLICATE_PROPOSAL),
|
|
879
864
|
});
|
|
880
865
|
|
|
881
|
-
// Emit slash event
|
|
882
866
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
883
867
|
{
|
|
884
868
|
validator: proposer,
|
|
@@ -887,6 +871,13 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
887
871
|
epochOrSlot: BigInt(slot),
|
|
888
872
|
},
|
|
889
873
|
]);
|
|
874
|
+
|
|
875
|
+
this.emit(WANT_TO_CLEAR_SLASH_EVENT, [
|
|
876
|
+
{
|
|
877
|
+
offenseType: OffenseType.ATTESTED_TO_INVALID_CHECKPOINT_PROPOSAL,
|
|
878
|
+
epochOrSlot: BigInt(slot),
|
|
879
|
+
},
|
|
880
|
+
]);
|
|
890
881
|
}
|
|
891
882
|
|
|
892
883
|
/**
|
|
@@ -896,9 +887,11 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
896
887
|
private handleDuplicateAttestation(info: DuplicateAttestationInfo): void {
|
|
897
888
|
const { slot, attester } = info;
|
|
898
889
|
|
|
899
|
-
this.log.
|
|
890
|
+
this.log.info(`Detected duplicate attestation offense from ${attester.toString()} at slot ${slot}`, {
|
|
900
891
|
attester: attester.toString(),
|
|
901
892
|
slot,
|
|
893
|
+
amount: this.config.slashDuplicateAttestationPenalty,
|
|
894
|
+
offenseType: getOffenseTypeName(OffenseType.DUPLICATE_ATTESTATION),
|
|
902
895
|
});
|
|
903
896
|
|
|
904
897
|
this.emit(WANT_TO_SLASH_EVENT, [
|
|
@@ -913,6 +906,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
913
906
|
|
|
914
907
|
async createBlockProposal(
|
|
915
908
|
blockHeader: BlockHeader,
|
|
909
|
+
checkpointNumber: CheckpointNumber,
|
|
916
910
|
indexWithinCheckpoint: IndexWithinCheckpoint,
|
|
917
911
|
inHash: Fr,
|
|
918
912
|
archive: Fr,
|
|
@@ -939,6 +933,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
939
933
|
);
|
|
940
934
|
const newProposal = await this.validationService.createBlockProposal(
|
|
941
935
|
blockHeader,
|
|
936
|
+
checkpointNumber,
|
|
942
937
|
indexWithinCheckpoint,
|
|
943
938
|
inHash,
|
|
944
939
|
archive,
|
|
@@ -946,7 +941,8 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
946
941
|
proposerAddress,
|
|
947
942
|
{
|
|
948
943
|
...options,
|
|
949
|
-
broadcastInvalidBlockProposal:
|
|
944
|
+
broadcastInvalidBlockProposal:
|
|
945
|
+
options.broadcastInvalidBlockProposal || this.config.broadcastInvalidBlockProposal,
|
|
950
946
|
},
|
|
951
947
|
);
|
|
952
948
|
this.lastProposedBlock = newProposal;
|
|
@@ -956,8 +952,9 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
956
952
|
async createCheckpointProposal(
|
|
957
953
|
checkpointHeader: CheckpointHeader,
|
|
958
954
|
archive: Fr,
|
|
955
|
+
checkpointNumber: CheckpointNumber,
|
|
959
956
|
feeAssetPriceModifier: bigint,
|
|
960
|
-
|
|
957
|
+
lastBlockProposal: BlockProposal | undefined,
|
|
961
958
|
proposerAddress: EthAddress | undefined,
|
|
962
959
|
options: CheckpointProposalOptions = {},
|
|
963
960
|
): Promise<CheckpointProposal> {
|
|
@@ -978,12 +975,20 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
978
975
|
const newProposal = await this.validationService.createCheckpointProposal(
|
|
979
976
|
checkpointHeader,
|
|
980
977
|
archive,
|
|
978
|
+
checkpointNumber,
|
|
981
979
|
feeAssetPriceModifier,
|
|
982
|
-
|
|
980
|
+
lastBlockProposal,
|
|
983
981
|
proposerAddress,
|
|
984
982
|
options,
|
|
985
983
|
);
|
|
986
984
|
this.lastProposedCheckpoint = newProposal;
|
|
985
|
+
// Self-record this slot's outcome on the re-execution tracker. Proposers don't run their
|
|
986
|
+
// own proposals through `handleCheckpointProposal`, so without this call the proposer's
|
|
987
|
+
// sentinel would see no outcome for slots it proposed and would mis-attribute itself as
|
|
988
|
+
// inactive. We pass the locally-computed `archive` (not `newProposal.archive`, which may
|
|
989
|
+
// be intentionally corrupted under test-only flags); from the proposer's local-view
|
|
990
|
+
// perspective the work it just completed is valid by definition.
|
|
991
|
+
this.proposalHandler.recordOwnCheckpointProposalAsValid(checkpointHeader.slotNumber, archive, checkpointNumber);
|
|
987
992
|
return newProposal;
|
|
988
993
|
}
|
|
989
994
|
|
|
@@ -995,16 +1000,24 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
995
1000
|
attestationsAndSigners: CommitteeAttestationsAndSigners,
|
|
996
1001
|
proposer: EthAddress,
|
|
997
1002
|
slot: SlotNumber,
|
|
998
|
-
|
|
1003
|
+
checkpointNumber: CheckpointNumber,
|
|
999
1004
|
): Promise<Signature> {
|
|
1000
|
-
return await this.validationService.signAttestationsAndSigners(
|
|
1005
|
+
return await this.validationService.signAttestationsAndSigners(
|
|
1006
|
+
attestationsAndSigners,
|
|
1007
|
+
proposer,
|
|
1008
|
+
slot,
|
|
1009
|
+
checkpointNumber,
|
|
1010
|
+
);
|
|
1001
1011
|
}
|
|
1002
1012
|
|
|
1003
|
-
async collectOwnAttestations(
|
|
1013
|
+
async collectOwnAttestations(
|
|
1014
|
+
proposal: CheckpointProposal,
|
|
1015
|
+
checkpointNumber: CheckpointNumber,
|
|
1016
|
+
): Promise<CheckpointAttestation[]> {
|
|
1004
1017
|
const slot = proposal.slotNumber;
|
|
1005
1018
|
const inCommittee = await this.epochCache.filterInCommittee(slot, this.getValidatorAddresses());
|
|
1006
1019
|
this.log.debug(`Collecting ${inCommittee.length} self-attestations for slot ${slot}`, { inCommittee });
|
|
1007
|
-
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee);
|
|
1020
|
+
const attestations = await this.createCheckpointAttestationsFromProposal(proposal, inCommittee, checkpointNumber);
|
|
1008
1021
|
|
|
1009
1022
|
if (!attestations) {
|
|
1010
1023
|
return [];
|
|
@@ -1023,6 +1036,7 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
1023
1036
|
proposal: CheckpointProposal,
|
|
1024
1037
|
required: number,
|
|
1025
1038
|
deadline: Date,
|
|
1039
|
+
checkpointNumber: CheckpointNumber,
|
|
1026
1040
|
): Promise<CheckpointAttestation[]> {
|
|
1027
1041
|
// Wait and poll the p2pClient's attestation pool for this checkpoint until we have enough attestations
|
|
1028
1042
|
const slot = proposal.slotNumber;
|
|
@@ -1035,33 +1049,23 @@ export class ValidatorClient extends (EventEmitter as new () => WatcherEmitter)
|
|
|
1035
1049
|
throw new AttestationTimeoutError(0, required, slot);
|
|
1036
1050
|
}
|
|
1037
1051
|
|
|
1038
|
-
await this.collectOwnAttestations(proposal);
|
|
1052
|
+
await this.collectOwnAttestations(proposal, checkpointNumber);
|
|
1039
1053
|
|
|
1040
|
-
const
|
|
1054
|
+
const proposalPayloadHash = proposal.getPayloadHash();
|
|
1041
1055
|
const myAddresses = this.getValidatorAddresses();
|
|
1042
1056
|
|
|
1043
1057
|
let attestations: CheckpointAttestation[] = [];
|
|
1044
1058
|
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
|
-
);
|
|
1059
|
+
// The pool already filters by proposal payload hash; if any attestation slips through with a
|
|
1060
|
+
// mismatched payload hash, drop it defensively. Equivocations are emitted as separate slash
|
|
1061
|
+
// events from libp2p_service.
|
|
1062
|
+
const collectedAttestations = await this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalPayloadHash);
|
|
1059
1063
|
|
|
1060
1064
|
// Log new attestations we collected
|
|
1061
1065
|
const oldSenders = attestations.map(attestation => attestation.getSender());
|
|
1062
1066
|
for (const collected of collectedAttestations) {
|
|
1063
1067
|
const collectedSender = collected.getSender();
|
|
1064
|
-
// Skip attestations with invalid signatures
|
|
1068
|
+
// Skip attestations with invalid signatures. Should not happen as we don't add invalid attestations to our pool.
|
|
1065
1069
|
if (!collectedSender) {
|
|
1066
1070
|
this.log.warn(`Skipping attestation with invalid signature for slot ${slot}`);
|
|
1067
1071
|
continue;
|