@aztec/stdlib 0.0.1-commit.e588bc7e5 → 0.0.1-commit.e5a3663dd

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 (338) hide show
  1. package/dest/abi/authorization_selector.d.ts +3 -6
  2. package/dest/abi/authorization_selector.d.ts.map +1 -1
  3. package/dest/abi/encoder.d.ts +1 -1
  4. package/dest/abi/encoder.d.ts.map +1 -1
  5. package/dest/abi/encoder.js +32 -6
  6. package/dest/abi/event_selector.d.ts +3 -6
  7. package/dest/abi/event_selector.d.ts.map +1 -1
  8. package/dest/abi/function_selector.d.ts +3 -6
  9. package/dest/abi/function_selector.d.ts.map +1 -1
  10. package/dest/abi/function_selector.js +1 -3
  11. package/dest/abi/note_selector.d.ts +3 -6
  12. package/dest/abi/note_selector.d.ts.map +1 -1
  13. package/dest/abi/note_selector.js +1 -3
  14. package/dest/abi/selector.d.ts +2 -2
  15. package/dest/abi/selector.d.ts.map +1 -1
  16. package/dest/abi/selector.js +1 -1
  17. package/dest/avm/revert_code.d.ts +8 -18
  18. package/dest/avm/revert_code.d.ts.map +1 -1
  19. package/dest/avm/revert_code.js +15 -30
  20. package/dest/aztec-address/index.d.ts +3 -6
  21. package/dest/aztec-address/index.d.ts.map +1 -1
  22. package/dest/aztec-address/index.js +2 -4
  23. package/dest/block/attestation_info.d.ts +3 -2
  24. package/dest/block/attestation_info.d.ts.map +1 -1
  25. package/dest/block/attestation_info.js +7 -5
  26. package/dest/block/block_data.d.ts +297 -8
  27. package/dest/block/block_data.d.ts.map +1 -1
  28. package/dest/block/block_data.js +16 -2
  29. package/dest/block/block_hash.d.ts +11 -10
  30. package/dest/block/block_hash.d.ts.map +1 -1
  31. package/dest/block/block_hash.js +10 -9
  32. package/dest/block/block_parameter.d.ts +30 -3
  33. package/dest/block/block_parameter.d.ts.map +1 -1
  34. package/dest/block/block_parameter.js +36 -2
  35. package/dest/block/l2_block_info.d.ts +6 -5
  36. package/dest/block/l2_block_info.d.ts.map +1 -1
  37. package/dest/block/l2_block_info.js +6 -5
  38. package/dest/block/l2_block_source.d.ts +39 -4
  39. package/dest/block/l2_block_source.d.ts.map +1 -1
  40. package/dest/block/l2_block_stream/interfaces.d.ts +6 -3
  41. package/dest/block/l2_block_stream/interfaces.d.ts.map +1 -1
  42. package/dest/block/l2_block_stream/l2_tips_store_base.d.ts +1 -1
  43. package/dest/block/l2_block_stream/l2_tips_store_base.d.ts.map +1 -1
  44. package/dest/block/l2_block_stream/l2_tips_store_base.js +1 -1
  45. package/dest/block/proposal/attestations_and_signers.d.ts +13 -6
  46. package/dest/block/proposal/attestations_and_signers.d.ts.map +1 -1
  47. package/dest/block/proposal/attestations_and_signers.js +26 -18
  48. package/dest/block/test/l2_tips_store_test_suite.js +1 -1
  49. package/dest/checkpoint/checkpoint_data.d.ts +7 -1
  50. package/dest/checkpoint/checkpoint_data.d.ts.map +1 -1
  51. package/dest/checkpoint/checkpoint_data.js +2 -0
  52. package/dest/config/chain-config.d.ts +2 -2
  53. package/dest/config/chain-config.d.ts.map +1 -1
  54. package/dest/config/chain-config.js +9 -3
  55. package/dest/config/sequencer-config.d.ts +5 -3
  56. package/dest/config/sequencer-config.d.ts.map +1 -1
  57. package/dest/config/sequencer-config.js +18 -4
  58. package/dest/contract/contract_address.d.ts +1 -1
  59. package/dest/contract/contract_address.js +2 -2
  60. package/dest/contract/private_function.d.ts +1 -1
  61. package/dest/contract/private_function.d.ts.map +1 -1
  62. package/dest/contract/private_function.js +2 -4
  63. package/dest/gas/fee_math.d.ts +49 -0
  64. package/dest/gas/fee_math.d.ts.map +1 -0
  65. package/dest/gas/fee_math.js +80 -0
  66. package/dest/gas/gas_fees.d.ts +5 -1
  67. package/dest/gas/gas_fees.d.ts.map +1 -1
  68. package/dest/gas/gas_fees.js +10 -1
  69. package/dest/gas/gas_settings.d.ts +40 -3
  70. package/dest/gas/gas_settings.d.ts.map +1 -1
  71. package/dest/gas/gas_settings.js +50 -6
  72. package/dest/gas/index.d.ts +2 -1
  73. package/dest/gas/index.d.ts.map +1 -1
  74. package/dest/gas/index.js +1 -0
  75. package/dest/ha-signing/config.d.ts +6 -6
  76. package/dest/ha-signing/config.d.ts.map +1 -1
  77. package/dest/ha-signing/config.js +4 -3
  78. package/dest/ha-signing/index.d.ts +2 -2
  79. package/dest/ha-signing/index.d.ts.map +1 -1
  80. package/dest/ha-signing/index.js +1 -1
  81. package/dest/ha-signing/local_config.d.ts +1 -1
  82. package/dest/ha-signing/local_config.d.ts.map +1 -1
  83. package/dest/ha-signing/local_config.js +2 -2
  84. package/dest/ha-signing/types.d.ts +37 -32
  85. package/dest/ha-signing/types.d.ts.map +1 -1
  86. package/dest/ha-signing/types.js +13 -6
  87. package/dest/hash/hash.d.ts +16 -1
  88. package/dest/hash/hash.d.ts.map +1 -1
  89. package/dest/hash/hash.js +32 -0
  90. package/dest/interfaces/archiver.d.ts +11 -1
  91. package/dest/interfaces/archiver.d.ts.map +1 -1
  92. package/dest/interfaces/archiver.js +10 -4
  93. package/dest/interfaces/aztec-node-admin.d.ts +22 -14
  94. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  95. package/dest/interfaces/aztec-node-admin.js +5 -4
  96. package/dest/interfaces/aztec-node-debug.d.ts +21 -0
  97. package/dest/interfaces/aztec-node-debug.d.ts.map +1 -0
  98. package/dest/interfaces/aztec-node-debug.js +18 -0
  99. package/dest/interfaces/aztec-node.d.ts +54 -55
  100. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  101. package/dest/interfaces/aztec-node.js +20 -16
  102. package/dest/interfaces/block_response.d.ts +156 -0
  103. package/dest/interfaces/block_response.d.ts.map +1 -0
  104. package/dest/interfaces/block_response.js +24 -0
  105. package/dest/interfaces/chain_tips.d.ts +304 -0
  106. package/dest/interfaces/chain_tips.d.ts.map +1 -0
  107. package/dest/interfaces/chain_tips.js +11 -0
  108. package/dest/interfaces/checkpoint_parameter.d.ts +27 -0
  109. package/dest/interfaces/checkpoint_parameter.d.ts.map +1 -0
  110. package/dest/interfaces/checkpoint_parameter.js +20 -0
  111. package/dest/interfaces/checkpoint_response.d.ts +312 -0
  112. package/dest/interfaces/checkpoint_response.d.ts.map +1 -0
  113. package/dest/interfaces/checkpoint_response.js +26 -0
  114. package/dest/interfaces/client.d.ts +7 -1
  115. package/dest/interfaces/client.d.ts.map +1 -1
  116. package/dest/interfaces/client.js +6 -0
  117. package/dest/interfaces/configs.d.ts +12 -2
  118. package/dest/interfaces/configs.d.ts.map +1 -1
  119. package/dest/interfaces/configs.js +3 -1
  120. package/dest/interfaces/l1_publish_info.d.ts +43 -0
  121. package/dest/interfaces/l1_publish_info.d.ts.map +1 -0
  122. package/dest/interfaces/l1_publish_info.js +26 -0
  123. package/dest/interfaces/merkle_tree_operations.d.ts +4 -3
  124. package/dest/interfaces/merkle_tree_operations.d.ts.map +1 -1
  125. package/dest/interfaces/prover-client.d.ts +1 -1
  126. package/dest/interfaces/prover-client.d.ts.map +1 -1
  127. package/dest/interfaces/prover-client.js +0 -3
  128. package/dest/interfaces/proving-job.d.ts +166 -166
  129. package/dest/interfaces/server.d.ts +6 -1
  130. package/dest/interfaces/server.d.ts.map +1 -1
  131. package/dest/interfaces/server.js +5 -0
  132. package/dest/interfaces/slasher.d.ts +1 -10
  133. package/dest/interfaces/slasher.d.ts.map +1 -1
  134. package/dest/interfaces/slasher.js +0 -2
  135. package/dest/interfaces/validator.d.ts +27 -18
  136. package/dest/interfaces/validator.d.ts.map +1 -1
  137. package/dest/interfaces/validator.js +2 -0
  138. package/dest/l1-contracts/index.d.ts +2 -2
  139. package/dest/l1-contracts/index.d.ts.map +1 -1
  140. package/dest/l1-contracts/index.js +1 -1
  141. package/dest/logs/log_id.d.ts +1 -1
  142. package/dest/logs/log_id.d.ts.map +1 -1
  143. package/dest/logs/log_id.js +1 -2
  144. package/dest/logs/siloed_tag.d.ts +5 -7
  145. package/dest/logs/siloed_tag.d.ts.map +1 -1
  146. package/dest/logs/siloed_tag.js +4 -0
  147. package/dest/logs/tag.d.ts +5 -6
  148. package/dest/logs/tag.d.ts.map +1 -1
  149. package/dest/logs/tag.js +4 -0
  150. package/dest/p2p/block_proposal.d.ts +22 -14
  151. package/dest/p2p/block_proposal.d.ts.map +1 -1
  152. package/dest/p2p/block_proposal.js +45 -40
  153. package/dest/p2p/checkpoint_attestation.d.ts +10 -8
  154. package/dest/p2p/checkpoint_attestation.d.ts.map +1 -1
  155. package/dest/p2p/checkpoint_attestation.js +17 -24
  156. package/dest/p2p/checkpoint_proposal.d.ts +20 -14
  157. package/dest/p2p/checkpoint_proposal.d.ts.map +1 -1
  158. package/dest/p2p/checkpoint_proposal.js +34 -51
  159. package/dest/p2p/consensus_payload.d.ts +18 -7
  160. package/dest/p2p/consensus_payload.d.ts.map +1 -1
  161. package/dest/p2p/consensus_payload.js +31 -19
  162. package/dest/p2p/gossipable.d.ts +4 -4
  163. package/dest/p2p/gossipable.d.ts.map +1 -1
  164. package/dest/p2p/signature_utils.d.ts +28 -19
  165. package/dest/p2p/signature_utils.d.ts.map +1 -1
  166. package/dest/p2p/signature_utils.js +118 -21
  167. package/dest/p2p/signed_txs.d.ts +15 -13
  168. package/dest/p2p/signed_txs.d.ts.map +1 -1
  169. package/dest/p2p/signed_txs.js +26 -24
  170. package/dest/parity/parity_base_private_inputs.d.ts +7 -3
  171. package/dest/parity/parity_base_private_inputs.d.ts.map +1 -1
  172. package/dest/parity/parity_base_private_inputs.js +7 -5
  173. package/dest/parity/parity_public_inputs.d.ts +7 -3
  174. package/dest/parity/parity_public_inputs.d.ts.map +1 -1
  175. package/dest/parity/parity_public_inputs.js +6 -3
  176. package/dest/rollup/block_headers_hash.d.ts +1 -1
  177. package/dest/rollup/block_headers_hash.d.ts.map +1 -1
  178. package/dest/rollup/block_headers_hash.js +8 -2
  179. package/dest/slashing/index.d.ts +2 -3
  180. package/dest/slashing/index.d.ts.map +1 -1
  181. package/dest/slashing/index.js +1 -2
  182. package/dest/slashing/serialization.d.ts +2 -6
  183. package/dest/slashing/serialization.d.ts.map +1 -1
  184. package/dest/slashing/serialization.js +0 -60
  185. package/dest/slashing/types.d.ts +4 -90
  186. package/dest/slashing/types.d.ts.map +1 -1
  187. package/dest/slashing/types.js +0 -14
  188. package/dest/slashing/{tally.d.ts → votes.d.ts} +1 -1
  189. package/dest/slashing/{tally.d.ts.map → votes.d.ts.map} +1 -1
  190. package/dest/slashing/{tally.js → votes.js} +1 -1
  191. package/dest/tests/factories.d.ts +2 -7
  192. package/dest/tests/factories.d.ts.map +1 -1
  193. package/dest/tests/factories.js +9 -19
  194. package/dest/tests/mocks.d.ts +7 -1
  195. package/dest/tests/mocks.d.ts.map +1 -1
  196. package/dest/tests/mocks.js +39 -30
  197. package/dest/timetable/index.d.ts +51 -1
  198. package/dest/timetable/index.d.ts.map +1 -1
  199. package/dest/timetable/index.js +218 -14
  200. package/dest/trees/nullifier_leaf.d.ts +2 -1
  201. package/dest/trees/nullifier_leaf.d.ts.map +1 -1
  202. package/dest/trees/nullifier_leaf.js +3 -0
  203. package/dest/tx/block_header.d.ts +2 -2
  204. package/dest/tx/block_header.d.ts.map +1 -1
  205. package/dest/tx/block_header.js +1 -1
  206. package/dest/tx/fee_provider.d.ts +10 -0
  207. package/dest/tx/fee_provider.d.ts.map +1 -0
  208. package/dest/tx/fee_provider.js +1 -0
  209. package/dest/tx/global_variable_builder.d.ts +3 -16
  210. package/dest/tx/global_variable_builder.d.ts.map +1 -1
  211. package/dest/tx/index.d.ts +2 -1
  212. package/dest/tx/index.d.ts.map +1 -1
  213. package/dest/tx/index.js +1 -0
  214. package/dest/tx/indexed_tx_effect.d.ts +1 -1
  215. package/dest/tx/indexed_tx_effect.d.ts.map +1 -1
  216. package/dest/tx/indexed_tx_effect.js +1 -2
  217. package/dest/tx/profiling.js +4 -4
  218. package/dest/tx/simulated_tx.d.ts +4 -4
  219. package/dest/tx/simulated_tx.d.ts.map +1 -1
  220. package/dest/tx/simulated_tx.js +3 -3
  221. package/dest/tx/tx.d.ts +3 -3
  222. package/dest/tx/tx.d.ts.map +1 -1
  223. package/dest/tx/tx_receipt.d.ts +8 -4
  224. package/dest/tx/tx_receipt.d.ts.map +1 -1
  225. package/dest/tx/tx_receipt.js +8 -15
  226. package/dest/types/shared.d.ts +1 -10
  227. package/dest/types/shared.d.ts.map +1 -1
  228. package/dest/types/shared.js +0 -9
  229. package/dest/vks/verification_key.d.ts +2 -137
  230. package/dest/vks/verification_key.d.ts.map +1 -1
  231. package/dest/vks/verification_key.js +5 -126
  232. package/dest/world-state/genesis_data.d.ts +11 -0
  233. package/dest/world-state/genesis_data.d.ts.map +1 -0
  234. package/dest/world-state/genesis_data.js +4 -0
  235. package/dest/world-state/index.d.ts +2 -1
  236. package/dest/world-state/index.d.ts.map +1 -1
  237. package/dest/world-state/index.js +1 -0
  238. package/dest/world-state/world_state_revision.d.ts +8 -1
  239. package/dest/world-state/world_state_revision.d.ts.map +1 -1
  240. package/dest/world-state/world_state_revision.js +7 -1
  241. package/package.json +8 -8
  242. package/src/abi/authorization_selector.ts +2 -8
  243. package/src/abi/encoder.ts +42 -6
  244. package/src/abi/event_selector.ts +2 -8
  245. package/src/abi/function_selector.ts +3 -12
  246. package/src/abi/note_selector.ts +3 -12
  247. package/src/abi/selector.ts +1 -1
  248. package/src/avm/revert_code.ts +25 -39
  249. package/src/aztec-address/index.ts +4 -10
  250. package/src/block/attestation_info.ts +11 -11
  251. package/src/block/block_data.ts +20 -4
  252. package/src/block/block_hash.ts +21 -14
  253. package/src/block/block_parameter.ts +35 -2
  254. package/src/block/l2_block_info.ts +8 -6
  255. package/src/block/l2_block_source.ts +43 -3
  256. package/src/block/l2_block_stream/interfaces.ts +6 -2
  257. package/src/block/l2_block_stream/l2_tips_store_base.ts +1 -1
  258. package/src/block/proposal/attestations_and_signers.ts +32 -17
  259. package/src/block/test/l2_tips_store_test_suite.ts +1 -1
  260. package/src/checkpoint/checkpoint_data.ts +4 -0
  261. package/src/config/chain-config.ts +9 -4
  262. package/src/config/sequencer-config.ts +34 -6
  263. package/src/contract/contract_address.ts +2 -2
  264. package/src/contract/private_function.ts +3 -1
  265. package/src/gas/README.md +31 -0
  266. package/src/gas/fee_math.ts +120 -0
  267. package/src/gas/gas_fees.ts +17 -4
  268. package/src/gas/gas_settings.ts +65 -12
  269. package/src/gas/index.ts +1 -0
  270. package/src/ha-signing/config.ts +5 -2
  271. package/src/ha-signing/index.ts +3 -1
  272. package/src/ha-signing/local_config.ts +2 -2
  273. package/src/ha-signing/types.ts +48 -34
  274. package/src/hash/hash.ts +27 -0
  275. package/src/interfaces/archiver.ts +21 -3
  276. package/src/interfaces/aztec-node-admin.ts +8 -8
  277. package/src/interfaces/aztec-node-debug.ts +40 -0
  278. package/src/interfaces/aztec-node.ts +120 -95
  279. package/src/interfaces/block_response.ts +79 -0
  280. package/src/interfaces/chain_tips.ts +24 -0
  281. package/src/interfaces/checkpoint_parameter.ts +22 -0
  282. package/src/interfaces/checkpoint_response.ts +84 -0
  283. package/src/interfaces/client.ts +6 -0
  284. package/src/interfaces/configs.ts +8 -1
  285. package/src/interfaces/l1_publish_info.ts +40 -0
  286. package/src/interfaces/merkle_tree_operations.ts +3 -2
  287. package/src/interfaces/prover-client.ts +2 -5
  288. package/src/interfaces/server.ts +5 -0
  289. package/src/interfaces/slasher.ts +0 -6
  290. package/src/interfaces/validator.ts +22 -9
  291. package/src/l1-contracts/index.ts +1 -1
  292. package/src/logs/log_id.ts +1 -2
  293. package/src/logs/siloed_tag.ts +8 -9
  294. package/src/logs/tag.ts +8 -8
  295. package/src/p2p/block_proposal.ts +96 -36
  296. package/src/p2p/checkpoint_attestation.ts +20 -29
  297. package/src/p2p/checkpoint_proposal.ts +88 -71
  298. package/src/p2p/consensus_payload.ts +50 -28
  299. package/src/p2p/gossipable.ts +4 -4
  300. package/src/p2p/signature_utils.ts +110 -25
  301. package/src/p2p/signed_txs.ts +46 -28
  302. package/src/parity/parity_base_private_inputs.ts +10 -4
  303. package/src/parity/parity_public_inputs.ts +9 -2
  304. package/src/rollup/block_headers_hash.ts +11 -2
  305. package/src/slashing/index.ts +1 -2
  306. package/src/slashing/serialization.ts +1 -81
  307. package/src/slashing/types.ts +3 -35
  308. package/src/slashing/{tally.ts → votes.ts} +1 -1
  309. package/src/tests/factories.ts +15 -21
  310. package/src/tests/mocks.ts +63 -39
  311. package/src/timetable/index.ts +308 -13
  312. package/src/trees/nullifier_leaf.ts +4 -0
  313. package/src/tx/block_header.ts +2 -2
  314. package/src/tx/fee_provider.ts +10 -0
  315. package/src/tx/global_variable_builder.ts +2 -18
  316. package/src/tx/index.ts +1 -0
  317. package/src/tx/indexed_tx_effect.ts +1 -2
  318. package/src/tx/profiling.ts +4 -4
  319. package/src/tx/simulated_tx.ts +6 -2
  320. package/src/tx/tx.ts +2 -2
  321. package/src/tx/tx_receipt.ts +11 -14
  322. package/src/types/shared.ts +0 -10
  323. package/src/vks/verification_key.ts +5 -184
  324. package/src/world-state/genesis_data.ts +15 -0
  325. package/src/world-state/index.ts +1 -0
  326. package/src/world-state/world_state_revision.ts +9 -1
  327. package/dest/abi/mocked_keys.d.ts +0 -2
  328. package/dest/abi/mocked_keys.d.ts.map +0 -1
  329. package/dest/abi/mocked_keys.js +0 -1
  330. package/dest/l1-contracts/slash_factory.d.ts +0 -45
  331. package/dest/l1-contracts/slash_factory.d.ts.map +0 -1
  332. package/dest/l1-contracts/slash_factory.js +0 -158
  333. package/dest/slashing/empire.d.ts +0 -31
  334. package/dest/slashing/empire.d.ts.map +0 -1
  335. package/dest/slashing/empire.js +0 -87
  336. package/src/abi/mocked_keys.ts +0 -2
  337. package/src/l1-contracts/slash_factory.ts +0 -180
  338. package/src/slashing/empire.ts +0 -104
