@aztec/stdlib 3.0.0-nightly.20251128 → 3.0.0-nightly.20251202

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 (143) hide show
  1. package/dest/avm/avm.d.ts +17 -9
  2. package/dest/avm/avm.d.ts.map +1 -1
  3. package/dest/avm/avm_circuit_public_inputs.d.ts +5 -3
  4. package/dest/avm/avm_circuit_public_inputs.d.ts.map +1 -1
  5. package/dest/avm/avm_proving_request.d.ts +9 -5
  6. package/dest/avm/avm_proving_request.d.ts.map +1 -1
  7. package/dest/block/in_block.d.ts +7 -5
  8. package/dest/block/in_block.d.ts.map +1 -1
  9. package/dest/block/l2_block.d.ts +3 -2
  10. package/dest/block/l2_block.d.ts.map +1 -1
  11. package/dest/block/l2_block.js +2 -1
  12. package/dest/block/l2_block_code_to_purge.d.ts +1 -1
  13. package/dest/block/l2_block_code_to_purge.d.ts.map +1 -1
  14. package/dest/block/l2_block_code_to_purge.js +3 -2
  15. package/dest/block/l2_block_header.d.ts +4 -3
  16. package/dest/block/l2_block_header.d.ts.map +1 -1
  17. package/dest/block/l2_block_header.js +1 -1
  18. package/dest/block/l2_block_source.d.ts +4 -4
  19. package/dest/block/l2_block_source.d.ts.map +1 -1
  20. package/dest/checkpoint/checkpoint.d.ts +13 -10
  21. package/dest/checkpoint/checkpoint.d.ts.map +1 -1
  22. package/dest/checkpoint/checkpoint.js +4 -4
  23. package/dest/checkpoint/published_checkpoint.d.ts +5 -3
  24. package/dest/checkpoint/published_checkpoint.d.ts.map +1 -1
  25. package/dest/epoch-helpers/index.d.ts +7 -7
  26. package/dest/epoch-helpers/index.d.ts.map +1 -1
  27. package/dest/epoch-helpers/index.js +9 -9
  28. package/dest/interfaces/archiver.js +1 -1
  29. package/dest/interfaces/aztec-node.d.ts +10 -4
  30. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  31. package/dest/interfaces/aztec-node.js +2 -1
  32. package/dest/interfaces/p2p.d.ts +3 -2
  33. package/dest/interfaces/p2p.d.ts.map +1 -1
  34. package/dest/interfaces/p2p.js +1 -1
  35. package/dest/interfaces/proving-job.d.ts +9 -5
  36. package/dest/interfaces/proving-job.d.ts.map +1 -1
  37. package/dest/interfaces/validator.d.ts +3 -3
  38. package/dest/interfaces/validator.d.ts.map +1 -1
  39. package/dest/kernel/private_call_data.d.ts +62 -5
  40. package/dest/kernel/private_call_data.d.ts.map +1 -1
  41. package/dest/kernel/private_call_data.js +105 -4
  42. package/dest/note/note_dao.d.ts +6 -3
  43. package/dest/note/note_dao.d.ts.map +1 -1
  44. package/dest/note/note_dao.js +10 -6
  45. package/dest/note/notes_filter.d.ts +3 -1
  46. package/dest/note/notes_filter.d.ts.map +1 -1
  47. package/dest/note/notes_filter.js +1 -0
  48. package/dest/p2p/block_attestation.d.ts +4 -9
  49. package/dest/p2p/block_attestation.d.ts.map +1 -1
  50. package/dest/p2p/block_proposal.d.ts +3 -2
  51. package/dest/p2p/block_proposal.d.ts.map +1 -1
  52. package/dest/p2p/block_proposal.js +1 -1
  53. package/dest/p2p/consensus_payload.d.ts +4 -182
  54. package/dest/p2p/consensus_payload.d.ts.map +1 -1
  55. package/dest/p2p/consensus_payload.js +14 -25
  56. package/dest/rollup/checkpoint_constant_data.d.ts +11 -5
  57. package/dest/rollup/checkpoint_constant_data.d.ts.map +1 -1
  58. package/dest/rollup/checkpoint_constant_data.js +11 -4
  59. package/dest/rollup/checkpoint_header.d.ts +11 -5
  60. package/dest/rollup/checkpoint_header.d.ts.map +1 -1
  61. package/dest/rollup/checkpoint_header.js +18 -11
  62. package/dest/schemas/schemas.d.ts +6 -1
  63. package/dest/schemas/schemas.d.ts.map +1 -1
  64. package/dest/schemas/schemas.js +2 -0
  65. package/dest/slashing/empire.js +2 -2
  66. package/dest/slashing/helpers.d.ts +5 -5
  67. package/dest/slashing/helpers.d.ts.map +1 -1
  68. package/dest/slashing/helpers.js +7 -6
  69. package/dest/slashing/interfaces.d.ts +3 -2
  70. package/dest/slashing/interfaces.d.ts.map +1 -1
  71. package/dest/tests/factories.d.ts +1 -1
  72. package/dest/tests/factories.d.ts.map +1 -1
  73. package/dest/tests/factories.js +5 -4
  74. package/dest/tests/mocks.d.ts +2 -3
  75. package/dest/tests/mocks.d.ts.map +1 -1
  76. package/dest/tests/mocks.js +6 -12
  77. package/dest/trees/append_only_tree_snapshot.d.ts +1 -4
  78. package/dest/trees/append_only_tree_snapshot.d.ts.map +1 -1
  79. package/dest/trees/append_only_tree_snapshot.js +0 -9
  80. package/dest/tx/block_header.d.ts +4 -3
  81. package/dest/tx/block_header.d.ts.map +1 -1
  82. package/dest/tx/block_header.js +1 -1
  83. package/dest/tx/global_variable_builder.d.ts +3 -2
  84. package/dest/tx/global_variable_builder.d.ts.map +1 -1
  85. package/dest/tx/global_variables.d.ts +26 -8
  86. package/dest/tx/global_variables.d.ts.map +1 -1
  87. package/dest/tx/global_variables.js +27 -10
  88. package/dest/tx/indexed_tx_effect.d.ts +3 -3
  89. package/dest/tx/indexed_tx_effect.d.ts.map +1 -1
  90. package/dest/tx/partial_state_reference.d.ts +1 -4
  91. package/dest/tx/partial_state_reference.d.ts.map +1 -1
  92. package/dest/tx/partial_state_reference.js +0 -10
  93. package/dest/tx/state_reference.d.ts +1 -4
  94. package/dest/tx/state_reference.d.ts.map +1 -1
  95. package/dest/tx/state_reference.js +0 -9
  96. package/dest/tx/tx.d.ts +2 -2
  97. package/dest/tx/tx.d.ts.map +1 -1
  98. package/dest/tx/tx.js +1 -0
  99. package/dest/validators/errors.d.ts +6 -7
  100. package/dest/validators/errors.d.ts.map +1 -1
  101. package/dest/validators/errors.js +2 -4
  102. package/dest/validators/schemas.d.ts +102 -48
  103. package/dest/validators/schemas.d.ts.map +1 -1
  104. package/dest/validators/schemas.js +6 -6
  105. package/dest/validators/types.d.ts +9 -9
  106. package/dest/validators/types.d.ts.map +1 -1
  107. package/package.json +8 -8
  108. package/src/block/in_block.ts +8 -5
  109. package/src/block/l2_block.ts +8 -2
  110. package/src/block/l2_block_code_to_purge.ts +3 -2
  111. package/src/block/l2_block_header.ts +3 -2
  112. package/src/block/l2_block_source.ts +3 -3
  113. package/src/checkpoint/checkpoint.ts +5 -5
  114. package/src/epoch-helpers/index.ts +19 -14
  115. package/src/interfaces/archiver.ts +1 -1
  116. package/src/interfaces/aztec-node.ts +14 -5
  117. package/src/interfaces/p2p.ts +4 -2
  118. package/src/interfaces/validator.ts +1 -2
  119. package/src/kernel/private_call_data.ts +130 -3
  120. package/src/note/note_dao.ts +11 -2
  121. package/src/note/notes_filter.ts +3 -0
  122. package/src/p2p/block_attestation.ts +2 -1
  123. package/src/p2p/block_proposal.ts +3 -2
  124. package/src/p2p/consensus_payload.ts +12 -28
  125. package/src/rollup/checkpoint_constant_data.ts +24 -5
  126. package/src/rollup/checkpoint_header.ts +21 -12
  127. package/src/schemas/schemas.ts +7 -0
  128. package/src/slashing/empire.ts +2 -2
  129. package/src/slashing/helpers.ts +12 -9
  130. package/src/slashing/interfaces.ts +3 -1
  131. package/src/tests/factories.ts +5 -4
  132. package/src/tests/mocks.ts +2 -16
  133. package/src/trees/append_only_tree_snapshot.ts +0 -12
  134. package/src/tx/block_header.ts +3 -2
  135. package/src/tx/global_variable_builder.ts +2 -1
  136. package/src/tx/global_variables.ts +30 -11
  137. package/src/tx/indexed_tx_effect.ts +2 -2
  138. package/src/tx/partial_state_reference.ts +0 -17
  139. package/src/tx/state_reference.ts +0 -15
  140. package/src/tx/tx.ts +2 -1
  141. package/src/validators/errors.ts +3 -4
  142. package/src/validators/schemas.ts +6 -6
  143. package/src/validators/types.ts +8 -8
