@aztec/stdlib 0.0.1-commit.6ebe706df → 0.0.1-commit.71324e566

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 (273) 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/avm.d.ts +300 -300
  18. package/dest/avm/revert_code.d.ts +8 -18
  19. package/dest/avm/revert_code.d.ts.map +1 -1
  20. package/dest/avm/revert_code.js +15 -30
  21. package/dest/aztec-address/index.d.ts +3 -6
  22. package/dest/aztec-address/index.d.ts.map +1 -1
  23. package/dest/aztec-address/index.js +2 -4
  24. package/dest/block/block_data.d.ts +8 -8
  25. package/dest/block/block_data.d.ts.map +1 -1
  26. package/dest/block/block_data.js +2 -2
  27. package/dest/block/block_hash.d.ts +11 -10
  28. package/dest/block/block_hash.d.ts.map +1 -1
  29. package/dest/block/block_hash.js +10 -9
  30. package/dest/block/l2_block_info.d.ts +6 -5
  31. package/dest/block/l2_block_info.d.ts.map +1 -1
  32. package/dest/block/l2_block_info.js +6 -5
  33. package/dest/block/l2_block_source.d.ts +80 -3
  34. package/dest/block/l2_block_source.d.ts.map +1 -1
  35. package/dest/block/l2_block_source.js +1 -0
  36. package/dest/block/l2_block_stream/interfaces.d.ts +6 -3
  37. package/dest/block/l2_block_stream/interfaces.d.ts.map +1 -1
  38. package/dest/block/l2_block_stream/l2_tips_store_base.d.ts +1 -1
  39. package/dest/block/l2_block_stream/l2_tips_store_base.d.ts.map +1 -1
  40. package/dest/block/l2_block_stream/l2_tips_store_base.js +18 -5
  41. package/dest/block/test/l2_tips_store_test_suite.d.ts +1 -1
  42. package/dest/block/test/l2_tips_store_test_suite.d.ts.map +1 -1
  43. package/dest/block/test/l2_tips_store_test_suite.js +4 -3
  44. package/dest/checkpoint/checkpoint.d.ts +7 -1
  45. package/dest/checkpoint/checkpoint.d.ts.map +1 -1
  46. package/dest/checkpoint/checkpoint.js +9 -1
  47. package/dest/checkpoint/checkpoint_data.d.ts +71 -5
  48. package/dest/checkpoint/checkpoint_data.d.ts.map +1 -1
  49. package/dest/checkpoint/checkpoint_data.js +10 -0
  50. package/dest/config/chain-config.d.ts +1 -1
  51. package/dest/config/chain-config.d.ts.map +1 -1
  52. package/dest/config/chain-config.js +7 -1
  53. package/dest/config/sequencer-config.d.ts +2 -2
  54. package/dest/config/sequencer-config.d.ts.map +1 -1
  55. package/dest/config/sequencer-config.js +10 -3
  56. package/dest/epoch-helpers/index.d.ts +5 -1
  57. package/dest/epoch-helpers/index.d.ts.map +1 -1
  58. package/dest/epoch-helpers/index.js +6 -0
  59. package/dest/file-store/factory.d.ts +4 -3
  60. package/dest/file-store/factory.d.ts.map +1 -1
  61. package/dest/file-store/factory.js +2 -2
  62. package/dest/file-store/http.d.ts +9 -2
  63. package/dest/file-store/http.d.ts.map +1 -1
  64. package/dest/file-store/http.js +20 -9
  65. package/dest/file-store/index.d.ts +2 -1
  66. package/dest/file-store/index.d.ts.map +1 -1
  67. package/dest/gas/fee_math.d.ts +49 -0
  68. package/dest/gas/fee_math.d.ts.map +1 -0
  69. package/dest/gas/fee_math.js +80 -0
  70. package/dest/gas/gas_fees.d.ts +1 -1
  71. package/dest/gas/gas_fees.d.ts.map +1 -1
  72. package/dest/gas/gas_fees.js +10 -1
  73. package/dest/gas/gas_settings.d.ts +40 -3
  74. package/dest/gas/gas_settings.d.ts.map +1 -1
  75. package/dest/gas/gas_settings.js +50 -6
  76. package/dest/gas/index.d.ts +2 -1
  77. package/dest/gas/index.d.ts.map +1 -1
  78. package/dest/gas/index.js +1 -0
  79. package/dest/ha-signing/index.d.ts +2 -2
  80. package/dest/ha-signing/index.d.ts.map +1 -1
  81. package/dest/ha-signing/index.js +1 -1
  82. package/dest/ha-signing/local_config.js +1 -1
  83. package/dest/ha-signing/types.d.ts +37 -32
  84. package/dest/ha-signing/types.d.ts.map +1 -1
  85. package/dest/ha-signing/types.js +13 -6
  86. package/dest/hash/hash.d.ts +4 -1
  87. package/dest/hash/hash.d.ts.map +1 -1
  88. package/dest/hash/hash.js +5 -0
  89. package/dest/interfaces/archiver.d.ts +1 -1
  90. package/dest/interfaces/archiver.d.ts.map +1 -1
  91. package/dest/interfaces/archiver.js +3 -1
  92. package/dest/interfaces/aztec-node-admin.d.ts +4 -14
  93. package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
  94. package/dest/interfaces/aztec-node-admin.js +3 -3
  95. package/dest/interfaces/aztec-node-debug.d.ts +21 -0
  96. package/dest/interfaces/aztec-node-debug.d.ts.map +1 -0
  97. package/dest/interfaces/aztec-node-debug.js +18 -0
  98. package/dest/interfaces/aztec-node.d.ts +10 -1
  99. package/dest/interfaces/aztec-node.d.ts.map +1 -1
  100. package/dest/interfaces/aztec-node.js +2 -0
  101. package/dest/interfaces/client.d.ts +2 -1
  102. package/dest/interfaces/client.d.ts.map +1 -1
  103. package/dest/interfaces/client.js +1 -0
  104. package/dest/interfaces/merkle_tree_operations.d.ts +4 -3
  105. package/dest/interfaces/merkle_tree_operations.d.ts.map +1 -1
  106. package/dest/interfaces/prover-client.d.ts +1 -1
  107. package/dest/interfaces/prover-client.d.ts.map +1 -1
  108. package/dest/interfaces/prover-client.js +0 -3
  109. package/dest/interfaces/slasher.d.ts +1 -10
  110. package/dest/interfaces/slasher.d.ts.map +1 -1
  111. package/dest/interfaces/slasher.js +0 -2
  112. package/dest/interfaces/validator.d.ts +9 -20
  113. package/dest/interfaces/validator.d.ts.map +1 -1
  114. package/dest/interfaces/validator.js +0 -1
  115. package/dest/l1-contracts/index.d.ts +2 -2
  116. package/dest/l1-contracts/index.d.ts.map +1 -1
  117. package/dest/l1-contracts/index.js +1 -1
  118. package/dest/logs/extended_directional_app_tagging_secret.d.ts +4 -4
  119. package/dest/logs/extended_directional_app_tagging_secret.d.ts.map +1 -1
  120. package/dest/logs/extended_directional_app_tagging_secret.js +12 -5
  121. package/dest/logs/log_id.d.ts +1 -1
  122. package/dest/logs/log_id.d.ts.map +1 -1
  123. package/dest/logs/log_id.js +1 -2
  124. package/dest/logs/shared_secret_derivation.d.ts +11 -10
  125. package/dest/logs/shared_secret_derivation.d.ts.map +1 -1
  126. package/dest/logs/shared_secret_derivation.js +15 -9
  127. package/dest/logs/siloed_tag.d.ts +8 -7
  128. package/dest/logs/siloed_tag.d.ts.map +1 -1
  129. package/dest/logs/siloed_tag.js +11 -3
  130. package/dest/logs/tag.d.ts +5 -6
  131. package/dest/logs/tag.d.ts.map +1 -1
  132. package/dest/logs/tag.js +4 -0
  133. package/dest/note/note_dao.d.ts +1 -1
  134. package/dest/note/note_dao.d.ts.map +1 -1
  135. package/dest/note/note_dao.js +1 -4
  136. package/dest/p2p/block_proposal.d.ts +6 -8
  137. package/dest/p2p/block_proposal.d.ts.map +1 -1
  138. package/dest/p2p/block_proposal.js +4 -9
  139. package/dest/p2p/checkpoint_attestation.d.ts +4 -6
  140. package/dest/p2p/checkpoint_attestation.d.ts.map +1 -1
  141. package/dest/p2p/checkpoint_attestation.js +2 -7
  142. package/dest/p2p/checkpoint_proposal.d.ts +8 -10
  143. package/dest/p2p/checkpoint_proposal.d.ts.map +1 -1
  144. package/dest/p2p/checkpoint_proposal.js +5 -24
  145. package/dest/p2p/gossipable.d.ts +4 -4
  146. package/dest/p2p/gossipable.d.ts.map +1 -1
  147. package/dest/slashing/index.d.ts +2 -3
  148. package/dest/slashing/index.d.ts.map +1 -1
  149. package/dest/slashing/index.js +1 -2
  150. package/dest/slashing/serialization.d.ts +2 -6
  151. package/dest/slashing/serialization.d.ts.map +1 -1
  152. package/dest/slashing/serialization.js +0 -60
  153. package/dest/slashing/types.d.ts +4 -90
  154. package/dest/slashing/types.d.ts.map +1 -1
  155. package/dest/slashing/types.js +0 -14
  156. package/dest/slashing/{tally.d.ts → votes.d.ts} +1 -1
  157. package/dest/slashing/{tally.d.ts.map → votes.d.ts.map} +1 -1
  158. package/dest/slashing/{tally.js → votes.js} +1 -1
  159. package/dest/tests/factories.d.ts +1 -1
  160. package/dest/tests/factories.d.ts.map +1 -1
  161. package/dest/tests/factories.js +11 -1
  162. package/dest/tests/mocks.d.ts +1 -1
  163. package/dest/tests/mocks.d.ts.map +1 -1
  164. package/dest/tests/mocks.js +14 -19
  165. package/dest/timetable/index.d.ts +51 -1
  166. package/dest/timetable/index.d.ts.map +1 -1
  167. package/dest/timetable/index.js +204 -14
  168. package/dest/tx/block_header.d.ts +2 -2
  169. package/dest/tx/block_header.d.ts.map +1 -1
  170. package/dest/tx/block_header.js +1 -1
  171. package/dest/tx/fee_provider.d.ts +10 -0
  172. package/dest/tx/fee_provider.d.ts.map +1 -0
  173. package/dest/tx/fee_provider.js +1 -0
  174. package/dest/tx/global_variable_builder.d.ts +3 -4
  175. package/dest/tx/global_variable_builder.d.ts.map +1 -1
  176. package/dest/tx/index.d.ts +2 -1
  177. package/dest/tx/index.d.ts.map +1 -1
  178. package/dest/tx/index.js +1 -0
  179. package/dest/tx/indexed_tx_effect.d.ts +1 -1
  180. package/dest/tx/indexed_tx_effect.d.ts.map +1 -1
  181. package/dest/tx/indexed_tx_effect.js +1 -2
  182. package/dest/tx/simulated_tx.d.ts +4 -4
  183. package/dest/tx/simulated_tx.d.ts.map +1 -1
  184. package/dest/tx/simulated_tx.js +3 -3
  185. package/dest/tx/tx.d.ts +3 -3
  186. package/dest/tx/tx.d.ts.map +1 -1
  187. package/dest/tx/tx_receipt.d.ts +8 -4
  188. package/dest/tx/tx_receipt.d.ts.map +1 -1
  189. package/dest/tx/tx_receipt.js +8 -15
  190. package/dest/world-state/genesis_data.d.ts +11 -0
  191. package/dest/world-state/genesis_data.d.ts.map +1 -0
  192. package/dest/world-state/genesis_data.js +4 -0
  193. package/dest/world-state/index.d.ts +2 -1
  194. package/dest/world-state/index.d.ts.map +1 -1
  195. package/dest/world-state/index.js +1 -0
  196. package/package.json +8 -8
  197. package/src/abi/authorization_selector.ts +2 -8
  198. package/src/abi/encoder.ts +42 -6
  199. package/src/abi/event_selector.ts +2 -8
  200. package/src/abi/function_selector.ts +3 -12
  201. package/src/abi/note_selector.ts +3 -12
  202. package/src/abi/selector.ts +1 -1
  203. package/src/avm/revert_code.ts +25 -39
  204. package/src/aztec-address/index.ts +4 -10
  205. package/src/block/block_data.ts +3 -4
  206. package/src/block/block_hash.ts +21 -14
  207. package/src/block/l2_block_info.ts +8 -6
  208. package/src/block/l2_block_source.ts +10 -2
  209. package/src/block/l2_block_stream/interfaces.ts +6 -2
  210. package/src/block/l2_block_stream/l2_tips_store_base.ts +25 -13
  211. package/src/block/test/l2_tips_store_test_suite.ts +9 -2
  212. package/src/checkpoint/checkpoint.ts +11 -1
  213. package/src/checkpoint/checkpoint_data.ts +40 -4
  214. package/src/config/chain-config.ts +7 -1
  215. package/src/config/sequencer-config.ts +14 -4
  216. package/src/epoch-helpers/index.ts +13 -0
  217. package/src/file-store/factory.ts +13 -4
  218. package/src/file-store/http.ts +29 -10
  219. package/src/file-store/index.ts +1 -0
  220. package/src/gas/README.md +31 -0
  221. package/src/gas/fee_math.ts +120 -0
  222. package/src/gas/gas_fees.ts +12 -4
  223. package/src/gas/gas_settings.ts +65 -12
  224. package/src/gas/index.ts +1 -0
  225. package/src/ha-signing/index.ts +3 -1
  226. package/src/ha-signing/local_config.ts +1 -1
  227. package/src/ha-signing/types.ts +48 -34
  228. package/src/hash/hash.ts +5 -0
  229. package/src/interfaces/archiver.ts +3 -1
  230. package/src/interfaces/aztec-node-admin.ts +5 -7
  231. package/src/interfaces/aztec-node-debug.ts +40 -0
  232. package/src/interfaces/aztec-node.ts +15 -0
  233. package/src/interfaces/client.ts +1 -0
  234. package/src/interfaces/merkle_tree_operations.ts +3 -2
  235. package/src/interfaces/prover-client.ts +2 -5
  236. package/src/interfaces/slasher.ts +0 -6
  237. package/src/interfaces/validator.ts +16 -13
  238. package/src/l1-contracts/index.ts +1 -1
  239. package/src/logs/extended_directional_app_tagging_secret.ts +19 -8
  240. package/src/logs/log_id.ts +1 -2
  241. package/src/logs/shared_secret_derivation.ts +21 -10
  242. package/src/logs/siloed_tag.ts +15 -11
  243. package/src/logs/tag.ts +8 -8
  244. package/src/note/note_dao.ts +1 -4
  245. package/src/p2p/block_proposal.ts +13 -9
  246. package/src/p2p/checkpoint_attestation.ts +5 -9
  247. package/src/p2p/checkpoint_proposal.ts +21 -36
  248. package/src/p2p/gossipable.ts +4 -4
  249. package/src/slashing/index.ts +1 -2
  250. package/src/slashing/serialization.ts +1 -81
  251. package/src/slashing/types.ts +3 -35
  252. package/src/slashing/{tally.ts → votes.ts} +1 -1
  253. package/src/tests/factories.ts +5 -1
  254. package/src/tests/mocks.ts +16 -12
  255. package/src/timetable/index.ts +293 -13
  256. package/src/tx/block_header.ts +2 -2
  257. package/src/tx/fee_provider.ts +10 -0
  258. package/src/tx/global_variable_builder.ts +2 -3
  259. package/src/tx/index.ts +1 -0
  260. package/src/tx/indexed_tx_effect.ts +1 -2
  261. package/src/tx/simulated_tx.ts +6 -2
  262. package/src/tx/tx.ts +2 -2
  263. package/src/tx/tx_receipt.ts +11 -14
  264. package/src/world-state/genesis_data.ts +15 -0
  265. package/src/world-state/index.ts +1 -0
  266. package/dest/l1-contracts/slash_factory.d.ts +0 -45
  267. package/dest/l1-contracts/slash_factory.d.ts.map +0 -1
  268. package/dest/l1-contracts/slash_factory.js +0 -158
  269. package/dest/slashing/empire.d.ts +0 -31
  270. package/dest/slashing/empire.d.ts.map +0 -1
  271. package/dest/slashing/empire.js +0 -87
  272. package/src/l1-contracts/slash_factory.ts +0 -180
  273. package/src/slashing/empire.ts +0 -104