package/src/gas/README.md CHANGED
@@ -84,6 +84,37 @@ else → use post (new fees)
84
84
  **Net effect**: L1 fee changes reach L2 with a 2-slot delay and can update at most once
85
85
  every 5 slots.
86
86
 
87
+ ### Worked Example
88
+
89
+ Suppose the oracle is updated at slot 10 with new L1 fees. Here is the timeline:
90
+
91
+ ```
92
+ Slot Oracle state Active fees Notes
93
+ ──── ──────────────────── ──────────── ──────────────────────────────────
94
+ 10 pre=A, post=B, soc=12 A Update queued. slotOfChange = 10 + LAG = 12.
95
+ 11 (same) A Still before slotOfChange → pre (A).
96
+ 12 (same) B slot >= slotOfChange → post (B) activates.
97
+ 13 (same) B B remains active.
98
+ 14 (same) B B remains active.
99
+ 15 Update allowed again B Earliest next update: soc + (LIFETIME - LAG)
100
+ = 12 + 3 = 15.
101
+ ```
102
+
103
+ Key observations:
104
+
105
+ 1. **Slots 10-11**: The old fees (A) are still in effect. Transactions submitted during
106
+ these slots see the old L1 cost. This is the **LAG** window — it gives pending
107
+ transactions 2 slots to land before fees change.
108
+
109
+ 2. **Slot 12**: The new fees (B) activate. Any checkpoint proposed at slot >= 12 uses B
110
+ for its sequencer/prover cost calculation.
111
+
112
+ 3. **Slots 12-14**: No new oracle update is accepted. The system is in a **cooldown**
113
+ period of `LIFETIME - LAG = 3` slots after the transition.
114
+
115
+ 4. **Slot 15**: A new oracle update can be queued (earliest `acceptableSlot`). If
116
+ triggered, the new values would activate at slot 15 + LAG = 17.
117
+
87
118
  ## Fee Asset Price
