@aztec/stdlib 0.0.1-commit.8c0b8ff → 0.0.1-commit.8cb2d04d8

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 (356) hide show
  1. package/dest/abi/abi.d.ts +191 -26
  2. package/dest/abi/abi.d.ts.map +1 -1
  3. package/dest/abi/abi.js +4 -45
  4. package/dest/abi/authorization_selector.d.ts +3 -6
  5. package/dest/abi/authorization_selector.d.ts.map +1 -1
  6. package/dest/abi/encoder.d.ts +1 -1
  7. package/dest/abi/encoder.d.ts.map +1 -1
  8. package/dest/abi/encoder.js +32 -6
  9. package/dest/abi/event_selector.d.ts +3 -6
  10. package/dest/abi/event_selector.d.ts.map +1 -1
  11. package/dest/abi/function_selector.d.ts +3 -6
  12. package/dest/abi/function_selector.d.ts.map +1 -1
  13. package/dest/abi/function_selector.js +1 -3
  14. package/dest/abi/note_selector.d.ts +3 -6
  15. package/dest/abi/note_selector.d.ts.map +1 -1
  16. package/dest/abi/note_selector.js +1 -3
  17. package/dest/avm/avm_accumulated_data.js +2 -2
  18. package/dest/avm/avm_circuit_public_inputs.js +2 -2
  19. package/dest/aztec-address/index.d.ts +3 -6
  20. package/dest/aztec-address/index.d.ts.map +1 -1
  21. package/dest/aztec-address/index.js +2 -4
  22. package/dest/block/block_data.d.ts +8 -8
  23. package/dest/block/block_data.d.ts.map +1 -1
  24. package/dest/block/block_data.js +2 -2
  25. package/dest/block/block_hash.d.ts +11 -10
  26. package/dest/block/block_hash.d.ts.map +1 -1
  27. package/dest/block/block_hash.js +10 -9
  28. package/dest/block/l2_block_info.d.ts +6 -5
  29. package/dest/block/l2_block_info.d.ts.map +1 -1
  30. package/dest/block/l2_block_info.js +6 -5
  31. package/dest/block/l2_block_source.d.ts +80 -3
  32. package/dest/block/l2_block_source.d.ts.map +1 -1
  33. package/dest/block/l2_block_source.js +1 -0
  34. package/dest/block/l2_block_stream/l2_tips_store_base.d.ts +1 -1
  35. package/dest/block/l2_block_stream/l2_tips_store_base.d.ts.map +1 -1
  36. package/dest/block/l2_block_stream/l2_tips_store_base.js +18 -5
  37. package/dest/block/test/l2_tips_store_test_suite.d.ts +1 -1
  38. package/dest/block/test/l2_tips_store_test_suite.d.ts.map +1 -1
  39. package/dest/block/test/l2_tips_store_test_suite.js +4 -3
  40. package/dest/checkpoint/checkpoint.d.ts +7 -1
  41. package/dest/checkpoint/checkpoint.d.ts.map +1 -1
  42. package/dest/checkpoint/checkpoint.js +9 -1
  43. package/dest/checkpoint/checkpoint_data.d.ts +71 -5
  44. package/dest/checkpoint/checkpoint_data.d.ts.map +1 -1
  45. package/dest/checkpoint/checkpoint_data.js +10 -0
  46. package/dest/config/chain-config.d.ts +1 -1
  47. package/dest/config/chain-config.d.ts.map +1 -1
  48. package/dest/config/chain-config.js +7 -1
  49. package/dest/config/index.d.ts +2 -1
  50. package/dest/config/index.d.ts.map +1 -1
  51. package/dest/config/index.js +1 -0
  52. package/dest/config/pipelining-config.d.ts +19 -0
  53. package/dest/config/pipelining-config.d.ts.map +1 -0
  54. package/dest/config/pipelining-config.js +18 -0
  55. package/dest/config/sequencer-config.d.ts +4 -2
  56. package/dest/config/sequencer-config.d.ts.map +1 -1
  57. package/dest/config/sequencer-config.js +11 -3
  58. package/dest/contract/contract_address.d.ts +3 -3
  59. package/dest/contract/contract_address.js +3 -3
  60. package/dest/contract/contract_class_id.d.ts +2 -2
  61. package/dest/contract/contract_class_id.js +2 -2
  62. package/dest/contract/index.d.ts +1 -3
  63. package/dest/contract/index.d.ts.map +1 -1
  64. package/dest/contract/index.js +0 -2
  65. package/dest/contract/interfaces/contract_class.d.ts +3 -156
  66. package/dest/contract/interfaces/contract_class.d.ts.map +1 -1
  67. package/dest/contract/interfaces/contract_class.js +1 -28
  68. package/dest/contract/private_function.d.ts +1 -1
  69. package/dest/contract/private_function.d.ts.map +1 -1
  70. package/dest/contract/private_function.js +2 -4
  71. package/dest/epoch-helpers/index.d.ts +3 -1
  72. package/dest/epoch-helpers/index.d.ts.map +1 -1
  73. package/dest/epoch-helpers/index.js +3 -0
  74. package/dest/file-store/factory.d.ts +4 -3
  75. package/dest/file-store/factory.d.ts.map +1 -1
  76. package/dest/file-store/factory.js +2 -2
  77. package/dest/file-store/http.d.ts +9 -2
  78. package/dest/file-store/http.d.ts.map +1 -1
  79. package/dest/file-store/http.js +20 -9
  80. package/dest/file-store/index.d.ts +2 -1
  81. package/dest/file-store/index.d.ts.map +1 -1
  82. package/dest/gas/fee_math.d.ts +49 -0
  83. package/dest/gas/fee_math.d.ts.map +1 -0
  84. package/dest/gas/fee_math.js +80 -0
  85. package/dest/gas/gas_fees.d.ts +1 -1
  86. package/dest/gas/gas_fees.d.ts.map +1 -1
  87. package/dest/gas/gas_fees.js +10 -1
  88. package/dest/gas/index.d.ts +2 -1
  89. package/dest/gas/index.d.ts.map +1 -1
  90. package/dest/gas/index.js +1 -0
  91. package/dest/ha-signing/config.d.ts +136 -0
  92. package/dest/ha-signing/config.d.ts.map +1 -0
  93. package/dest/ha-signing/config.js +97 -0
  94. package/dest/ha-signing/index.d.ts +4 -0
  95. package/dest/ha-signing/index.d.ts.map +1 -0
  96. package/dest/ha-signing/index.js +3 -0
  97. package/dest/ha-signing/local_config.d.ts +63 -0
  98. package/dest/ha-signing/local_config.d.ts.map +1 -0
  99. package/dest/ha-signing/local_config.js +24 -0
  100. package/dest/ha-signing/types.d.ts +90 -0
  101. package/dest/ha-signing/types.d.ts.map +1 -0
  102. package/dest/ha-signing/types.js +39 -0
  103. package/dest/hash/hash.d.ts +16 -1
  104. package/dest/hash/hash.d.ts.map +1 -1
  105. package/dest/hash/hash.js +32 -0
  106. package/dest/interfaces/archiver.d.ts +1 -1
  107. package/dest/interfaces/archiver.d.ts.map +1 -1
  108. package/dest/interfaces/archiver.js +3 -1
  109. package/dest/interfaces/aztec-node-admin.d.ts +16 -17
  110. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  111. package/dest/interfaces/aztec-node-admin.js +3 -3
  112. package/dest/interfaces/aztec-node.d.ts +10 -1
  113. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  114. package/dest/interfaces/aztec-node.js +2 -0
  115. package/dest/interfaces/l2_logs_source.d.ts +5 -3
  116. package/dest/interfaces/l2_logs_source.d.ts.map +1 -1
  117. package/dest/interfaces/merkle_tree_operations.d.ts +4 -3
  118. package/dest/interfaces/merkle_tree_operations.d.ts.map +1 -1
  119. package/dest/interfaces/prover-client.d.ts +1 -1
  120. package/dest/interfaces/prover-client.d.ts.map +1 -1
  121. package/dest/interfaces/prover-client.js +0 -3
  122. package/dest/interfaces/proving-job.d.ts +200 -200
  123. package/dest/interfaces/slasher.d.ts +1 -10
  124. package/dest/interfaces/slasher.d.ts.map +1 -1
  125. package/dest/interfaces/slasher.js +0 -2
  126. package/dest/interfaces/validator.d.ts +45 -36
  127. package/dest/interfaces/validator.d.ts.map +1 -1
  128. package/dest/interfaces/validator.js +2 -3
  129. package/dest/kernel/claimed_length_array.js +1 -1
  130. package/dest/kernel/hints/private_kernel_reset_hints.d.ts +1 -1
  131. package/dest/kernel/hints/private_kernel_reset_hints.d.ts.map +1 -1
  132. package/dest/kernel/padded_side_effects.js +1 -1
  133. package/dest/kernel/private_to_avm_accumulated_data.js +2 -2
  134. package/dest/kernel/private_to_public_accumulated_data.js +2 -2
  135. package/dest/kernel/private_to_rollup_accumulated_data.js +1 -1
  136. package/dest/kv-store/config.d.ts +17 -0
  137. package/dest/kv-store/config.d.ts.map +1 -0
  138. package/dest/kv-store/config.js +26 -0
  139. package/dest/kv-store/index.d.ts +2 -0
  140. package/dest/kv-store/index.d.ts.map +1 -0
  141. package/dest/kv-store/index.js +1 -0
  142. package/dest/l1-contracts/index.d.ts +2 -2
  143. package/dest/l1-contracts/index.d.ts.map +1 -1
  144. package/dest/l1-contracts/index.js +1 -1
  145. package/dest/logs/log_id.d.ts +1 -1
  146. package/dest/logs/log_id.d.ts.map +1 -1
  147. package/dest/logs/log_id.js +1 -2
  148. package/dest/logs/private_log.js +1 -1
  149. package/dest/logs/public_log.d.ts +1 -1
  150. package/dest/logs/public_log.d.ts.map +1 -1
  151. package/dest/logs/public_log.js +1 -7
  152. package/dest/logs/siloed_tag.d.ts +5 -7
  153. package/dest/logs/siloed_tag.d.ts.map +1 -1
  154. package/dest/logs/siloed_tag.js +4 -0
  155. package/dest/logs/tag.d.ts +5 -6
  156. package/dest/logs/tag.d.ts.map +1 -1
  157. package/dest/logs/tag.js +4 -0
  158. package/dest/messaging/l1_to_l2_message_source.d.ts +4 -2
  159. package/dest/messaging/l1_to_l2_message_source.d.ts.map +1 -1
  160. package/dest/p2p/block_proposal.d.ts +7 -9
  161. package/dest/p2p/block_proposal.d.ts.map +1 -1
  162. package/dest/p2p/block_proposal.js +5 -10
  163. package/dest/p2p/checkpoint_attestation.d.ts +4 -6
  164. package/dest/p2p/checkpoint_attestation.d.ts.map +1 -1
  165. package/dest/p2p/checkpoint_attestation.js +2 -7
  166. package/dest/p2p/checkpoint_proposal.d.ts +9 -11
  167. package/dest/p2p/checkpoint_proposal.d.ts.map +1 -1
  168. package/dest/p2p/checkpoint_proposal.js +6 -25
  169. package/dest/p2p/gossipable.d.ts +4 -4
  170. package/dest/p2p/gossipable.d.ts.map +1 -1
  171. package/dest/parity/parity_base_private_inputs.js +1 -1
  172. package/dest/proofs/chonk_proof.d.ts +46 -2
  173. package/dest/proofs/chonk_proof.d.ts.map +1 -1
  174. package/dest/proofs/chonk_proof.js +84 -15
  175. package/dest/rollup/base_rollup_hints.js +2 -2
  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/rollup/block_root_rollup_private_inputs.js +5 -5
  180. package/dest/rollup/checkpoint_rollup_public_inputs.js +1 -1
  181. package/dest/rollup/checkpoint_root_rollup_private_inputs.js +3 -3
  182. package/dest/rollup/root_rollup_public_inputs.js +1 -1
  183. package/dest/rollup/tree_snapshot_diff_hints.js +2 -2
  184. package/dest/slashing/index.d.ts +2 -3
  185. package/dest/slashing/index.d.ts.map +1 -1
  186. package/dest/slashing/index.js +1 -2
  187. package/dest/slashing/serialization.d.ts +2 -6
  188. package/dest/slashing/serialization.d.ts.map +1 -1
  189. package/dest/slashing/serialization.js +0 -60
  190. package/dest/slashing/types.d.ts +4 -90
  191. package/dest/slashing/types.d.ts.map +1 -1
  192. package/dest/slashing/types.js +0 -14
  193. package/dest/slashing/{tally.d.ts → votes.d.ts} +1 -1
  194. package/dest/slashing/{tally.d.ts.map → votes.d.ts.map} +1 -1
  195. package/dest/slashing/{tally.js → votes.js} +1 -1
  196. package/dest/tests/factories.d.ts +3 -10
  197. package/dest/tests/factories.d.ts.map +1 -1
  198. package/dest/tests/factories.js +11 -34
  199. package/dest/tests/mocks.d.ts +1 -1
  200. package/dest/tests/mocks.d.ts.map +1 -1
  201. package/dest/tests/mocks.js +12 -17
  202. package/dest/timetable/index.d.ts +51 -1
  203. package/dest/timetable/index.d.ts.map +1 -1
  204. package/dest/timetable/index.js +204 -14
  205. package/dest/trees/nullifier_leaf.d.ts +2 -1
  206. package/dest/trees/nullifier_leaf.d.ts.map +1 -1
  207. package/dest/trees/nullifier_leaf.js +3 -0
  208. package/dest/tx/block_header.d.ts +2 -2
  209. package/dest/tx/block_header.d.ts.map +1 -1
  210. package/dest/tx/block_header.js +1 -1
  211. package/dest/tx/fee_provider.d.ts +10 -0
  212. package/dest/tx/fee_provider.d.ts.map +1 -0
  213. package/dest/tx/fee_provider.js +1 -0
  214. package/dest/tx/global_variable_builder.d.ts +3 -4
  215. package/dest/tx/global_variable_builder.d.ts.map +1 -1
  216. package/dest/tx/index.d.ts +2 -1
  217. package/dest/tx/index.d.ts.map +1 -1
  218. package/dest/tx/index.js +1 -0
  219. package/dest/tx/indexed_tx_effect.d.ts +1 -1
  220. package/dest/tx/indexed_tx_effect.d.ts.map +1 -1
  221. package/dest/tx/indexed_tx_effect.js +1 -2
  222. package/dest/tx/protocol_contracts.js +2 -2
  223. package/dest/tx/simulated_tx.d.ts +151 -26
  224. package/dest/tx/simulated_tx.d.ts.map +1 -1
  225. package/dest/tx/tx.d.ts +3 -3
  226. package/dest/tx/tx.d.ts.map +1 -1
  227. package/dest/types/shared.d.ts +1 -10
  228. package/dest/types/shared.d.ts.map +1 -1
  229. package/dest/types/shared.js +0 -9
  230. package/dest/vks/verification_key.d.ts +2 -137
  231. package/dest/vks/verification_key.d.ts.map +1 -1
  232. package/dest/vks/verification_key.js +5 -126
  233. package/dest/vks/vk_data.js +1 -1
  234. package/dest/world-state/genesis_data.d.ts +11 -0
  235. package/dest/world-state/genesis_data.d.ts.map +1 -0
  236. package/dest/world-state/genesis_data.js +4 -0
  237. package/dest/world-state/index.d.ts +2 -1
  238. package/dest/world-state/index.d.ts.map +1 -1
  239. package/dest/world-state/index.js +1 -0
  240. package/package.json +11 -10
  241. package/src/abi/abi.ts +14 -67
  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/avm/avm_accumulated_data.ts +6 -6
  248. package/src/avm/avm_circuit_public_inputs.ts +4 -4
  249. package/src/aztec-address/index.ts +4 -10
  250. package/src/block/block_data.ts +3 -4
  251. package/src/block/block_hash.ts +21 -14
  252. package/src/block/l2_block_info.ts +8 -6
  253. package/src/block/l2_block_source.ts +10 -2
  254. package/src/block/l2_block_stream/l2_tips_store_base.ts +25 -13
  255. package/src/block/test/l2_tips_store_test_suite.ts +9 -2
  256. package/src/checkpoint/checkpoint.ts +11 -1
  257. package/src/checkpoint/checkpoint_data.ts +40 -4
  258. package/src/config/chain-config.ts +7 -1
  259. package/src/config/index.ts +1 -0
  260. package/src/config/pipelining-config.ts +31 -0
  261. package/src/config/sequencer-config.ts +17 -4
  262. package/src/contract/contract_address.ts +3 -3
  263. package/src/contract/contract_class_id.ts +2 -2
  264. package/src/contract/index.ts +0 -2
  265. package/src/contract/interfaces/contract_class.ts +2 -82
  266. package/src/contract/private_function.ts +3 -1
  267. package/src/epoch-helpers/index.ts +5 -0
  268. package/src/file-store/factory.ts +13 -4
  269. package/src/file-store/http.ts +29 -10
  270. package/src/file-store/index.ts +1 -0
  271. package/src/gas/README.md +31 -0
  272. package/src/gas/fee_math.ts +120 -0
  273. package/src/gas/gas_fees.ts +12 -4
  274. package/src/gas/index.ts +1 -0
  275. package/src/ha-signing/config.ts +156 -0
  276. package/src/ha-signing/index.ts +29 -0
  277. package/src/ha-signing/local_config.ts +46 -0
  278. package/src/ha-signing/types.ts +126 -0
  279. package/src/hash/hash.ts +27 -0
  280. package/src/interfaces/archiver.ts +3 -1
  281. package/src/interfaces/aztec-node-admin.ts +5 -7
  282. package/src/interfaces/aztec-node.ts +15 -0
  283. package/src/interfaces/l2_logs_source.ts +4 -1
  284. package/src/interfaces/merkle_tree_operations.ts +3 -2
  285. package/src/interfaces/prover-client.ts +2 -5
  286. package/src/interfaces/slasher.ts +0 -6
  287. package/src/interfaces/validator.ts +53 -44
  288. package/src/kernel/claimed_length_array.ts +2 -2
  289. package/src/kernel/hints/private_kernel_reset_hints.ts +2 -5
  290. package/src/kernel/hints/read_request_hints.ts +3 -3
  291. package/src/kernel/padded_side_effects.ts +3 -3
  292. package/src/kernel/private_to_avm_accumulated_data.ts +4 -4
  293. package/src/kernel/private_to_public_accumulated_data.ts +10 -10
  294. package/src/kernel/private_to_rollup_accumulated_data.ts +5 -5
  295. package/src/kv-store/config.ts +36 -0
  296. package/src/kv-store/index.ts +1 -0
  297. package/src/l1-contracts/index.ts +1 -1
  298. package/src/logs/log_id.ts +1 -2
  299. package/src/logs/private_log.ts +1 -1
  300. package/src/logs/public_log.ts +1 -11
  301. package/src/logs/siloed_tag.ts +8 -9
  302. package/src/logs/tag.ts +8 -8
  303. package/src/messaging/l1_to_l2_message_source.ts +3 -1
  304. package/src/p2p/block_proposal.ts +14 -10
  305. package/src/p2p/checkpoint_attestation.ts +5 -9
  306. package/src/p2p/checkpoint_proposal.ts +22 -37
  307. package/src/p2p/gossipable.ts +4 -4
  308. package/src/parity/parity_base_private_inputs.ts +1 -1
  309. package/src/proofs/chonk_proof.ts +90 -12
  310. package/src/rollup/base_rollup_hints.ts +2 -2
  311. package/src/rollup/block_headers_hash.ts +11 -2
  312. package/src/rollup/block_root_rollup_private_inputs.ts +8 -8
  313. package/src/rollup/checkpoint_rollup_public_inputs.ts +2 -2
  314. package/src/rollup/checkpoint_root_rollup_private_inputs.ts +4 -4
  315. package/src/rollup/root_rollup_public_inputs.ts +2 -2
  316. package/src/rollup/tree_snapshot_diff_hints.ts +5 -5
  317. package/src/slashing/index.ts +1 -2
  318. package/src/slashing/serialization.ts +1 -81
  319. package/src/slashing/types.ts +3 -35
  320. package/src/slashing/{tally.ts → votes.ts} +1 -1
  321. package/src/tests/factories.ts +5 -42
  322. package/src/tests/mocks.ts +14 -10
  323. package/src/timetable/index.ts +293 -13
  324. package/src/trees/nullifier_leaf.ts +4 -0
  325. package/src/tx/block_header.ts +2 -2
  326. package/src/tx/fee_provider.ts +10 -0
  327. package/src/tx/global_variable_builder.ts +2 -3
  328. package/src/tx/index.ts +1 -0
  329. package/src/tx/indexed_tx_effect.ts +1 -2
  330. package/src/tx/protocol_contracts.ts +2 -2
  331. package/src/tx/tx.ts +2 -2
  332. package/src/types/shared.ts +0 -10
  333. package/src/vks/verification_key.ts +5 -184
  334. package/src/vks/vk_data.ts +1 -1
  335. package/src/world-state/genesis_data.ts +15 -0
  336. package/src/world-state/index.ts +1 -0
  337. package/dest/abi/mocked_keys.d.ts +0 -2
  338. package/dest/abi/mocked_keys.d.ts.map +0 -1
  339. package/dest/abi/mocked_keys.js +0 -1
  340. package/dest/contract/private_function_membership_proof.d.ts +0 -32
  341. package/dest/contract/private_function_membership_proof.d.ts.map +0 -1
  342. package/dest/contract/private_function_membership_proof.js +0 -124
  343. package/dest/contract/utility_function_membership_proof.d.ts +0 -27
  344. package/dest/contract/utility_function_membership_proof.d.ts.map +0 -1
  345. package/dest/contract/utility_function_membership_proof.js +0 -87
  346. package/dest/l1-contracts/slash_factory.d.ts +0 -45
  347. package/dest/l1-contracts/slash_factory.d.ts.map +0 -1
  348. package/dest/l1-contracts/slash_factory.js +0 -158
  349. package/dest/slashing/empire.d.ts +0 -31
  350. package/dest/slashing/empire.d.ts.map +0 -1
  351. package/dest/slashing/empire.js +0 -87
  352. package/src/abi/mocked_keys.ts +0 -2
  353. package/src/contract/private_function_membership_proof.ts +0 -167
  354. package/src/contract/utility_function_membership_proof.ts +0 -118
  355. package/src/l1-contracts/slash_factory.ts +0 -180
  356. package/src/slashing/empire.ts +0 -104
