@aztec/stdlib 0.0.1-commit.43597cc1 → 0.0.1-commit.4ad48494d

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 (59) hide show
  1. package/dest/contract/interfaces/node-info.d.ts +3 -1
  2. package/dest/contract/interfaces/node-info.d.ts.map +1 -1
  3. package/dest/contract/interfaces/node-info.js +2 -1
  4. package/dest/hash/hash.d.ts +2 -1
  5. package/dest/hash/hash.d.ts.map +1 -1
  6. package/dest/hash/hash.js +6 -0
  7. package/dest/interfaces/aztec-node-admin.d.ts +7 -1
  8. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  9. package/dest/interfaces/slasher.d.ts +5 -1
  10. package/dest/interfaces/slasher.d.ts.map +1 -1
  11. package/dest/interfaces/slasher.js +1 -0
  12. package/dest/interfaces/validator.d.ts +13 -2
  13. package/dest/interfaces/validator.d.ts.map +1 -1
  14. package/dest/interfaces/validator.js +3 -1
  15. package/dest/logs/siloed_tag.d.ts +1 -1
  16. package/dest/logs/siloed_tag.d.ts.map +1 -1
  17. package/dest/logs/siloed_tag.js +2 -6
  18. package/dest/note/notes_filter.d.ts +5 -2
  19. package/dest/note/notes_filter.d.ts.map +1 -1
  20. package/dest/p2p/constants.d.ts +3 -1
  21. package/dest/p2p/constants.d.ts.map +1 -1
  22. package/dest/p2p/constants.js +1 -0
  23. package/dest/slashing/empire.d.ts +1 -1
  24. package/dest/slashing/empire.d.ts.map +1 -1
  25. package/dest/slashing/empire.js +1 -0
  26. package/dest/slashing/helpers.d.ts +2 -2
  27. package/dest/slashing/helpers.d.ts.map +1 -1
  28. package/dest/slashing/helpers.js +3 -0
  29. package/dest/slashing/types.d.ts +5 -3
  30. package/dest/slashing/types.d.ts.map +1 -1
  31. package/dest/slashing/types.js +7 -1
  32. package/dest/trees/public_data_leaf.d.ts +2 -1
  33. package/dest/trees/public_data_leaf.d.ts.map +1 -1
  34. package/dest/trees/public_data_leaf.js +7 -6
  35. package/dest/tx/validator/empty_validator.d.ts +2 -2
  36. package/dest/tx/validator/empty_validator.d.ts.map +1 -1
  37. package/dest/tx/validator/tx_validator.d.ts +2 -2
  38. package/dest/tx/validator/tx_validator.d.ts.map +1 -1
  39. package/dest/validators/schemas.d.ts +30 -30
  40. package/dest/validators/schemas.d.ts.map +1 -1
  41. package/dest/validators/schemas.js +4 -3
  42. package/dest/validators/types.d.ts +3 -3
  43. package/dest/validators/types.d.ts.map +1 -1
  44. package/package.json +9 -9
  45. package/src/contract/interfaces/node-info.ts +3 -0
  46. package/src/hash/hash.ts +4 -0
  47. package/src/interfaces/slasher.ts +2 -0
  48. package/src/interfaces/validator.ts +9 -1
  49. package/src/logs/siloed_tag.ts +2 -3
  50. package/src/note/notes_filter.ts +4 -1
  51. package/src/p2p/constants.ts +3 -0
  52. package/src/slashing/empire.ts +2 -1
  53. package/src/slashing/helpers.ts +4 -0
  54. package/src/slashing/types.ts +7 -0
  55. package/src/trees/public_data_leaf.ts +11 -5
  56. package/src/tx/validator/empty_validator.ts +1 -1
  57. package/src/tx/validator/tx_validator.ts +1 -1
  58. package/src/validators/schemas.ts +8 -1
  59. package/src/validators/types.ts +5 -4
@@ -22,6 +22,8 @@ export enum OffenseType {
22
22
  ATTESTED_DESCENDANT_OF_INVALID = 7,
23
23
  /** A proposer sent duplicate proposals for the same position (slot, indexWithinCheckpoint for blocks or slot for checkpoints) */
24
24
  DUPLICATE_PROPOSAL = 8,
25
+ /** A validator signed attestations for different proposals at the same slot (equivocation) */
26
+ DUPLICATE_ATTESTATION = 9,
25
27
  }
26
28
 
