@aztec/stdlib 0.0.1-commit.e3c1de76 → 0.0.1-commit.e558bd1c

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 (68) hide show
  1. package/dest/block/in_block.js +1 -1
  2. package/dest/interfaces/aztec-node-admin.d.ts +11 -2
  3. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  4. package/dest/interfaces/aztec-node-admin.js +3 -1
  5. package/dest/interfaces/aztec-node.d.ts +28 -21
  6. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  7. package/dest/interfaces/aztec-node.js +1 -1
  8. package/dest/interfaces/get_logs_response.d.ts +8 -1
  9. package/dest/interfaces/get_logs_response.d.ts.map +1 -1
  10. package/dest/interfaces/p2p.d.ts +2 -2
  11. package/dest/interfaces/p2p.d.ts.map +1 -1
  12. package/dest/interfaces/prover-broker.d.ts +16 -1
  13. package/dest/interfaces/prover-broker.d.ts.map +1 -1
  14. package/dest/interfaces/prover-broker.js +4 -1
  15. package/dest/interfaces/prover-client.d.ts +6 -1
  16. package/dest/interfaces/prover-client.d.ts.map +1 -1
  17. package/dest/interfaces/prover-client.js +5 -0
  18. package/dest/interfaces/proving-job.d.ts +34 -34
  19. package/dest/interfaces/slasher.d.ts +5 -1
  20. package/dest/interfaces/slasher.d.ts.map +1 -1
  21. package/dest/interfaces/slasher.js +1 -0
  22. package/dest/interfaces/validator.d.ts +37 -2
  23. package/dest/interfaces/validator.d.ts.map +1 -1
  24. package/dest/interfaces/validator.js +1 -0
  25. package/dest/keys/derivation.d.ts +3 -3
  26. package/dest/keys/derivation.js +8 -8
  27. package/dest/keys/key_types.d.ts +1 -1
  28. package/dest/keys/utils.d.ts +1 -1
  29. package/dest/keys/utils.d.ts.map +1 -1
  30. package/dest/keys/utils.js +7 -3
  31. package/dest/logs/extended_public_log.d.ts +7 -1
  32. package/dest/logs/extended_public_log.d.ts.map +1 -1
  33. package/dest/logs/log_id.d.ts +10 -7
  34. package/dest/logs/log_id.d.ts.map +1 -1
  35. package/dest/logs/log_id.js +15 -13
  36. package/dest/p2p/checkpoint_proposal.d.ts +8 -1
  37. package/dest/p2p/checkpoint_proposal.d.ts.map +1 -1
  38. package/dest/p2p/checkpoint_proposal.js +9 -0
  39. package/dest/slashing/empire.d.ts +1 -1
  40. package/dest/slashing/empire.d.ts.map +1 -1
  41. package/dest/slashing/empire.js +1 -0
  42. package/dest/slashing/helpers.d.ts +2 -2
  43. package/dest/slashing/helpers.d.ts.map +1 -1
  44. package/dest/slashing/helpers.js +3 -0
  45. package/dest/slashing/tally.d.ts +2 -1
  46. package/dest/slashing/tally.d.ts.map +1 -1
  47. package/dest/slashing/tally.js +6 -2
  48. package/dest/slashing/types.d.ts +5 -3
  49. package/dest/slashing/types.d.ts.map +1 -1
  50. package/dest/slashing/types.js +7 -1
  51. package/package.json +20 -10
  52. package/src/block/in_block.ts +1 -1
  53. package/src/interfaces/aztec-node-admin.ts +3 -2
  54. package/src/interfaces/aztec-node.ts +34 -24
  55. package/src/interfaces/p2p.ts +1 -1
  56. package/src/interfaces/prover-broker.ts +22 -0
  57. package/src/interfaces/prover-client.ts +7 -0
  58. package/src/interfaces/slasher.ts +2 -0
  59. package/src/interfaces/validator.ts +2 -1
  60. package/src/keys/derivation.ts +8 -8
  61. package/src/keys/key_types.ts +1 -1
  62. package/src/keys/utils.ts +7 -3
  63. package/src/logs/log_id.ts +15 -12
  64. package/src/p2p/checkpoint_proposal.ts +10 -0
  65. package/src/slashing/empire.ts +2 -1
  66. package/src/slashing/helpers.ts +4 -0
  67. package/src/slashing/tally.ts +8 -2
  68. package/src/slashing/types.ts +7 -0