@@ -17,13 +17,15 @@ export class NoteDao {
17
17
  public note: Note,
18
18
  /** The address of the contract that created the note (i.e. the address used by the kernel during siloing). */
19
19
  public contractAddress: AztecAddress,
20
+ /** The owner of the note - generally the account that can spend the note. */
21
+ public owner: AztecAddress,
20
22
  /**
21
23
  * The storage location of the note. This value is not used for anything in PXE, but we do index by storage slot
22
24
  * since contracts typically make queries based on it.
23
25
  */
24
26
  public storageSlot: Fr,
25
27
  /**
26
- * The randomness injected to the note.
28
+ * The randomness injected to the note hash preimage.
27
29
  */
28
30
  public randomness: Fr,
29
31
  /** The nonce that was injected into the note hash preimage in order to guarantee uniqueness. */
@@ -60,6 +62,7 @@ export class NoteDao {
60
62
  return serializeToBuffer([
61
63
  this.note,
62
64
  this.contractAddress,
65
+ this.owner,
63
66
  this.storageSlot,
64
67
  this.randomness,
65
68
  this.noteNonce,
@@ -77,6 +80,7 @@ export class NoteDao {
77
80
 
78
81
  const note = Note.fromBuffer(reader);
79
82
  const contractAddress = AztecAddress.fromBuffer(reader);
83
+ const owner = AztecAddress.fromBuffer(reader);
80
84
  const storageSlot = Fr.fromBuffer(reader);
81
85
  const randomness = Fr.fromBuffer(reader);
82
86
  const noteNonce = Fr.fromBuffer(reader);
@@ -90,6 +94,7 @@ export class NoteDao {
90
94
  return new NoteDao(
91
95
  note,
92
96
  contractAddress,
97
+ owner,
93
98
  storageSlot,
94
99
  randomness,
95
100
  noteNonce,
@@ -118,12 +123,15 @@ export class NoteDao {
118
123
  public getSize() {
119
124
  const indexSize = Math.ceil(Math.log2(Number(this.index)));
120
125
  const noteSize = 4 + this.note.items.length * Fr.SIZE_IN_BYTES;
121
- return noteSize + AztecAddress.SIZE_IN_BYTES + Fr.SIZE_IN_BYTES * 4 + TxHash.SIZE + Point.SIZE_IN_BYTES + indexSize;
126
+ return (
127
+ noteSize + AztecAddress.SIZE_IN_BYTES * 2 + Fr.SIZE_IN_BYTES * 4 + TxHash.SIZE + Point.SIZE_IN_BYTES + indexSize
128
+ );
122
129
  }
123
130
 
124
131
  static async random({
125
132
  note = Note.random(),
126
133
  contractAddress = undefined,
134
+ owner = undefined,
127
135
  storageSlot = Fr.random(),
128
136
  randomness = Fr.random(),
129
137
  noteNonce = Fr.random(),
@@ -137,6 +145,7 @@ export class NoteDao {
137
145
  return new NoteDao(
138
146
  note,
139
147
  contractAddress ?? (await AztecAddress.random()),
148
+ owner ?? (await AztecAddress.random()),
140
149
  storageSlot,
141
150
  randomness,
142
151
  noteNonce,
@@ -16,6 +16,8 @@ export type NotesFilter = {
16
16
  * @remarks Providing a contract address is required as we need that information to trigger private state sync.
17
17
  */
18
18
  contractAddress: AztecAddress;
19
+ /** The owner of the note. */
20
+ owner?: AztecAddress;
19
21
  /** The specific storage location of the note on the contract. */
20
22
  storageSlot?: Fr;
21
23
  /** The status of the note. Defaults to 'ACTIVE'. */
@@ -28,6 +30,7 @@ export type NotesFilter = {
28
30
 
29
31
  export const NotesFilterSchema: ZodFor<NotesFilter> = z.object({
30
32
  contractAddress: schemas.AztecAddress,
33
+ owner: schemas.AztecAddress.optional(),
31
34
  storageSlot: schemas.Fr.optional(),
32
35
  status: z.nativeEnum(NoteStatus).optional(),
33
36
  siloedNullifier: schemas.Fr.optional(),
@@ -1,3 +1,4 @@
1
+ import { SlotNumber } from '@aztec/foundation/branded-types';
1
2
  import { Buffer32 } from '@aztec/foundation/buffer';
2
3
  import { keccak256, tryRecoverAddress } from '@aztec/foundation/crypto';
3
4
  import type { EthAddress } from '@aztec/foundation/eth-address';
@@ -62,7 +63,7 @@ export class BlockAttestation extends Gossipable {
62
63
  return this.payload.archive;
63
64
  }
64
65
 
65
- get slotNumber(): Fr {
66
+ get slotNumber(): SlotNumber {
66
67
  return this.payload.header.slotNumber;
67
68
  }
68
69
 
@@ -1,3 +1,4 @@
1
+ import { SlotNumber } from '@aztec/foundation/branded-types';
1
2
  import { Buffer32 } from '@aztec/foundation/buffer';
2
3
  import { keccak256, tryRecoverAddress } from '@aztec/foundation/crypto';
3
4
  import type { EthAddress } from '@aztec/foundation/eth-address';
@@ -65,13 +66,13 @@ export class BlockProposal extends Gossipable {
65
66
  return this.payload.archive;
66
67
  }
67
68
 
68
- get slotNumber(): Fr {
69
+ get slotNumber(): SlotNumber {
69
70
  return this.payload.header.slotNumber;
70
71
  }
71
72
 
72
73
  toBlockInfo(): Omit<L2BlockInfo, 'blockNumber'> {
73
74
  return {
74
- slotNumber: this.slotNumber.toNumber(),
75
+ slotNumber: this.slotNumber,
75
76
  lastArchive: this.payload.header.lastArchiveRoot,
76
77
  timestamp: this.payload.header.timestamp,
77
78
  archive: this.archive,
@@ -10,7 +10,6 @@ import { z } from 'zod';
10
10
  import type { L2Block } from '../block/l2_block.js';
11
11
  import type { Checkpoint } from '../checkpoint/checkpoint.js';
12
12
  import { CheckpointHeader } from '../rollup/checkpoint_header.js';
13
- import { StateReference } from '../tx/state_reference.js';
14
13
  import type { Signable, SignatureDomainSeparator } from './signature_utils.js';
15
14
 
16
15
  export class ConsensusPayload implements Signable {
@@ -21,8 +20,6 @@ export class ConsensusPayload implements Signable {
21
20
  public readonly header: CheckpointHeader,
22
21
  /** The archive root after the block is added */
23
22
  public readonly archive: Fr,
24
- /** The state reference after the block is added */
25
- public readonly stateReference: StateReference,
26
23
  ) {}
27
24
 
28
25
  static get schema() {
@@ -30,13 +27,12 @@ export class ConsensusPayload implements Signable {
30
27
  .object({
31
28
  header: CheckpointHeader.schema,
32
29
  archive: schemas.Fr,
33
- stateReference: StateReference.schema,
34
30
  })
35
- .transform(obj => new ConsensusPayload(obj.header, obj.archive, obj.stateReference));
31
+ .transform(obj => new ConsensusPayload(obj.header, obj.archive));
36
32
  }
37
33
 
38
34
  static getFields(fields: FieldsOf<ConsensusPayload>) {
39
- return [fields.header, fields.archive, fields.stateReference] as const;
35
+ return [fields.header, fields.archive] as const;
40
36
  }
41
37
 
42
38
  getPayloadToSign(domainSeparator: SignatureDomainSeparator): Buffer {
@@ -44,64 +40,53 @@ export class ConsensusPayload implements Signable {
44
40
  'uint8, ' + //domainSeperator
45
41
  '(' +
46
42
  'bytes32, ' + // archive
47
- '((bytes32,uint32),((bytes32,uint32),(bytes32,uint32),(bytes32,uint32))), ' + // stateReference
48
43
  '(int256), ' + // oracleInput
49
44
  'bytes32' + // headerHash
50
45
  ')',
51
46
  );
52
47
  const archiveRoot = this.archive.toString();
53
- const stateReference = this.stateReference.toAbi();
54
48
 
55
49
  const headerHash = this.header.hash().toString();
56
50
  const encodedData = encodeAbiParameters(abi, [
57
51
  domainSeparator,
58
- [archiveRoot, stateReference, [0n] /* @todo See #9963 */, headerHash],
52
+ [archiveRoot, [0n] /* @todo See #9963 */, headerHash],
59
53
  ] as const);
60
54
 
61
55
  return hexToBuffer(encodedData);
62
56
  }
63
57
 
64
58
  toBuffer(): Buffer {
65
- return serializeToBuffer([this.header, this.archive, this.stateReference]);
59
+ return serializeToBuffer([this.header, this.archive]);
66
60
  }
67
61
 
68
62
  public equals(other: ConsensusPayload): boolean {
69
- return (
70
- this.header.equals(other.header) &&
71
- this.archive.equals(other.archive) &&
72
- this.stateReference.equals(other.stateReference)
73
- );
63
+ return this.header.equals(other.header) && this.archive.equals(other.archive);
74
64
  }
75
65
 
76
66
  static fromBuffer(buf: Buffer | BufferReader): ConsensusPayload {
77
67
  const reader = BufferReader.asReader(buf);
78
- const payload = new ConsensusPayload(
79
- reader.readObject(CheckpointHeader),
80
- reader.readObject(Fr),
81
- reader.readObject(StateReference),
82
- );
68
+ const payload = new ConsensusPayload(reader.readObject(CheckpointHeader), reader.readObject(Fr));
83
69
  return payload;
84
70
  }
85
71
 
86
72
  static fromFields(fields: FieldsOf<ConsensusPayload>): ConsensusPayload {
87
- return new ConsensusPayload(fields.header, fields.archive, fields.stateReference);
73
+ return new ConsensusPayload(fields.header, fields.archive);
88
74
  }
89
75
 
90
76
  static fromBlock(block: L2Block): ConsensusPayload {
91
- return new ConsensusPayload(block.header.toCheckpointHeader(), block.archive.root, block.header.state);
77
+ return new ConsensusPayload(block.header.toCheckpointHeader(), block.archive.root);
92
78
  }
93
79
 
94
80
  static fromCheckpoint(checkpoint: Checkpoint): ConsensusPayload {
95
- const lastBlock = checkpoint.blocks.at(-1)!;
96
- return new ConsensusPayload(checkpoint.header, checkpoint.archive.root, lastBlock.header.state);
81
+ return new ConsensusPayload(checkpoint.header, checkpoint.archive.root);
97
82
  }
98
83
 
99
84
  static empty(): ConsensusPayload {
100
- return new ConsensusPayload(CheckpointHeader.empty(), Fr.ZERO, StateReference.empty());
85
+ return new ConsensusPayload(CheckpointHeader.empty(), Fr.ZERO);
101
86
  }
102
87
 
103
88
  static random(): ConsensusPayload {
104
- return new ConsensusPayload(CheckpointHeader.random(), Fr.random(), StateReference.random());
89
+ return new ConsensusPayload(CheckpointHeader.random(), Fr.random());
105
90
  }
106
91
 
107
92
  /**
@@ -121,11 +106,10 @@ export class ConsensusPayload implements Signable {
121
106
  return {
122
107
  header: this.header.toInspect(),
123
108
  archive: this.archive.toString(),
124
- stateReference: this.stateReference.toInspect(),
125
109
  };
126
110
  }
127
111
 
128
112
  toString() {
129
- return `header: ${this.header.toString()}, archive: ${this.archive.toString()}, stateReference: ${this.stateReference.l1ToL2MessageTree.root.toString()}`;
113
+ return `header: ${this.header.toString()}, archive: ${this.archive.toString()}}`;
130
114
  }
131
115
  }
@@ -1,3 +1,4 @@
1
+ import { SlotNumber } from '@aztec/foundation/branded-types';
1
2
  import { EthAddress } from '@aztec/foundation/eth-address';
2
3
  import { Fr } from '@aztec/foundation/fields';
3
4
  import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
@@ -24,7 +25,7 @@ export class CheckpointConstantData {
24
25
  /** Identifier of the prover. */
25
26
  public proverId: Fr,
26
27
  /** Slot number of the checkpoint. */
27
- public slotNumber: Fr,
28
+ public slotNumber: SlotNumber,
28
29
  /** Coinbase address of the rollup. */
29
30
  public coinbase: EthAddress,
30
31
  /** Address to receive fees. */
@@ -58,7 +59,7 @@ export class CheckpointConstantData {
58
59
  Fr.ZERO,
59
60
  Fr.ZERO,
60
61
  Fr.ZERO,
61
- Fr.ZERO,
62
+ SlotNumber.ZERO,
62
63
  EthAddress.ZERO,
63
64
  AztecAddress.ZERO,
64
65
  GasFees.empty(),
@@ -66,7 +67,17 @@ export class CheckpointConstantData {
66
67
  }
67
68
 
68
69
  toBuffer() {
69
- return serializeToBuffer(...CheckpointConstantData.getFields(this));
70
+ return serializeToBuffer(
71
+ this.chainId,
72
+ this.version,
73
+ this.vkTreeRoot,
74
+ this.protocolContractsHash,
75
+ this.proverId,
76
+ new Fr(this.slotNumber),
77
+ this.coinbase,
78
+ this.feeRecipient,
79
+ this.gasFees,
80
+ );
70
81
  }
71
82
 
72
83
  static fromBuffer(buffer: Buffer | BufferReader) {
@@ -77,13 +88,21 @@ export class CheckpointConstantData {
77
88
  Fr.fromBuffer(reader),
78
89
  Fr.fromBuffer(reader),
79
90
  Fr.fromBuffer(reader),
80
- Fr.fromBuffer(reader),
91
+ SlotNumber(Fr.fromBuffer(reader).toNumber()),
81
92
  reader.readObject(EthAddress),
82
93
  reader.readObject(AztecAddress),
83
94
  reader.readObject(GasFees),
84
95
  );
85
96
  }
86
97
 
98
+ /**
99
+ * Returns the slot number as a SlotNumber branded type.
100
+ * @deprecated Use slotNumber directly instead.
101
+ */
102
+ getSlotNumber(): SlotNumber {
103
+ return this.slotNumber;
104
+ }
105
+
87
106
  toInspect() {
88
107
  return {
89
108
  chainId: this.chainId.toNumber(),
@@ -91,7 +110,7 @@ export class CheckpointConstantData {
91
110
  vkTreeRoot: this.vkTreeRoot.toString(),
92
111
  protocolContractsHash: this.protocolContractsHash.toString(),
93
112
  proverId: this.proverId.toString(),
94
- slotNumber: this.slotNumber.toNumber(),
113
+ slotNumber: this.slotNumber,
95
114
  coinbase: this.coinbase.toString(),
96
115
  feeRecipient: this.feeRecipient.toString(),
97
116
  gasFees: this.gasFees.toInspect(),
@@ -1,4 +1,5 @@
1
1
  import type { ViemHeader } from '@aztec/ethereum';
2
+ import { SlotNumber } from '@aztec/foundation/branded-types';
2
3
  import { sha256ToField } from '@aztec/foundation/crypto';
3
4
  import { EthAddress } from '@aztec/foundation/eth-address';
4
5
  import { Fr } from '@aztec/foundation/fields';
@@ -25,7 +26,7 @@ export class CheckpointHeader {
25
26
  /** Content commitment of the L2 block. */
26
27
  public contentCommitment: ContentCommitment,
27
28
  /** Slot number of the L2 block */
28
- public slotNumber: Fr,
29
+ public slotNumber: SlotNumber,
29
30
  /** Timestamp of the L2 block. */
30
31
  public timestamp: UInt64,
31
32
  /** Recipient of block reward. */
@@ -44,7 +45,7 @@ export class CheckpointHeader {
44
45
  lastArchiveRoot: schemas.Fr,
45
46
  blockHeadersHash: schemas.Fr,
46
47
  contentCommitment: ContentCommitment.schema,
47
- slotNumber: schemas.Fr,
48
+ slotNumber: schemas.SlotNumber,
48
49
  timestamp: schemas.BigInt,
49
50
  coinbase: schemas.EthAddress,
50
51
  feeRecipient: schemas.AztecAddress,
@@ -79,7 +80,7 @@ export class CheckpointHeader {
79
80
  reader.readObject(Fr),
80
81
  reader.readObject(Fr),
81
82
  reader.readObject(ContentCommitment),
82
- Fr.fromBuffer(reader),
83
+ SlotNumber(Fr.fromBuffer(reader).toNumber()),
83
84
  reader.readUInt64(),
84
85
  reader.readObject(EthAddress),
85
86
  reader.readObject(AztecAddress),
@@ -93,7 +94,7 @@ export class CheckpointHeader {
93
94
  this.lastArchiveRoot.equals(other.lastArchiveRoot) &&
94
95
  this.blockHeadersHash.equals(other.blockHeadersHash) &&
95
96
  this.contentCommitment.equals(other.contentCommitment) &&
96
- this.slotNumber.equals(other.slotNumber) &&
97
+ this.slotNumber === other.slotNumber &&
97
98
  this.timestamp === other.timestamp &&
98
99
  this.coinbase.equals(other.coinbase) &&
99
100
  this.feeRecipient.equals(other.feeRecipient) &&
@@ -108,7 +109,7 @@ export class CheckpointHeader {
108
109
  this.lastArchiveRoot,
109
110
  this.blockHeadersHash,
110
111
  this.contentCommitment,
111
- this.slotNumber,
112
+ new Fr(this.slotNumber),
112
113
  bigintToUInt64BE(this.timestamp),
113
114
  this.coinbase,
114
115
  this.feeRecipient,
@@ -126,7 +127,7 @@ export class CheckpointHeader {
126
127
  lastArchiveRoot: Fr.ZERO,
127
128
  blockHeadersHash: Fr.ZERO,
128
129
  contentCommitment: ContentCommitment.empty(),
129
- slotNumber: Fr.ZERO,
130
+ slotNumber: SlotNumber.ZERO,
130
131
  timestamp: 0n,
131
132
  coinbase: EthAddress.ZERO,
132
133
  feeRecipient: AztecAddress.ZERO,
@@ -141,7 +142,7 @@ export class CheckpointHeader {
141
142
  lastArchiveRoot: Fr.random(),
142
143
  blockHeadersHash: Fr.random(),
143
144
  contentCommitment: ContentCommitment.random(),
144
- slotNumber: new Fr(BigInt(Math.floor(Math.random() * 1000) + 1)),
145
+ slotNumber: SlotNumber(Math.floor(Math.random() * 1000) + 1),
145
146
  timestamp: BigInt(Math.floor(Date.now() / 1000)),
146
147
  coinbase: EthAddress.random(),
147
148
  feeRecipient: new AztecAddress(Fr.random()),
@@ -156,7 +157,7 @@ export class CheckpointHeader {
156
157
  this.lastArchiveRoot.isZero() &&
157
158
  this.blockHeadersHash.isZero() &&
158
159
  this.contentCommitment.isEmpty() &&
159
- this.slotNumber.isZero() &&
160
+ this.slotNumber === 0 &&
160
161
  this.timestamp === 0n &&
161
162
  this.coinbase.isZero() &&
162
163
  this.feeRecipient.isZero() &&
@@ -182,7 +183,7 @@ export class CheckpointHeader {
182
183
  Fr.fromString(header.lastArchiveRoot),
183
184
  Fr.fromString(header.blockHeadersHash),
184
185
  ContentCommitment.fromViem(header.contentCommitment),
185
- new Fr(header.slotNumber),
186
+ SlotNumber.fromBigInt(header.slotNumber),
186
187
  header.timestamp,
187
188
  new EthAddress(hexToBuffer(header.coinbase)),
188
189
  new AztecAddress(hexToBuffer(header.feeRecipient)),
@@ -191,12 +192,20 @@ export class CheckpointHeader {
191
192
  );
192
193
  }
193
194
 
195
+ /**
196
+ * Returns the slot number as a SlotNumber branded type.
197
+ * @deprecated Use slotNumber directly instead.
198
+ */
199
+ getSlotNumber(): SlotNumber {
200
+ return this.slotNumber;
201
+ }
202
+
194
203
  toViem(): ViemHeader {
195
204
  return {
196
205
  lastArchiveRoot: this.lastArchiveRoot.toString(),
197
206
  blockHeadersHash: this.blockHeadersHash.toString(),
198
207
  contentCommitment: this.contentCommitment.toViem(),
199
- slotNumber: this.slotNumber.toBigInt(),
208
+ slotNumber: BigInt(this.slotNumber),
200
209
  timestamp: this.timestamp,
201
210
  coinbase: this.coinbase.toString(),
202
211
  feeRecipient: `0x${this.feeRecipient.toBuffer().toString('hex').padStart(64, '0')}`,
@@ -213,7 +222,7 @@ export class CheckpointHeader {
213
222
  lastArchive: this.lastArchiveRoot.toString(),
214
223
  blockHeadersHash: this.blockHeadersHash.toString(),
215
224
  contentCommitment: this.contentCommitment.toInspect(),
216
- slotNumber: this.slotNumber.toBigInt(),
225
+ slotNumber: this.slotNumber,
217
226
  timestamp: this.timestamp,
218
227
  coinbase: this.coinbase.toString(),
219
228
  feeRecipient: this.feeRecipient.toString(),
@@ -228,7 +237,7 @@ export class CheckpointHeader {
228
237
  lastArchiveRoot: ${this.lastArchiveRoot.toString()},
229
238
  blockHeadersHash: ${this.blockHeadersHash.toString()},
230
239
  contentCommitment: ${inspect(this.contentCommitment)},
231
- slotNumber: ${this.slotNumber.toBigInt()},
240
+ slotNumber: ${this.slotNumber},
232
241
  timestamp: ${this.timestamp},
233
242
  coinbase: ${this.coinbase.toString()},
234
243
  feeRecipient: ${this.feeRecipient.toString()},
@@ -1,3 +1,4 @@
1
+ import type { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
1
2
  import type { Buffer32 } from '@aztec/foundation/buffer';
2
3
  import type { EthAddress } from '@aztec/foundation/eth-address';
3
4
  import type { Fq, Fr, Point } from '@aztec/foundation/fields';
@@ -65,6 +66,12 @@ export const schemas = {
65
66
  /** Accepts a hex string. */
66
67
  EventSelector: EventSelector.schema,
67
68
 
69
+ /** Accepts a number, bigint, or string and coerces to SlotNumber. */
70
+ SlotNumber: foundationSchemas.SlotNumber as ZodFor<SlotNumber>,
71
+
72
+ /** Accepts a number, bigint, or string and coerces to EpochNumber. */
73
+ EpochNumber: foundationSchemas.EpochNumber as ZodFor<EpochNumber>,
74
+
68
75
  GasUsed: z.object({
69
76
  totalGas: Gas.schema,
70
77
  teardownGas: Gas.schema,
@@ -1,4 +1,4 @@
1
- import { EpochNumber } from '@aztec/foundation/branded-types';
1
+ import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
2
2
 
3
3
  import { getRoundForSlot, getRoundsForEpoch } from './helpers.js';
4
4
  import type { Offense, OffenseIdentifier, SlashPayload, SlashPayloadRound, ValidatorSlash } from './types.js';
@@ -85,7 +85,7 @@ export function getFirstEligibleRoundForOffense(
85
85
  case OffenseType.ATTESTED_DESCENDANT_OF_INVALID:
86
86
  case OffenseType.BROADCASTED_INVALID_BLOCK_PROPOSAL: {
87
87
  const slot = offense.epochOrSlot;
88
- const detectedSlot = slot + 1n;
88
+ const detectedSlot = SlotNumber.fromBigInt(slot + 1n);
89
89
  return getRoundForSlot(detectedSlot, constants).round + 1n;
90
90
  }
91
91
  // Assume these are epoch-based offenses, even though we should never have to process these
@@ -1,4 +1,4 @@
1
- import { EpochNumber } from '@aztec/foundation/branded-types';
1
+ import { EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
2
2
 
3
3
  import { type L1RollupConstants, getEpochAtSlot, getSlotRangeForEpoch } from '../epoch-helpers/index.js';
4
4
  import type { SlasherConfig } from '../interfaces/slasher.js';
@@ -6,12 +6,13 @@ import { type Offense, OffenseType } from './types.js';
6
6
 
7
7
  /** Returns the voting round number and voting slot within the round for a given L2 slot. */
8
8
  export function getRoundForSlot(
9
- slot: bigint,
9
+ slot: SlotNumber,
10
10
  constants: { slashingRoundSize: number },
11
- ): { round: bigint; votingSlot: bigint } {
11
+ ): { round: bigint; votingSlot: SlotNumber } {
12
12
  const roundSize = BigInt(constants.slashingRoundSize);
13
- const round = slot / roundSize;
14
- const votingSlot = slot % roundSize;
13
+ const slotBigInt = BigInt(slot);
14
+ const round = slotBigInt / roundSize;
15
+ const votingSlot = SlotNumber.fromBigInt(slotBigInt % roundSize);
15
16
  return { round, votingSlot };
16
17
  }
17
18
 
@@ -32,8 +33,8 @@ export function getEpochsForRound(
32
33
  constants: { slashingRoundSize: number; epochDuration: number },
33
34
  ): EpochNumber[] {
34
35
  const epochs: EpochNumber[] = [];
35
- const firstSlot = round * BigInt(constants.slashingRoundSize);
36
- const lastSlot = firstSlot + BigInt(constants.slashingRoundSize) - 1n;
36
+ const firstSlot = SlotNumber.fromBigInt(round * BigInt(constants.slashingRoundSize));
37
+ const lastSlot = SlotNumber(firstSlot + constants.slashingRoundSize - 1);
37
38
  const startEpoch = getEpochAtSlot(firstSlot, constants);
38
39
  const endEpoch = getEpochAtSlot(lastSlot, constants);
39
40
  for (let epoch = startEpoch; epoch <= endEpoch; epoch = EpochNumber(epoch + 1)) {
@@ -103,9 +104,11 @@ export function getTimeUnitForOffense(offense: OffenseType): 'epoch' | 'slot' {
103
104
  export function getSlotForOffense(
104
105
  offense: Pick<Offense, 'epochOrSlot' | 'offenseType'>,
105
106
  constants: Pick<L1RollupConstants, 'epochDuration'>,
106
- ): bigint {
107
+ ): SlotNumber {
107
108
  const { epochOrSlot, offenseType } = offense;
108
- return getTimeUnitForOffense(offenseType) === 'epoch' ? epochOrSlot * BigInt(constants.epochDuration) : epochOrSlot;
109
+ return getTimeUnitForOffense(offenseType) === 'epoch'
110
+ ? SlotNumber.fromBigInt(epochOrSlot * BigInt(constants.epochDuration))
111
+ : SlotNumber.fromBigInt(epochOrSlot);
109
112
  }
110
113
 
111
114
  /** Returns the epoch for a given offense. If the offense type or epoch is not defined, returns undefined. */
@@ -1,3 +1,5 @@
1
+ import type { SlotNumber } from '@aztec/foundation/branded-types';
2
+
1
3
  import type { ProposerSlashAction } from './types.js';
2
4
 
3
5
  export interface ProposerSlashActionProvider {
@@ -7,5 +9,5 @@ export interface ProposerSlashActionProvider {
7
9
  * @param slotNumber - The current slot number
8
10
  * @returns The actions to take
9
11
  */
10
- getProposerActions(slotNumber: bigint): Promise<ProposerSlashAction[]>;
12
+ getProposerActions(slotNumber: SlotNumber): Promise<ProposerSlashAction[]>;
11
13
  }
@@ -43,6 +43,7 @@ import {
43
43
  VK_TREE_HEIGHT,
44
44
  } from '@aztec/constants';
45
45
  import { type FieldsOf, makeTuple } from '@aztec/foundation/array';
46
+ import { SlotNumber } from '@aztec/foundation/branded-types';
46
47
  import { compact } from '@aztec/foundation/collection';
47
48
  import { Grumpkin, SchnorrSignature, poseidon2HashWithSeparator, sha256 } from '@aztec/foundation/crypto';
48
49
  import { EthAddress } from '@aztec/foundation/eth-address';
@@ -694,7 +695,7 @@ export function makeGlobalVariables(seed = 1, overrides: Partial<FieldsOf<Global
694
695
  chainId: new Fr(seed),
695
696
  version: new Fr(seed + 1),
696
697
  blockNumber: seed + 2,
697
- slotNumber: new Fr(seed + 3),
698
+ slotNumber: SlotNumber(seed + 3),
698
699
  timestamp: BigInt(seed + 4),
699
700
  coinbase: EthAddress.fromField(new Fr(seed + 5)),
700
701
  feeRecipient: AztecAddress.fromField(new Fr(seed + 6)),
@@ -775,7 +776,7 @@ function makeCheckpointConstantData(seed = 1) {
775
776
  fr(seed + 2),
776
777
  fr(seed + 3),
777
778
  fr(seed + 4),
778
- fr(seed + 5),
779
+ SlotNumber(seed + 5),
779
780
  makeEthAddress(seed + 6),
780
781
  makeAztecAddress(seed + 7),
781
782
  makeGasFees(seed + 8),
@@ -916,7 +917,7 @@ export function makeL2BlockHeader(
916
917
  overrides?.state ?? makeStateReference(seed + 0x600),
917
918
  makeGlobalVariables((seed += 0x700), {
918
919
  ...(blockNumber ? { blockNumber } : {}),
919
- ...(slotNumber ? { slotNumber: new Fr(slotNumber) } : {}),
920
+ ...(slotNumber ? { slotNumber: SlotNumber(slotNumber) } : {}),
920
921
  }),
921
922
  new Fr(seed + 0x800),
922
923
  new Fr(seed + 0x900),
@@ -930,7 +931,7 @@ export function makeCheckpointHeader(seed = 0) {
930
931
  lastArchiveRoot: fr(seed + 0x100),
931
932
  blockHeadersHash: fr(seed + 0x150),
932
933
  contentCommitment: makeContentCommitment(seed + 0x200),
933
- slotNumber: new Fr(seed + 0x300),
934
+ slotNumber: SlotNumber(seed + 0x300),
934
935
  timestamp: BigInt(seed + 0x400),
935
936
  coinbase: makeEthAddress(seed + 0x500),
936
937
  feeRecipient: makeAztecAddress(seed + 0x600),
@@ -56,7 +56,6 @@ import {
56
56
  PrivateCallExecutionResult,
57
57
  PrivateExecutionResult,
58
58
  ProtocolContracts,
59
- StateReference,
60
59
  Tx,
61
60
  TxConstantData,
62
61
  makeProcessedTxFromPrivateOnlyTx,
@@ -408,7 +407,6 @@ export interface MakeConsensusPayloadOptions {
408
407
  proposerSigner?: Secp256k1Signer;
409
408
  header?: L2BlockHeader;
410
409
  archive?: Fr;
411
- stateReference?: StateReference;
412
410
  txHashes?: TxHash[];
413
411
  txs?: Tx[];
414
412
  }
@@ -418,12 +416,11 @@ const makeAndSignConsensusPayload = (
418
416
  options?: MakeConsensusPayloadOptions,
419
417
  ) => {
420
418
  const header = options?.header ?? makeL2BlockHeader(1);
421
- const { signer = Secp256k1Signer.random(), archive = Fr.random(), stateReference = header.state } = options ?? {};
419
+ const { signer = Secp256k1Signer.random(), archive = Fr.random() } = options ?? {};
422
420
 
423
421
  const payload = ConsensusPayload.fromFields({
424
422
  header: header.toCheckpointHeader(),
425
423
  archive,
426
- stateReference,
427
424
  });
428
425
 
429
426
  const hash = getHashedSignaturePayloadEthSignedMessage(payload, domainSeparator);
@@ -452,18 +449,11 @@ export const makeBlockProposal = (options?: MakeConsensusPayloadOptions): BlockP
452
449
  // TODO(https://github.com/AztecProtocol/aztec-packages/issues/8028)
453
450
  export const makeBlockAttestation = (options: MakeConsensusPayloadOptions = {}): BlockAttestation => {
454
451
  const header = options.header ?? makeL2BlockHeader(1);
455
- const {
456
- signer,
457
- attesterSigner = signer,
458
- proposerSigner = signer,
459
- archive = Fr.random(),
460
- stateReference = header.state,
461
- } = options;
452
+ const { signer, attesterSigner = signer, proposerSigner = signer, archive = Fr.random() } = options;
462
453
 
463
454
  const payload = ConsensusPayload.fromFields({
464
455
  header: header.toCheckpointHeader(),
465
456
  archive,
466
- stateReference,
467
457
  });
468
458
 
469
459
  return makeBlockAttestationFromPayload(payload, attesterSigner, proposerSigner);
@@ -476,12 +466,10 @@ export const makeAttestationFromCheckpoint = (
476
466
  ): BlockAttestation => {
477
467
  const header = checkpoint.header;
478
468
  const archive = checkpoint.archive.root;
479
- const stateReference = checkpoint.blocks.at(-1)!.header.state;
480
469
 
481
470
  const payload = ConsensusPayload.fromFields({
482
471
  header,
483
472
  archive,
484
- stateReference,
485
473
  });
486
474
 
487
475
  return makeBlockAttestationFromPayload(payload, attesterSigner, proposerSigner);
@@ -494,12 +482,10 @@ export const makeBlockAttestationFromBlock = (
494
482
  ): BlockAttestation => {
495
483
  const header = block.header;
496
484
  const archive = block.archive.root;
497
- const stateReference = block.header.state;
498
485
 
499
486
  const payload = ConsensusPayload.fromFields({
500
487
  header: header.toCheckpointHeader(),
501
488
  archive,
502
- stateReference,
503
489
  });
504
490
 
505
491
  return makeBlockAttestationFromPayload(payload, attesterSigner, proposerSigner);
@@ -1,4 +1,3 @@
1
- import type { ViemAppendOnlyTreeSnapshot } from '@aztec/ethereum';
2
1
  import { Fr } from '@aztec/foundation/fields';
3
2
  import { schemas } from '@aztec/foundation/schemas';
4
3
  import { BufferReader, FieldReader, serializeToBuffer } from '@aztec/foundation/serialize';
@@ -72,17 +71,6 @@ export class AppendOnlyTreeSnapshot {
72
71
  return new AppendOnlyTreeSnapshot(reader.readField(), Number(reader.readField().toBigInt()));
73
72
  }
74
73
 
75
- static fromViem(snapshot: ViemAppendOnlyTreeSnapshot) {
76
- return new AppendOnlyTreeSnapshot(Fr.fromString(snapshot.root), snapshot.nextAvailableLeafIndex);
77
- }
78
-
79
- toViem(): ViemAppendOnlyTreeSnapshot {
80
- return {
81
- root: this.root.toString(),
82
- nextAvailableLeafIndex: this.nextAvailableLeafIndex,
83
- };
84
- }
85
-
86
74
  toAbi(): [`0x${string}`, number] {
87
75
  return [this.root.toString(), this.nextAvailableLeafIndex];
88
76
  }