@aztec/validator-client 0.0.1-commit.fcb71a6 → 0.0.1-commit.fffb133c
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 +282 -0
- package/dest/block_proposal_handler.d.ts +20 -9
- package/dest/block_proposal_handler.d.ts.map +1 -1
- package/dest/block_proposal_handler.js +333 -78
- package/dest/checkpoint_builder.d.ts +67 -0
- package/dest/checkpoint_builder.d.ts.map +1 -0
- package/dest/checkpoint_builder.js +160 -0
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +13 -8
- package/dest/duties/validation_service.d.ts +41 -12
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +109 -26
- package/dest/factory.d.ts +13 -10
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +2 -2
- package/dest/index.d.ts +3 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -0
- package/dest/key_store/ha_key_store.d.ts +99 -0
- package/dest/key_store/ha_key_store.d.ts.map +1 -0
- package/dest/key_store/ha_key_store.js +208 -0
- package/dest/key_store/index.d.ts +2 -1
- package/dest/key_store/index.d.ts.map +1 -1
- package/dest/key_store/index.js +1 -0
- package/dest/key_store/interface.d.ts +36 -6
- package/dest/key_store/interface.d.ts.map +1 -1
- package/dest/key_store/local_key_store.d.ts +10 -5
- package/dest/key_store/local_key_store.d.ts.map +1 -1
- package/dest/key_store/local_key_store.js +8 -4
- package/dest/key_store/node_keystore_adapter.d.ts +18 -5
- package/dest/key_store/node_keystore_adapter.d.ts.map +1 -1
- package/dest/key_store/node_keystore_adapter.js +18 -4
- package/dest/key_store/web3signer_key_store.d.ts +10 -5
- package/dest/key_store/web3signer_key_store.d.ts.map +1 -1
- package/dest/key_store/web3signer_key_store.js +8 -4
- package/dest/metrics.d.ts +1 -1
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +8 -33
- package/dest/tx_validator/index.d.ts +3 -0
- package/dest/tx_validator/index.d.ts.map +1 -0
- package/dest/tx_validator/index.js +2 -0
- package/dest/tx_validator/nullifier_cache.d.ts +14 -0
- package/dest/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/tx_validator/nullifier_cache.js +24 -0
- package/dest/tx_validator/tx_validator_factory.d.ts +18 -0
- package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -0
- package/dest/tx_validator/tx_validator_factory.js +54 -0
- package/dest/validator.d.ts +45 -20
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +314 -84
- package/package.json +19 -13
- package/src/block_proposal_handler.ts +252 -44
- package/src/checkpoint_builder.ts +284 -0
- package/src/config.ts +12 -7
- package/src/duties/validation_service.ts +153 -31
- package/src/factory.ts +17 -11
- package/src/index.ts +2 -0
- package/src/key_store/ha_key_store.ts +269 -0
- package/src/key_store/index.ts +1 -0
- package/src/key_store/interface.ts +44 -5
- package/src/key_store/local_key_store.ts +13 -4
- package/src/key_store/node_keystore_adapter.ts +27 -4
- package/src/key_store/web3signer_key_store.ts +17 -4
- package/src/metrics.ts +7 -34
- package/src/tx_validator/index.ts +2 -0
- package/src/tx_validator/nullifier_cache.ts +30 -0
- package/src/tx_validator/tx_validator_factory.ts +135 -0
- package/src/validator.ts +429 -107
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High Availability Key Store
|
|
3
|
+
*
|
|
4
|
+
* A ValidatorKeyStore wrapper that adds slashing protection for HA validator setups.
|
|
5
|
+
* When multiple validator nodes are running, only one node will sign for a given duty.
|
|
6
|
+
*/
|
|
7
|
+
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
8
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
9
|
+
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
10
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
11
|
+
import type { EthRemoteSignerConfig } from '@aztec/node-keystore';
|
|
12
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
13
|
+
import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validator-ha-signer/errors';
|
|
14
|
+
import {
|
|
15
|
+
type HAProtectedSigningContext,
|
|
16
|
+
type SigningContext,
|
|
17
|
+
isHAProtectedContext,
|
|
18
|
+
} from '@aztec/validator-ha-signer/types';
|
|
19
|
+
import type { ValidatorHASigner } from '@aztec/validator-ha-signer/validator-ha-signer';
|
|
20
|
+
|
|
21
|
+
import { type TypedDataDefinition, hashTypedData } from 'viem';
|
|
22
|
+
|
|
23
|
+
import type { ExtendedValidatorKeyStore } from './interface.js';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* High Availability Key Store
|
|
27
|
+
*
|
|
28
|
+
* Wraps a base ExtendedValidatorKeyStore and ValidatorHASigner to provide
|
|
29
|
+
* HA-protected signing operations (when context is provided).
|
|
30
|
+
*
|
|
31
|
+
* The extended interface methods (getAttesterAddresses, getCoinbaseAddress, etc.)
|
|
32
|
+
* are pure pass-through since they don't require HA coordination.
|
|
33
|
+
*
|
|
34
|
+
* Usage:
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const baseKeyStore = NodeKeystoreAdapter.fromPrivateKeys(privateKeys);
|
|
37
|
+
* const haSigner = new ValidatorHASigner(db, config);
|
|
38
|
+
* const haKeyStore = new HAKeyStore(baseKeyStore, haSigner);
|
|
39
|
+
*
|
|
40
|
+
* // Without context - signs directly (no HA protection)
|
|
41
|
+
* const sig = await haKeyStore.signMessageWithAddress(addr, msg);
|
|
42
|
+
*
|
|
43
|
+
* // With context - HA protected, throws DutyAlreadySignedError if already signed
|
|
44
|
+
* const result = await haKeyStore.signMessageWithAddress(addr, msg, {
|
|
45
|
+
* slot: 100n,
|
|
46
|
+
* blockNumber: 50n,
|
|
47
|
+
* dutyType: DutyType.BLOCK_PROPOSAL,
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export class HAKeyStore implements ExtendedValidatorKeyStore {
|
|
52
|
+
private readonly log = createLogger('ha-key-store');
|
|
53
|
+
|
|
54
|
+
constructor(
|
|
55
|
+
private readonly baseKeyStore: ExtendedValidatorKeyStore,
|
|
56
|
+
private readonly haSigner: ValidatorHASigner,
|
|
57
|
+
) {
|
|
58
|
+
this.log.info('HAKeyStore initialized', {
|
|
59
|
+
nodeId: haSigner.nodeId,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Sign typed data with all addresses.
|
|
65
|
+
* Coordinates across nodes to prevent double-signing for most duty types.
|
|
66
|
+
* AUTH_REQUEST and TXS duties bypass HA protection since signing multiple times is safe.
|
|
67
|
+
* Returns only signatures that were successfully claimed by this node.
|
|
68
|
+
*/
|
|
69
|
+
async signTypedData(typedData: TypedDataDefinition, context: SigningContext): Promise<Signature[]> {
|
|
70
|
+
// no need for HA protection on auth request and txs signatures
|
|
71
|
+
if (!isHAProtectedContext(context)) {
|
|
72
|
+
return this.baseKeyStore.signTypedData(typedData, context);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Sign each address with HA protection
|
|
76
|
+
const addresses = this.getAddresses();
|
|
77
|
+
const results = await Promise.allSettled(
|
|
78
|
+
addresses.map(addr => this.signTypedDataWithAddress(addr, typedData, context)),
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
// Filter out failures (already signed by other nodes or other errors)
|
|
82
|
+
return results
|
|
83
|
+
.filter((result): result is PromiseFulfilledResult<Signature> => {
|
|
84
|
+
if (result.status === 'fulfilled') {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
// Log expected HA errors (already signed) at debug level
|
|
88
|
+
if (result.reason instanceof DutyAlreadySignedError) {
|
|
89
|
+
this.log.debug(`Duty already signed by another node`, {
|
|
90
|
+
dutyType: context.dutyType,
|
|
91
|
+
slot: context.slot,
|
|
92
|
+
signedByNode: result.reason.signedByNode,
|
|
93
|
+
});
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
// Re-throw unexpected errors
|
|
97
|
+
throw result.reason;
|
|
98
|
+
})
|
|
99
|
+
.map(result => result.value);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Sign a message with all addresses.
|
|
104
|
+
* Coordinates across nodes to prevent double-signing for most duty types.
|
|
105
|
+
* AUTH_REQUEST and TXS duties bypass HA protection since signing multiple times is safe.
|
|
106
|
+
* Returns only signatures that were successfully claimed by this node.
|
|
107
|
+
*/
|
|
108
|
+
async signMessage(message: Buffer32, context: SigningContext): Promise<Signature[]> {
|
|
109
|
+
// no need for HA protection on auth request and txs signatures
|
|
110
|
+
if (!isHAProtectedContext(context)) {
|
|
111
|
+
return this.baseKeyStore.signMessage(message, context);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Sign each address with HA protection
|
|
115
|
+
const addresses = this.getAddresses();
|
|
116
|
+
const results = await Promise.allSettled(
|
|
117
|
+
addresses.map(addr => this.signMessageWithAddress(addr, message, context)),
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
// Filter out failures (already signed by other nodes or other errors)
|
|
121
|
+
return results
|
|
122
|
+
.filter((result): result is PromiseFulfilledResult<Signature> => {
|
|
123
|
+
if (result.status === 'fulfilled') {
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
// Log expected HA errors (already signed) at debug level
|
|
127
|
+
if (result.reason instanceof DutyAlreadySignedError) {
|
|
128
|
+
this.log.debug(`Duty already signed by another node`, {
|
|
129
|
+
dutyType: context.dutyType,
|
|
130
|
+
slot: context.slot,
|
|
131
|
+
signedByNode: result.reason.signedByNode,
|
|
132
|
+
});
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
// Re-throw unexpected errors
|
|
136
|
+
throw result.reason;
|
|
137
|
+
})
|
|
138
|
+
.map(result => result.value);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Sign typed data with a specific address.
|
|
143
|
+
* Coordinates across nodes to prevent double-signing for most duty types.
|
|
144
|
+
* AUTH_REQUEST and TXS duties bypass HA protection since signing multiple times is safe.
|
|
145
|
+
* @throws DutyAlreadySignedError if the duty was already signed by another node
|
|
146
|
+
* @throws SlashingProtectionError if attempting to sign different data for the same slot
|
|
147
|
+
*/
|
|
148
|
+
async signTypedDataWithAddress(
|
|
149
|
+
address: EthAddress,
|
|
150
|
+
typedData: TypedDataDefinition,
|
|
151
|
+
context: SigningContext,
|
|
152
|
+
): Promise<Signature> {
|
|
153
|
+
// AUTH_REQUEST and TXS bypass HA protection - multiple signatures are safe
|
|
154
|
+
if (!isHAProtectedContext(context)) {
|
|
155
|
+
return this.baseKeyStore.signTypedDataWithAddress(address, typedData, context);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Compute signing root from typed data for HA tracking
|
|
159
|
+
const digest = hashTypedData(typedData);
|
|
160
|
+
const messageHash = Buffer32.fromString(digest);
|
|
161
|
+
|
|
162
|
+
try {
|
|
163
|
+
return await this.haSigner.signWithProtection(address, messageHash, context, () =>
|
|
164
|
+
this.baseKeyStore.signTypedDataWithAddress(address, typedData, context),
|
|
165
|
+
);
|
|
166
|
+
} catch (error) {
|
|
167
|
+
this.processSigningError(error, context);
|
|
168
|
+
throw error;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Sign a message with a specific address.
|
|
174
|
+
* Coordinates across nodes to prevent double-signing for most duty types.
|
|
175
|
+
* AUTH_REQUEST and TXS duties bypass HA protection since signing multiple times is safe.
|
|
176
|
+
* @throws DutyAlreadySignedError if the duty was already signed by another node
|
|
177
|
+
* @throws SlashingProtectionError if attempting to sign different data for the same slot
|
|
178
|
+
*/
|
|
179
|
+
async signMessageWithAddress(address: EthAddress, message: Buffer32, context: SigningContext): Promise<Signature> {
|
|
180
|
+
// no need for HA protection on auth request and txs signatures
|
|
181
|
+
if (!isHAProtectedContext(context)) {
|
|
182
|
+
return this.baseKeyStore.signMessageWithAddress(address, message, context);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
try {
|
|
186
|
+
return await this.haSigner.signWithProtection(address, message, context, messageHash =>
|
|
187
|
+
this.baseKeyStore.signMessageWithAddress(address, messageHash, context),
|
|
188
|
+
);
|
|
189
|
+
} catch (error) {
|
|
190
|
+
this.processSigningError(error, context);
|
|
191
|
+
throw error;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
196
|
+
// pass-through methods (no HA logic needed)
|
|
197
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
198
|
+
|
|
199
|
+
getAddress(index: number): EthAddress {
|
|
200
|
+
return this.baseKeyStore.getAddress(index);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
getAddresses(): EthAddress[] {
|
|
204
|
+
return this.baseKeyStore.getAddresses();
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
getAttesterAddresses(): EthAddress[] {
|
|
208
|
+
return this.baseKeyStore.getAttesterAddresses();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
getCoinbaseAddress(attesterAddress: EthAddress): EthAddress {
|
|
212
|
+
return this.baseKeyStore.getCoinbaseAddress(attesterAddress);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
getPublisherAddresses(attesterAddress: EthAddress): EthAddress[] {
|
|
216
|
+
return this.baseKeyStore.getPublisherAddresses(attesterAddress);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
getFeeRecipient(attesterAddress: EthAddress): AztecAddress {
|
|
220
|
+
return this.baseKeyStore.getFeeRecipient(attesterAddress);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
getRemoteSignerConfig(attesterAddress: EthAddress): EthRemoteSignerConfig | undefined {
|
|
224
|
+
return this.baseKeyStore.getRemoteSignerConfig(attesterAddress);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Process signing errors from the HA signer.
|
|
229
|
+
* Logs expected HA errors (already signed) at appropriate levels.
|
|
230
|
+
* Re-throws unexpected errors.
|
|
231
|
+
*/
|
|
232
|
+
private processSigningError(error: unknown, context: HAProtectedSigningContext) {
|
|
233
|
+
if (error instanceof DutyAlreadySignedError) {
|
|
234
|
+
this.log.debug(`Duty already signed by another node with the same payload`, {
|
|
235
|
+
dutyType: context.dutyType,
|
|
236
|
+
slot: context.slot,
|
|
237
|
+
signedByNode: error.signedByNode,
|
|
238
|
+
});
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (error instanceof SlashingProtectionError) {
|
|
243
|
+
this.log.warn(`Duty already signed by another node with different payload`, {
|
|
244
|
+
dutyType: context.dutyType,
|
|
245
|
+
slot: context.slot,
|
|
246
|
+
existingMessageHash: error.existingMessageHash,
|
|
247
|
+
attemptedMessageHash: error.attemptedMessageHash,
|
|
248
|
+
});
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Re-throw errors
|
|
253
|
+
throw error;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Start the high-availability key store
|
|
258
|
+
*/
|
|
259
|
+
public start(): Promise<void> {
|
|
260
|
+
return Promise.resolve(this.haSigner.start());
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Stop the high-availability key store
|
|
265
|
+
*/
|
|
266
|
+
public async stop() {
|
|
267
|
+
await this.haSigner.stop();
|
|
268
|
+
}
|
|
269
|
+
}
|
package/src/key_store/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
|
3
3
|
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
4
4
|
import type { EthRemoteSignerConfig } from '@aztec/node-keystore';
|
|
5
5
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
|
+
import type { SigningContext } from '@aztec/validator-ha-signer/types';
|
|
6
7
|
|
|
7
8
|
import type { TypedDataDefinition } from 'viem';
|
|
8
9
|
|
|
@@ -26,17 +27,45 @@ export interface ValidatorKeyStore {
|
|
|
26
27
|
*/
|
|
27
28
|
getAddresses(): EthAddress[];
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Sign typed data with all keystore private keys
|
|
32
|
+
* @param typedData - The complete EIP-712 typed data structure
|
|
33
|
+
* @param context - Signing context for HA slashing protection
|
|
34
|
+
* @returns signatures (when context provided with HA, only successfully claimed signatures are returned)
|
|
35
|
+
*/
|
|
36
|
+
signTypedData(typedData: TypedDataDefinition, context: SigningContext): Promise<Signature[]>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Sign typed data with a specific address's private key
|
|
40
|
+
* @param address - The address of the signer to use
|
|
41
|
+
* @param typedData - The complete EIP-712 typed data structure
|
|
42
|
+
* @param context - Signing context for HA slashing protection
|
|
43
|
+
* @returns signature
|
|
44
|
+
*/
|
|
45
|
+
signTypedDataWithAddress(
|
|
46
|
+
address: EthAddress,
|
|
47
|
+
typedData: TypedDataDefinition,
|
|
48
|
+
context: SigningContext,
|
|
49
|
+
): Promise<Signature>;
|
|
50
|
+
|
|
31
51
|
/**
|
|
32
52
|
* Flavor of sign message that followed EIP-712 eth signed message prefix
|
|
33
53
|
* Note: this is only required when we are using ecdsa signatures over secp256k1
|
|
34
54
|
*
|
|
35
55
|
* @param message - The message to sign.
|
|
36
|
-
* @
|
|
56
|
+
* @param context - Signing context for HA slashing protection
|
|
57
|
+
* @returns The signatures (when context provided with HA, only successfully claimed signatures are returned).
|
|
37
58
|
*/
|
|
38
|
-
signMessage(message: Buffer32): Promise<Signature[]>;
|
|
39
|
-
|
|
59
|
+
signMessage(message: Buffer32, context: SigningContext): Promise<Signature[]>;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Sign a message with a specific address's private key
|
|
63
|
+
* @param address - The address of the signer to use
|
|
64
|
+
* @param message - The message to sign
|
|
65
|
+
* @param context - Signing context for HA slashing protection
|
|
66
|
+
* @returns signature
|
|
67
|
+
*/
|
|
68
|
+
signMessageWithAddress(address: EthAddress, message: Buffer32, context: SigningContext): Promise<Signature>;
|
|
40
69
|
}
|
|
41
70
|
|
|
42
71
|
/**
|
|
@@ -79,4 +108,14 @@ export interface ExtendedValidatorKeyStore extends ValidatorKeyStore {
|
|
|
79
108
|
* @returns the remote signer configuration or undefined
|
|
80
109
|
*/
|
|
81
110
|
getRemoteSignerConfig(attesterAddress: EthAddress): EthRemoteSignerConfig | undefined;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Start the key store
|
|
114
|
+
*/
|
|
115
|
+
start(): Promise<void>;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Stop the key store
|
|
119
|
+
*/
|
|
120
|
+
stop(): Promise<void>;
|
|
82
121
|
}
|
|
@@ -2,6 +2,7 @@ import { Buffer32 } from '@aztec/foundation/buffer';
|
|
|
2
2
|
import { Secp256k1Signer } from '@aztec/foundation/crypto/secp256k1-signer';
|
|
3
3
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
4
|
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
5
|
+
import type { SigningContext } from '@aztec/validator-ha-signer/types';
|
|
5
6
|
|
|
6
7
|
import { type TypedDataDefinition, hashTypedData } from 'viem';
|
|
7
8
|
|
|
@@ -46,9 +47,10 @@ export class LocalKeyStore implements ValidatorKeyStore {
|
|
|
46
47
|
/**
|
|
47
48
|
* Sign a message with all keystore private keys
|
|
48
49
|
* @param typedData - The complete EIP-712 typed data structure (domain, types, primaryType, message)
|
|
50
|
+
* @param _context - Signing context (ignored by LocalKeyStore, used for HA protection)
|
|
49
51
|
* @return signature
|
|
50
52
|
*/
|
|
51
|
-
public signTypedData(typedData: TypedDataDefinition): Promise<Signature[]> {
|
|
53
|
+
public signTypedData(typedData: TypedDataDefinition, _context: SigningContext): Promise<Signature[]> {
|
|
52
54
|
const digest = hashTypedData(typedData);
|
|
53
55
|
return Promise.all(this.signers.map(signer => signer.sign(Buffer32.fromString(digest))));
|
|
54
56
|
}
|
|
@@ -57,10 +59,15 @@ export class LocalKeyStore implements ValidatorKeyStore {
|
|
|
57
59
|
* Sign a message with a specific address's private key
|
|
58
60
|
* @param address - The address of the signer to use
|
|
59
61
|
* @param typedData - The complete EIP-712 typed data structure (domain, types, primaryType, message)
|
|
62
|
+
* @param _context - Signing context (ignored by LocalKeyStore, used for HA protection)
|
|
60
63
|
* @returns signature for the specified address
|
|
61
64
|
* @throws Error if the address is not found in the keystore
|
|
62
65
|
*/
|
|
63
|
-
public signTypedDataWithAddress(
|
|
66
|
+
public signTypedDataWithAddress(
|
|
67
|
+
address: EthAddress,
|
|
68
|
+
typedData: TypedDataDefinition,
|
|
69
|
+
_context: SigningContext,
|
|
70
|
+
): Promise<Signature> {
|
|
64
71
|
const signer = this.signersByAddress.get(address.toString());
|
|
65
72
|
if (!signer) {
|
|
66
73
|
throw new Error(`No signer found for address ${address.toString()}`);
|
|
@@ -73,9 +80,10 @@ export class LocalKeyStore implements ValidatorKeyStore {
|
|
|
73
80
|
* Sign a message using eth_sign with all keystore private keys
|
|
74
81
|
*
|
|
75
82
|
* @param message - The message to sign
|
|
83
|
+
* @param _context - Signing context (ignored by LocalKeyStore, used for HA protection)
|
|
76
84
|
* @return signatures
|
|
77
85
|
*/
|
|
78
|
-
public signMessage(message: Buffer32): Promise<Signature[]> {
|
|
86
|
+
public signMessage(message: Buffer32, _context: SigningContext): Promise<Signature[]> {
|
|
79
87
|
return Promise.all(this.signers.map(signer => signer.signMessage(message)));
|
|
80
88
|
}
|
|
81
89
|
|
|
@@ -83,10 +91,11 @@ export class LocalKeyStore implements ValidatorKeyStore {
|
|
|
83
91
|
* Sign a message using eth_sign with a specific address's private key
|
|
84
92
|
* @param address - The address of the signer to use
|
|
85
93
|
* @param message - The message to sign
|
|
94
|
+
* @param _context - Signing context (ignored by LocalKeyStore, used for HA protection)
|
|
86
95
|
* @returns signature for the specified address
|
|
87
96
|
* @throws Error if the address is not found in the keystore
|
|
88
97
|
*/
|
|
89
|
-
public signMessageWithAddress(address: EthAddress, message: Buffer32): Promise<Signature> {
|
|
98
|
+
public signMessageWithAddress(address: EthAddress, message: Buffer32, _context: SigningContext): Promise<Signature> {
|
|
90
99
|
const signer = this.signersByAddress.get(address.toString());
|
|
91
100
|
if (!signer) {
|
|
92
101
|
throw new Error(`No signer found for address ${address.toString()}`);
|
|
@@ -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(
|
|
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(
|
|
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(
|
|
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
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { BlockProposal } from '@aztec/stdlib/p2p';
|
|
2
2
|
import {
|
|
3
3
|
Attributes,
|
|
4
|
+
type Gauge,
|
|
4
5
|
type Histogram,
|
|
5
6
|
Metrics,
|
|
6
7
|
type TelemetryClient,
|
|
7
8
|
type UpDownCounter,
|
|
8
|
-
ValueType,
|
|
9
9
|
} from '@aztec/telemetry-client';
|
|
10
10
|
|
|
11
11
|
export class ValidatorMetrics {
|
|
@@ -16,55 +16,28 @@ export class ValidatorMetrics {
|
|
|
16
16
|
|
|
17
17
|
private reexMana: Histogram;
|
|
18
18
|
private reexTx: Histogram;
|
|
19
|
-
private reexDuration:
|
|
19
|
+
private reexDuration: Gauge;
|
|
20
20
|
|
|
21
21
|
constructor(telemetryClient: TelemetryClient) {
|
|
22
22
|
const meter = telemetryClient.getMeter('Validator');
|
|
23
23
|
|
|
24
|
-
this.failedReexecutionCounter = meter.createUpDownCounter(Metrics.VALIDATOR_FAILED_REEXECUTION_COUNT
|
|
25
|
-
description: 'The number of failed re-executions',
|
|
26
|
-
unit: 'count',
|
|
27
|
-
valueType: ValueType.INT,
|
|
28
|
-
});
|
|
24
|
+
this.failedReexecutionCounter = meter.createUpDownCounter(Metrics.VALIDATOR_FAILED_REEXECUTION_COUNT);
|
|
29
25
|
|
|
30
|
-
this.successfulAttestationsCount = meter.createUpDownCounter(Metrics.VALIDATOR_ATTESTATION_SUCCESS_COUNT
|
|
31
|
-
description: 'The number of successful attestations',
|
|
32
|
-
valueType: ValueType.INT,
|
|
33
|
-
});
|
|
26
|
+
this.successfulAttestationsCount = meter.createUpDownCounter(Metrics.VALIDATOR_ATTESTATION_SUCCESS_COUNT);
|
|
34
27
|
|
|
35
28
|
this.failedAttestationsBadProposalCount = meter.createUpDownCounter(
|
|
36
29
|
Metrics.VALIDATOR_ATTESTATION_FAILED_BAD_PROPOSAL_COUNT,
|
|
37
|
-
{
|
|
38
|
-
description: 'The number of failed attestations due to invalid block proposals',
|
|
39
|
-
valueType: ValueType.INT,
|
|
40
|
-
},
|
|
41
30
|
);
|
|
42
31
|
|
|
43
32
|
this.failedAttestationsNodeIssueCount = meter.createUpDownCounter(
|
|
44
33
|
Metrics.VALIDATOR_ATTESTATION_FAILED_NODE_ISSUE_COUNT,
|
|
45
|
-
{
|
|
46
|
-
description: 'The number of failed attestations due to node issues (timeout, missing data, etc.)',
|
|
47
|
-
valueType: ValueType.INT,
|
|
48
|
-
},
|
|
49
34
|
);
|
|
50
35
|
|
|
51
|
-
this.reexMana = meter.createHistogram(Metrics.VALIDATOR_RE_EXECUTION_MANA
|
|
52
|
-
description: 'The mana consumed by blocks',
|
|
53
|
-
valueType: ValueType.DOUBLE,
|
|
54
|
-
unit: 'Mmana',
|
|
55
|
-
});
|
|
36
|
+
this.reexMana = meter.createHistogram(Metrics.VALIDATOR_RE_EXECUTION_MANA);
|
|
56
37
|
|
|
57
|
-
this.reexTx = meter.createHistogram(Metrics.VALIDATOR_RE_EXECUTION_TX_COUNT
|
|
58
|
-
description: 'The number of txs in a block proposal',
|
|
59
|
-
valueType: ValueType.INT,
|
|
60
|
-
unit: 'tx',
|
|
61
|
-
});
|
|
38
|
+
this.reexTx = meter.createHistogram(Metrics.VALIDATOR_RE_EXECUTION_TX_COUNT);
|
|
62
39
|
|
|
63
|
-
this.reexDuration = meter.createGauge(Metrics.VALIDATOR_RE_EXECUTION_TIME
|
|
64
|
-
description: 'The time taken to re-execute a transaction',
|
|
65
|
-
unit: 'ms',
|
|
66
|
-
valueType: ValueType.INT,
|
|
67
|
-
});
|
|
40
|
+
this.reexDuration = meter.createGauge(Metrics.VALIDATOR_RE_EXECUTION_TIME);
|
|
68
41
|
}
|
|
69
42
|
|
|
70
43
|
public recordReex(time: number, txs: number, mManaTotal: number) {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { NullifierSource } from '@aztec/p2p';
|
|
2
|
+
import type { MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
|
|
3
|
+
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Implements a nullifier source by checking a DB and an in-memory collection.
|
|
7
|
+
* Intended for validating transactions as they are added to a block.
|
|
8
|
+
*/
|
|
9
|
+
export class NullifierCache implements NullifierSource {
|
|
10
|
+
nullifiers: Set<string>;
|
|
11
|
+
|
|
12
|
+
constructor(private db: MerkleTreeReadOperations) {
|
|
13
|
+
this.nullifiers = new Set();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public async nullifiersExist(nullifiers: Buffer[]): Promise<boolean[]> {
|
|
17
|
+
const cacheResults = nullifiers.map(n => this.nullifiers.has(n.toString()));
|
|
18
|
+
const toCheckDb = nullifiers.filter((_n, index) => !cacheResults[index]);
|
|
19
|
+
const dbHits = await this.db.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, toCheckDb);
|
|
20
|
+
|
|
21
|
+
let dbIndex = 0;
|
|
22
|
+
return nullifiers.map((_n, index) => cacheResults[index] || dbHits[dbIndex++] !== undefined);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public addNullifiers(nullifiers: Buffer[]) {
|
|
26
|
+
for (const nullifier of nullifiers) {
|
|
27
|
+
this.nullifiers.add(nullifier.toString());
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|