@@ -87,28 +87,31 @@ export interface AztecNode
87
87
  /**
88
88
  * Find the indexes of the given leaves in the given tree along with a block metadata pointing to the block in which
89
89
  * the leaves were inserted.
90
- * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
90
+ * @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data.
91
91
  * @param treeId - The tree to search in.
92
92
  * @param leafValues - The values to search for.
93
93
  * @returns The indices of leaves and the block metadata of a block in which the leaves were inserted.
94
94
  */
95
95
  findLeavesIndexes(
96
- block: BlockParameter,
96
+ referenceBlock: BlockParameter,
97
97
  treeId: MerkleTreeId,
98
98
  leafValues: Fr[],
99
99
  ): Promise<(DataInBlock<bigint> | undefined)[]>;
100
100
 
101
101
  /**
102
102
  * Returns a nullifier membership witness for a given nullifier at a given block.
103
- * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
103
+ * @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data.
104
104
  * @param nullifier - Nullifier we try to find witness for.
105
105
  * @returns The nullifier membership witness (if found).
106
106
  */
107
- getNullifierMembershipWitness(block: BlockParameter, nullifier: Fr): Promise<NullifierMembershipWitness | undefined>;
107
+ getNullifierMembershipWitness(
108
+ referenceBlock: BlockParameter,
109
+ nullifier: Fr,
110
+ ): Promise<NullifierMembershipWitness | undefined>;
108
111
 
109
112
  /**
110
113
  * Returns a low nullifier membership witness for a given nullifier at a given block.
111
- * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
114
+ * @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data.
112
115
  * @param nullifier - Nullifier we try to find the low nullifier witness for.
113
116
  * @returns The low nullifier membership witness (if found).
114
117
  * @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
@@ -116,49 +119,56 @@ export interface AztecNode
116
119
  * we are trying to prove non-inclusion for.
117
120
  */
118
121
  getLowNullifierMembershipWitness(
119
- block: BlockParameter,
122
+ referenceBlock: BlockParameter,
120
123
  nullifier: Fr,
121
124
  ): Promise<NullifierMembershipWitness | undefined>;
122
125
 
123
126
  /**
124
127
  * Returns a public data tree witness for a given leaf slot at a given block.
125
- * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
128
+ * @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data.
126
129
  * @param leafSlot - The leaf slot we try to find the witness for.
127
130
  * @returns The public data witness (if found).
128
131
  * @remarks The witness can be used to compute the current value of the public data tree leaf. If the low leaf preimage corresponds to an
129
132
  * "in range" slot, means that the slot doesn't exist and the value is 0. If the low leaf preimage corresponds to the exact slot, the current value
130
133
  * is contained in the leaf preimage.
131
134
  */