@@ -162,6 +162,11 @@ export function getProofSubmissionDeadlineTimestamp(
162
162
  return getTimestampForSlot(deadlineSlot, constants);
163
163
  }
164
164
 
165
+ /** Computes the quorum size required for a committee (⌊2n/3⌋ + 1). */
166
+ export function computeQuorum(committeeSize: number): number {
167
+ return Math.floor((committeeSize * 2) / 3) + 1;
168
+ }
169
+
165
170
  /** Returns the timestamp to start building a block for a given L2 slot. Computed as the start timestamp of the slot minus one L1 slot duration. */
166
171
  export function getSlotStartBuildTimestamp(
167
172
  slotNumber: SlotNumber,
@@ -1,7 +1,7 @@
1
1
  import { type Logger, createLogger } from '@aztec/foundation/log';
2
2
 
3
3
  import { GoogleCloudFileStore } from './gcs.js';
4
- import { HttpFileStore } from './http.js';
4
+ import { HttpFileStore, type HttpFileStoreOptions } from './http.js';
5
5
  import type { FileStore, ReadOnlyFileStore } from './interface.js';
6
6
  import { LocalFileStore } from './local.js';
7
7
  import { S3FileStore } from './s3.js';
@@ -59,17 +59,26 @@ export async function createFileStore(
59
59
  }
60
60
  }
