@aztec/validator-client 0.0.1-commit.96bb3f7 → 0.0.1-commit.96dac018d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/README.md +53 -24
  2. package/dest/block_proposal_handler.d.ts +9 -9
  3. package/dest/block_proposal_handler.d.ts.map +1 -1
  4. package/dest/block_proposal_handler.js +35 -54
  5. package/dest/checkpoint_builder.d.ts +24 -25
  6. package/dest/checkpoint_builder.d.ts.map +1 -1
  7. package/dest/checkpoint_builder.js +62 -37
  8. package/dest/config.d.ts +1 -1
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +12 -14
  11. package/dest/duties/validation_service.d.ts +20 -7
  12. package/dest/duties/validation_service.d.ts.map +1 -1
  13. package/dest/duties/validation_service.js +75 -22
  14. package/dest/factory.d.ts +2 -2
  15. package/dest/factory.d.ts.map +1 -1
  16. package/dest/factory.js +1 -1
  17. package/dest/index.d.ts +1 -2
  18. package/dest/index.d.ts.map +1 -1
  19. package/dest/index.js +0 -1
  20. package/dest/key_store/ha_key_store.d.ts +99 -0
  21. package/dest/key_store/ha_key_store.d.ts.map +1 -0
  22. package/dest/key_store/ha_key_store.js +208 -0
  23. package/dest/key_store/index.d.ts +2 -1
  24. package/dest/key_store/index.d.ts.map +1 -1
  25. package/dest/key_store/index.js +1 -0
  26. package/dest/key_store/interface.d.ts +36 -6
  27. package/dest/key_store/interface.d.ts.map +1 -1
  28. package/dest/key_store/local_key_store.d.ts +10 -5
  29. package/dest/key_store/local_key_store.d.ts.map +1 -1
  30. package/dest/key_store/local_key_store.js +8 -4
  31. package/dest/key_store/node_keystore_adapter.d.ts +18 -5
  32. package/dest/key_store/node_keystore_adapter.d.ts.map +1 -1
  33. package/dest/key_store/node_keystore_adapter.js +18 -4
  34. package/dest/key_store/web3signer_key_store.d.ts +10 -5
  35. package/dest/key_store/web3signer_key_store.d.ts.map +1 -1
  36. package/dest/key_store/web3signer_key_store.js +8 -4
  37. package/dest/metrics.d.ts +4 -3
  38. package/dest/metrics.d.ts.map +1 -1
  39. package/dest/metrics.js +34 -5
  40. package/dest/validator.d.ts +43 -18
  41. package/dest/validator.d.ts.map +1 -1
  42. package/dest/validator.js +233 -94
  43. package/package.json +21 -17
  44. package/src/block_proposal_handler.ts +48 -69
  45. package/src/checkpoint_builder.ts +104 -43
  46. package/src/config.ts +11 -13
  47. package/src/duties/validation_service.ts +100 -25
  48. package/src/factory.ts +1 -0
  49. package/src/index.ts +0 -1
  50. package/src/key_store/ha_key_store.ts +269 -0
  51. package/src/key_store/index.ts +1 -0
  52. package/src/key_store/interface.ts +44 -5
  53. package/src/key_store/local_key_store.ts +13 -4
  54. package/src/key_store/node_keystore_adapter.ts +27 -4
  55. package/src/key_store/web3signer_key_store.ts +17 -4
  56. package/src/metrics.ts +45 -6
  57. package/src/validator.ts +303 -114
  58. package/dest/tx_validator/index.d.ts +0 -3
  59. package/dest/tx_validator/index.d.ts.map +0 -1
  60. package/dest/tx_validator/index.js +0 -2
  61. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  62. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  63. package/dest/tx_validator/nullifier_cache.js +0 -24
  64. package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
  65. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  66. package/dest/tx_validator/tx_validator_factory.js +0 -53
  67. package/src/tx_validator/index.ts +0 -2
  68. package/src/tx_validator/nullifier_cache.ts +0 -30
  69. package/src/tx_validator/tx_validator_factory.ts +0 -133
@@ -6,6 +6,7 @@ import { KeystoreManager, loadKeystoreFile } from '@aztec/node-keystore';
6
6
  import type { EthRemoteSignerConfig } from '@aztec/node-keystore';
7
7
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
8
8
  import { InvalidValidatorPrivateKeyError } from '@aztec/stdlib/validators';