88
119
 
89
120
  Fees are computed in ETH internally but converted to the fee asset (Fee Juice) via
@@ -0,0 +1,120 @@
1
+ /**
2
+ * TypeScript port of fee computation logic from FeeLib.sol.
3
+ * Used to predict worst-case min fees over a future window of L2 slots.
4
+ */
5
+
6
+ // Constants matching FeeLib.sol
7
+ export const MINIMUM_CONGESTION_MULTIPLIER = 1_000_000_000n;
8
+ export const L1_GAS_PER_CHECKPOINT_PROPOSED = 300_000n;
9
+ export const L1_GAS_PER_EPOCH_VERIFIED = 3_600_000n;
10
+ export const BLOBS_PER_CHECKPOINT = 3n;
11
+ export const BLOB_GAS_PER_BLOB = 2n ** 17n;
12
+ export const MAGIC_CONGESTION_VALUE_MULTIPLIER = 854_700_854n;
13
+ export const MAGIC_CONGESTION_VALUE_DIVISOR = 100_000_000n;
14
+ export const ETH_PER_FEE_ASSET_PRECISION = 1_000_000_000_000n;
15
+ export const MIN_ETH_PER_FEE_ASSET = 100n;
16
+
17
+ /** Number of L2 slots of lag before new oracle values activate. Defines the prediction window. */
18
+ export const FEE_ORACLE_LAG = 2;
19
+
20
+ /** Expected mana usage per checkpoint for fee prediction. */
21
+ export enum ManaUsageEstimate {
22
+ /** No usage — fees decrease as congestion drains. */
23
+ None = 'none',
24
+ /** Target usage — congestion stays roughly flat (steady state). */
25
+ Target = 'target',
26
+ /** Limit usage (2x target) — worst case, congestion grows maximally. */
27
+ Limit = 'limit',
28
+ }
29
+
30
+ /** Parameters for computing the mana min fee at a given point in time. */
31
+ export type ManaMinFeeParams = {
32
+ l1BaseFee: bigint;
33
+ l1BlobFee: bigint;
34
+ manaTarget: bigint;
35
+ epochDuration: bigint;
36
+ provingCostPerManaEth: bigint;
37
+ excessMana: bigint;
38
+ ethPerFeeAsset: bigint;
39
+ };
40
+
41
+ /**
42
+ * Taylor series approximation of `factor * e^(numerator/denominator)`.
43
+ * Direct port of FeeLib.sol fakeExponential (EIP-4844 style).
44
+ */
45
+ export function fakeExponential(factor: bigint, numerator: bigint, denominator: bigint): bigint {
46
+ let i = 1n;
47
+ let output = 0n;
48
+ let numeratorAccumulator = factor * denominator;
49
+ while (numeratorAccumulator > 0n) {
50
+ output += numeratorAccumulator;
51
+ numeratorAccumulator = (numeratorAccumulator * numerator) / (denominator * i);
52
+ i += 1n;
53
+ }
54
+ return output / denominator;
55
+ }
56
+
57
+ /** Computes excess mana for the next checkpoint, clamped to zero. */
58
+ export function computeExcessMana(prevExcessMana: bigint, prevManaUsed: bigint, manaTarget: bigint): bigint {
59
+ const sum = prevExcessMana + prevManaUsed;
60
+ return sum > manaTarget ? sum - manaTarget : 0n;
61
+ }
62
+
63
+ /** Computes the congestion multiplier from excess mana (1e9 = no congestion). */
64
+ export function computeCongestionMultiplier(excessMana: bigint, manaTarget: bigint): bigint {
65
+ const denominator = (manaTarget * MAGIC_CONGESTION_VALUE_MULTIPLIER) / MAGIC_CONGESTION_VALUE_DIVISOR;
66
+ const cappedNumerator = excessMana < denominator * 100n ? excessMana : denominator * 100n;
67
+ return fakeExponential(MINIMUM_CONGESTION_MULTIPLIER, cappedNumerator, denominator);
68
+ }
69
+
70
+ /** Ceiling division for positive bigints. */
71
+ function ceilDiv(a: bigint, b: bigint): bigint {
72
+ return (a + b - 1n) / b;
73
+ }
74
+
75
+ /** Converts an ETH value to fee asset value using ethPerFeeAsset (1e12 precision). */
76
+ function toFeeAsset(ethValue: bigint, ethPerFeeAsset: bigint): bigint {
77
+ if (ethPerFeeAsset === 0n) {
78
+ return 0n;
79
+ }
80
+ return ceilDiv(ethValue * ETH_PER_FEE_ASSET_PRECISION, ethPerFeeAsset);
81
+ }
82
+
83
+ /**
84
+ * Computes the full mana min fee (sequencer + prover + congestion) in fee asset terms.
85
+ * Mirrors FeeLib.getManaMinFeeComponentsAt + summedMinFee.
86
+ */
87
+ export function computeManaMinFee(params: ManaMinFeeParams): bigint {
88
+ const { l1BaseFee, l1BlobFee, manaTarget, epochDuration, provingCostPerManaEth, excessMana, ethPerFeeAsset } = params;
89
+
90
+ if (manaTarget === 0n) {
91
+ return 0n;
92
+ }
93
+
94
+ // Sequencer cost per mana (in ETH)
95
+ const ethUsed = L1_GAS_PER_CHECKPOINT_PROPOSED * l1BaseFee + BLOBS_PER_CHECKPOINT * BLOB_GAS_PER_BLOB * l1BlobFee;
96
+ const sequencerCostEth = ceilDiv(ethUsed, manaTarget);
97
+
98
+ // Prover cost per mana (in ETH): L1 verification gas + governance-set proving cost
99
+ const proverCostEth =
100
+ ceilDiv(ceilDiv(L1_GAS_PER_EPOCH_VERIFIED * l1BaseFee, epochDuration), manaTarget) + provingCostPerManaEth;
101
+
102
+ // Total base cost in ETH (congestion is computed on this)
103
+ const totalEth = sequencerCostEth + proverCostEth;
104
+
105
+ // Congestion multiplier and cost (in ETH)
106
+ const congestionMul = computeCongestionMultiplier(excessMana, manaTarget);
107
+ const congestionCostEth = (totalEth * congestionMul) / MINIMUM_CONGESTION_MULTIPLIER - totalEth;
108
+
109
+ // Convert all components to fee asset
110
+ const clampedEthPerFeeAsset = ethPerFeeAsset < MIN_ETH_PER_FEE_ASSET ? MIN_ETH_PER_FEE_ASSET : ethPerFeeAsset;
111
+ const sequencerCost = toFeeAsset(sequencerCostEth, clampedEthPerFeeAsset);
112
+ const proverCost = toFeeAsset(proverCostEth, clampedEthPerFeeAsset);
113
+ const congestionCost = toFeeAsset(congestionCostEth, clampedEthPerFeeAsset);
114
+
115
+ const total = sequencerCost + proverCost + congestionCost;
116
+
117
+ // Cap at uint128 max (matching FeeLib.summedMinFee)
118
+ const UINT128_MAX = (1n << 128n) - 1n;
119
+ return total < UINT128_MAX ? total : UINT128_MAX;
120
+ }
@@ -15,6 +15,17 @@ import { z } from 'zod';
15
15
  import type { UInt128 } from '../types/shared.js';