@@ -2,10 +2,14 @@ import type { PublishedCheckpoint } from '../../checkpoint/published_checkpoint.
2
2
  import type { L2Block } from '../l2_block.js';
3
3
  import type { CheckpointId, L2BlockId, L2Tips } from '../l2_block_source.js';
4
4
 
5
+ /** Provides the current chain tips. Implemented by world-state, l2-tips-store, and AztecNode. */
6
+ export interface L2TipsProvider {
7
+ getL2Tips(): Promise<L2Tips>;
8
+ }
9
+
5
10
  /** Interface to the local view of the chain. Implemented by world-state and l2-tips-store. */
6
- export interface L2BlockStreamLocalDataProvider {
11
+ export interface L2BlockStreamLocalDataProvider extends L2TipsProvider {
7
12
  getL2BlockHash(number: number): Promise<string | undefined>;
8
- getL2Tips(): Promise<L2Tips>;
9
13
  }
10
14
 
11
15
  /** Interface to a handler of events emitted. */
@@ -1,7 +1,7 @@
1
- import { GENESIS_BLOCK_HEADER_HASH } from '@aztec/constants';
2
1
  import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
3
2
 
4
3
  import type { PublishedCheckpoint } from '../../checkpoint/published_checkpoint.js';
4
+ import { GENESIS_BLOCK_HEADER_HASH } from '../block_hash.js';
5
5
  import type { L2Block } from '../l2_block.js';
6
6
  import {
7
7
  type CheckpointId,
@@ -66,24 +66,29 @@ export abstract class L2TipsStoreBase implements L2BlockStreamEventHandler, L2Bl
66
66
 
67
67
  public getL2Tips(): Promise<L2Tips> {
68
68
  return this.runInTransaction(async () => {
69
- const [proposedBlockId, finalizedBlockId, provenBlockId, checkpointedBlockId] = await Promise.all([
70
- this.getBlockId('proposed'),
71
- this.getBlockId('finalized'),
72
- this.getBlockId('proven'),
73
- this.getBlockId('checkpointed'),
74
- ]);
75
-
76
- const [finalizedCheckpointId, provenCheckpointId, checkpointedCheckpointId] = await Promise.all([
77
- this.getCheckpointId('finalized'),
78
- this.getCheckpointId('proven'),
79
- this.getCheckpointId('checkpointed'),
80
- ]);
69
+ const [proposedBlockId, finalizedBlockId, provenBlockId, checkpointedBlockId, proposedCheckpointBlockId] =
70
+ await Promise.all([
71
+ this.getBlockId('proposed'),
72
+ this.getBlockId('finalized'),
73
+ this.getBlockId('proven'),
74
+ this.getBlockId('checkpointed'),
75
+ this.getBlockId('proposedCheckpoint'),
76
+ ]);
77
+
78
+ const [finalizedCheckpointId, provenCheckpointId, checkpointedCheckpointId, proposedCheckpointId] =
79
+ await Promise.all([
80
+ this.getCheckpointId('finalized'),
81
+ this.getCheckpointId('proven'),
82
+ this.getCheckpointId('checkpointed'),
83
+ this.getCheckpointId('proposedCheckpoint'),
84
+ ]);
81
85
 
82
86
  return {
83
87
  proposed: proposedBlockId,
84
88
  finalized: { block: finalizedBlockId, checkpoint: finalizedCheckpointId },
85
89
  proven: { block: provenBlockId, checkpoint: provenCheckpointId },
86
90
  checkpointed: { block: checkpointedBlockId, checkpoint: checkpointedCheckpointId },
91
+ proposedCheckpoint: { block: proposedCheckpointBlockId, checkpoint: proposedCheckpointId },
87
92
  };
88
93
  });
89
94
  }
@@ -164,6 +169,12 @@ export abstract class L2TipsStoreBase implements L2BlockStreamEventHandler, L2Bl
164
169
  await this.runInTransaction(async () => {
165
170
  await this.saveTag('checkpointed', event.block);
166
171
  await this.saveCheckpoint(event.checkpoint);
172
+ // proposedCheckpoint is always >= checkpointed. If checkpointed has caught up
173
+ // or surpassed it, advance proposedCheckpoint to match.
174
+ const proposedCheckpointBlock = await this.getBlockId('proposedCheckpoint');
175
+ if (event.block.number > proposedCheckpointBlock.number) {
176
+ await this.saveTag('proposedCheckpoint', event.block);
177
+ }
167
178
  });
168
179
  }
169
180
 
@@ -174,6 +185,7 @@ export abstract class L2TipsStoreBase implements L2BlockStreamEventHandler, L2Bl
174
185
  await this.runInTransaction(async () => {
175
186
  await this.saveTag('proposed', event.block);
176
187
  await this.saveTag('checkpointed', event.block);
188
+ await this.saveTag('proposedCheckpoint', event.block);
177
189
  const storeProven = await this.getBlockId('proven');
178
190
  if (storeProven.number > event.block.number) {
179
191
  await this.saveTag('proven', event.block);
@@ -1,4 +1,3 @@
1
- import { GENESIS_BLOCK_HEADER_HASH } from '@aztec/constants';
2
1
  import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
3
2
  import { times } from '@aztec/foundation/collection';
4
3
  import { Fr } from '@aztec/foundation/curves/bn254';
@@ -13,6 +12,7 @@ import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/
13
12
 
14
13
  import { jestExpect as expect } from '@jest/expect';
15
14
 
15
+ import { GENESIS_BLOCK_HEADER_HASH } from '../block_hash.js';
16
16
  import type { L2TipsStore } from '../l2_block_stream/index.js';
17
17
 
18
18
  export function testL2TipsStore(makeTipsStore: () => Promise<L2TipsStore>) {
@@ -67,11 +67,18 @@ export function testL2TipsStore(makeTipsStore: () => Promise<L2TipsStore>) {
67
67
  checkpoint: makeCheckpointIdForBlock(blockNumber),
68
68
  });
69
69
 
70
- const makeTips = (proposed: number, proven: number, finalized: number, checkpointed: number = 0) => ({
70
+ const makeTips = (
71
+ proposed: number,
72
+ proven: number,
73
+ finalized: number,
74
+ checkpointed: number = 0,
75
+ proposedCheckpoint: number = 0,
76
+ ) => ({
71
77
  proposed: makeTip(proposed),
72
78
  proven: makeTipId(proven),
73
79
  finalized: makeTipId(finalized),
74
80
  checkpointed: makeTipId(checkpointed),
81
+ proposedCheckpoint: makeTipId(proposedCheckpoint),
75
82
  });
76
83
 
77
84
  const makeCheckpoint = async (checkpointNumber: number, blocks: L2Block[]): Promise<PublishedCheckpoint> => {
@@ -100,7 +100,16 @@ export class Checkpoint {
100
100
  * checkpoints up to and including this one in the epoch.
101
101
  */
102
102
  public getCheckpointOutHash(): Fr {
103
- const msgs = this.blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs));
103
+ return Checkpoint.getCheckpointOutHash(this.blocks);
104
+ }
105
+
106
+ /**
107
+ * Returns the out hash computed from all l2-to-l1 messages in this checkpoint.
108
+ * Note: This value is different from the out hash in the header, which is the **accumulated** out hash over all
109
+ * checkpoints up to and including this one in the epoch.
110
+ */
111
+ static getCheckpointOutHash(blocks: L2Block[]): Fr {
112
+ const msgs = blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs));
104
113
  return computeCheckpointOutHash(msgs);
105
114
  }
106
115
 
@@ -165,6 +174,7 @@ export class Checkpoint {
165
174
  let lastArchive = previousArchive;
166
175
  for (let i = 0; i < numBlocks; i++) {
167
176
  const block = await L2Block.random(BlockNumber(startBlockNumber + i), {
177
+ checkpointNumber,
168
178
  indexWithinCheckpoint: IndexWithinCheckpoint(i),
169
179
  ...options,
170
180
  ...(lastArchive ? { lastArchive } : {}),
@@ -14,18 +14,54 @@ import { CheckpointHeader } from '../rollup/checkpoint_header.js';
14
14
  import { AppendOnlyTreeSnapshot } from '../trees/append_only_tree_snapshot.js';
15
15
  import { L1PublishedData } from './published_checkpoint.js';
16
16
 
17
- /** Lightweight checkpoint metadata without full block data. */
18
- export type CheckpointData = {
17
+ /** Base type for checkpoint data */
18
+ export type CommonCheckpointData = {
19
19
  checkpointNumber: CheckpointNumber;
20
20
  header: CheckpointHeader;
21
- archive: AppendOnlyTreeSnapshot;
22
- checkpointOutHash: Fr;
23
21
  startBlock: BlockNumber;
24
22
  blockCount: number;
23
+ };
24
+
25
+ /** Data stored with checkpoint data after publishing on l1 */
26
+ export type L1EnrichedCheckpointData = {
25
27
  attestations: CommitteeAttestation[];
26
28
  l1: L1PublishedData;
27
29
  };
28
30
 
31
+ /** Data stored alongside checkpoint data in storage */
32
+ export type StorageEnrichedCheckpointData = {
33
+ archive: AppendOnlyTreeSnapshot;
34
+ checkpointOutHash: Fr;
35
+ };
36
+
37
+ /** Data stored only with proposed checkpoint data */
38
+ export type ProposedOnlyCheckpointData = {
39
+ totalManaUsed: bigint;
40
+ feeAssetPriceModifier: bigint;
41
+ };
42
+
43
+ /** Lightweight checkpoint metadata without full block data. */
44
+ export type CheckpointData = CommonCheckpointData & StorageEnrichedCheckpointData & L1EnrichedCheckpointData;
45
+
46
+ /** Input for setting a proposed checkpoint. The archive and checkpointOutHash are computed
47
+ * internally by the block store from the stored blocks. */
48
+ export type ProposedCheckpointInput = CommonCheckpointData & ProposedOnlyCheckpointData;
49
+
50
+ /** Full data for a proposed checkpoint (proposed but not yet L1-confirmed).
51
+ * Includes fee-relevant fields used during pipelining to compute the fee header override. */
52
+ export type ProposedCheckpointData = ProposedCheckpointInput & StorageEnrichedCheckpointData;
53
+
54
+ export const ProposedCheckpointDataSchema = z.object({
55
+ checkpointNumber: CheckpointNumberSchema,
56
+ header: CheckpointHeader.schema,
57
+ archive: AppendOnlyTreeSnapshot.schema,
58
+ checkpointOutHash: schemas.Fr,
59
+ startBlock: BlockNumberSchema,
60
+ blockCount: z.number(),
61
+ totalManaUsed: schemas.BigInt,
62
+ feeAssetPriceModifier: schemas.BigInt,
63
+ });
64
+
29
65
  export const CheckpointDataSchema = z
30
66
  .object({
31
67
  checkpointNumber: CheckpointNumberSchema,
@@ -21,7 +21,13 @@ export const chainConfigMappings: ConfigMappingsType<ChainConfig> = {
21
21
  rollupVersion: {
22
22
  env: 'ROLLUP_VERSION',
23
23
  description: 'The version of the rollup.',
24
- parseEnv: (val: string) => (Number.isSafeInteger(parseInt(val, 10)) ? parseInt(val, 10) : undefined),
24
+ parseEnv: (val: string) => {
25
+ const parsed = parseInt(val, 10);
26
+ if (!Number.isSafeInteger(parsed)) {
27
+ throw new Error(`Invalid rollup version: ${val}`);
28
+ }
29
+ return parsed;
30
+ },
25
31
  },
26
32
  l1Contracts: {
27
33
  description: 'The deployed L1 contract addresses',
@@ -1,6 +1,7 @@
1
1
  import type { ConfigMappingsType } from '@aztec/foundation/config';
2
2
 
3
3
  import type { SequencerConfig } from '../interfaces/configs.js';
4
+ import { DEFAULT_P2P_PROPAGATION_TIME } from '../timetable/index.js';
4
5
 
5
6
  /** Default maximum number of transactions per block. */
6
7
  export const DEFAULT_MAX_TXS_PER_BLOCK = 32;
@@ -12,26 +13,35 @@ export const DEFAULT_MAX_TXS_PER_BLOCK = 32;
12
13
  * to avoid duplication.
13
14
  */
14
15
  export const sharedSequencerConfigMappings: ConfigMappingsType<
15
- Pick<SequencerConfig, 'blockDurationMs' | 'expectedBlockProposalsPerSlot' | 'maxTxsPerBlock'>
16
+ Pick<
17
+ SequencerConfig,
18
+ 'blockDurationMs' | 'expectedBlockProposalsPerSlot' | 'maxTxsPerBlock' | 'attestationPropagationTime'
19
+ >
16
20
  > = {
17
21
  blockDurationMs: {
18
22
  env: 'SEQ_BLOCK_DURATION_MS',
19
23
  description:
20
24
  'Duration per block in milliseconds when building multiple blocks per slot. ' +
21
25
  'If undefined (default), builds a single block per slot using the full slot duration.',
22
- parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
26
+ parseEnv: (val: string) => parseInt(val, 10),
23
27
  },
24
28
  expectedBlockProposalsPerSlot: {
25
29
  env: 'SEQ_EXPECTED_BLOCK_PROPOSALS_PER_SLOT',
26
30
  description:
27
31
  'Expected number of block proposals per slot for P2P peer scoring. ' +
28
32
  '0 (default) disables block proposal scoring. Set to a positive value to enable.',
29
- parseEnv: (val: string) => (val ? parseInt(val, 10) : 0),
33
+ parseEnv: (val: string) => parseInt(val, 10),
30
34
  defaultValue: 0,
31
35
  },
32
36
  maxTxsPerBlock: {
33
37
  env: 'SEQ_MAX_TX_PER_BLOCK',
34
38
  description: 'The maximum number of txs to include in a block.',
35
- parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
39
+ parseEnv: (val: string) => parseInt(val, 10),
40
+ },
41
+ attestationPropagationTime: {
42
+ env: 'SEQ_ATTESTATION_PROPAGATION_TIME',
43
+ description: 'How many seconds it takes for proposals and attestations to travel across the p2p layer (one-way).',
44
+ parseEnv: (val: string) => parseFloat(val),
45
+ defaultValue: DEFAULT_P2P_PROPAGATION_TIME,
36
46
  },
37
47
  };
@@ -68,6 +68,14 @@ export function getNextL1SlotTimestamp(
68
68
  return constants.l1GenesisTime + (currentL1Slot + 1n) * BigInt(constants.ethereumSlotDuration);
69
69
  }
70
70
 
71
+ /** Returns the timestamp of the last L1 slot within a given L2 slot. */
72
+ export function getLastL1SlotTimestampForL2Slot(
73
+ slot: SlotNumber,
74
+ constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration' | 'ethereumSlotDuration'>,
75
+ ): bigint {
76
+ return getTimestampForSlot(slot, constants) + BigInt(constants.slotDuration - constants.ethereumSlotDuration);
77
+ }
78
+
71
79
  /** Returns the L2 slot number at the next L1 block based on the current timestamp. */
72
80
  export function getSlotAtNextL1Block(
73
81
  currentL1Timestamp: bigint,
@@ -154,6 +162,11 @@ export function getProofSubmissionDeadlineTimestamp(
154
162
  return getTimestampForSlot(deadlineSlot, constants);
155
163
  }
156
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
+
157
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. */
158
171
  export function getSlotStartBuildTimestamp(
159
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