9
+ import type { SigningContext } from '@aztec/validator-ha-signer/types';
9
10
 
10
11
  import type { TypedDataDefinition } from 'viem';
11
12
  import { privateKeyToAccount } from 'viem/accounts';
@@ -230,9 +231,10 @@ export class NodeKeystoreAdapter implements ExtendedValidatorKeyStore {
230
231
  /**
231
232
  * Sign typed data with all attester signers across validators.
232
233
  * @param typedData EIP-712 typed data
234
+ * @param _context Signing context (ignored by NodeKeystoreAdapter, used for HA protection)
233
235
  * @returns Array of signatures in validator order, flattened
234
236
  */
235
- async signTypedData(typedData: TypedDataDefinition): Promise<Signature[]> {
237
+ async signTypedData(typedData: TypedDataDefinition, _context: SigningContext): Promise<Signature[]> {
236
238
  const jobs: Promise<Signature>[] = [];
237
239
  for (const i of this.validatorIndices()) {
238
240
  const v = this.ensureValidator(i);
@@ -246,9 +248,10 @@ export class NodeKeystoreAdapter implements ExtendedValidatorKeyStore {
246
248
  /**
247
249
  * Sign a message with all attester signers across validators.
248
250
  * @param message 32-byte message (already hashed/padded as needed)
251
+ * @param _context Signing context (ignored by NodeKeystoreAdapter, used for HA protection)
249
252
  * @returns Array of signatures in validator order, flattened
250
253
  */
251
- async signMessage(message: Buffer32): Promise<Signature[]> {
254
+ async signMessage(message: Buffer32, _context: SigningContext): Promise<Signature[]> {
252
255
  const jobs: Promise<Signature>[] = [];
253
256
  for (const i of this.validatorIndices()) {
254
257
  const v = this.ensureValidator(i);
@@ -264,10 +267,15 @@ export class NodeKeystoreAdapter implements ExtendedValidatorKeyStore {
264
267
  * Hydrates caches on-demand when the address is first seen.
265
268
  * @param address Address to sign with
266
269
  * @param typedData EIP-712 typed data
270
+ * @param _context Signing context (ignored by NodeKeystoreAdapter, used for HA protection)
267
271
  * @returns Signature from the signer matching the address
268
272
  * @throws Error when no signer exists for the address
269
273
  */
270
- async signTypedDataWithAddress(address: EthAddress, typedData: TypedDataDefinition): Promise<Signature> {
274
+ async signTypedDataWithAddress(
275
+ address: EthAddress,
276
+ typedData: TypedDataDefinition,
277
+ _context: SigningContext,
278
+ ): Promise<Signature> {
271
279
  const entry = this.addressIndex.get(NodeKeystoreAdapter.key(address));
272
280
  if (entry) {
273
281
  return await this.keystoreManager.signTypedData(entry.signer, typedData);
@@ -290,10 +298,11 @@ export class NodeKeystoreAdapter implements ExtendedValidatorKeyStore {
290
298
  * Hydrates caches on-demand when the address is first seen.
291
299
  * @param address Address to sign with
292
300
  * @param message 32-byte message
301
+ * @param _context Signing context (ignored by NodeKeystoreAdapter, used for HA protection)
293
302
  * @returns Signature from the signer matching the address
294
303
  * @throws Error when no signer exists for the address
295
304
  */
296
- async signMessageWithAddress(address: EthAddress, message: Buffer32): Promise<Signature> {
305
+ async signMessageWithAddress(address: EthAddress, message: Buffer32, _context: SigningContext): Promise<Signature> {
297
306
  const entry = this.addressIndex.get(NodeKeystoreAdapter.key(address));
298
307
  if (entry) {
299
308
  return await this.keystoreManager.signMessage(entry.signer, message);
@@ -372,4 +381,18 @@ export class NodeKeystoreAdapter implements ExtendedValidatorKeyStore {
372
381
  const validatorIndex = this.findValidatorIndexForAttester(attesterAddress);
373
382
  return this.keystoreManager.getEffectiveRemoteSignerConfig(validatorIndex, attesterAddress);
374
383
  }
384
+
385
+ /**
386
+ * Start the key store - no-op
387
+ */
388
+ start(): Promise<void> {
389
+ return Promise.resolve();
390
+ }
391
+
392
+ /**
393
+ * Stop the key store - no-op
394
+ */
395
+ stop(): Promise<void> {
396
+ return Promise.resolve();
397
+ }
375
398
  }
@@ -2,6 +2,7 @@ import type { Buffer32 } from '@aztec/foundation/buffer';
2
2
  import { normalizeSignature } from '@aztec/foundation/crypto/secp256k1-signer';
3
3
  import { EthAddress } from '@aztec/foundation/eth-address';
4
4
  import { Signature } from '@aztec/foundation/eth-signature';
5
+ import type { SigningContext } from '@aztec/validator-ha-signer/types';
5
6
 
6
7
  import type { TypedDataDefinition } from 'viem';
7
8
 
@@ -44,9 +45,10 @@ export class Web3SignerKeyStore implements ValidatorKeyStore {
44
45
  /**
45
46
  * Sign EIP-712 typed data with all keystore addresses
46
47
  * @param typedData - The complete EIP-712 typed data structure (domain, types, primaryType, message)
48
+ * @param _context - Signing context (ignored by Web3SignerKeyStore, used for HA protection)
47
49
  * @return signatures
48
50
  */
49
- public signTypedData(typedData: TypedDataDefinition): Promise<Signature[]> {
51
+ public signTypedData(typedData: TypedDataDefinition, _context: SigningContext): Promise<Signature[]> {
50
52
  return Promise.all(this.addresses.map(address => this.makeJsonRpcSignTypedDataRequest(address, typedData)));
51
53
  }
52
54
 
@@ -54,10 +56,15 @@ export class Web3SignerKeyStore implements ValidatorKeyStore {
54
56
  * Sign EIP-712 typed data with a specific address
55
57
  * @param address - The address of the signer to use
56
58
  * @param typedData - The complete EIP-712 typed data structure (domain, types, primaryType, message)
59
+ * @param _context - Signing context (ignored by Web3SignerKeyStore, used for HA protection)
57
60
  * @returns signature for the specified address
58
61
  * @throws Error if the address is not found in the keystore or signing fails
59
62
  */
60
- public async signTypedDataWithAddress(address: EthAddress, typedData: TypedDataDefinition): Promise<Signature> {
63
+ public async signTypedDataWithAddress(
64
+ address: EthAddress,
65
+ typedData: TypedDataDefinition,
66
+ _context: SigningContext,
67
+ ): Promise<Signature> {
61
68
  if (!this.addresses.some(addr => addr.equals(address))) {
62
69
  throw new Error(`Address ${address.toString()} not found in keystore`);
63
70
  }
@@ -69,9 +76,10 @@ export class Web3SignerKeyStore implements ValidatorKeyStore {
69
76
  * Sign a message with all keystore addresses using EIP-191 prefix
70
77
  *
71
78
  * @param message - The message to sign
79
+ * @param _context - Signing context (ignored by Web3SignerKeyStore, used for HA protection)
72
80
  * @return signatures
73
81
  */
74
- public signMessage(message: Buffer32): Promise<Signature[]> {
82
+ public signMessage(message: Buffer32, _context: SigningContext): Promise<Signature[]> {
75
83
  return Promise.all(this.addresses.map(address => this.makeJsonRpcSignRequest(address, message)));
76
84
  }
77
85
 
@@ -79,10 +87,15 @@ export class Web3SignerKeyStore implements ValidatorKeyStore {
79
87
  * Sign a message with a specific address using EIP-191 prefix
80
88
  * @param address - The address of the signer to use
81
89
  * @param message - The message to sign
90
+ * @param _context - Signing context (ignored by Web3SignerKeyStore, used for HA protection)
82
91
  * @returns signature for the specified address
83
92
  * @throws Error if the address is not found in the keystore or signing fails
84
93
  */
85
- public async signMessageWithAddress(address: EthAddress, message: Buffer32): Promise<Signature> {
94
+ public async signMessageWithAddress(
95
+ address: EthAddress,
96
+ message: Buffer32,
97
+ _context: SigningContext,
98
+ ): Promise<Signature> {
86
99
  if (!this.addresses.some(addr => addr.equals(address))) {
87
100
  throw new Error(`Address ${address.toString()} not found in keystore`);
88
101
  }
package/src/metrics.ts CHANGED
@@ -6,8 +6,11 @@ import {
6
6
  Metrics,
7
7
  type TelemetryClient,
8
8
  type UpDownCounter,
9
+ createUpDownCounterWithDefault,
9
10
  } from '@aztec/telemetry-client';
10
11
 
12
+ import type { BlockProposalValidationFailureReason } from './block_proposal_handler.js';
13
+
11
14
  export class ValidatorMetrics {
12
15
  private failedReexecutionCounter: UpDownCounter;
13
16
  private successfulAttestationsCount: UpDownCounter;
@@ -21,16 +24,44 @@ export class ValidatorMetrics {
21
24
  constructor(telemetryClient: TelemetryClient) {
22
25
  const meter = telemetryClient.getMeter('Validator');
23
26
 
24
- this.failedReexecutionCounter = meter.createUpDownCounter(Metrics.VALIDATOR_FAILED_REEXECUTION_COUNT);
27
+ this.failedReexecutionCounter = createUpDownCounterWithDefault(meter, Metrics.VALIDATOR_FAILED_REEXECUTION_COUNT, {
28
+ [Attributes.STATUS]: ['failed'],
29
+ });
25
30
 
26
- this.successfulAttestationsCount = meter.createUpDownCounter(Metrics.VALIDATOR_ATTESTATION_SUCCESS_COUNT);
31
+ this.successfulAttestationsCount = createUpDownCounterWithDefault(
32
+ meter,
33
+ Metrics.VALIDATOR_ATTESTATION_SUCCESS_COUNT,
34
+ );
27
35
 
28
- this.failedAttestationsBadProposalCount = meter.createUpDownCounter(
36
+ this.failedAttestationsBadProposalCount = createUpDownCounterWithDefault(
37
+ meter,
29
38
  Metrics.VALIDATOR_ATTESTATION_FAILED_BAD_PROPOSAL_COUNT,
39
+ {
40
+ [Attributes.ERROR_TYPE]: [
41
+ 'invalid_proposal',
42
+ 'state_mismatch',
43
+ 'failed_txs',
44
+ 'in_hash_mismatch',
45
+ 'parent_block_wrong_slot',
46
+ ],
47
+ [Attributes.IS_COMMITTEE_MEMBER]: [true, false],
48
+ },
30
49
  );
31
50
 
32
- this.failedAttestationsNodeIssueCount = meter.createUpDownCounter(
51
+ this.failedAttestationsNodeIssueCount = createUpDownCounterWithDefault(
52
+ meter,
33
53
  Metrics.VALIDATOR_ATTESTATION_FAILED_NODE_ISSUE_COUNT,
54
+ {
55
+ [Attributes.ERROR_TYPE]: [
56
+ 'parent_block_not_found',
57
+ 'global_variables_mismatch',
58
+ 'block_number_already_exists',
59
+ 'txs_not_available',
60
+ 'timeout',
61
+ 'unknown_error',
62
+ ],
63
+ [Attributes.IS_COMMITTEE_MEMBER]: [true, false],
64
+ },
34
65
  );
35
66
 
36
67
  this.reexMana = meter.createHistogram(Metrics.VALIDATOR_RE_EXECUTION_MANA);
@@ -58,14 +89,22 @@ export class ValidatorMetrics {
58
89
  this.successfulAttestationsCount.add(num);
59
90
  }
60
91
 
61
- public incFailedAttestationsBadProposal(num: number, reason: string, inCommittee: boolean) {
92
+ public incFailedAttestationsBadProposal(
93
+ num: number,
94
+ reason: BlockProposalValidationFailureReason,
95
+ inCommittee: boolean,
96
+ ) {
62
97
  this.failedAttestationsBadProposalCount.add(num, {
63
98
  [Attributes.ERROR_TYPE]: reason,
64
99
  [Attributes.IS_COMMITTEE_MEMBER]: inCommittee,
65
100
  });
66
101
  }
67
102
 
68
- public incFailedAttestationsNodeIssue(num: number, reason: string, inCommittee: boolean) {
103
+ public incFailedAttestationsNodeIssue(
104
+ num: number,
105
+ reason: BlockProposalValidationFailureReason,
106
+ inCommittee: boolean,
107
+ ) {
69
108
  this.failedAttestationsNodeIssueCount.add(num, {
70
109
  [Attributes.ERROR_TYPE]: reason,
71
110
  [Attributes.IS_COMMITTEE_MEMBER]: inCommittee,