16
16
  import type { GasDimensions } from './gas.js';
17
17
 
18
+ /**
19
+ * Multiplies a bigint by a non-integer scalar and returns the ceiling of the result.
20
+ * Avoids converting the bigint to Number (which loses precision above 2^53) by instead
21
+ * scaling the scalar into a bigint rational and performing ceiling division.
22
+ */
23
+ function bigintMulCeil(value: bigint, scalar: number): bigint {
24
+ const SCALE = 1_000_000_000_000n; // 1e12
25
+ const scaledScalar = BigInt(Math.round(scalar * 1e12));
26
+ return (value * scaledScalar + SCALE - 1n) / SCALE;
27
+ }
28
+
18
29
  /** Gas prices for each dimension. */
19
30
  export class GasFees {
20
31
  public readonly feePerDaGas: UInt128;
@@ -60,10 +71,7 @@ export class GasFees {
60
71
  const s = BigInt(scalar);
61
72
  return new GasFees(this.feePerDaGas * s, this.feePerL2Gas * s);
62
73
  } else {
63
- return new GasFees(
64
- BigInt(Math.ceil(Number(this.feePerDaGas) * scalar)),
65
- BigInt(Math.ceil(Number(this.feePerL2Gas) * scalar)),
66
- );
74
+ return new GasFees(bigintMulCeil(this.feePerDaGas, scalar), bigintMulCeil(this.feePerL2Gas, scalar));
67
75
  }
68
76
  }