61
61
 
62
- export async function createReadOnlyFileStore(config: string, logger?: Logger): Promise<ReadOnlyFileStore>;
63
- export async function createReadOnlyFileStore(config: undefined, logger?: Logger): Promise<undefined>;
62
+ export async function createReadOnlyFileStore(
63
+ config: string,
64
+ logger?: Logger,
65
+ options?: HttpFileStoreOptions,
66
+ ): Promise<ReadOnlyFileStore>;
67
+ export async function createReadOnlyFileStore(
68
+ config: undefined,
69
+ logger?: Logger,
70
+ options?: HttpFileStoreOptions,
71
+ ): Promise<undefined>;
64
72
  export async function createReadOnlyFileStore(
65
73
  config: string | undefined,
66
74
  logger = createLogger('stdlib:file-store'),
75
+ options?: HttpFileStoreOptions,
67
76
  ): Promise<ReadOnlyFileStore | undefined> {
68
77
  if (config === undefined) {
69
78
  return undefined;
70
79
  } else if (config.startsWith('http://') || config.startsWith('https://')) {
71
80
  logger.info(`Creating read-only HTTP file store at ${config}`);
72
- return new HttpFileStore(config, logger);
81
+ return new HttpFileStore(config, logger, options);
73
82
  } else {
74
83
  return await createFileStore(config, logger);
75
84
  }
@@ -10,6 +10,14 @@ import { pipeline } from 'stream/promises';
10
10
 
11
11
  import type { ReadOnlyFileStore } from './interface.js';
12
12
 
13
+ /** Options for configuring HttpFileStore behavior. */
14
+ export interface HttpFileStoreOptions {
15
+ /** Retry backoff intervals in seconds. Empty array disables retries. Default: [1, 1, 3]. */
16
+ retryBackoff?: number[];
17
+ /** Request timeout in milliseconds. Default: no timeout (axios default). */
18
+ timeoutMs?: number;
19
+ }
20
+
13
21
  export class HttpFileStore implements ReadOnlyFileStore {
14
22
  private readonly axiosInstance: AxiosInstance;
15
23
  private readonly fetch: <T>(config: AxiosRequestConfig) => Promise<AxiosResponse<T>>;
@@ -17,17 +25,28 @@ export class HttpFileStore implements ReadOnlyFileStore {
17
25
  constructor(
18
26
  private readonly baseUrl: string,
19
27
  private readonly log: Logger = createLogger('stdlib:http-file-store'),
28
+ options?: HttpFileStoreOptions,
20
29
  ) {
21
- this.axiosInstance = axios.create();
22
- this.fetch = async <T>(config: AxiosRequestConfig) => {
23
- return await retry(
24
- () => this.axiosInstance.request<T>(config),
25
- `Fetching ${config.url}`,
26
- makeBackoff([1, 1, 3]),
27
- this.log,
28
- /*failSilently=*/ true,
29
- );
30
- };
30
+ this.axiosInstance = axios.create({
31
+ ...(options?.timeoutMs !== undefined && { timeout: options.timeoutMs }),
32
+ });
33
+
34
+ const retryBackoff = options?.retryBackoff ?? [1, 1, 3];
35
+ if (retryBackoff.length > 0) {
36
+ this.fetch = async <T>(config: AxiosRequestConfig) => {
37
+ return await retry(
38
+ () => this.axiosInstance.request<T>(config),
39
+ `Fetching ${config.url}`,
40
+ makeBackoff(retryBackoff),
41
+ this.log,
42
+ /*failSilently=*/ true,
43
+ );
44
+ };
45
+ } else {
46
+ this.fetch = async <T>(config: AxiosRequestConfig) => {
47
+ return await this.axiosInstance.request<T>(config);
48
+ };
49
+ }
31
50
  }
32
51
 
33
52
  public async read(pathOrUrl: string): Promise<Buffer> {
@@ -1,2 +1,3 @@
1
1
  export * from './interface.js';
2
2
  export * from './factory.js';
3
+ export { type HttpFileStoreOptions } from './http.js';
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
 
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';
@@ -0,0 +1,156 @@
1
+ import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
2
+ import {
3
+ type ConfigMappingsType,
4
+ booleanConfigHelper,
5
+ getConfigFromMappings,
6
+ getDefaultConfig,
7
+ numberConfigHelper,
8
+ optionalNumberConfigHelper,
9
+ } from '@aztec/foundation/config';
10
+ import { EthAddress } from '@aztec/foundation/eth-address';
11
+ import type { ZodFor } from '@aztec/foundation/schemas';
12
+
13
+ import { z } from 'zod';
14
+
15
+ /**
16
+ * Base signing protection configuration shared by both HA (Postgres) and local (LMDB) signers.
17
+ */
18
+ export interface BaseSignerConfig {
19
+ /** L1 contract addresses (rollup address required) */
20
+ l1Contracts: Pick<L1ContractAddresses, 'rollupAddress'>;
21
+ /** Unique identifier for this node */
22
+ nodeId: string;
23
+ /** How long to wait between polls when a duty is being signed (ms) */
24
+ pollingIntervalMs: number;
25
+ /** Maximum time to wait for a duty being signed to complete (ms) */
26
+ signingTimeoutMs: number;
27
+ /** Maximum age of a stuck duty in ms (defaults to 2x hardcoded Aztec slot duration if not set) */
28
+ maxStuckDutiesAgeMs?: number;
29
+ /** Optional: clean up old duties after this many hours (disabled if not set) */
30
+ cleanupOldDutiesAfterHours?: number;
31
+ }
32
+
33
+ export const baseSignerConfigMappings: ConfigMappingsType<BaseSignerConfig> = {
34
+ l1Contracts: {
35
+ description: 'L1 contract addresses (rollup address required)',
36
+ nested: {
37
+ rollupAddress: {
38
+ description: 'The Ethereum address of the rollup contract (must be set programmatically)',
39
+ parseEnv: (val: string) => EthAddress.fromString(val),
40
+ },
41
+ },
42
+ },
43
+ nodeId: {
44
+ env: 'VALIDATOR_HA_NODE_ID',
45
+ description: 'The unique identifier for this node',
46
+ defaultValue: '',
47
+ },
48
+ pollingIntervalMs: {
49
+ env: 'VALIDATOR_HA_POLLING_INTERVAL_MS',
50
+ description: 'The number of ms to wait between polls when a duty is being signed',
51
+ ...numberConfigHelper(100),
52
+ },
53
+ signingTimeoutMs: {
54
+ env: 'VALIDATOR_HA_SIGNING_TIMEOUT_MS',
55
+ description: 'The maximum time to wait for a duty being signed to complete',
56
+ ...numberConfigHelper(3_000),
57
+ },
58
+ maxStuckDutiesAgeMs: {
59
+ env: 'VALIDATOR_HA_MAX_STUCK_DUTIES_AGE_MS',
60
+ description: 'The maximum age of a stuck duty in ms (defaults to 2x Aztec slot duration)',
61
+ ...optionalNumberConfigHelper(),
62
+ },
63
+ cleanupOldDutiesAfterHours: {
64
+ env: 'VALIDATOR_HA_OLD_DUTIES_MAX_AGE_H',
65
+ description: 'Optional: clean up old duties after this many hours (disabled if not set)',
66
+ ...optionalNumberConfigHelper(),
67
+ },
68
+ };
69
+
70
+ export const BaseSignerConfigSchema = z.object({
71
+ l1Contracts: z.object({ rollupAddress: z.instanceof(EthAddress) }),
72
+ nodeId: z.string(),
73
+ pollingIntervalMs: z.number().min(0),
74
+ signingTimeoutMs: z.number().min(0),
75
+ maxStuckDutiesAgeMs: z.number().min(0).optional(),
76
+ cleanupOldDutiesAfterHours: z.number().min(0).optional(),
77
+ }) satisfies ZodFor<BaseSignerConfig>;
78
+
79
+ /**
80
+ * Configuration for the Validator HA Signer.
81
+ *
82
+ * Extends BaseSignerConfig with a flag to enable HA mode and Postgres connection settings.
83
+ */
84
+ export interface ValidatorHASignerConfig extends BaseSignerConfig {
85
+ /** Whether HA signing / slashing protection is enabled */
86
+ haSigningEnabled: boolean;
87
+ /**
88
+ * PostgreSQL connection string
89
+ * Format: postgresql://user:password@host:port/database
90
+ */
91
+ databaseUrl?: string;
92
+ /** Maximum number of clients in the pool (default: 10) */
93
+ poolMaxCount?: number;
94
+ /** Minimum number of clients in the pool (default: 0) */
95
+ poolMinCount?: number;
96
+ /** Idle timeout in milliseconds (default: 10000) */
97
+ poolIdleTimeoutMs?: number;
98
+ /** Connection timeout in milliseconds (default: 0, no timeout) */
99
+ poolConnectionTimeoutMs?: number;
100
+ }
101
+
102
+ export const validatorHASignerConfigMappings: ConfigMappingsType<ValidatorHASignerConfig> = {
103
+ ...baseSignerConfigMappings,
104
+ haSigningEnabled: {
105
+ env: 'VALIDATOR_HA_SIGNING_ENABLED',
106
+ description: 'Whether HA signing / slashing protection is enabled',
107
+ ...booleanConfigHelper(false),
108
+ },
109
+ databaseUrl: {
110
+ env: 'VALIDATOR_HA_DATABASE_URL',
111
+ description:
112
+ 'PostgreSQL connection string for validator HA signer (format: postgresql://user:password@host:port/database)',
113
+ },
114
+ poolMaxCount: {
115
+ env: 'VALIDATOR_HA_POOL_MAX',
116
+ description: 'Maximum number of clients in the pool',
117
+ ...numberConfigHelper(10),
118
+ },
119
+ poolMinCount: {
120
+ env: 'VALIDATOR_HA_POOL_MIN',
121
+ description: 'Minimum number of clients in the pool',
122
+ ...numberConfigHelper(0),
123
+ },
124
+ poolIdleTimeoutMs: {
125
+ env: 'VALIDATOR_HA_POOL_IDLE_TIMEOUT_MS',
126
+ description: 'Idle timeout in milliseconds',
127
+ ...numberConfigHelper(10_000),
128
+ },
129
+ poolConnectionTimeoutMs: {
130
+ env: 'VALIDATOR_HA_POOL_CONNECTION_TIMEOUT_MS',
131
+ description: 'Connection timeout in milliseconds (0 means no timeout)',
132
+ ...numberConfigHelper(0),
133
+ },
134
+ };
135
+
136
+ export const defaultValidatorHASignerConfig: ValidatorHASignerConfig = getDefaultConfig(
137
+ validatorHASignerConfigMappings,
138
+ );
139
+
140
+ /**
141
+ * Returns the validator HA signer configuration from environment variables.
142
+ * Note: If an environment variable is not set, the default value is used.
143
+ * @returns The validator HA signer configuration.
144
+ */
145
+ export function getConfigEnvVars(): ValidatorHASignerConfig {
146
+ return getConfigFromMappings<ValidatorHASignerConfig>(validatorHASignerConfigMappings);
147
+ }
148
+
149
+ export const ValidatorHASignerConfigSchema = BaseSignerConfigSchema.extend({
150
+ haSigningEnabled: z.boolean(),
151
+ databaseUrl: z.string().optional(),
152
+ poolMaxCount: z.number().min(0).optional(),
153
+ poolMinCount: z.number().min(0).optional(),
154
+ poolIdleTimeoutMs: z.number().min(0).optional(),
155
+ poolConnectionTimeoutMs: z.number().min(0).optional(),
156
+ }) satisfies ZodFor<ValidatorHASignerConfig>;
@@ -0,0 +1,29 @@
1
+ export {
2
+ type BaseSignerConfig,
3
+ BaseSignerConfigSchema,
4
+ baseSignerConfigMappings,
5
+ type ValidatorHASignerConfig,
6
+ ValidatorHASignerConfigSchema,
7
+ defaultValidatorHASignerConfig,
8
+ getConfigEnvVars,
9
+ validatorHASignerConfigMappings,
10
+ } from './config.js';
11
+ export {
12
+ type LocalSignerConfig,
13
+ LocalSignerConfigSchema,
14
+ getLocalSignerConfigEnvVars,
15
+ localSignerConfigMappings,
16
+ } from './local_config.js';
17
+ export {
18
+ DutyType,
19
+ type AttestationSigningContext,
20
+ type BlockProposalSigningContext,
21
+ type CheckpointProposalSigningContext,
22
+ type HAProtectedSigningContext,
23
+ type NoHAProtectionSigningContext,
24
+ type SigningContext,
25
+ type VoteSigningContext,
26
+ getBlockNumberFromSigningContext,
27
+ getCheckpointNumberFromSigningContext,
28
+ isHAProtectedContext,
29
+ } from './types.js';
@@ -0,0 +1,46 @@
1
+ import { type ConfigMappingsType, getConfigFromMappings } from '@aztec/foundation/config';
2
+ import { zodFor } from '@aztec/foundation/schemas';
3
+ import { type DataStoreConfig, dataConfigMappings } from '@aztec/stdlib/kv-store';
4
+
5
+ import { z } from 'zod';
6
+
7
+ import { type BaseSignerConfig, BaseSignerConfigSchema, baseSignerConfigMappings } from './config.js';
8
+
9
+ /**
10
+ * Configuration for local (single-node) slashing protection.
11
+ *
12
+ * Combines the base signing protection fields (shared with HA mode) with
13
+ * DataStoreConfig for the local LMDB backing store, plus a per-store map-size
14
+ * override. Used when HA signing is disabled.
15
+ */
16
+ export type LocalSignerConfig = BaseSignerConfig &
17
+ DataStoreConfig & {
18
+ /** Maximum size of the local signing-protection LMDB store in KB. Overwrites the general dataStoreMapSizeKb. */
19
+ signingProtectionMapSizeKb?: number;
20
+ };
21
+
22
+ export const localSignerConfigMappings: ConfigMappingsType<LocalSignerConfig> = {
23
+ ...baseSignerConfigMappings,
24
+ ...dataConfigMappings,
25
+ signingProtectionMapSizeKb: {
26
+ env: 'SIGNING_PROTECTION_MAP_SIZE_KB',
27
+ description:
28
+ 'Maximum size of the local signing-protection LMDB store in KB. Overwrites the general dataStoreMapSizeKb.',
29
+ parseEnv: (val: string) => +val,
30
+ },
31
+ };
32
+
33
+ export const LocalSignerConfigSchema = zodFor<LocalSignerConfig>()(
34
+ BaseSignerConfigSchema.extend({
35
+ dataDirectory: z.string().optional(),
36
+ dataStoreMapSizeKb: z.number(),
37
+ signingProtectionMapSizeKb: z.number().optional(),
38
+ }),
39
+ );
40
+
41
+ /**
42
+ * Returns the local signer configuration from environment variables.
43
+ */
44
+ export function getLocalSignerConfigEnvVars(): LocalSignerConfig {
45
+ return getConfigFromMappings<LocalSignerConfig>(localSignerConfigMappings);
46
+ }
@@ -0,0 +1,126 @@
1
+ import {
2
+ BlockNumber,
3
+ CheckpointNumber,
4
+ type IndexWithinCheckpoint,
5
+ type SlotNumber,
6
+ } from '@aztec/foundation/branded-types';
7
+
8
+ /**
9
+ * Type of validator duty being performed
10
+ */
11
+ export enum DutyType {
12
+ BLOCK_PROPOSAL = 'BLOCK_PROPOSAL',
13
+ CHECKPOINT_PROPOSAL = 'CHECKPOINT_PROPOSAL',
14
+ ATTESTATION = 'ATTESTATION',
15
+ ATTESTATIONS_AND_SIGNERS = 'ATTESTATIONS_AND_SIGNERS',
16
+ GOVERNANCE_VOTE = 'GOVERNANCE_VOTE',
17
+ SLASHING_VOTE = 'SLASHING_VOTE',
18
+ AUTH_REQUEST = 'AUTH_REQUEST',
19
+ TXS = 'TXS',
20
+ }
21
+
22
+ /**
23
+ * Signing context for block proposals.
24
+ * Includes both the block number and the checkpoint number the block belongs to.
25
+ */
26
+ export interface BlockProposalSigningContext {
27
+ slot: SlotNumber;
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;
33
+ }
34
+
35
+ /**
36
+ * Signing context for checkpoint proposals.
37
+ * Includes the checkpoint number being proposed, but not a block number.
38
+ */
39
+ export interface CheckpointProposalSigningContext {
40
+ slot: SlotNumber;
41
+ checkpointNumber: CheckpointNumber;
42
+ dutyType: DutyType.CHECKPOINT_PROPOSAL;
43
+ }
44
+
45
+ /**
46
+ * Signing context for attestation duties (checkpoint attestations).
47
+ * Includes the checkpoint number when available (from proposal validation).
48
+ */
49
+ export interface AttestationSigningContext {
50
+ slot: SlotNumber;
51
+ checkpointNumber: CheckpointNumber;
52
+ dutyType: DutyType.ATTESTATION | DutyType.ATTESTATIONS_AND_SIGNERS;
53
+ }
54
+
55
+ /**
56
+ * Signing context for governance/slashing votes which only need slot for HA protection.
57
+ */
58
+ export interface VoteSigningContext {
59
+ slot: SlotNumber;
60
+ dutyType: DutyType.GOVERNANCE_VOTE | DutyType.SLASHING_VOTE;
61
+ }
62
+
63
+ /**
64
+ * Signing context for duties which don't require slot/blockNumber
65
+ * as they don't need HA protection (AUTH_REQUEST, TXS).
66
+ */
67
+ export interface NoHAProtectionSigningContext {
68
+ dutyType: DutyType.AUTH_REQUEST | DutyType.TXS;
69
+ }
70
+
71
+ /**
72
+ * Signing contexts that require HA protection (excludes AUTH_REQUEST and TXS).
73
+ * Used by the HA signer's signWithProtection method.
74
+ */
75
+ export type HAProtectedSigningContext =
76
+ | BlockProposalSigningContext
77
+ | CheckpointProposalSigningContext
78
+ | AttestationSigningContext
79
+ | VoteSigningContext;
80
+
81
+ /**
82
+ * Context required for slashing protection during signing operations.
83
+ * Uses discriminated union to enforce type safety:
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
89
+ */
90
+ export type SigningContext = HAProtectedSigningContext | NoHAProtectionSigningContext;
91
+
92
+ /**
93
+ * Type guard to check if a SigningContext requires HA protection.
94
+ * Returns true for contexts that need HA protection, false for AUTH_REQUEST and TXS.
95
+ */
96
+ export function isHAProtectedContext(context: SigningContext): context is HAProtectedSigningContext {
97
+ return context.dutyType !== DutyType.AUTH_REQUEST && context.dutyType !== DutyType.TXS;
98
+ }
99
+
100
+ /**
101
+ * Gets the block number from a signing context.
102
+ * Only BLOCK_PROPOSAL duties carry a block number; all others return BlockNumber(0).
103
+ */
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 {
117
+ if (
118
+ context.dutyType === DutyType.BLOCK_PROPOSAL ||
119
+ context.dutyType === DutyType.CHECKPOINT_PROPOSAL ||
120
+ context.dutyType === DutyType.ATTESTATION ||
121
+ context.dutyType === DutyType.ATTESTATIONS_AND_SIGNERS
122
+ ) {
123
+ return context.checkpointNumber;
124
+ }
125
+ return CheckpointNumber(0);
126
+ }