@aztec/validator-client 0.0.1-commit.5de5ca79e → 0.0.1-commit.6201a7b05

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.
@@ -1,17 +1,9 @@
1
- import {
2
- BlockNumber,
3
- type CheckpointNumber,
4
- IndexWithinCheckpoint,
5
- type SlotNumber,
6
- } from '@aztec/foundation/branded-types';
7
- import { Buffer32 } from '@aztec/foundation/buffer';
8
- import { keccak256 } from '@aztec/foundation/crypto/keccak';
1
+ import { type CheckpointNumber, IndexWithinCheckpoint, type SlotNumber } from '@aztec/foundation/branded-types';
9
2
  import { Fr } from '@aztec/foundation/curves/bn254';
10
3
  import type { EthAddress } from '@aztec/foundation/eth-address';
11
4
  import type { Signature } from '@aztec/foundation/eth-signature';
12
5
  import { createLogger } from '@aztec/foundation/log';
13
- import type { CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
14
- import type { CreateCheckpointProposalLastBlockData } from '@aztec/stdlib/interfaces/server';
6
+ import { CommitteeAttestationsAndSigners } from '@aztec/stdlib/block';
15
7
  import {
16
8
  BlockProposal,
17
9
  type BlockProposalOptions,
@@ -20,7 +12,8 @@ import {
20
12
  type CheckpointProposalCore,
21
13
  type CheckpointProposalOptions,
22
14
  ConsensusPayload,
23
- SignatureDomainSeparator,
15
+ type CoordinationSignatureContext,
16
+ getCoordinationSignatureTypedData,
24
17
  } from '@aztec/stdlib/p2p';
25
18
  import type { CheckpointHeader } from '@aztec/stdlib/rollup';
26
19
  import type { BlockHeader, Tx } from '@aztec/stdlib/tx';
@@ -32,6 +25,7 @@ import type { ValidatorKeyStore } from '../key_store/interface.js';
32
25
  export class ValidationService {
33
26
  constructor(
34
27
  private keyStore: ValidatorKeyStore,
28
+ private signatureContext: CoordinationSignatureContext,
35
29
  private log = createLogger('validator:validation-service'),
36
30
  ) {}
37
31
 
@@ -52,6 +46,7 @@ export class ValidationService {
52
46
  */
53
47
  public createBlockProposal(
54
48
  blockHeader: BlockHeader,
49
+ checkpointNumber: CheckpointNumber,
55
50
  blockIndexWithinCheckpoint: IndexWithinCheckpoint,
56
51
  inHash: Fr,
57
52
  archive: Fr,
@@ -67,17 +62,26 @@ export class ValidationService {
67
62
 
68
63
  // Create a signer that uses the appropriate address
69
64
  const address = proposerAttesterAddress ?? this.keyStore.getAddress(0);
70
- const payloadSigner = (payload: Buffer32, context: SigningContext) =>
71
- this.keyStore.signMessageWithAddress(address, payload, context);
65
+ const payloadSigner = (
66
+ typedData: Parameters<ValidatorKeyStore['signTypedDataWithAddress']>[1],
67
+ context: SigningContext,
68
+ ) => this.keyStore.signTypedDataWithAddress(address, typedData, context);
69
+ const txsSigner = (
70
+ typedData: Parameters<ValidatorKeyStore['signTypedDataWithAddress']>[1],
71
+ context: SigningContext,
72
+ ) => this.keyStore.signTypedDataWithAddress(address, typedData, context);
72
73
 
73
74
  return BlockProposal.createProposalFromSigner(
74
75
  blockHeader,
76
+ checkpointNumber,
75
77
  blockIndexWithinCheckpoint,
76
78
  inHash,
77
79
  archive,
78
80
  txs.map(tx => tx.getTxHash()),
79
81
  options.publishFullTxs ? txs : undefined,
82
+ this.signatureContext,
80
83
  payloadSigner,
84
+ txsSigner,
81
85
  );
82
86
  }
83
87
 
@@ -86,7 +90,7 @@ export class ValidationService {
86
90
  *
87
91
  * @param checkpointHeader - The checkpoint header containing aggregated data
88
92
  * @param archive - The archive of the checkpoint
89
- * @param lastBlockInfo - Info about the last block (header, index, txs) or undefined
93
+ * @param lastBlockProposal - Signed block proposal for the last block in the checkpoint, or undefined
90
94
  * @param proposerAttesterAddress - The address of the proposer
91
95
  * @param options - Checkpoint proposal options
92
96
  *
@@ -95,36 +99,36 @@ export class ValidationService {
95
99
  public createCheckpointProposal(
96
100
  checkpointHeader: CheckpointHeader,
97
101
  archive: Fr,
102
+ checkpointNumber: CheckpointNumber,
98
103
  feeAssetPriceModifier: bigint,
99
- lastBlockInfo: CreateCheckpointProposalLastBlockData | undefined,
104
+ lastBlockProposal: BlockProposal | undefined,
100
105
  proposerAttesterAddress: EthAddress | undefined,
101
106
  options: CheckpointProposalOptions,
102
107
  ): Promise<CheckpointProposal> {
103
- // For testing: change the archive to trigger state_mismatch validation failure
108
+ // For testing: change the archive to trigger state_mismatch validation failure.
109
+ // If there's a last block proposal, use its (already invalid) archive to keep signatures consistent
110
+ // so P2P validation passes and the slasher can detect the offense.
104
111
  if (options.broadcastInvalidCheckpointProposal) {
105
- archive = Fr.random();
112
+ archive = lastBlockProposal?.archiveRoot ?? Fr.random();
106
113
  this.log.warn(`Creating INVALID checkpoint proposal for slot ${checkpointHeader.slotNumber}`);
107
114
  }
108
115
 
109
116
  // Create a signer that takes payload and context, and uses the appropriate address
110
- const payloadSigner = (payload: Buffer32, context: SigningContext) => {
117
+ const payloadSigner = (
118
+ typedData: Parameters<ValidatorKeyStore['signTypedDataWithAddress']>[1],
119
+ context: SigningContext,
120
+ ) => {
111
121
  const address = proposerAttesterAddress ?? this.keyStore.getAddress(0);
112
- return this.keyStore.signMessageWithAddress(address, payload, context);
113
- };
114
-
115
- // Last block to include in the proposal
116
- const lastBlock = lastBlockInfo && {
117
- blockHeader: lastBlockInfo.blockHeader,
118
- indexWithinCheckpoint: lastBlockInfo.indexWithinCheckpoint,
119
- txHashes: lastBlockInfo.txs.map(tx => tx.getTxHash()),
120
- txs: options.publishFullTxs ? lastBlockInfo.txs : undefined,
122
+ return this.keyStore.signTypedDataWithAddress(address, typedData, context);
121
123
  };
122
124
 
123
125
  return CheckpointProposal.createProposalFromSigner(
124
126
  checkpointHeader,
125
127
  archive,
128
+ checkpointNumber,
126
129
  feeAssetPriceModifier,
127
- lastBlock,
130
+ lastBlockProposal,
131
+ this.signatureContext,
128
132
  payloadSigner,
129
133
  );
130
134
  }
@@ -142,29 +146,27 @@ export class ValidationService {
142
146
  async attestToCheckpointProposal(
143
147
  proposal: CheckpointProposalCore,
144
148
  attestors: EthAddress[],
149
+ checkpointNumber: CheckpointNumber,
145
150
  ): Promise<CheckpointAttestation[]> {
146
151
  // Create the attestation payload from the checkpoint proposal
147
- const payload = new ConsensusPayload(proposal.checkpointHeader, proposal.archive, proposal.feeAssetPriceModifier);
148
- const buf = Buffer32.fromBuffer(
149
- keccak256(payload.getPayloadToSign(SignatureDomainSeparator.checkpointAttestation)),
152
+ const payload = new ConsensusPayload(
153
+ proposal.checkpointHeader,
154
+ proposal.archive,
155
+ proposal.feeAssetPriceModifier,
156
+ this.signatureContext,
150
157
  );
158
+ const typedData = getCoordinationSignatureTypedData(payload);
151
159
 
152
- // TODO(spy/ha): Use checkpointNumber instead of blockNumber once CheckpointHeader includes it.
153
- // CheckpointProposalCore doesn't have lastBlock info, so use 0 as a proxy.
154
- // blockNumber is NOT used for the primary key so it's safe to use here.
155
- // See CheckpointHeader TODO and SigningContext types documentation.
156
- const blockNumber = BlockNumber(0);
157
160
  const context: SigningContext = {
158
161
  slot: proposal.slotNumber,
159
- blockNumber,
162
+ checkpointNumber,
160
163
  dutyType: DutyType.ATTESTATION,
161
164
  };
162
165
 
163
166
  // Sign each attestor in parallel, catching HA errors per-attestor
164
167
  const results = await Promise.allSettled(
165
168
  attestors.map(async attestor => {
166
- const sig = await this.keyStore.signMessageWithAddress(attestor, buf, context);
167
- // return new BlockAttestation(proposal.payload, sig, proposal.signature);
169
+ const sig = await this.keyStore.signTypedDataWithAddress(attestor, typedData, context);
168
170
  return new CheckpointAttestation(payload, sig, proposal.signature);
169
171
  }),
170
172
  );
@@ -195,7 +197,6 @@ export class ValidationService {
195
197
  * @param attestationsAndSigners - The attestations and signers to sign
196
198
  * @param proposer - The proposer address to sign with
197
199
  * @param slot - The slot number for HA signing context
198
- * @param blockNumber - The block or checkpoint number for HA signing context
199
200
  * @returns signature
200
201
  * @throws DutyAlreadySignedError if already signed by another HA node
201
202
  * @throws SlashingProtectionError if attempting to sign different data for same slot
@@ -204,17 +205,15 @@ export class ValidationService {
204
205
  attestationsAndSigners: CommitteeAttestationsAndSigners,
205
206
  proposer: EthAddress,
206
207
  slot: SlotNumber,
207
- blockNumber: BlockNumber | CheckpointNumber,
208
+ checkpointNumber: CheckpointNumber,
208
209
  ): Promise<Signature> {
209
210
  const context: SigningContext = {
210
211
  slot,
211
- blockNumber,
212
+ checkpointNumber,
212
213
  dutyType: DutyType.ATTESTATIONS_AND_SIGNERS,
213
214
  };
214
215
 
215
- const buf = Buffer32.fromBuffer(
216
- keccak256(attestationsAndSigners.getPayloadToSign(SignatureDomainSeparator.attestationsAndSigners)),
217
- );
218
- return this.keyStore.signMessageWithAddress(proposer, buf, context);
216
+ const typedData = getCoordinationSignatureTypedData(attestationsAndSigners);
217
+ return this.keyStore.signTypedDataWithAddress(proposer, typedData, context);
219
218
  }
220
219
  }
package/src/factory.ts CHANGED
@@ -9,12 +9,12 @@ import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
9
9
  import type { TelemetryClient } from '@aztec/telemetry-client';
10
10
  import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
11
11
 
12
- import { BlockProposalHandler } from './block_proposal_handler.js';
13
12
  import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
14
13
  import { ValidatorMetrics } from './metrics.js';
14
+ import { ProposalHandler } from './proposal_handler.js';
15
15
  import { ValidatorClient } from './validator.js';
16
16
 
17
- export function createBlockProposalHandler(
17
+ export function createProposalHandler(
18
18
  config: ValidatorClientFullConfig,
19
19
  deps: {
20
20
  checkpointsBuilder: FullNodeCheckpointsBuilder;
@@ -23,6 +23,7 @@ export function createBlockProposalHandler(
23
23
  l1ToL2MessageSource: L1ToL2MessageSource;
24
24
  p2pClient: P2PClient;
25
25
  epochCache: EpochCache;
26
+ blobClient: BlobClientInterface;
26
27
  dateProvider: DateProvider;
27
28
  telemetry: TelemetryClient;
28
29
  },
@@ -31,8 +32,12 @@ export function createBlockProposalHandler(
31
32
  const blockProposalValidator = new BlockProposalValidator(deps.epochCache, {
32
33
  txsPermitted: !config.disableTransactions,
33
34
  maxTxsPerBlock: config.validateMaxTxsPerBlock ?? config.validateMaxTxsPerCheckpoint,
35
+ signatureContext: {
36
+ chainId: config.l1ChainId,
37
+ rollupAddress: config.l1Contracts.rollupAddress,
38
+ },
34
39
  });
35
- return new BlockProposalHandler(
40
+ return new ProposalHandler(
36
41
  deps.checkpointsBuilder,
37
42
  deps.worldState,
38
43
  deps.blockSource,
@@ -41,9 +46,11 @@ export function createBlockProposalHandler(
41
46
  blockProposalValidator,
42
47
  deps.epochCache,
43
48
  config,
49
+ deps.blobClient,
44
50
  metrics,
45
51
  deps.dateProvider,
46
52
  deps.telemetry,
53
+ undefined,
47
54
  );
48
55
  }
49
56
 
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './block_proposal_handler.js';
1
+ export * from './proposal_handler.js';
2
2
  export * from './checkpoint_builder.js';
3
3
  export * from './config.js';
4
4
  export * from './factory.js';
package/src/metrics.ts CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  createUpDownCounterWithDefault,
12
12
  } from '@aztec/telemetry-client';
13
13
 
14
- import type { BlockProposalValidationFailureReason } from './block_proposal_handler.js';
14
+ import type { BlockProposalValidationFailureReason } from './proposal_handler.js';
15
15
 
16
16
  export class ValidatorMetrics {
17
17
  private failedReexecutionCounter: UpDownCounter;
@@ -24,6 +24,8 @@ export class ValidatorMetrics {
24
24
  private reexMana: Histogram;
25
25
  private reexTx: Histogram;
26
26
  private reexDuration: Gauge;
27
+ private checkpointProposalToPipelinedStateDuration: Histogram;
28
+ private checkpointProposalReceiveOffsetFromNextSlotBoundary: Histogram;
27
29
 
28
30
  constructor(telemetryClient: TelemetryClient) {
29
31
  const meter = telemetryClient.getMeter('Validator');
@@ -77,6 +79,12 @@ export class ValidatorMetrics {
77
79
  this.reexTx = meter.createHistogram(Metrics.VALIDATOR_RE_EXECUTION_TX_COUNT);
78
80
 
79
81
  this.reexDuration = meter.createGauge(Metrics.VALIDATOR_RE_EXECUTION_TIME);
82
+ this.checkpointProposalToPipelinedStateDuration = meter.createHistogram(
83
+ Metrics.VALIDATOR_CHECKPOINT_PROPOSAL_TO_PIPELINED_STATE_DURATION,
84
+ );
85
+ this.checkpointProposalReceiveOffsetFromNextSlotBoundary = meter.createHistogram(
86
+ Metrics.VALIDATOR_CHECKPOINT_PROPOSAL_RECEIVE_OFFSET_FROM_NEXT_SLOT_BOUNDARY,
87
+ );
80
88
  }
81
89
 
82
90
  public recordReex(time: number, txs: number, mManaTotal: number) {
@@ -85,6 +93,16 @@ export class ValidatorMetrics {
85
93
  this.reexMana.record(mManaTotal);
86
94
  }
87
95
 
96
+ public recordCheckpointProposalToPipelinedStateDuration(durationMs: number) {
97
+ this.checkpointProposalToPipelinedStateDuration.record(Math.ceil(durationMs));
98
+ }
99
+
100
+ public recordCheckpointProposalReceiveOffsetFromNextSlotBoundary(offsetMs: number) {
101
+ this.checkpointProposalReceiveOffsetFromNextSlotBoundary.record(Math.ceil(Math.abs(offsetMs)), {
102
+ [Attributes.SLOT_BOUNDARY_SIDE]: offsetMs < 0 ? 'before' : 'after',
103
+ });
104
+ }
105
+
88
106
  public recordFailedReexecution(proposal: BlockProposal) {
89
107
  const proposer = proposal.getSender();
90
108
  this.failedReexecutionCounter.add(1, {