132
- getPublicDataWitness(block: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined>;
135
+ getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined>;
133
136
 
134
137
  /**
135
- * Returns a membership witness for a given archive leaf at a given block.
136
- * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
137
- * @param archive - The archive leaf we try to find the witness for.
138
+ * Returns a membership witness for a given block hash in the archive tree.
139
+ *
140
+ * Block hashes are the leaves of the archive tree. Each time a new block is added to the chain,
141
+ * its block hash is appended as a new leaf to the archive tree. This method finds the membership
142
+ * witness (leaf index and sibling path) for a given block hash, which can be used to prove that
143
+ * a specific block exists in the chain's history.
144
+ *
145
+ * @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
146
+ * (which contains the root of the archive tree in which we are searching for the block hash).
147
+ * @param blockHash - The block hash to find in the archive tree.
138
148
  */
139
- getArchiveMembershipWitness(
140
- block: BlockParameter,
141
- archive: Fr,
149
+ getBlockHashMembershipWitness(
150
+ referenceBlock: BlockParameter,
151
+ blockHash: BlockHash,
142
152
  ): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined>;
143
153
 
144
154
  /**
145
155
  * Returns a membership witness for a given note hash at a given block.
146
- * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
156
+ * @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data.
147
157
  * @param noteHash - The note hash we try to find the witness for.
148
158
  */
149
159
  getNoteHashMembershipWitness(
150
- block: BlockParameter,
160
+ referenceBlock: BlockParameter,
151
161
  noteHash: Fr,
152
162
  ): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined>;
153
163
 
154
164
  /**
155
165
  * Returns the index and a sibling path for a leaf in the committed l1 to l2 data tree.
156
- * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
166
+ * @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data.
157
167
  * @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
158
168
  * @returns A tuple of the index and the sibling path of the L1ToL2Message (undefined if not found).
159
169
  */
160
170
  getL1ToL2MessageMembershipWitness(
161
- block: BlockParameter,
171
+ referenceBlock: BlockParameter,
162
172
  l1ToL2Message: Fr,
163
173
  ): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined>;
164
174
 
@@ -183,10 +193,10 @@ export interface AztecNode
183
193
 
184
194
  /**
185
195
  * Get a block specified by its block number or 'latest'.
186
- * @param number - The block number or 'latest'.
196
+ * @param blockParameter - The block parameter (block number, block hash, or 'latest').
187
197
  * @returns The requested block.
188
198
  */
189
- getBlock(number: BlockParameter): Promise<L2Block | undefined>;
199
+ getBlock(blockParameter: BlockParameter): Promise<L2Block | undefined>;
190
200
 
191
201
  /**
192
202
  * Get a block specified by its hash.
@@ -392,12 +402,12 @@ export interface AztecNode
392
402
  * @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
393
403
  * Aztec's version of `eth_getStorageAt`.
394
404
  *
395
- * @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
405
+ * @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data.
396
406
  * @param contract - Address of the contract to query.
397
407
  * @param slot - Slot to query.
398
408
  * @returns Storage value at the given contract slot.
399
409
  */
400
- getPublicStorageAt(block: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr>;
410
+ getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr>;
401
411
 
402
412
  /**
403
413
  * Returns the block header for a given block number, block hash, or 'latest'.
@@ -492,9 +502,9 @@ export const AztecNodeApiSchema: ApiSchemaFor<AztecNode> = {
492
502
  .args(BlockParameterSchema, schemas.Fr)
493
503
  .returns(PublicDataWitness.schema.optional()),
494
504
 
495
- getArchiveMembershipWitness: z
505
+ getBlockHashMembershipWitness: z
496
506
  .function()
497
- .args(BlockParameterSchema, schemas.Fr)
507
+ .args(BlockParameterSchema, BlockHash.schema)
498
508
  .returns(MembershipWitness.schemaFor(ARCHIVE_HEIGHT).optional()),
499
509
 
500
510
  getNoteHashMembershipWitness: z
@@ -63,7 +63,7 @@ export interface P2PApiWithAttestations extends P2PApiWithoutAttestations {
63
63
 
64
64
  export interface P2PClient extends P2PApiWithAttestations {
65
65
  /** Manually adds checkpoint attestations to the p2p client attestation pool. */
66
- addCheckpointAttestations(attestations: CheckpointAttestation[]): Promise<void>;
66
+ addOwnCheckpointAttestations(attestations: CheckpointAttestation[]): Promise<void>;
67
67
  }
68
68
 
69
69
  export type P2PApi<T extends P2PClientType = P2PClientType.Full> = T extends P2PClientType.Full
@@ -1,3 +1,5 @@
1
+ import type { EpochNumber } from '@aztec/foundation/branded-types';
2
+
1
3
  import type { ProvingRequestType } from '../proofs/proving_request_type.js';
2
4
  import type { ProofUri, ProvingJob, ProvingJobId, ProvingJobStatus } from './proving-job.js';
3
5
 
@@ -88,3 +90,23 @@ export interface ProvingJobConsumer {
88
90
  }
89
91
 
90
92
  export interface ProvingJobBroker extends ProvingJobProducer, ProvingJobConsumer {}
93
+
94
+ /**
95
+ * Debug interface for replaying proving jobs from stored inputs.
96
+ * Used for benchmarking different agent configurations against the same workload.
97
+ */
98
+ export interface ProvingJobBrokerDebug {
99
+ /**
100
+ * Replays a proving job by re-enqueuing it with inputs from the configured proof store.
101
+ * The proof type is parsed from the job ID (format: epoch:typeName:hash).
102
+ * @param jobId - The original job ID to replay
103
+ * @param epochNumber - The epoch number to assign
104
+ * @param inputsUri - The proof inputs location
105
+ */
106
+ replayProvingJob(
107
+ jobId: ProvingJobId,
108
+ type: ProvingRequestType,
109
+ epochNumber: EpochNumber,
110
+ inputsUri: ProofUri,
111
+ ): Promise<ProvingJobStatus>;
112
+ }
@@ -35,6 +35,8 @@ export type ProverConfig = ActualProverConfig & {
35
35
  proverId?: EthAddress;
36
36
  /** Number of proving agents to start within the prover. */
37
37
  proverAgentCount: number;
38
+ /** Where to store proving request. Must be accessible to both prover node and agents. If not set will inline-encode the parameters */
39
+ proofStore?: string;
38
40
  /** Store for failed proof inputs. */
39
41
  failedProofStore?: string;
40
42
  };
@@ -48,6 +50,7 @@ export const ProverConfigSchema = zodFor<ProverConfig>()(
48
50
  proverTestDelayMs: z.number(),
49
51
  proverTestDelayFactor: z.number(),
50
52
  proverAgentCount: z.number(),
53
+ proofStore: z.string().optional(),
51
54
  failedProofStore: z.string().optional(),
52
55
  cancelJobsOnStop: z.boolean(),
53
56
  }),
@@ -87,6 +90,10 @@ export const proverConfigMappings: ConfigMappingsType<ProverConfig> = {
87
90
  description: 'The number of prover agents to start',
88
91
  ...numberConfigHelper(1),
89
92
  },
93
+ proofStore: {
94
+ env: 'PROVER_PROOF_STORE',
95
+ description: 'Optional proof input store for the prover',
96
+ },
90
97
  failedProofStore: {
91
98
  env: 'PROVER_FAILED_PROOF_STORE',
92
99
  description:
@@ -18,6 +18,7 @@ export interface SlasherConfig {
18
18
  slashDataWithholdingPenalty: bigint;
19
19
  slashInactivityPenalty: bigint;
20
20
  slashBroadcastedInvalidBlockPenalty: bigint;
21
+ slashDuplicateProposalPenalty: bigint;
21
22
  slashProposeInvalidAttestationsPenalty: bigint;
22
23
  slashAttestDescendantOfInvalidPenalty: bigint;
23
24
  slashUnknownPenalty: bigint;
@@ -40,6 +41,7 @@ export const SlasherConfigSchema = zodFor<SlasherConfig>()(
40
41
  slashInactivityConsecutiveEpochThreshold: z.number(),
41
42
  slashInactivityPenalty: schemas.BigInt,
42
43
  slashProposeInvalidAttestationsPenalty: schemas.BigInt,
44
+ slashDuplicateProposalPenalty: schemas.BigInt,
43
45
  slashAttestDescendantOfInvalidPenalty: schemas.BigInt,
44
46
  slashUnknownPenalty: schemas.BigInt,
45
47
  slashOffenseExpirationRounds: z.number(),
@@ -60,7 +60,7 @@ export type ValidatorClientConfig = ValidatorHASignerConfig & {
60
60
 
61
61
  export type ValidatorClientFullConfig = ValidatorClientConfig &
62
62
  Pick<SequencerConfig, 'txPublicSetupAllowList' | 'broadcastInvalidBlockProposal'> &
63
- Pick<SlasherConfig, 'slashBroadcastedInvalidBlockPenalty'> & {
63
+ Pick<SlasherConfig, 'slashBroadcastedInvalidBlockPenalty' | 'slashDuplicateProposalPenalty'> & {
64
64
  /**
65
65
  * Whether transactions are disabled for this node
66
66
  * @remarks This should match the property in P2PConfig. It's not picked from there to avoid circular dependencies.
@@ -87,6 +87,7 @@ export const ValidatorClientFullConfigSchema = zodFor<Omit<ValidatorClientFullCo
87
87
  txPublicSetupAllowList: z.array(AllowedElementSchema).optional(),
88
88
  broadcastInvalidBlockProposal: z.boolean().optional(),
89
89
  slashBroadcastedInvalidBlockPenalty: schemas.BigInt,
90
+ slashDuplicateProposalPenalty: schemas.BigInt,
90
91
  disableTransactions: z.boolean().optional(),
91
92
  }),
92
93
  );
@@ -10,8 +10,8 @@ import type { KeyPrefix } from './key_types.js';
10
10
  import { PublicKeys } from './public_keys.js';
11
11
  import { getKeyGenerator } from './utils.js';
12
12
 
13
- export function computeAppNullifierSecretKey(masterNullifierSecretKey: GrumpkinScalar, app: AztecAddress): Promise<Fr> {
14
- return computeAppSecretKey(masterNullifierSecretKey, app, 'n'); // 'n' is the key prefix for nullifier secret key
13
+ export function computeAppNullifierHidingKey(masterNullifierHidingKey: GrumpkinScalar, app: AztecAddress): Promise<Fr> {
14
+ return computeAppSecretKey(masterNullifierHidingKey, app, 'n'); // 'n' is the key prefix for nullifier hiding key
15
15
  }
16
16
 
17
17
  export function computeAppSecretKey(skM: GrumpkinScalar, app: AztecAddress, keyPrefix: KeyPrefix): Promise<Fr> {
@@ -26,8 +26,8 @@ export async function computeOvskApp(ovsk: GrumpkinScalar, app: AztecAddress): P
26
26
  return GrumpkinScalar.fromBuffer(ovskAppFr.toBuffer());
27
27
  }
28
28
 
29
- export function deriveMasterNullifierSecretKey(secretKey: Fr): GrumpkinScalar {
30
- return sha512ToGrumpkinScalar([secretKey, GeneratorIndex.NSK_M]);
29
+ export function deriveMasterNullifierHidingKey(secretKey: Fr): GrumpkinScalar {
30
+ return sha512ToGrumpkinScalar([secretKey, GeneratorIndex.NHK_M]);
31
31
  }
32
32
 
33
33
  export function deriveMasterIncomingViewingSecretKey(secretKey: Fr): GrumpkinScalar {
@@ -93,15 +93,15 @@ export function derivePublicKeyFromSecretKey(secretKey: Fq) {
93
93
  * @returns The derived keys.
94
94
  */
95
95
  export async function deriveKeys(secretKey: Fr) {
96
- // First we derive master secret keys - we use sha512 here because this derivation will never take place
96
+ // First we derive master secret/hiding keys - we use sha512 here because this derivation will never take place
97
97
  // in a circuit
98
- const masterNullifierSecretKey = deriveMasterNullifierSecretKey(secretKey);
98
+ const masterNullifierHidingKey = deriveMasterNullifierHidingKey(secretKey);
99
99
  const masterIncomingViewingSecretKey = deriveMasterIncomingViewingSecretKey(secretKey);
100
100
  const masterOutgoingViewingSecretKey = deriveMasterOutgoingViewingSecretKey(secretKey);
101
101
  const masterTaggingSecretKey = sha512ToGrumpkinScalar([secretKey, GeneratorIndex.TSK_M]);
102
102
 
103
103
  // Then we derive master public keys
104
- const masterNullifierPublicKey = await derivePublicKeyFromSecretKey(masterNullifierSecretKey);
104
+ const masterNullifierPublicKey = await derivePublicKeyFromSecretKey(masterNullifierHidingKey);
105
105
  const masterIncomingViewingPublicKey = await derivePublicKeyFromSecretKey(masterIncomingViewingSecretKey);
106
106
  const masterOutgoingViewingPublicKey = await derivePublicKeyFromSecretKey(masterOutgoingViewingSecretKey);
107
107
  const masterTaggingPublicKey = await derivePublicKeyFromSecretKey(masterTaggingSecretKey);
@@ -115,7 +115,7 @@ export async function deriveKeys(secretKey: Fr) {
115
115
  );
116
116
 
117
117
  return {
118
- masterNullifierSecretKey,
118
+ masterNullifierHidingKey,
119
119
  masterIncomingViewingSecretKey,
120
120
  masterOutgoingViewingSecretKey,
121
121
  masterTaggingSecretKey,
@@ -1,5 +1,5 @@
1
1
  import type { GeneratorIndex } from '@aztec/constants';
2
2
 
3
- export type KeyGenerator = GeneratorIndex.NSK_M | GeneratorIndex.IVSK_M | GeneratorIndex.OVSK_M | GeneratorIndex.TSK_M;
3
+ export type KeyGenerator = GeneratorIndex.NHK_M | GeneratorIndex.IVSK_M | GeneratorIndex.OVSK_M | GeneratorIndex.TSK_M;
4
4
  export type KeyPrefix = 'n' | 'iv' | 'ov' | 't';
5
5
  export const KEY_PREFIXES: KeyPrefix[] = ['n', 'iv', 'ov', 't'];
package/src/keys/utils.ts CHANGED
@@ -3,7 +3,11 @@ import { GeneratorIndex } from '@aztec/constants';
3
3
  import type { KeyGenerator, KeyPrefix } from './key_types.js';
4
4
 
5
5
  export function getKeyGenerator(prefix: KeyPrefix): KeyGenerator {
6
- // We get enum key by capitalizing key prefix and concatenating it with 'SK_M'
7
- const enumKey = `${prefix.toUpperCase()}SK_M`;
8
- return GeneratorIndex[enumKey as keyof typeof GeneratorIndex] as KeyGenerator;
6
+ const map: Record<KeyPrefix, KeyGenerator> = {
7
+ n: GeneratorIndex.NHK_M,
8
+ iv: GeneratorIndex.IVSK_M,
9
+ ov: GeneratorIndex.OVSK_M,
10
+ t: GeneratorIndex.TSK_M,
11
+ };
12
+ return map[prefix];
9
13
  }
@@ -8,20 +8,17 @@ import { z } from 'zod';
8
8
 
9
9
  import { BlockHash } from '../block/block_hash.js';
10
10
  import { schemas } from '../schemas/index.js';
11
+ import { TxHash } from '../tx/tx_hash.js';
11
12
 
12
13
  /** A globally unique log id. */
13
14
  export class LogId {
14
- /**
15
- * Parses a log id from a string.
16
- * @param blockNumber - The block number.
17
- * @param txIndex - The transaction index.
18
- * @param logIndex - The log index.
19
- */
20
15
  constructor(
21
16
  /** The block number the log was emitted in. */
22
17
  public readonly blockNumber: BlockNumber,
23
18
  /** The hash of the block the log was emitted in. */
24
19
  public readonly blockHash: BlockHash,
20
+ /** The hash of the transaction the log was emitted in. */
21
+ public readonly txHash: TxHash,
25
22
  /** The index of a tx in a block the log was emitted in. */
26
23
  public readonly txIndex: number,
27
24
  /** The index of a log the tx was emitted in. */
@@ -42,6 +39,7 @@ export class LogId {
42
39
  return new LogId(
43
40
  BlockNumber(Math.floor(Math.random() * 1000) + 1),
44
41
  BlockHash.random(),
42
+ TxHash.random(),
45
43
  Math.floor(Math.random() * 1000),
46
44
  Math.floor(Math.random() * 100),
47
45
  );
@@ -52,11 +50,13 @@ export class LogId {
52
50
  .object({
53
51
  blockNumber: BlockNumberSchema,
54
52
  blockHash: BlockHash.schema,
53
+ txHash: TxHash.schema,
55
54
  txIndex: schemas.Integer,
56
55
  logIndex: schemas.Integer,
57
56
  })
58
57
  .transform(
59
- ({ blockNumber, blockHash, txIndex, logIndex }) => new LogId(blockNumber, blockHash, txIndex, logIndex),
58
+ ({ blockNumber, blockHash, txHash, txIndex, logIndex }) =>
59
+ new LogId(blockNumber, blockHash, txHash, txIndex, logIndex),
60
60
  );
61
61
  }
62
62
 
@@ -68,6 +68,7 @@ export class LogId {
68
68
  return Buffer.concat([
69
69
  toBufferBE(BigInt(this.blockNumber), 4),
70
70
  this.blockHash.toBuffer(),
71
+ this.txHash.toBuffer(),
71
72
  toBufferBE(BigInt(this.txIndex), 4),
72
73
  toBufferBE(BigInt(this.logIndex), 4),
73
74
  ]);
@@ -83,10 +84,11 @@ export class LogId {
83
84
 
84
85
  const blockNumber = BlockNumber(reader.readNumber());
85
86
  const blockHash = new BlockHash(reader.readObject(Fr));
87
+ const txHash = reader.readObject(TxHash);
86
88
  const txIndex = reader.readNumber();
87
89
  const logIndex = reader.readNumber();
88
90
 
89
- return new LogId(blockNumber, blockHash, txIndex, logIndex);
91
+ return new LogId(blockNumber, blockHash, txHash, txIndex, logIndex);
90
92
  }
91
93
 
92
94
  /**
@@ -94,7 +96,7 @@ export class LogId {
94
96
  * @returns A string representation of the log id.
95
97
  */
96
98
  public toString(): string {
97
- return `${this.blockNumber}-${this.txIndex}-${this.logIndex}-${this.blockHash.toString()}`;
99
+ return `${this.blockNumber}-${this.txIndex}-${this.logIndex}-${this.blockHash.toString()}-${this.txHash.toString()}`;
98
100
  }
99
101
 
100
102
  /**
@@ -103,13 +105,14 @@ export class LogId {
103
105
  * @returns A log id.
104
106
  */
105
107
  static fromString(data: string): LogId {
106
- const [rawBlockNumber, rawTxIndex, rawLogIndex, rawBlockHash] = data.split('-');
108
+ const [rawBlockNumber, rawTxIndex, rawLogIndex, rawBlockHash, rawTxHash] = data.split('-');
107
109
  const blockNumber = BlockNumber(Number(rawBlockNumber));
108
110
  const blockHash = BlockHash.fromString(rawBlockHash);
111
+ const txHash = TxHash.fromString(rawTxHash);
109
112
  const txIndex = Number(rawTxIndex);
110
113
  const logIndex = Number(rawLogIndex);
111
114
 
112
- return new LogId(blockNumber, blockHash, txIndex, logIndex);
115
+ return new LogId(blockNumber, blockHash, txHash, txIndex, logIndex);
113
116
  }
114
117
 
115
118
  /**
@@ -117,6 +120,6 @@ export class LogId {
117
120
  * @returns A human readable representation of the log id.
118
121
  */
119
122
  public toHumanReadable(): string {
120
- return `logId: (blockNumber: ${this.blockNumber}, blockHash: ${this.blockHash.toString()}, txIndex: ${this.txIndex}, logIndex: ${this.logIndex})`;
123
+ return `logId: (blockNumber: ${this.blockNumber}, blockHash: ${this.blockHash.toString()}, txHash: ${this.txHash.toString()}, txIndex: ${this.txIndex}, logIndex: ${this.logIndex})`;
121
124
  }
122
125
  }
@@ -148,6 +148,16 @@ export class CheckpointProposal extends Gossipable {
148
148
  };
149
149
  }
150
150
 
151
+ toCheckpointInfo() {
152
+ return {
153
+ slotNumber: this.slotNumber,
154
+ archive: this.archive,
155
+ lastBlockNumber: this.lastBlock?.blockHeader.getBlockNumber(),
156
+ lastBlockIndex: this.lastBlock?.indexWithinCheckpoint,
157
+ blockHeadersHash: this.checkpointHeader.blockHeadersHash,
158
+ };
159
+ }
160
+
151
161
  /**
152
162
  * Get the payload to sign for this checkpoint proposal.
153
163
  * The signature is over the checkpoint header + archive root (for consensus).
@@ -83,7 +83,8 @@ export function getFirstEligibleRoundForOffense(
83
83
  case OffenseType.PROPOSED_INSUFFICIENT_ATTESTATIONS:
84
84
  case OffenseType.PROPOSED_INCORRECT_ATTESTATIONS:
85
85
  case OffenseType.ATTESTED_DESCENDANT_OF_INVALID:
86
- case OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL: {
86
+ case OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL:
87
+ case OffenseType.DUPLICATE_PROPOSAL: {
87
88
  const slot = offense.epochOrSlot;
88
89
  const detectedSlot = SlotNumber.fromBigInt(slot + 1n);
89
90
  return getRoundForSlot(detectedSlot, constants).round + 1n;
@@ -50,6 +50,7 @@ export function getPenaltyForOffense(
50
50
  SlasherConfig,
51
51
  | 'slashAttestDescendantOfInvalidPenalty'
52
52
  | 'slashBroadcastedInvalidBlockPenalty'
53
+ | 'slashDuplicateProposalPenalty'
53
54
  | 'slashPrunePenalty'
54
55
  | 'slashDataWithholdingPenalty'
55
56
  | 'slashUnknownPenalty'
@@ -71,6 +72,8 @@ export function getPenaltyForOffense(
71
72
  return config.slashAttestDescendantOfInvalidPenalty;
72
73
  case OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL:
73
74
  return config.slashBroadcastedInvalidBlockPenalty;
75
+ case OffenseType.DUPLICATE_PROPOSAL:
76
+ return config.slashDuplicateProposalPenalty;
74
77
  case OffenseType.UNKNOWN:
75
78
  return config.slashUnknownPenalty;
76
79
  default: {
@@ -85,6 +88,7 @@ export function getTimeUnitForOffense(offense: OffenseType): 'epoch' | 'slot' {
85
88
  switch (offense) {
86
89
  case OffenseType.ATTESTED_DESCENDANT_OF_INVALID:
87
90
  case OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL:
91
+ case OffenseType.DUPLICATE_PROPOSAL:
88
92
  case OffenseType.PROPOSED_INCORRECT_ATTESTATIONS:
89
93
  case OffenseType.PROPOSED_INSUFFICIENT_ATTESTATIONS:
90
94
  return 'slot';
@@ -1,4 +1,5 @@
1
1
  import { sumBigint } from '@aztec/foundation/bigint';
2
+ import { padArrayEnd } from '@aztec/foundation/collection';
2
3
  import { EthAddress } from '@aztec/foundation/eth-address';
3
4
  import type { PartialBy } from '@aztec/foundation/types';
4
5
 
@@ -20,9 +21,10 @@ export function getSlashConsensusVotesFromOffenses(
20
21
  settings: {
21
22
  slashingAmounts: [bigint, bigint, bigint];
22
23
  epochDuration: number;
24
+ targetCommitteeSize: number;
23
25
  },
24
26
  ): ValidatorSlashVote[] {
25
- const { slashingAmounts } = settings;
27
+ const { slashingAmounts, targetCommitteeSize } = settings;
26
28
 
27
29
  if (committees.length !== epochsForCommittees.length) {
28
30
  throw new Error('committees and epochsForCommittees must have the same length');
@@ -31,7 +33,9 @@ export function getSlashConsensusVotesFromOffenses(
31
33
  const votes = committees.flatMap((committee, committeeIndex) => {
32
34
  const committeeEpoch = epochsForCommittees[committeeIndex];
33
35
 
34
- return committee.map(validator => {
36
+ // Map over actual committee members, then pad to targetCommitteeSize.
37
+ // Padding handles cases where committees may be empty (e.g., when there aren't enough validators to fill the committee size during network startup).
38
+ const votes = committee.map(validator => {
35
39
  // Find offenses for this validator in this specific epoch.
36
40
  // If an offense has no epoch, it is considered for all epochs due to a slashAlways setting.
37
41
  const validatorOffenses = offenses.filter(
@@ -45,6 +49,8 @@ export function getSlashConsensusVotesFromOffenses(
45
49
  const slashUnits = getSlashUnitsForAmount(slashAmount, slashingAmounts);
46
50
  return Number(slashUnits);
47
51
  });
52
+
53
+ return padArrayEnd(votes, 0, targetCommitteeSize);
48
54
  });
49
55
 
50
56
  return votes;
@@ -20,6 +20,8 @@ export enum OffenseType {
20
20
  PROPOSED_INCORRECT_ATTESTATIONS = 6,
21
21
  /** A committee member attested to a block that was built as a descendent of an invalid block (as in a block with invalid attestations) */
22
22
  ATTESTED_DESCENDANT_OF_INVALID = 7,
23
+ /** A proposer sent duplicate proposals for the same position (slot, indexWithinCheckpoint for blocks or slot for checkpoints) */
24
+ DUPLICATE_PROPOSAL = 8,
23
25
  }
24
26
 
25
27
  export function getOffenseTypeName(offense: OffenseType) {
@@ -40,6 +42,8 @@ export function getOffenseTypeName(offense: OffenseType) {
40
42
  return 'proposed_incorrect_attestations';
41
43
  case OffenseType.ATTESTED_DESCENDANT_OF_INVALID:
42
44
  return 'attested_descendant_of_invalid';
45
+ case OffenseType.DUPLICATE_PROPOSAL:
46
+ return 'duplicate_proposal';
43
47
  default:
44
48
  throw new Error(`Unknown offense type: ${offense}`);
45
49
  }
@@ -56,6 +60,7 @@ export const OffenseToBigInt: Record<OffenseType, bigint> = {
56
60
  [OffenseType.PROPOSED_INSUFFICIENT_ATTESTATIONS]: 5n,
57
61
  [OffenseType.PROPOSED_INCORRECT_ATTESTATIONS]: 6n,
58
62
  [OffenseType.ATTESTED_DESCENDANT_OF_INVALID]: 7n,
63
+ [OffenseType.DUPLICATE_PROPOSAL]: 8n,
59
64
  };
60
65
 
61
66
  export function bigIntToOffense(offense: bigint): OffenseType {
@@ -76,6 +81,8 @@ export function bigIntToOffense(offense: bigint): OffenseType {
76
81
  return OffenseType.PROPOSED_INCORRECT_ATTESTATIONS;
77
82
  case 7n:
78
83
  return OffenseType.ATTESTED_DESCENDANT_OF_INVALID;
84
+ case 8n:
85
+ return OffenseType.DUPLICATE_PROPOSAL;
79
86
  default:
80
87
  throw new Error(`Unknown offense: ${offense}`);
81
88
  }