69
77
 
@@ -126,3 +134,8 @@ export class GasFees {
126
134
  return `GasFees { feePerDaGas=${this.feePerDaGas} feePerL2Gas=${this.feePerL2Gas} }`;
127
135
  }
128
136
  }
137
+
138
+ /** Provides projected minimum gas fees for the next block. */
139
+ export interface BlockMinFeesProvider {
140
+ getCurrentMinFees(): Promise<GasFees>;
141
+ }
@@ -1,10 +1,4 @@
1
- import {
2
- DEFAULT_DA_GAS_LIMIT,
3
- DEFAULT_L2_GAS_LIMIT,
4
- DEFAULT_TEARDOWN_DA_GAS_LIMIT,
5
- DEFAULT_TEARDOWN_L2_GAS_LIMIT,
6
- GAS_SETTINGS_LENGTH,
7
- } from '@aztec/constants';
1
+ import { GAS_SETTINGS_LENGTH, MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
8
2
  import { Fr } from '@aztec/foundation/curves/bn254';
9
3
  import { BufferReader, FieldReader, serializeToBuffer, serializeToFields } from '@aztec/foundation/serialize';
10
4
  import type { FieldsOf } from '@aztec/foundation/types';
@@ -14,6 +8,21 @@ import { z } from 'zod';
14
8
  import { Gas, GasDimensions } from './gas.js';
15
9
  import { GasFees } from './gas_fees.js';
16
10
 
11
+ /** Approximate max DA gas limit. Arbitrary, assuming 4 blocks per checkpoint — users should use gas estimation. */
12
+ export const APPROXIMATE_MAX_DA_GAS_PER_BLOCK = Math.floor(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT / 4);
13
+ /** Fallback teardown L2 gas limit. Arbitrary — users should use gas estimation. */
14
+ export const FALLBACK_TEARDOWN_L2_GAS_LIMIT = Math.floor(MAX_PROCESSABLE_L2_GAS / 8);
15
+ /** Fallback teardown DA gas limit. Arbitrary — users should use gas estimation. */
16
+ export const FALLBACK_TEARDOWN_DA_GAS_LIMIT = Math.floor(APPROXIMATE_MAX_DA_GAS_PER_BLOCK / 2);
17
+
18
+ // For gas estimation, we use intentionally high limits above what the network can process,
19
+ // so the simulation runs without hitting gas caps. Since teardown gas is counted towards total,
20
+ // the total estimation limit is teardown + max processable.
21
+ export const GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT = MAX_PROCESSABLE_L2_GAS;
22
+ export const GAS_ESTIMATION_L2_GAS_LIMIT = GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT + MAX_PROCESSABLE_L2_GAS;
23
+ export const GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT = MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT;
24
+ export const GAS_ESTIMATION_DA_GAS_LIMIT = GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT + MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT;
25
+
17
26
  // docs:start:gas_settings_vars
18
27
  /** Gas usage and fees limits set by the transaction sender for different dimensions and phases. */
19
28
  export class GasSettings {
@@ -95,18 +104,62 @@ export class GasSettings {
95
104
  return new GasSettings(Gas.empty(), Gas.empty(), GasFees.empty(), GasFees.empty());
96
105
  }
97
106
 
98
- /** Default gas settings to use when user has not provided them. Requires explicit max fees per gas. */
99
- static default(overrides: {
107
+ /**
108
+ * Fills in gas limits high enough for transactions to be included in most cases.
109
+ * gasLimits is set to the maximum the protocol allows; since teardown gas is reserved
110
+ * from gasLimits during private execution (see gas_meter.nr), the effective gas available
111
+ * for app logic will be gasLimits - teardownGasLimits - privateOverhead.
112
+ * The DA gas limit is set to an approximate max per block assuming 4 blocks per checkpoint,
113
+ * since using the maximum per checkpoint would cause nodes to reject transactions.
114
+ * These values won't work if:
115
+ * - Teardown consumes more than the arbitrarily assigned fallback limits
116
+ * - The rest of the transaction consumes more than the remaining gas after teardown
117
+ * - The DA gas limit is too low for the transaction, while still within the checkpoint limit
118
+ */
119
+ static fallback(overrides: {
120
+ gasLimits?: Gas;
121
+ teardownGasLimits?: Gas;
122
+ maxFeesPerGas: GasFees;
123
+ maxPriorityFeesPerGas?: GasFees;
124
+ }) {
125
+ return GasSettings.from({
126
+ gasLimits: overrides.gasLimits ?? {
127
+ l2Gas: MAX_PROCESSABLE_L2_GAS,
128
+ daGas: APPROXIMATE_MAX_DA_GAS_PER_BLOCK,
129
+ },
130
+ teardownGasLimits: overrides.teardownGasLimits ?? {
131
+ l2Gas: FALLBACK_TEARDOWN_L2_GAS_LIMIT,
132
+ daGas: FALLBACK_TEARDOWN_DA_GAS_LIMIT,
133
+ },
134
+ maxFeesPerGas: overrides.maxFeesPerGas,
135
+ maxPriorityFeesPerGas: overrides.maxPriorityFeesPerGas ?? GasFees.empty(),
136
+ });
137
+ }
138
+
139
+ /**
140
+ * Gas settings for simulation/estimation only.
141
+ * Since teardown gas is reserved upfront from gasLimits during private execution (see gas_meter.nr),
142
+ * the effective gas available for app logic is gasLimits - teardownGasLimits - privateOverhead.
143
+ * To ensure estimation never hits gas caps, we set both limits above what the protocol allows:
144
+ * teardown gets MAX_PROCESSABLE and gasLimits gets teardown + MAX_PROCESSABLE, so the full
145
+ * processable amount remains available for each phase independently. To be used in conjunction
146
+ * with skipTxValidation: true during public simulation, or the node would reject the transaction
147
+ * outright due to gas limits being above protocol max.
148
+ */
149
+ static forEstimation(overrides: {
100
150
  gasLimits?: Gas;
101
151
  teardownGasLimits?: Gas;
102
152
  maxFeesPerGas: GasFees;
103
153
  maxPriorityFeesPerGas?: GasFees;
104
154
  }) {
105
155
  return GasSettings.from({
106
- gasLimits: overrides.gasLimits ?? { l2Gas: DEFAULT_L2_GAS_LIMIT, daGas: DEFAULT_DA_GAS_LIMIT },
156
+ gasLimits: overrides.gasLimits ?? {
157
+ l2Gas: GAS_ESTIMATION_L2_GAS_LIMIT,
158
+ daGas: GAS_ESTIMATION_DA_GAS_LIMIT,
159
+ },
107
160
  teardownGasLimits: overrides.teardownGasLimits ?? {
108
- l2Gas: DEFAULT_TEARDOWN_L2_GAS_LIMIT,
109
- daGas: DEFAULT_TEARDOWN_DA_GAS_LIMIT,
161
+ l2Gas: GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT,
162
+ daGas: GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT,
110
163
  },
111
164
  maxFeesPerGas: overrides.maxFeesPerGas,
112
165
  maxPriorityFeesPerGas: overrides.maxPriorityFeesPerGas ?? GasFees.empty(),
package/src/gas/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './fee_math.js';
1
2
  export * from './gas.js';
2
3
  export * from './gas_fees.js';
3
4
  export * from './gas_settings.js';
@@ -1,11 +1,13 @@
1
1
  import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
2
2
  import {
3
3
  type ConfigMappingsType,
4
+ SecretValue,
4
5
  booleanConfigHelper,
5
6
  getConfigFromMappings,
6
7
  getDefaultConfig,
7
8
  numberConfigHelper,
8
9
  optionalNumberConfigHelper,
10
+ secretStringConfigHelper,
9
11
  } from '@aztec/foundation/config';
10
12
  import { EthAddress } from '@aztec/foundation/eth-address';
11
13
  import type { ZodFor } from '@aztec/foundation/schemas';
@@ -88,7 +90,7 @@ export interface ValidatorHASignerConfig extends BaseSignerConfig {
88
90
  * PostgreSQL connection string
89
91
  * Format: postgresql://user:password@host:port/database
90
92
  */
91
- databaseUrl?: string;
93
+ databaseUrl?: SecretValue<string>;
92
94
  /** Maximum number of clients in the pool (default: 10) */
93
95
  poolMaxCount?: number;
94
96
  /** Minimum number of clients in the pool (default: 0) */
@@ -110,6 +112,7 @@ export const validatorHASignerConfigMappings: ConfigMappingsType<ValidatorHASign
110
112
  env: 'VALIDATOR_HA_DATABASE_URL',
111
113
  description:
112
114
  'PostgreSQL connection string for validator HA signer (format: postgresql://user:password@host:port/database)',
115
+ ...secretStringConfigHelper(),
113
116
  },
114
117
  poolMaxCount: {
115
118
  env: 'VALIDATOR_HA_POOL_MAX',
@@ -148,7 +151,7 @@ export function getConfigEnvVars(): ValidatorHASignerConfig {
148
151
 
149
152
  export const ValidatorHASignerConfigSchema = BaseSignerConfigSchema.extend({
150
153
  haSigningEnabled: z.boolean(),
151
- databaseUrl: z.string().optional(),
154
+ databaseUrl: SecretValue.schema(z.string()).optional(),
152
155
  poolMaxCount: z.number().min(0).optional(),
153
156
  poolMinCount: z.number().min(0).optional(),
154
157
  poolIdleTimeoutMs: z.number().min(0).optional(),
@@ -16,12 +16,14 @@ export {
16
16
  } from './local_config.js';
17
17
  export {
18
18
  DutyType,
19
+ type AttestationSigningContext,
19
20
  type BlockProposalSigningContext,
21
+ type CheckpointProposalSigningContext,
20
22
  type HAProtectedSigningContext,
21
23
  type NoHAProtectionSigningContext,
22
- type OtherSigningContext,
23
24
  type SigningContext,
24
25
  type VoteSigningContext,
25
26
  getBlockNumberFromSigningContext,
27
+ getCheckpointNumberFromSigningContext,
26
28
  isHAProtectedContext,
27
29
  } from './types.js';
@@ -1,4 +1,4 @@
1
- import { type ConfigMappingsType, getConfigFromMappings } from '@aztec/foundation/config';
1
+ import { type ConfigMappingsType, getConfigFromMappings, optionalNumberConfigHelper } from '@aztec/foundation/config';
2
2
  import { zodFor } from '@aztec/foundation/schemas';
3
3
  import { type DataStoreConfig, dataConfigMappings } from '@aztec/stdlib/kv-store';
4
4
 
@@ -26,7 +26,7 @@ export const localSignerConfigMappings: ConfigMappingsType<LocalSignerConfig> =
26
26
  env: 'SIGNING_PROTECTION_MAP_SIZE_KB',
27
27
  description:
28
28
  'Maximum size of the local signing-protection LMDB store in KB. Overwrites the general dataStoreMapSizeKb.',
29
- parseEnv: (val: string | undefined) => (val ? +val : undefined),
29
+ ...optionalNumberConfigHelper(),
30
30
  },
31
31
  };
32
32
 
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  BlockNumber,
3
- type CheckpointNumber,
3
+ CheckpointNumber,
4
4
  type IndexWithinCheckpoint,
5
5
  type SlotNumber,
6
6
  } from '@aztec/foundation/branded-types';
@@ -20,40 +20,40 @@ export enum DutyType {
20
20
  }
21
21
 
22
22
  /**
23
- * Base context for signing operations
23
+ * Signing context for block proposals.
24
+ * Includes both the block number and the checkpoint number the block belongs to.
24
25
  */
25
- interface BaseSigningContext {
26
- /** Slot number for this duty */
26
+ export interface BlockProposalSigningContext {
27
27
  slot: SlotNumber;
28
- /**
29
- * Block or checkpoint number for this duty.
30
- * For block proposals, this is the block number.
31
- * For checkpoint proposals, this is the checkpoint number.
32
- */
33
- blockNumber: BlockNumber | CheckpointNumber;
28
+ blockNumber: BlockNumber;
29
+ checkpointNumber: CheckpointNumber;
30
+ /** Block index within checkpoint (0, 1, 2...). Required for block proposals. */
31
+ blockIndexWithinCheckpoint: IndexWithinCheckpoint;
32
+ dutyType: DutyType.BLOCK_PROPOSAL;
34
33
  }
35
34
 
36
35
  /**
37
- * Signing context for block proposals.
38
- * blockIndexWithinCheckpoint is REQUIRED and must be >= 0.
36
+ * Signing context for checkpoint proposals.
37
+ * Includes the checkpoint number being proposed, but not a block number.
39
38
  */
40
- export interface BlockProposalSigningContext extends BaseSigningContext {
41
- /** Block index within checkpoint (0, 1, 2...). Required for block proposals. */
42
- blockIndexWithinCheckpoint: IndexWithinCheckpoint;
43
- dutyType: DutyType.BLOCK_PROPOSAL;
39
+ export interface CheckpointProposalSigningContext {
40
+ slot: SlotNumber;
41
+ checkpointNumber: CheckpointNumber;
42
+ dutyType: DutyType.CHECKPOINT_PROPOSAL;
44
43
  }
45
44
 
46
45
  /**
47
- * Signing context for non-block-proposal duties that require HA protection.
48
- * blockIndexWithinCheckpoint is not applicable (internally always -1).
46
+ * Signing context for attestation duties (checkpoint attestations).
47
+ * Includes the checkpoint number when available (from proposal validation).
49
48
  */
50
- export interface OtherSigningContext extends BaseSigningContext {
51
- dutyType: DutyType.CHECKPOINT_PROPOSAL | DutyType.ATTESTATION | DutyType.ATTESTATIONS_AND_SIGNERS;
49
+ export interface AttestationSigningContext {
50
+ slot: SlotNumber;
51
+ checkpointNumber: CheckpointNumber;
52
+ dutyType: DutyType.ATTESTATION | DutyType.ATTESTATIONS_AND_SIGNERS;
52
53
  }
53
54
 
54
55
  /**
55
56
  * Signing context for governance/slashing votes which only need slot for HA protection.
56
- * blockNumber is not applicable (internally always 0).
57
57
  */
58
58
  export interface VoteSigningContext {
59
59
  slot: SlotNumber;
@@ -69,18 +69,23 @@ export interface NoHAProtectionSigningContext {
69
69
  }
70
70
 
71
71
  /**
72
- * Signing contexts that require HA protection (excludes AUTH_REQUEST).
72
+ * Signing contexts that require HA protection (excludes AUTH_REQUEST and TXS).
73
73
  * Used by the HA signer's signWithProtection method.
74
74
  */
75
- export type HAProtectedSigningContext = BlockProposalSigningContext | OtherSigningContext | VoteSigningContext;
75
+ export type HAProtectedSigningContext =
76
+ | BlockProposalSigningContext
77
+ | CheckpointProposalSigningContext
78
+ | AttestationSigningContext
79
+ | VoteSigningContext;
76
80
 
77
81
  /**
78
82
  * Context required for slashing protection during signing operations.
79
83
  * Uses discriminated union to enforce type safety:
80
- * - BLOCK_PROPOSAL duties MUST have blockIndexWithinCheckpoint >= 0
81
- * - Other duty types do NOT have blockIndexWithinCheckpoint (internally -1)
82
- * - Vote duties only need slot (blockNumber is internally 0)
83
- * - AUTH_REQUEST and TXS duties don't need slot/blockNumber (no HA protection needed)
84
+ * - BLOCK_PROPOSAL duties have blockNumber, checkpointNumber, and blockIndexWithinCheckpoint
85
+ * - CHECKPOINT_PROPOSAL duties have checkpointNumber
86
+ * - ATTESTATION/ATTESTATIONS_AND_SIGNERS duties have only slot
87
+ * - Vote duties have only slot
88
+ * - AUTH_REQUEST and TXS duties don't need HA protection
84
89
  */
85
90
  export type SigningContext = HAProtectedSigningContext | NoHAProtectionSigningContext;
86
91
 
@@ -94,19 +99,28 @@ export function isHAProtectedContext(context: SigningContext): context is HAProt
94
99
 
95
100
  /**
96
101
  * Gets the block number from a signing context.
97
- * - Vote duties (GOVERNANCE_VOTE, SLASHING_VOTE): returns BlockNumber(0)
98
- * - Other duties: returns the blockNumber from the context
102
+ * Only BLOCK_PROPOSAL duties carry a block number; all others return BlockNumber(0).
99
103
  */
100
- export function getBlockNumberFromSigningContext(context: HAProtectedSigningContext): BlockNumber | CheckpointNumber {
101
- // Check for duty types that have blockNumber
104
+ export function getBlockNumberFromSigningContext(context: HAProtectedSigningContext): BlockNumber {
105
+ if (context.dutyType === DutyType.BLOCK_PROPOSAL) {
106
+ return context.blockNumber;
107
+ }
108
+ return BlockNumber(0);
109
+ }
110
+
111
+ /**
112
+ * Gets the checkpoint number from a signing context.
113
+ * BLOCK_PROPOSAL, CHECKPOINT_PROPOSAL, ATTESTATION, and ATTESTATIONS_AND_SIGNERS duties carry a checkpoint number;
114
+ * vote duties return CheckpointNumber(0).
115
+ */
116
+ export function getCheckpointNumberFromSigningContext(context: HAProtectedSigningContext): CheckpointNumber {
102
117
  if (
103
118
  context.dutyType === DutyType.BLOCK_PROPOSAL ||
104
119
  context.dutyType === DutyType.CHECKPOINT_PROPOSAL ||
105
120
  context.dutyType === DutyType.ATTESTATION ||
106
121
  context.dutyType === DutyType.ATTESTATIONS_AND_SIGNERS
107
122
  ) {
108
- return context.blockNumber;
123
+ return context.checkpointNumber;
109
124
  }
110
- // Vote duties (GOVERNANCE_VOTE, SLASHING_VOTE) don't have blockNumber
111
- return BlockNumber(0);
125
+ return CheckpointNumber(0);
112
126
  }
package/src/hash/hash.ts CHANGED
@@ -6,6 +6,21 @@ import type { EthAddress } from '@aztec/foundation/eth-address';
6
6
 
7
7
  import { AztecAddress } from '../aztec-address/index.js';
8
8
 
9
+ /** Computes a Poseidon2 merkle tree internal node hash for append-only trees (note-hash, L1->L2, archive). */
10
+ export function computeMerkleHash(left: Fr, right: Fr): Promise<Fr> {
11
+ return poseidon2HashWithSeparator([left, right], DomainSeparator.MERKLE_HASH);
12
+ }
13
+
14
+ /** Merkle-node hasher for the nullifier tree's sibling paths. */
15
+ export function computeNullifierMerkleHash(left: Fr, right: Fr): Promise<Fr> {
16
+ return poseidon2HashWithSeparator([left, right], DomainSeparator.NULLIFIER_MERKLE);
17
+ }
18
+
19
+ /** Merkle-node hasher for the public-data tree's sibling paths. */
20
+ export function computePublicDataMerkleHash(left: Fr, right: Fr): Promise<Fr> {
21
+ return poseidon2HashWithSeparator([left, right], DomainSeparator.PUBLIC_DATA_MERKLE);
22
+ }
23
+
9
24
  /**
10
25
  * Computes a hash of a given verification key.
11
26
  * @param keyAsFields - The verification key as fields.
@@ -103,6 +118,18 @@ export function computeLogTag(rawTag: number | bigint | boolean | Fr | Buffer, d
103
118
  return poseidon2HashWithSeparator([new Fr(rawTag)], domSep);
104
119
  }
105
120
 
121
+ /**
122
+ * Computes the commitment of a private event from its preimage.
123
+ * @param randomness - Random value emitted alongside the event to prevent preimage brute-forcing.
124
+ * @param eventSelector - Event selector as an Fr.
125
+ * @param content - Serialized event content.
126
+ *
127
+ * @dev Must match the implementation in aztec-nr/aztec/src/event/event_interface.nr > compute_private_serialized_event_commitment
128
+ */
129
+ export function computePrivateEventCommitment(randomness: Fr, eventSelector: Fr, content: Fr[]): Promise<Fr> {
130
+ return poseidon2HashWithSeparator([randomness, eventSelector, ...content], DomainSeparator.EVENT_COMMITMENT);
131
+ }
132
+
106
133
  export function computeSiloedPrivateLogFirstField(contract: AztecAddress, field: Fr): Promise<Fr> {
107
134
  return poseidon2HashWithSeparator([contract, field], DomainSeparator.PRIVATE_LOG_FIRST_FIELD);
108
135
  }
@@ -4,7 +4,7 @@ import type { ApiSchemaFor } from '@aztec/foundation/schemas';
4
4
 
5
5
  import { z } from 'zod';
6
6
 
7
- import { BlockDataSchema } from '../block/block_data.js';
7
+ import { BlockDataSchema, BlockDataWithCheckpointContextSchema } from '../block/block_data.js';
8
8
  import { BlockHash } from '../block/block_hash.js';
9
9
  import { CheckpointedL2Block } from '../block/checkpointed_l2_block.js';
10
10
  import { L2Block } from '../block/l2_block.js';
@@ -60,8 +60,14 @@ export type ArchiverSpecificConfig = {
60
60
  /** Whether to allow starting the archiver without debug/trace method support on Ethereum hosts */
61
61
  ethereumAllowNoDebugHosts?: boolean;
62
62
 
63
+ /** Skip the startup check that probes the L1 RPC for historical logs on the Rollup contract. */
64
+ archiverSkipHistoricalLogsCheck?: boolean;
65
+
63
66
  /** Skip validating checkpoint attestations (for testing purposes only) */
64
67
  skipValidateCheckpointAttestations?: boolean;
68
+
69
+ /** Skip promoting proposed checkpoints during L1 sync (for testing purposes only) */
70
+ skipPromoteProposedCheckpointDuringL1Sync?: boolean;
65
71
  };
66
72
 
67
73
  export const ArchiverSpecificConfigSchema = z.object({
@@ -72,7 +78,9 @@ export const ArchiverSpecificConfigSchema = z.object({
72
78
  archiverStoreMapSizeKb: schemas.Integer.optional(),
73
79
  maxAllowedEthClientDriftSeconds: schemas.Integer.optional(),
74
80
  ethereumAllowNoDebugHosts: z.boolean().optional(),
81
+ archiverSkipHistoricalLogsCheck: z.boolean().optional(),
75
82
  skipValidateCheckpointAttestations: z.boolean().optional(),
83
+ skipPromoteProposedCheckpointDuringL1Sync: z.boolean().optional(),
76
84
  });
77
85
 
78
86
  export type ArchiverApi = Omit<
@@ -109,6 +117,16 @@ export const ArchiverApiSchema: ApiSchemaFor<ArchiverApi> = {
109
117
  getBlockHeaderByArchive: z.function().args(schemas.Fr).returns(BlockHeader.schema.optional()),
110
118
  getBlockData: z.function().args(BlockNumberSchema).returns(BlockDataSchema.optional()),
111
119
  getBlockDataByArchive: z.function().args(schemas.Fr).returns(BlockDataSchema.optional()),
120
+ getBlockDataWithCheckpointContext: z
121
+ .function()
122
+ .args(BlockNumberSchema)
123
+ .returns(BlockDataWithCheckpointContextSchema.optional()),
124
+ getCheckpointData: z.function().args(CheckpointNumberSchema).returns(CheckpointDataSchema.optional()),
125
+ getCheckpointDataRange: z
126
+ .function()
127
+ .args(CheckpointNumberSchema, schemas.Integer)
128
+ .returns(z.array(CheckpointDataSchema)),
129
+ getCheckpointNumberBySlot: z.function().args(schemas.SlotNumber).returns(CheckpointNumberSchema.optional()),
112
130
  getL2Block: z.function().args(BlockNumberSchema).returns(L2Block.schema.optional()),
113
131
  getL2BlockByHash: z.function().args(BlockHash.schema).returns(L2Block.schema.optional()),
114
132
  getL2BlockByArchive: z.function().args(schemas.Fr).returns(L2Block.schema.optional()),
@@ -150,8 +168,8 @@ export const ArchiverApiSchema: ApiSchemaFor<ArchiverApi> = {
150
168
  .args()
151
169
  .returns(z.object({ genesisArchiveRoot: schemas.Fr })),
152
170
  getL1Timestamp: z.function().args().returns(schemas.BigInt.optional()),
153
- getProposedCheckpoint: z.function().args().returns(ProposedCheckpointDataSchema.optional()),
154
- getProposedCheckpointOnly: z.function().args().returns(ProposedCheckpointDataSchema.optional()),
171
+ getLastCheckpoint: z.function().args().returns(ProposedCheckpointDataSchema.optional()),
172
+ getLastProposedCheckpoint: z.function().args().returns(ProposedCheckpointDataSchema.optional()),
155
173
  syncImmediate: z.function().args().returns(z.void()),
156
174
  isPendingChainInvalid: z.function().args().returns(z.boolean()),
157
175
  getPendingChainValidationStatus: z.function().args().returns(ValidateCheckpointResultSchema),