@aztec/stdlib 0.0.1-commit.3f296a7d2 → 0.0.1-commit.3f5453c7b

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 (219) hide show
  1. package/dest/abi/decoder.d.ts +5 -44
  2. package/dest/abi/decoder.d.ts.map +1 -1
  3. package/dest/abi/decoder.js +12 -67
  4. package/dest/abi/function_selector.js +1 -1
  5. package/dest/abi/function_signature_decoder.d.ts +43 -0
  6. package/dest/abi/function_signature_decoder.d.ts.map +1 -0
  7. package/dest/abi/function_signature_decoder.js +66 -0
  8. package/dest/abi/index.d.ts +2 -1
  9. package/dest/abi/index.d.ts.map +1 -1
  10. package/dest/abi/index.js +1 -0
  11. package/dest/abi/selector.d.ts +2 -2
  12. package/dest/abi/selector.d.ts.map +1 -1
  13. package/dest/abi/selector.js +1 -1
  14. package/dest/avm/avm.d.ts +300 -300
  15. package/dest/avm/revert_code.d.ts +8 -18
  16. package/dest/avm/revert_code.d.ts.map +1 -1
  17. package/dest/avm/revert_code.js +15 -30
  18. package/dest/block/l2_block_source.d.ts +80 -3
  19. package/dest/block/l2_block_source.d.ts.map +1 -1
  20. package/dest/block/l2_block_source.js +1 -0
  21. package/dest/block/l2_block_stream/l2_tips_store_base.d.ts +1 -1
  22. package/dest/block/l2_block_stream/l2_tips_store_base.d.ts.map +1 -1
  23. package/dest/block/l2_block_stream/l2_tips_store_base.js +17 -4
  24. package/dest/block/test/l2_tips_store_test_suite.d.ts +1 -1
  25. package/dest/block/test/l2_tips_store_test_suite.d.ts.map +1 -1
  26. package/dest/block/test/l2_tips_store_test_suite.js +3 -2
  27. package/dest/checkpoint/checkpoint.d.ts +7 -1
  28. package/dest/checkpoint/checkpoint.d.ts.map +1 -1
  29. package/dest/checkpoint/checkpoint.js +9 -1
  30. package/dest/checkpoint/checkpoint_data.d.ts +71 -5
  31. package/dest/checkpoint/checkpoint_data.d.ts.map +1 -1
  32. package/dest/checkpoint/checkpoint_data.js +10 -0
  33. package/dest/config/sequencer-config.d.ts +2 -2
  34. package/dest/config/sequencer-config.d.ts.map +1 -1
  35. package/dest/config/sequencer-config.js +7 -0
  36. package/dest/epoch-helpers/index.d.ts +5 -1
  37. package/dest/epoch-helpers/index.d.ts.map +1 -1
  38. package/dest/epoch-helpers/index.js +6 -0
  39. package/dest/file-store/factory.d.ts +4 -3
  40. package/dest/file-store/factory.d.ts.map +1 -1
  41. package/dest/file-store/factory.js +2 -2
  42. package/dest/file-store/http.d.ts +9 -2
  43. package/dest/file-store/http.d.ts.map +1 -1
  44. package/dest/file-store/http.js +20 -9
  45. package/dest/file-store/index.d.ts +2 -1
  46. package/dest/file-store/index.d.ts.map +1 -1
  47. package/dest/gas/fee_math.d.ts +49 -0
  48. package/dest/gas/fee_math.d.ts.map +1 -0
  49. package/dest/gas/fee_math.js +80 -0
  50. package/dest/gas/gas_fees.d.ts +1 -1
  51. package/dest/gas/gas_fees.d.ts.map +1 -1
  52. package/dest/gas/gas_fees.js +10 -1
  53. package/dest/gas/gas_settings.d.ts +40 -3
  54. package/dest/gas/gas_settings.d.ts.map +1 -1
  55. package/dest/gas/gas_settings.js +50 -6
  56. package/dest/gas/index.d.ts +2 -1
  57. package/dest/gas/index.d.ts.map +1 -1
  58. package/dest/gas/index.js +1 -0
  59. package/dest/hash/hash.d.ts +4 -1
  60. package/dest/hash/hash.d.ts.map +1 -1
  61. package/dest/hash/hash.js +5 -0
  62. package/dest/interfaces/archiver.d.ts +1 -1
  63. package/dest/interfaces/archiver.d.ts.map +1 -1
  64. package/dest/interfaces/archiver.js +3 -1
  65. package/dest/interfaces/aztec-node-admin.d.ts +4 -14
  66. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  67. package/dest/interfaces/aztec-node-admin.js +3 -3
  68. package/dest/interfaces/aztec-node-debug.d.ts +21 -0
  69. package/dest/interfaces/aztec-node-debug.d.ts.map +1 -0
  70. package/dest/interfaces/aztec-node-debug.js +18 -0
  71. package/dest/interfaces/aztec-node.d.ts +10 -1
  72. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  73. package/dest/interfaces/aztec-node.js +2 -0
  74. package/dest/interfaces/client.d.ts +2 -1
  75. package/dest/interfaces/client.d.ts.map +1 -1
  76. package/dest/interfaces/client.js +1 -0
  77. package/dest/interfaces/slasher.d.ts +1 -10
  78. package/dest/interfaces/slasher.d.ts.map +1 -1
  79. package/dest/interfaces/slasher.js +0 -2
  80. package/dest/interfaces/validator.d.ts +4 -15
  81. package/dest/interfaces/validator.d.ts.map +1 -1
  82. package/dest/interfaces/validator.js +0 -1
  83. package/dest/l1-contracts/index.d.ts +2 -2
  84. package/dest/l1-contracts/index.d.ts.map +1 -1
  85. package/dest/l1-contracts/index.js +1 -1
  86. package/dest/logs/extended_directional_app_tagging_secret.d.ts +4 -4
  87. package/dest/logs/extended_directional_app_tagging_secret.d.ts.map +1 -1
  88. package/dest/logs/extended_directional_app_tagging_secret.js +12 -5
  89. package/dest/logs/message_context.d.ts +4 -7
  90. package/dest/logs/message_context.d.ts.map +1 -1
  91. package/dest/logs/message_context.js +23 -9
  92. package/dest/logs/pending_tagged_log.d.ts +2 -3
  93. package/dest/logs/pending_tagged_log.d.ts.map +1 -1
  94. package/dest/logs/pending_tagged_log.js +2 -2
  95. package/dest/logs/shared_secret_derivation.d.ts +11 -10
  96. package/dest/logs/shared_secret_derivation.d.ts.map +1 -1
  97. package/dest/logs/shared_secret_derivation.js +15 -9
  98. package/dest/logs/siloed_tag.d.ts +4 -1
  99. package/dest/logs/siloed_tag.d.ts.map +1 -1
  100. package/dest/logs/siloed_tag.js +7 -3
  101. package/dest/messaging/l1_to_l2_message.d.ts +3 -2
  102. package/dest/messaging/l1_to_l2_message.d.ts.map +1 -1
  103. package/dest/messaging/l1_to_l2_message.js +11 -13
  104. package/dest/note/note_dao.d.ts +1 -1
  105. package/dest/note/note_dao.d.ts.map +1 -1
  106. package/dest/note/note_dao.js +1 -4
  107. package/dest/p2p/checkpoint_proposal.d.ts +2 -2
  108. package/dest/p2p/checkpoint_proposal.d.ts.map +1 -1
  109. package/dest/p2p/checkpoint_proposal.js +3 -15
  110. package/dest/proofs/chonk_proof.d.ts +46 -2
  111. package/dest/proofs/chonk_proof.d.ts.map +1 -1
  112. package/dest/proofs/chonk_proof.js +85 -10
  113. package/dest/slashing/index.d.ts +2 -3
  114. package/dest/slashing/index.d.ts.map +1 -1
  115. package/dest/slashing/index.js +1 -2
  116. package/dest/slashing/serialization.d.ts +2 -6
  117. package/dest/slashing/serialization.d.ts.map +1 -1
  118. package/dest/slashing/serialization.js +0 -60
  119. package/dest/slashing/types.d.ts +4 -90
  120. package/dest/slashing/types.d.ts.map +1 -1
  121. package/dest/slashing/types.js +0 -14
  122. package/dest/slashing/{tally.d.ts → votes.d.ts} +1 -1
  123. package/dest/slashing/{tally.d.ts.map → votes.d.ts.map} +1 -1
  124. package/dest/slashing/{tally.js → votes.js} +1 -1
  125. package/dest/tests/factories.d.ts +1 -1
  126. package/dest/tests/factories.d.ts.map +1 -1
  127. package/dest/tests/factories.js +11 -1
  128. package/dest/tests/mocks.d.ts +1 -1
  129. package/dest/tests/mocks.d.ts.map +1 -1
  130. package/dest/tests/mocks.js +13 -18
  131. package/dest/timetable/index.d.ts +51 -1
  132. package/dest/timetable/index.d.ts.map +1 -1
  133. package/dest/timetable/index.js +204 -14
  134. package/dest/tx/capsule.d.ts +6 -2
  135. package/dest/tx/capsule.d.ts.map +1 -1
  136. package/dest/tx/capsule.js +9 -3
  137. package/dest/tx/fee_provider.d.ts +10 -0
  138. package/dest/tx/fee_provider.d.ts.map +1 -0
  139. package/dest/tx/fee_provider.js +1 -0
  140. package/dest/tx/global_variable_builder.d.ts +3 -4
  141. package/dest/tx/global_variable_builder.d.ts.map +1 -1
  142. package/dest/tx/index.d.ts +2 -1
  143. package/dest/tx/index.d.ts.map +1 -1
  144. package/dest/tx/index.js +1 -0
  145. package/dest/tx/simulated_tx.d.ts +4 -4
  146. package/dest/tx/simulated_tx.d.ts.map +1 -1
  147. package/dest/tx/simulated_tx.js +3 -3
  148. package/dest/tx/tx_receipt.d.ts +8 -4
  149. package/dest/tx/tx_receipt.d.ts.map +1 -1
  150. package/dest/tx/tx_receipt.js +8 -15
  151. package/dest/world-state/genesis_data.d.ts +11 -0
  152. package/dest/world-state/genesis_data.d.ts.map +1 -0
  153. package/dest/world-state/genesis_data.js +4 -0
  154. package/dest/world-state/index.d.ts +2 -1
  155. package/dest/world-state/index.d.ts.map +1 -1
  156. package/dest/world-state/index.js +1 -0
  157. package/package.json +8 -8
  158. package/src/abi/decoder.ts +23 -78
  159. package/src/abi/function_selector.ts +1 -1
  160. package/src/abi/function_signature_decoder.ts +77 -0
  161. package/src/abi/index.ts +1 -0
  162. package/src/abi/selector.ts +1 -1
  163. package/src/avm/revert_code.ts +25 -39
  164. package/src/block/l2_block_source.ts +10 -2
  165. package/src/block/l2_block_stream/l2_tips_store_base.ts +24 -12
  166. package/src/block/test/l2_tips_store_test_suite.ts +8 -1
  167. package/src/checkpoint/checkpoint.ts +11 -1
  168. package/src/checkpoint/checkpoint_data.ts +40 -4
  169. package/src/config/sequencer-config.ts +11 -1
  170. package/src/epoch-helpers/index.ts +13 -0
  171. package/src/file-store/factory.ts +13 -4
  172. package/src/file-store/http.ts +29 -10
  173. package/src/file-store/index.ts +1 -0
  174. package/src/gas/README.md +31 -0
  175. package/src/gas/fee_math.ts +120 -0
  176. package/src/gas/gas_fees.ts +12 -4
  177. package/src/gas/gas_settings.ts +65 -12
  178. package/src/gas/index.ts +1 -0
  179. package/src/hash/hash.ts +5 -0
  180. package/src/interfaces/archiver.ts +3 -1
  181. package/src/interfaces/aztec-node-admin.ts +5 -7
  182. package/src/interfaces/aztec-node-debug.ts +40 -0
  183. package/src/interfaces/aztec-node.ts +15 -0
  184. package/src/interfaces/client.ts +1 -0
  185. package/src/interfaces/slasher.ts +0 -6
  186. package/src/interfaces/validator.ts +2 -9
  187. package/src/l1-contracts/index.ts +1 -1
  188. package/src/logs/extended_directional_app_tagging_secret.ts +19 -8
  189. package/src/logs/message_context.ts +17 -7
  190. package/src/logs/pending_tagged_log.ts +1 -3
  191. package/src/logs/shared_secret_derivation.ts +21 -10
  192. package/src/logs/siloed_tag.ts +7 -2
  193. package/src/messaging/l1_to_l2_message.ts +12 -9
  194. package/src/note/note_dao.ts +1 -4
  195. package/src/p2p/checkpoint_proposal.ts +10 -26
  196. package/src/proofs/chonk_proof.ts +91 -5
  197. package/src/slashing/index.ts +1 -2
  198. package/src/slashing/serialization.ts +1 -81
  199. package/src/slashing/types.ts +3 -35
  200. package/src/slashing/{tally.ts → votes.ts} +1 -1
  201. package/src/tests/factories.ts +5 -1
  202. package/src/tests/mocks.ts +14 -12
  203. package/src/timetable/index.ts +293 -13
  204. package/src/tx/capsule.ts +10 -2
  205. package/src/tx/fee_provider.ts +10 -0
  206. package/src/tx/global_variable_builder.ts +2 -3
  207. package/src/tx/index.ts +1 -0
  208. package/src/tx/simulated_tx.ts +6 -2
  209. package/src/tx/tx_receipt.ts +11 -14
  210. package/src/world-state/genesis_data.ts +15 -0
  211. package/src/world-state/index.ts +1 -0
  212. package/dest/l1-contracts/slash_factory.d.ts +0 -45
  213. package/dest/l1-contracts/slash_factory.d.ts.map +0 -1
  214. package/dest/l1-contracts/slash_factory.js +0 -158
  215. package/dest/slashing/empire.d.ts +0 -31
  216. package/dest/slashing/empire.d.ts.map +0 -1
  217. package/dest/slashing/empire.js +0 -87
  218. package/src/l1-contracts/slash_factory.ts +0 -180
  219. package/src/slashing/empire.ts +0 -104