27
29
  export function getOffenseTypeName(offense: OffenseType) {
@@ -44,6 +46,8 @@ export function getOffenseTypeName(offense: OffenseType) {
44
46
  return 'attested_descendant_of_invalid';
45
47
  case OffenseType.DUPLICATE_PROPOSAL:
46
48
  return 'duplicate_proposal';
49
+ case OffenseType.DUPLICATE_ATTESTATION:
50
+ return 'duplicate_attestation';
47
51
  default:
48
52
  throw new Error(`Unknown offense type: ${offense}`);
49
53
  }
@@ -61,6 +65,7 @@ export const OffenseToBigInt: Record<OffenseType, bigint> = {
61
65
  [OffenseType.PROPOSED_INCORRECT_ATTESTATIONS]: 6n,
62
66
  [OffenseType.ATTESTED_DESCENDANT_OF_INVALID]: 7n,
63
67
  [OffenseType.DUPLICATE_PROPOSAL]: 8n,
68
+ [OffenseType.DUPLICATE_ATTESTATION]: 9n,
64
69
  };
65
70
 
66
71
  export function bigIntToOffense(offense: bigint): OffenseType {
@@ -83,6 +88,8 @@ export function bigIntToOffense(offense: bigint): OffenseType {
83
88
  return OffenseType.ATTESTED_DESCENDANT_OF_INVALID;
84
89
  case 8n:
85
90
  return OffenseType.DUPLICATE_PROPOSAL;
91
+ case 9n:
92
+ return OffenseType.DUPLICATE_ATTESTATION;
86
93
  default:
87
94
  throw new Error(`Unknown offense: ${offense}`);
88
95
  }
@@ -1,4 +1,5 @@
1
1
  import { toBigIntBE, toBufferBE } from '@aztec/foundation/bigint-buffer';
2
+ import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
2
3
  import { Fr } from '@aztec/foundation/curves/bn254';
3
4
  import { schemas } from '@aztec/foundation/schemas';
4
5
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
@@ -81,11 +82,15 @@ export class PublicDataTreeLeafPreimage implements IndexedTreeLeafPreimage {
81
82
  toHashInputs(): Buffer[] {
82
83
  return [
83
84
  ...this.leaf.toHashInputs(),
84
- Buffer.from(toBufferBE(this.nextIndex, 32)),
85
85
  Buffer.from(this.nextKey.toBuffer()),
86
+ Buffer.from(toBufferBE(this.nextIndex, 32)),
86
87
  ];
87
88
  }
88
89
 
90
+ hash(): Promise<Fr> {
91
+ return poseidon2Hash(this.toHashInputs());
92
+ }
93
+
89
94
  clone(): PublicDataTreeLeafPreimage {
90
95
  return new PublicDataTreeLeafPreimage(this.leaf.clone(), this.nextKey, this.nextIndex);
91
96
  }
@@ -104,10 +109,11 @@ export class PublicDataTreeLeafPreimage implements IndexedTreeLeafPreimage {
104
109
 
105
110
  static fromBuffer(buffer: Buffer | BufferReader): PublicDataTreeLeafPreimage {
106
111
  const reader = BufferReader.asReader(buffer);
107
- const value = PublicDataTreeLeaf.fromBuffer(reader);
108
- const nextIndex = toBigIntBE(reader.readBytes(32));
109
- const nextSlot = Fr.fromBuffer(reader);
110
- return new PublicDataTreeLeafPreimage(value, nextSlot, nextIndex);
112
+ return new PublicDataTreeLeafPreimage(
113
+ PublicDataTreeLeaf.fromBuffer(reader),
114
+ Fr.fromBuffer(reader),
115
+ toBigIntBE(reader.readBytes(32)),
116
+ );
111
117
  }
112
118
 
113
119
  static fromLeaf(leaf: PublicDataTreeLeaf, nextKey: bigint, nextIndex: bigint): PublicDataTreeLeafPreimage {
@@ -1,6 +1,6 @@
1
1
  import type { AnyTx, TxValidationResult, TxValidator } from './tx_validator.js';
2
2
 
3
- export class EmptyTxValidator<T extends AnyTx = AnyTx> implements TxValidator<T> {
3
+ export class EmptyTxValidator<T = AnyTx> implements TxValidator<T> {
4
4
  public validateTx(_tx: T): Promise<TxValidationResult> {
5
5
  return Promise.resolve({ result: 'valid' });
6
6
  }
@@ -20,7 +20,7 @@ export type TxValidationResult =
20
20
  | { result: 'invalid'; reason: string[] }
21
21
  | { result: 'skipped'; reason: string[] };
22
22
 
23
- export interface TxValidator<T extends AnyTx = AnyTx> {
23
+ export interface TxValidator<T = AnyTx> {
24
24
  validateTx(tx: T): Promise<TxValidationResult>;
25
25
  }
26
26
 
@@ -12,7 +12,14 @@ import type {
12
12
  } from './types.js';
13
13
 
14
14
  export const ValidatorStatusInSlotSchema = zodFor<ValidatorStatusInSlot>()(
15
- z.enum(['block-mined', 'block-proposed', 'block-missed', 'attestation-sent', 'attestation-missed']),
15
+ z.enum([
16
+ 'checkpoint-mined',
17
+ 'checkpoint-proposed',
18
+ 'checkpoint-missed',
19
+ 'blocks-missed',
20
+ 'attestation-sent',
21
+ 'attestation-missed',
22
+ ]),
16
23
  );
17
24
 
18
25
  export const ValidatorStatusHistorySchema = zodFor<ValidatorStatusHistory>()(
@@ -1,12 +1,13 @@
1
1
  import type { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
2
2
  import type { EthAddress } from '@aztec/foundation/eth-address';
3
3
 
4
- export type ValidatorStatusType = 'block' | 'attestation';
4
+ export type ValidatorStatusType = 'proposer' | 'attestation';
5
5
 
6
6
  export type ValidatorStatusInSlot =
7
- | 'block-mined'
8
- | 'block-proposed'
9
- | 'block-missed'
7
+ | 'checkpoint-mined'
8
+ | 'checkpoint-proposed'
9
+ | 'checkpoint-missed'
10
+ | 'blocks-missed'
10
11
  | 'attestation-sent'
11
12
  | 'attestation-missed';
12
13