@@ -161,7 +161,7 @@ export class CheckpointProposal extends Gossipable {
161
161
  checkpointHeader: CheckpointHeader,
162
162
  archiveRoot: Fr,
163
163
  feeAssetPriceModifier: bigint,
164
- lastBlockInfo: CheckpointLastBlockData | undefined,
164
+ lastBlockProposal: BlockProposal | undefined,
165
165
  payloadSigner: (payload: Buffer32, context: SigningContext) => Promise<Signature>,
166
166
  ): Promise<CheckpointProposal> {
167
167
  // Sign the checkpoint payload with CHECKPOINT_PROPOSAL duty type
@@ -175,35 +175,19 @@ export class CheckpointProposal extends Gossipable {
175
175
 
176
176
  const checkpointContext: SigningContext = {
177
177
  slot: checkpointHeader.slotNumber,
178
- blockNumber: lastBlockInfo?.blockHeader?.globalVariables.blockNumber ?? BlockNumber(0),
178
+ blockNumber: lastBlockProposal?.blockNumber ?? BlockNumber(0),
179
179
  dutyType: DutyType.CHECKPOINT_PROPOSAL,
180
180
  };
181
181
 
182
- if (lastBlockInfo) {
183
- // Sign block proposal before signing checkpoint proposal to ensure HA protection
184
- const lastBlockProposal = await BlockProposal.createProposalFromSigner(
185
- lastBlockInfo.blockHeader,
186
- lastBlockInfo.indexWithinCheckpoint,
187
- checkpointHeader.inHash,
188
- archiveRoot,
189
- lastBlockInfo.txHashes,
190
- lastBlockInfo.txs,
191
- payloadSigner,
192
- );
193
-
194
- const checkpointSignature = await payloadSigner(checkpointHash, checkpointContext);
195
-
196
- return new CheckpointProposal(checkpointHeader, archiveRoot, feeAssetPriceModifier, checkpointSignature, {
197
- blockHeader: lastBlockInfo.blockHeader,
198
- indexWithinCheckpoint: lastBlockInfo.indexWithinCheckpoint,
199
- txHashes: lastBlockInfo.txHashes,
200
- signature: lastBlockProposal.signature,
201
- signedTxs: lastBlockProposal.signedTxs,
202
- });
203
- }
204
-
205
182
  const checkpointSignature = await payloadSigner(checkpointHash, checkpointContext);
206
- return new CheckpointProposal(checkpointHeader, archiveRoot, feeAssetPriceModifier, checkpointSignature);
183
+
184
+ return new CheckpointProposal(
185
+ checkpointHeader,
186
+ archiveRoot,
187
+ feeAssetPriceModifier,
188
+ checkpointSignature,
189
+ lastBlockProposal,
190
+ );
207
191
  }
208
192
 
209
193
  /**
@@ -1,21 +1,41 @@
1
+ import { BarretenbergSync, flattenChonkProofFields } from '@aztec/bb.js';
1
2
  import { CHONK_PROOF_LENGTH } from '@aztec/constants';
2
3
  import { times } from '@aztec/foundation/collection';
3
4
  import { randomBytes } from '@aztec/foundation/crypto/random';
4
5
  import { Fr } from '@aztec/foundation/curves/bn254';
5
6
  import { bufferSchemaFor } from '@aztec/foundation/schemas';
6
- import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
7
+ import { BufferReader, numToUInt32BE, serializeToBuffer } from '@aztec/foundation/serialize';
8
+
9
+ /**
10
+ * Serialization format detection for ChonkProof is size-based:
11
+ * - UNCOMPRESSED (legacy): [field_count=1632: uint32] [fields...] → total ≈ 52KB (>= 40KB)
12
+ * - COMPRESSED: [byte_count: uint32] [compressed_bytes] → total ≈ 35KB (< 40KB)
13
+ *
14
+ * Detection: if the first uint32 equals CHONK_PROOF_LENGTH (1632), it's legacy format
15
+ * (field count). Otherwise, it's compressed format (byte count). The old uncompressed
16
+ * format is never smaller than 40KB; compressed proofs are always smaller than 40KB.
17
+ */
7
18
 
8
19
  // CHONK: "Client Honk" - An UltraHonk variant with incremental folding and delayed non-native arithmetic.
9
20
  export class ChonkProof {
21
+ /**
22
+ * Optional compressed proof bytes from chonk compression (point compression + u256 encoding).
23
+ * When set, toBuffer() will serialize in compressed format (~1.7x smaller).
24
+ * When reading from compressed format, this is populated and fields are decompressed on demand.
25
+ */
26
+ public compressedProof?: Buffer;
27
+
10
28
  constructor(
11
29
  // The proof fields.
12
30
  // For native verification, attach public inputs via `attachPublicInputs(publicInputs)`.
13
31
  // Not using Tuple here due to the length being too high.
14
32
  public fields: Fr[],
33
+ compressedProof?: Buffer,
15
34
  ) {
16
35
  if (fields.length !== CHONK_PROOF_LENGTH) {
17
36
  throw new Error(`Invalid ChonkProof length: ${fields.length}`);
18
37
  }
38
+ this.compressedProof = compressedProof;
19
39
  }
20
40
 
21
41
  public attachPublicInputs(publicInputs: Fr[]) {
@@ -53,19 +73,84 @@ export class ChonkProof {
53
73
  return this.toBuffer();
54
74
  }
55
75
 
76
+ /**
77
+ * Deserialize a ChonkProof from a buffer.
78
+ * Supports both legacy (field elements) and compressed (chonk compression) formats.
79
+ *
80
+ * Size-based format detection:
81
+ * - First uint32 == CHONK_PROOF_LENGTH (1632): legacy format, read field elements
82
+ * Total proof data ≈ 52KB (always >= 40KB)
83
+ * - Otherwise: compressed format, first uint32 is byte count of compressed data
84
+ * Total proof data ≈ 35KB (always < 40KB)
85
+ */
56
86
  static fromBuffer(buffer: Buffer | BufferReader): ChonkProof {
57
87
  const reader = BufferReader.asReader(buffer);
58
- const proofLength = reader.readNumber();
59
- const proof = reader.readArray(proofLength, Fr);
60
- return new ChonkProof(proof);
88
+ const firstUint32 = reader.readNumber();
89
+
90
+ if (firstUint32 === CHONK_PROOF_LENGTH) {
91
+ // Legacy format: firstUint32 is the field count (1632)
92
+ // Widen to `number` to prevent TS from narrowing to literal 1632,
93
+ // which would cause Tuple<Fr, 1632> to exceed the recursion limit.
94
+ const fieldCount: number = firstUint32;
95
+ const proof = reader.readArray(fieldCount, Fr);
96
+ return new ChonkProof(proof);
97
+ }
98
+
99
+ // Compressed format: firstUint32 is the compressed byte count
100
+ const compressedBytes = reader.readBytes(firstUint32);
101
+ return ChonkProof.fromCompressedBytes(Buffer.from(compressedBytes));
102
+ }
103
+
104
+ /**
105
+ * Create a ChonkProof from compressed bytes by decompressing via the BarretenbergSync API.
106
+ * The compressed format uses point compression and u256 encoding (from PR #20645).
107
+ *
108
+ * @param compressed - Compressed proof bytes from chonk compression
109
+ * @returns ChonkProof with both fields and compressed bytes populated
110
+ */
111
+ static fromCompressedBytes(compressed: Buffer): ChonkProof {
112
+ const api = BarretenbergSync.getSingleton();
113
+ const result = api.chonkDecompressProof({ compressedProof: new Uint8Array(compressed) });
114
+
115
+ // Flatten the structured bb.js ChonkProof into flat Fr[] field elements
116
+ const flatFields = flattenChonkProofFields(result.proof);
117
+ const fields = flatFields.map(f => Fr.fromBuffer(Buffer.from(f)));
118
+
119
+ // The decompressed proof includes public inputs in hidingOinkProof.
120
+ // Since ChonkProof stores fields WITHOUT public inputs, strip them.
121
+ // The number of public inputs = total fields - CHONK_PROOF_LENGTH
122
+ if (fields.length > CHONK_PROOF_LENGTH) {
123
+ const numPubInputs = fields.length - CHONK_PROOF_LENGTH;
124
+ const proofFields = fields.slice(numPubInputs);
125
+ return new ChonkProof(proofFields, compressed);
126
+ }
127
+
128
+ return new ChonkProof(fields, compressed);
61
129
  }
62
130
 
131
+ /**
132
+ * Serialize the proof to a buffer.
133
+ * If compressed bytes are available, uses the compressed format (~1.7x smaller).
134
+ * Otherwise falls back to legacy field element format.
135
+ */
63
136
  public toBuffer() {
137
+ if (this.compressedProof) {
138
+ // Compressed format: [compressed_byte_count: uint32] [compressed_bytes]
139
+ return Buffer.concat([numToUInt32BE(this.compressedProof.length), this.compressedProof]);
140
+ }
141
+ // Legacy format: [field_count=1632: uint32] [fields...]
64
142
  return serializeToBuffer(this.fields.length, this.fields);
65
143
  }
66
144
  }
67
145
 
68
146
  export class ChonkProofWithPublicInputs {
147
+ /**
148
+ * Optional compressed proof bytes (covers the full proof WITH public inputs).
149
+ * Set by the prover when using chonk compression. Flows through to ChonkProof
150
+ * via removePublicInputs() so the Tx can serialize in compressed format.
151
+ */
152
+ public compressedProof?: Buffer;
153
+
69
154
  constructor(
70
155
  // The proof fields with public inputs.
71
156
  // For recursive verification, use without public inputs via `removePublicInputs()`.
@@ -83,7 +168,8 @@ export class ChonkProofWithPublicInputs {
83
168
 
84
169
  public removePublicInputs() {
85
170
  const numPublicInputs = this.fieldsWithPublicInputs.length - CHONK_PROOF_LENGTH;
86
- return new ChonkProof(this.fieldsWithPublicInputs.slice(numPublicInputs));
171
+ // Flow compressed proof bytes through so the ChonkProof can serialize efficiently
172
+ return new ChonkProof(this.fieldsWithPublicInputs.slice(numPublicInputs), this.compressedProof);
87
173
  }
88
174
 
89
175
  public isEmpty() {
@@ -1,6 +1,5 @@
1
1
  export * from './types.js';
2
2
  export * from './interfaces.js';
3
3
  export * from './helpers.js';
4
- export * from './empire.js';
5
- export * from './tally.js';
4
+ export * from './votes.js';
6
5
  export * from './serialization.js';
@@ -1,15 +1,7 @@
1
- import { times } from '@aztec/foundation/collection';
2
1
  import { EthAddress } from '@aztec/foundation/eth-address';
3
2
  import { BufferReader, bigintToUInt64BE, bigintToUInt128BE, serializeToBuffer } from '@aztec/foundation/serialize';
4
3
 
5
- import type {
6
- Offense,
7
- OffenseType,
8
- SlashPayload,
9
- SlashPayloadRound,
10
- ValidatorSlash,
11
- ValidatorSlashOffense,
12
- } from './types.js';
4
+ import type { Offense, OffenseType } from './types.js';
13
5
 
14
6
  export function serializeOffense(offense: Offense): Buffer {
15
7
  return serializeToBuffer(
@@ -29,75 +21,3 @@ export function deserializeOffense(buffer: Buffer): Offense {
29
21
 
30
22
  return { validator, amount, offenseType: offense, epochOrSlot };
31
23
  }
32
-
33
- function serializeValidatorSlashOffense(offense: ValidatorSlashOffense): Buffer {
34
- return serializeToBuffer(bigintToUInt64BE(offense.epochOrSlot), offense.offenseType);
35
- }
36
-
37
- function deserializeValidatorSlashOffense(buffer: Buffer | BufferReader): ValidatorSlashOffense {
38
- const reader = BufferReader.asReader(buffer);
39
- return {
40
- epochOrSlot: reader.readUInt64(),
41
- offenseType: reader.readNumber() as OffenseType,
42
- };
43
- }
44
-
45
- function serializeValidatorSlash(slash: ValidatorSlash): Buffer {
46
- return serializeToBuffer(
47
- slash.validator,
48
- bigintToUInt128BE(slash.amount),
49
- slash.offenses.length,
50
- slash.offenses.map(serializeValidatorSlashOffense),
51
- );
52
- }
53
-
54
- function deserializeValidatorSlash(buffer: Buffer | BufferReader): ValidatorSlash {
55
- const reader = BufferReader.asReader(buffer);
56
- const validator = reader.readObject(EthAddress);
57
- const amount = reader.readUInt128();
58
- const offensesCount = reader.readNumber();
59
- const offenses = times(offensesCount, () => deserializeValidatorSlashOffense(reader));
60
-
61
- return { validator, amount, offenses };
62
- }
63
-
64
- export function serializeSlashPayload(payload: SlashPayload): Buffer {
65
- return serializeToBuffer(
66
- payload.address,
67
- payload.slashes.length,
68
- payload.slashes.map(serializeValidatorSlash),
69
- bigintToUInt64BE(payload.timestamp),
70
- );
71
- }
72
-
73
- export function deserializeSlashPayload(buffer: Buffer): SlashPayload {
74
- const reader = BufferReader.asReader(buffer);
75
- const address = reader.readObject(EthAddress);
76
- const slashesCount = reader.readNumber();
77
- const slashes = times(slashesCount, () => deserializeValidatorSlash(reader));
78
- const timestamp = reader.readUInt64();
79
- return { address, slashes, timestamp };
80
- }
81
-
82
- export function serializeSlashPayloadRound(payload: SlashPayloadRound): Buffer {
83
- return serializeToBuffer(
84
- payload.address,
85
- payload.slashes.length,
86
- payload.slashes.map(serializeValidatorSlash),
87
- bigintToUInt64BE(payload.timestamp),
88
- Number(payload.votes),
89
- bigintToUInt64BE(payload.round),
90
- );
91
- }
92
-
93
- export function deserializeSlashPayloadRound(buffer: Buffer): SlashPayloadRound {
94
- const reader = BufferReader.asReader(buffer);
95
- const address = reader.readObject(EthAddress);
96
- const slashesCount = reader.readNumber();
97
- const slashes = times(slashesCount, () => deserializeValidatorSlash(reader));
98
- const timestamp = reader.readUInt64();
99
- const votes = BigInt(reader.readNumber());
100
- const round = reader.readUInt64();
101
-
102
- return { address, slashes, timestamp, votes, round };
103
- }
@@ -126,45 +126,13 @@ export type ValidatorSlash = {
126
126
  offenses: ValidatorSlashOffense[];
127
127
  };
128
128
 
129
- /** Slash payload as published by the empire slash proposer */
130
- export type SlashPayload = {
131
- address: EthAddress;
132
- slashes: ValidatorSlash[];
133
- timestamp: bigint;
134
- };
135
-
136
- /** Slash payload with round information from empire slash proposer */
137
- export type SlashPayloadRound = SlashPayload & { votes: bigint; round: bigint };
138
-
139
- export const SlashPayloadRoundSchema = zodFor<SlashPayloadRound>()(
140
- z.object({
141
- address: schemas.EthAddress,
142
- timestamp: schemas.BigInt,
143
- votes: schemas.BigInt,
144
- round: schemas.BigInt,
145
- slashes: z.array(
146
- z.object({
147
- validator: schemas.EthAddress,
148
- amount: schemas.BigInt,
149
- offenses: z.array(z.object({ offenseType: OffenseTypeSchema, epochOrSlot: schemas.BigInt })),
150
- }),
151
- ),
152
- }),
153
- );
154
-
155
- /** Votes for a validator slash in the consensus slash proposer */
129
+ /** Votes for a validator slash in the slashing proposer */
156
130
  export type ValidatorSlashVote = number;
157
131
 
158
132
  export type ProposerSlashAction =
159
- /** Create a new slash payload on an empire-based slash proposer */
160
- | { type: 'create-empire-payload'; data: ValidatorSlash[] }
161
- /** Vote for a slashing payload on an empire-based slash proposer */
162
- | { type: 'vote-empire-payload'; payload: EthAddress }
163
- /** Execute a slashing payload on an empire-based slash proposer */
164
- | { type: 'execute-empire-payload'; round: bigint }
165
- /** Vote for offenses on a consensus slashing proposer */
133
+ /** Vote for offenses on the slashing proposer */
166
134
  | { type: 'vote-offenses'; votes: ValidatorSlashVote[]; committees: EthAddress[][]; round: bigint }
167
- /** Execute a slashing round on a consensus slashing proposer */
135
+ /** Execute a slashing round on the slashing proposer */
168
136
  | { type: 'execute-slash'; committees: EthAddress[][]; round: bigint };
169
137
 
170
138
  export type ProposerSlashActionType = ProposerSlashAction['type'];
@@ -28,7 +28,7 @@ export function getSlashConsensusVotesFromOffenses(
28
28
  targetCommitteeSize: number;
29
29
  maxSlashedValidators?: number;
30
30
  },
31
- logger: Logger = createLogger('slasher:tally'),
31
+ logger: Logger = createLogger('slasher:votes'),
32
32
  ): ValidatorSlashVote[] {
33
33
  const { slashingAmounts, targetCommitteeSize, maxSlashedValidators } = settings;
34
34
 
@@ -232,7 +232,7 @@ export function makeTxContext(seed: number = 1): TxContext {
232
232
  * Creates a default instance of gas settings. No seed value is used to ensure we allocate a sensible amount of gas for testing.
233
233
  */
234
234
  export function makeGasSettings() {
235
- return GasSettings.default({ maxFeesPerGas: new GasFees(10, 10) });
235
+ return GasSettings.fallback({ maxFeesPerGas: new GasFees(10, 10) });
236
236
  }
237
237
 
238
238
  /**
@@ -1715,6 +1715,10 @@ export function makeL2Tips(
1715
1715
  block: { number: bn, hash },
1716
1716
  checkpoint: { number: cpn, hash: cph },
1717
1717
  },
1718
+ proposedCheckpoint: {
1719
+ block: { number: bn, hash },
1720
+ checkpoint: { number: cpn, hash: cph },
1721
+ },
1718
1722
  proven: {
1719
1723
  block: { number: bn, hash },
1720
1724
  checkpoint: { number: cpn, hash: cph },
@@ -134,7 +134,7 @@ export const mockTx = async (
134
134
  const data = PrivateKernelTailCircuitPublicInputs.empty();
135
135
  const firstNullifier = new Nullifier(new Fr(seed + 1), Fr.ZERO, 0);
136
136
  data.constants.anchorBlockHeader = anchorBlockHeader;
137
- data.constants.txContext.gasSettings = GasSettings.default({ gasLimits, maxFeesPerGas, maxPriorityFeesPerGas });
137
+ data.constants.txContext.gasSettings = GasSettings.fallback({ gasLimits, maxFeesPerGas, maxPriorityFeesPerGas });
138
138
  data.feePayer = feePayer ?? (await AztecAddress.random());
139
139
  data.gasUsed = gasUsed;
140
140
  data.constants.txContext.chainId = chainId;
@@ -200,7 +200,7 @@ export async function mockProcessedTx({
200
200
  db,
201
201
  chainId = Fr.ZERO,
202
202
  version = Fr.ZERO,
203
- gasSettings = GasSettings.default({ maxFeesPerGas: new GasFees(10, 10) }),
203
+ gasSettings = GasSettings.fallback({ maxFeesPerGas: new GasFees(10, 10) }),
204
204
  vkTreeRoot = Fr.ZERO,
205
205
  protocolContracts = makeProtocolContracts(seed + 0x100),
206
206
  globalVariables = GlobalVariables.empty(),
@@ -596,28 +596,30 @@ export const makeBlockProposal = (options?: MakeBlockProposalOptions): Promise<B
596
596
  );
597
597
  };
598
598
 
599
- export const makeCheckpointProposal = (options?: MakeCheckpointProposalOptions): Promise<CheckpointProposal> => {
600
- const blockHeader = options?.lastBlock?.blockHeader ?? makeBlockHeader(1);
599
+ export const makeCheckpointProposal = async (options?: MakeCheckpointProposalOptions): Promise<CheckpointProposal> => {
601
600
  const checkpointHeader = options?.checkpointHeader ?? makeCheckpointHeader(1);
602
601
  const archiveRoot = options?.archiveRoot ?? Fr.random();
603
602
  const feeAssetPriceModifier = options?.feeAssetPriceModifier ?? 0n;
604
603
  const signer = options?.signer ?? Secp256k1Signer.random();
605
604
 
606
- // Build lastBlock info if provided
607
- const lastBlockInfo = options?.lastBlock
608
- ? {
609
- blockHeader,
610
- indexWithinCheckpoint: options.lastBlock.indexWithinCheckpoint ?? IndexWithinCheckpoint(4), // Last block in a 5-block checkpoint
611
- txHashes: options.lastBlock.txHashes ?? [0, 1, 2, 3, 4, 5].map(() => TxHash.random()),
605
+ // Build a signed block proposal if lastBlock options are provided
606
+ const lastBlockProposal = options?.lastBlock
607
+ ? await makeBlockProposal({
608
+ blockHeader: options.lastBlock.blockHeader,
609
+ indexWithinCheckpoint: options.lastBlock.indexWithinCheckpoint ?? IndexWithinCheckpoint(4),
610
+ inHash: checkpointHeader.inHash,
611
+ archiveRoot,
612
+ txHashes: options.lastBlock.txHashes,
612
613
  txs: options.lastBlock.txs,
613
- }
614
+ signer,
615
+ })
614
616
  : undefined;
615
617
 
616
618
  return CheckpointProposal.createProposalFromSigner(
617
619
  checkpointHeader,
618
620
  archiveRoot,
619
621
  feeAssetPriceModifier,
620
- lastBlockInfo,
622
+ lastBlockProposal,
621
623
  payload => Promise.resolve(signer.signMessage(payload)),
622
624
  );
623
625
  };