@aztec/ethereum 0.0.0-test.1 → 0.0.1-commit.017a351

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 (285) hide show
  1. package/dest/account.d.ts +2 -0
  2. package/dest/account.d.ts.map +1 -0
  3. package/dest/account.js +4 -0
  4. package/dest/chain.d.ts +1 -1
  5. package/dest/client.d.ts +28 -4
  6. package/dest/client.d.ts.map +1 -1
  7. package/dest/client.js +73 -3
  8. package/dest/config.d.ts +70 -23
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +151 -34
  11. package/dest/constants.d.ts +1 -1
  12. package/dest/contracts/chain_state_override.d.ts +78 -0
  13. package/dest/contracts/chain_state_override.d.ts.map +1 -0
  14. package/dest/contracts/chain_state_override.js +137 -0
  15. package/dest/contracts/empire_base.d.ts +25 -8
  16. package/dest/contracts/empire_base.d.ts.map +1 -1
  17. package/dest/contracts/empire_base.js +75 -2
  18. package/dest/contracts/errors.d.ts +7 -0
  19. package/dest/contracts/errors.d.ts.map +1 -0
  20. package/dest/contracts/errors.js +12 -0
  21. package/dest/contracts/fee_asset_handler.d.ts +20 -0
  22. package/dest/contracts/fee_asset_handler.d.ts.map +1 -0
  23. package/dest/contracts/fee_asset_handler.js +59 -0
  24. package/dest/contracts/fee_asset_price_oracle.d.ts +105 -0
  25. package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
  26. package/dest/contracts/fee_asset_price_oracle.js +656 -0
  27. package/dest/contracts/fee_juice.d.ts +6 -7
  28. package/dest/contracts/fee_juice.d.ts.map +1 -1
  29. package/dest/contracts/fee_juice.js +27 -20
  30. package/dest/contracts/governance.d.ts +131 -43
  31. package/dest/contracts/governance.d.ts.map +1 -1
  32. package/dest/contracts/governance.js +281 -87
  33. package/dest/contracts/governance_proposer.d.ts +49 -13
  34. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  35. package/dest/contracts/governance_proposer.js +483 -26
  36. package/dest/contracts/gse.d.ts +32 -0
  37. package/dest/contracts/gse.d.ts.map +1 -0
  38. package/dest/contracts/gse.js +72 -0
  39. package/dest/contracts/inbox.d.ts +47 -0
  40. package/dest/contracts/inbox.d.ts.map +1 -0
  41. package/dest/contracts/inbox.js +85 -0
  42. package/dest/contracts/index.d.ts +11 -2
  43. package/dest/contracts/index.d.ts.map +1 -1
  44. package/dest/contracts/index.js +10 -1
  45. package/dest/contracts/log.d.ts +13 -0
  46. package/dest/contracts/log.d.ts.map +1 -0
  47. package/dest/contracts/log.js +1 -0
  48. package/dest/contracts/multicall.d.ts +136 -0
  49. package/dest/contracts/multicall.d.ts.map +1 -0
  50. package/dest/contracts/multicall.js +264 -0
  51. package/dest/contracts/outbox.d.ts +64 -0
  52. package/dest/contracts/outbox.d.ts.map +1 -0
  53. package/dest/contracts/outbox.js +113 -0
  54. package/dest/contracts/registry.d.ts +12 -5
  55. package/dest/contracts/registry.d.ts.map +1 -1
  56. package/dest/contracts/registry.js +74 -17
  57. package/dest/contracts/rollup.d.ts +5526 -52
  58. package/dest/contracts/rollup.d.ts.map +1 -1
  59. package/dest/contracts/rollup.js +1446 -118
  60. package/dest/contracts/slasher_contract.d.ts +44 -0
  61. package/dest/contracts/slasher_contract.d.ts.map +1 -0
  62. package/dest/contracts/slasher_contract.js +75 -0
  63. package/dest/contracts/slashing_proposer.d.ts +133 -15
  64. package/dest/contracts/slashing_proposer.d.ts.map +1 -1
  65. package/dest/contracts/slashing_proposer.js +293 -22
  66. package/dest/contracts/utils.d.ts +3 -0
  67. package/dest/contracts/utils.d.ts.map +1 -0
  68. package/dest/contracts/utils.js +11 -0
  69. package/dest/deploy_aztec_l1_contracts.d.ts +256 -0
  70. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
  71. package/dest/deploy_aztec_l1_contracts.js +411 -0
  72. package/dest/deploy_l1_contract.d.ts +68 -0
  73. package/dest/deploy_l1_contract.d.ts.map +1 -0
  74. package/dest/deploy_l1_contract.js +312 -0
  75. package/dest/eth-signer/eth-signer.d.ts +21 -0
  76. package/dest/eth-signer/eth-signer.d.ts.map +1 -0
  77. package/dest/eth-signer/eth-signer.js +5 -0
  78. package/dest/eth-signer/index.d.ts +2 -0
  79. package/dest/eth-signer/index.d.ts.map +1 -0
  80. package/dest/eth-signer/index.js +1 -0
  81. package/dest/forwarder_proxy.d.ts +32 -0
  82. package/dest/forwarder_proxy.d.ts.map +1 -0
  83. package/dest/forwarder_proxy.js +93 -0
  84. package/dest/generated/l1-contracts-defaults.d.ts +30 -0
  85. package/dest/generated/l1-contracts-defaults.d.ts.map +1 -0
  86. package/dest/generated/l1-contracts-defaults.js +30 -0
  87. package/dest/l1_artifacts.d.ts +79270 -0
  88. package/dest/l1_artifacts.d.ts.map +1 -0
  89. package/dest/l1_artifacts.js +151 -0
  90. package/dest/l1_contract_addresses.d.ts +61 -45
  91. package/dest/l1_contract_addresses.d.ts.map +1 -1
  92. package/dest/l1_contract_addresses.js +99 -76
  93. package/dest/l1_reader.d.ts +8 -6
  94. package/dest/l1_reader.d.ts.map +1 -1
  95. package/dest/l1_reader.js +20 -12
  96. package/dest/l1_tx_utils/config.d.ts +65 -0
  97. package/dest/l1_tx_utils/config.d.ts.map +1 -0
  98. package/dest/l1_tx_utils/config.js +109 -0
  99. package/dest/l1_tx_utils/constants.d.ts +12 -0
  100. package/dest/l1_tx_utils/constants.d.ts.map +1 -0
  101. package/dest/l1_tx_utils/constants.js +39 -0
  102. package/dest/l1_tx_utils/factory.d.ts +32 -0
  103. package/dest/l1_tx_utils/factory.d.ts.map +1 -0
  104. package/dest/l1_tx_utils/factory.js +22 -0
  105. package/dest/l1_tx_utils/fee-strategies/index.d.ts +10 -0
  106. package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -0
  107. package/dest/l1_tx_utils/fee-strategies/index.js +12 -0
  108. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +8 -0
  109. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -0
  110. package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +129 -0
  111. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +23 -0
  112. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -0
  113. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +191 -0
  114. package/dest/l1_tx_utils/fee-strategies/types.d.ts +51 -0
  115. package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -0
  116. package/dest/l1_tx_utils/fee-strategies/types.js +3 -0
  117. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +41 -0
  118. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -0
  119. package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +42 -0
  120. package/dest/l1_tx_utils/index-blobs.d.ts +3 -0
  121. package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -0
  122. package/dest/l1_tx_utils/index-blobs.js +2 -0
  123. package/dest/l1_tx_utils/index.d.ts +13 -0
  124. package/dest/l1_tx_utils/index.d.ts.map +1 -0
  125. package/dest/l1_tx_utils/index.js +13 -0
  126. package/dest/l1_tx_utils/interfaces.d.ts +76 -0
  127. package/dest/l1_tx_utils/interfaces.d.ts.map +1 -0
  128. package/dest/l1_tx_utils/interfaces.js +4 -0
  129. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +233 -0
  130. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
  131. package/dest/l1_tx_utils/l1_fee_analyzer.js +506 -0
  132. package/dest/l1_tx_utils/l1_tx_utils.d.ts +113 -0
  133. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -0
  134. package/dest/l1_tx_utils/l1_tx_utils.js +658 -0
  135. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +83 -0
  136. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -0
  137. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +328 -0
  138. package/dest/l1_tx_utils/signer.d.ts +4 -0
  139. package/dest/l1_tx_utils/signer.d.ts.map +1 -0
  140. package/dest/l1_tx_utils/signer.js +16 -0
  141. package/dest/l1_tx_utils/tx_delayer.d.ts +58 -0
  142. package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
  143. package/dest/l1_tx_utils/tx_delayer.js +223 -0
  144. package/dest/l1_tx_utils/types.d.ts +67 -0
  145. package/dest/l1_tx_utils/types.d.ts.map +1 -0
  146. package/dest/l1_tx_utils/types.js +26 -0
  147. package/dest/l1_tx_utils/utils.d.ts +4 -0
  148. package/dest/l1_tx_utils/utils.d.ts.map +1 -0
  149. package/dest/l1_tx_utils/utils.js +14 -0
  150. package/dest/l1_types.d.ts +6 -0
  151. package/dest/l1_types.d.ts.map +1 -0
  152. package/dest/l1_types.js +1 -0
  153. package/dest/publisher_manager.d.ts +30 -0
  154. package/dest/publisher_manager.d.ts.map +1 -0
  155. package/dest/publisher_manager.js +162 -0
  156. package/dest/queries.d.ts +17 -4
  157. package/dest/queries.d.ts.map +1 -1
  158. package/dest/queries.js +120 -12
  159. package/dest/test/chain_monitor.d.ts +95 -0
  160. package/dest/test/chain_monitor.d.ts.map +1 -0
  161. package/dest/test/chain_monitor.js +249 -0
  162. package/dest/test/eth_cheat_codes.d.ts +237 -0
  163. package/dest/test/eth_cheat_codes.d.ts.map +1 -0
  164. package/dest/test/eth_cheat_codes.js +573 -0
  165. package/dest/test/eth_cheat_codes_with_state.d.ts +2 -2
  166. package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -1
  167. package/dest/test/eth_cheat_codes_with_state.js +1 -1
  168. package/dest/test/index.d.ts +4 -3
  169. package/dest/test/index.d.ts.map +1 -1
  170. package/dest/test/index.js +3 -2
  171. package/dest/test/rollup_cheat_codes.d.ts +118 -0
  172. package/dest/test/rollup_cheat_codes.d.ts.map +1 -0
  173. package/dest/test/rollup_cheat_codes.js +344 -0
  174. package/dest/test/start_anvil.d.ts +30 -2
  175. package/dest/test/start_anvil.d.ts.map +1 -1
  176. package/dest/test/start_anvil.js +147 -24
  177. package/dest/test/upgrade_utils.d.ts +6 -5
  178. package/dest/test/upgrade_utils.d.ts.map +1 -1
  179. package/dest/test/upgrade_utils.js +23 -16
  180. package/dest/types.d.ts +62 -8
  181. package/dest/types.d.ts.map +1 -1
  182. package/dest/types.js +3 -1
  183. package/dest/utils.d.ts +25 -4
  184. package/dest/utils.d.ts.map +1 -1
  185. package/dest/utils.js +142 -91
  186. package/dest/zkPassportVerifierAddress.d.ts +15 -0
  187. package/dest/zkPassportVerifierAddress.d.ts.map +1 -0
  188. package/dest/zkPassportVerifierAddress.js +11 -0
  189. package/package.json +52 -26
  190. package/src/account.ts +5 -0
  191. package/src/client.ts +107 -5
  192. package/src/config.ts +218 -43
  193. package/src/contracts/README.md +157 -0
  194. package/src/contracts/chain_state_override.ts +200 -0
  195. package/src/contracts/empire_base.ts +77 -7
  196. package/src/contracts/errors.ts +13 -0
  197. package/src/contracts/fee_asset_handler.ts +66 -0
  198. package/src/contracts/fee_asset_price_oracle.ts +285 -0
  199. package/src/contracts/fee_juice.ts +29 -15
  200. package/src/contracts/governance.ts +343 -74
  201. package/src/contracts/governance_proposer.ts +128 -25
  202. package/src/contracts/gse.ts +88 -0
  203. package/src/contracts/inbox.ts +123 -0
  204. package/src/contracts/index.ts +10 -1
  205. package/src/contracts/log.ts +13 -0
  206. package/src/contracts/multicall.ts +296 -0
  207. package/src/contracts/outbox.ts +132 -0
  208. package/src/contracts/registry.ts +81 -26
  209. package/src/contracts/rollup.ts +1246 -90
  210. package/src/contracts/slasher_contract.ts +89 -0
  211. package/src/contracts/slashing_proposer.ts +296 -27
  212. package/src/contracts/utils.ts +14 -0
  213. package/src/deploy_aztec_l1_contracts.ts +646 -0
  214. package/src/deploy_l1_contract.ts +362 -0
  215. package/src/eth-signer/eth-signer.ts +25 -0
  216. package/src/eth-signer/index.ts +1 -0
  217. package/src/forwarder_proxy.ts +108 -0
  218. package/src/generated/l1-contracts-defaults.ts +32 -0
  219. package/src/l1_artifacts.ts +231 -0
  220. package/src/l1_contract_addresses.ts +121 -80
  221. package/src/l1_reader.ts +31 -16
  222. package/src/l1_tx_utils/README.md +177 -0
  223. package/src/l1_tx_utils/config.ts +181 -0
  224. package/src/l1_tx_utils/constants.ts +29 -0
  225. package/src/l1_tx_utils/factory.ts +64 -0
  226. package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
  227. package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +163 -0
  228. package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +245 -0
  229. package/src/l1_tx_utils/fee-strategies/types.ts +56 -0
  230. package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +108 -0
  231. package/src/l1_tx_utils/index-blobs.ts +2 -0
  232. package/src/l1_tx_utils/index.ts +15 -0
  233. package/src/l1_tx_utils/interfaces.ts +86 -0
  234. package/src/l1_tx_utils/l1_fee_analyzer.ts +803 -0
  235. package/src/l1_tx_utils/l1_tx_utils.ts +789 -0
  236. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +424 -0
  237. package/src/l1_tx_utils/signer.ts +28 -0
  238. package/src/l1_tx_utils/tx_delayer.ts +303 -0
  239. package/src/l1_tx_utils/types.ts +85 -0
  240. package/src/l1_tx_utils/utils.ts +16 -0
  241. package/src/l1_types.ts +6 -0
  242. package/src/publisher_manager.ts +203 -0
  243. package/src/queries.ts +149 -17
  244. package/src/test/chain_monitor.ts +307 -0
  245. package/src/test/eth_cheat_codes.ts +600 -0
  246. package/src/test/eth_cheat_codes_with_state.ts +1 -1
  247. package/src/test/index.ts +3 -2
  248. package/src/test/rollup_cheat_codes.ts +388 -0
  249. package/src/test/start_anvil.ts +189 -22
  250. package/src/test/upgrade_utils.ts +30 -21
  251. package/src/types.ts +71 -7
  252. package/src/utils.ts +164 -96
  253. package/src/zkPassportVerifierAddress.ts +15 -0
  254. package/dest/contracts/forwarder.d.ts +0 -24
  255. package/dest/contracts/forwarder.d.ts.map +0 -1
  256. package/dest/contracts/forwarder.js +0 -101
  257. package/dest/deploy_l1_contracts.d.ts +0 -21210
  258. package/dest/deploy_l1_contracts.d.ts.map +0 -1
  259. package/dest/deploy_l1_contracts.js +0 -687
  260. package/dest/eth_cheat_codes.d.ts +0 -147
  261. package/dest/eth_cheat_codes.d.ts.map +0 -1
  262. package/dest/eth_cheat_codes.js +0 -303
  263. package/dest/index.d.ts +0 -14
  264. package/dest/index.d.ts.map +0 -1
  265. package/dest/index.js +0 -13
  266. package/dest/l1_tx_utils.d.ts +0 -192
  267. package/dest/l1_tx_utils.d.ts.map +0 -1
  268. package/dest/l1_tx_utils.js +0 -641
  269. package/dest/l1_tx_utils_with_blobs.d.ts +0 -12
  270. package/dest/l1_tx_utils_with_blobs.d.ts.map +0 -1
  271. package/dest/l1_tx_utils_with_blobs.js +0 -64
  272. package/dest/test/delayed_tx_utils.d.ts +0 -8
  273. package/dest/test/delayed_tx_utils.d.ts.map +0 -1
  274. package/dest/test/delayed_tx_utils.js +0 -21
  275. package/dest/test/tx_delayer.d.ts +0 -25
  276. package/dest/test/tx_delayer.d.ts.map +0 -1
  277. package/dest/test/tx_delayer.js +0 -116
  278. package/src/contracts/forwarder.ts +0 -132
  279. package/src/deploy_l1_contracts.ts +0 -948
  280. package/src/eth_cheat_codes.ts +0 -314
  281. package/src/index.ts +0 -13
  282. package/src/l1_tx_utils.ts +0 -847
  283. package/src/l1_tx_utils_with_blobs.ts +0 -86
  284. package/src/test/delayed_tx_utils.ts +0 -24
  285. package/src/test/tx_delayer.ts +0 -163
package/src/config.ts CHANGED
@@ -1,11 +1,26 @@
1
1
  import {
2
2
  type ConfigMappingsType,
3
3
  bigintConfigHelper,
4
+ booleanConfigHelper,
4
5
  getConfigFromMappings,
6
+ getDefaultConfig,
5
7
  numberConfigHelper,
8
+ omitConfigMappings,
9
+ optionalNumberConfigHelper,
6
10
  } from '@aztec/foundation/config';
11
+ import { EthAddress } from '@aztec/foundation/eth-address';
7
12
 
8
- import { type L1TxUtilsConfig, l1TxUtilsConfigMappings } from './l1_tx_utils.js';
13
+ import { l1ContractsDefaultEnv } from './generated/l1-contracts-defaults.js';
14
+ import { type L1TxUtilsConfig, l1TxUtilsConfigMappings } from './l1_tx_utils/config.js';
15
+
16
+ export type GenesisStateConfig = {
17
+ /** Whether to populate the genesis state with initial fee juice for the test accounts */
18
+ testAccounts: boolean;
19
+ /** Whether to populate the genesis state with initial fee juice for the sponsored FPC */
20
+ sponsoredFPC: boolean;
21
+ /** Additional addresses to prefund with fee juice at genesis */
22
+ prefundAddresses: string[];
23
+ };
9
24
 
10
25
  export type L1ContractsConfig = {
11
26
  /** How many seconds an L1 slot lasts. */
@@ -16,88 +31,248 @@ export type L1ContractsConfig = {
16
31
  aztecEpochDuration: number;
17
32
  /** The target validator committee size. */
18
33
  aztecTargetCommitteeSize: number;
19
- /** The number of L2 slots that we can wait for a proof of an epoch to be produced. */
20
- aztecProofSubmissionWindow: number;
34
+ /** The number of epochs to lag behind the current epoch for validator selection. */
35
+ lagInEpochsForValidatorSet: number;
36
+ /** The number of epochs to lag behind the current epoch for randao selection. */
37
+ lagInEpochsForRandao: number;
38
+ /** The number of checkpoints to lag in the inbox (prevents sequencer DOS attacks). */
39
+ inboxLag: number;
40
+ /** The number of epochs after an epoch ends that proofs are still accepted. */
41
+ aztecProofSubmissionEpochs: number;
42
+ /** The deposit amount for a validator */
43
+ activationThreshold: bigint;
21
44
  /** The minimum stake for a validator. */
22
- minimumStake: bigint;
23
- /** The slashing quorum */
24
- slashingQuorum: number;
25
- /** The slashing round size */
26
- slashingRoundSize: number;
27
- /** Governance proposing quorum */
28
- governanceProposerQuorum: number;
45
+ ejectionThreshold: bigint;
46
+ /** The local ejection threshold for a validator. Stricter than ejectionThreshold but local to a specific rollup */
47
+ localEjectionThreshold: bigint;
48
+ /** The slashing quorum, i.e. how many slots must signal for the same payload in a round for it to be submittable to the Slasher (defaults to slashRoundSize / 2 + 1) */
49
+ slashingQuorum?: number;
50
+ /** The slashing round size, i.e. how many epochs are in a slashing round */
51
+ slashingRoundSizeInEpochs: number;
52
+ /** The slashing lifetime in rounds. I.e., if 1, round N must be submitted before round N + 2 */
53
+ slashingLifetimeInRounds: number;
54
+ /** The slashing execution delay in rounds. I.e., if 1, round N may not be submitted until round N + 2 */
55
+ slashingExecutionDelayInRounds: number;
56
+ /** The slashing vetoer. May blacklist a payload from being submitted. */
57
+ slashingVetoer: EthAddress;
58
+ /** How many slashing rounds back we slash (ie when slashing in round N, we slash for offenses committed during epochs of round N-offset) */
59
+ slashingOffsetInRounds: number;
60
+ /** How long slashing can be disabled for in seconds when vetoer disables it */
61
+ slashingDisableDuration: number;
62
+ /** Whether to deploy a slasher proposer */
63
+ slasherEnabled: boolean;
64
+ /** Minimum amount that can be slashed */
65
+ slashAmountSmall: bigint;
66
+ /** Medium amount to slash */
67
+ slashAmountMedium: bigint;
68
+ /** Largest amount that can be slashed per round */
69
+ slashAmountLarge: bigint;
70
+ /** Governance proposing quorum (defaults to roundSize/2 + 1) */
71
+ governanceProposerQuorum?: number;
29
72
  /** Governance proposing round size */
30
73
  governanceProposerRoundSize: number;
74
+ /** Governance voting duration in seconds (only for local/devnet/next-net, default 3600) */
75
+ governanceVotingDuration?: number;
76
+ /** The mana target for the rollup */
77
+ manaTarget: bigint;
78
+ /** The proving cost per mana */
79
+ provingCostPerMana: bigint;
80
+ /** The initial ETH per fee asset price (with 1e12 precision) */
81
+ initialEthPerFeeAsset: bigint;
82
+ /** The number of seconds to wait for an exit */
83
+ exitDelaySeconds: number;
31
84
  } & L1TxUtilsConfig;
32
85
 
33
- export const DefaultL1ContractsConfig = {
34
- ethereumSlotDuration: 12,
35
- aztecSlotDuration: 24,
36
- aztecEpochDuration: 16,
37
- aztecTargetCommitteeSize: 48,
38
- aztecProofSubmissionWindow: 31, // you have a full epoch to submit a proof after the epoch to prove ends
39
- minimumStake: BigInt(100e18),
40
- slashingQuorum: 6,
41
- slashingRoundSize: 10,
42
- governanceProposerQuorum: 6,
43
- governanceProposerRoundSize: 10,
44
- } satisfies L1ContractsConfig;
45
-
86
+ /**
87
+ * Config mappings for L1ContractsConfig.
88
+ * Default values come from generated l1-contracts-defaults.json (source: defaults.yml).
89
+ * Real deployments use forge scripts which require explicit env vars (vm.envUint).
90
+ */
46
91
  export const l1ContractsConfigMappings: ConfigMappingsType<L1ContractsConfig> = {
47
92
  ethereumSlotDuration: {
48
93
  env: 'ETHEREUM_SLOT_DURATION',
49
94
  description: 'How many seconds an L1 slot lasts.',
50
- ...numberConfigHelper(DefaultL1ContractsConfig.ethereumSlotDuration),
95
+ ...numberConfigHelper(l1ContractsDefaultEnv.ETHEREUM_SLOT_DURATION),
51
96
  },
52
97
  aztecSlotDuration: {
53
98
  env: 'AZTEC_SLOT_DURATION',
54
99
  description: 'How many seconds an L2 slots lasts (must be multiple of ethereum slot duration).',
55
- ...numberConfigHelper(DefaultL1ContractsConfig.aztecSlotDuration),
100
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_SLOT_DURATION),
56
101
  },
57
102
  aztecEpochDuration: {
58
103
  env: 'AZTEC_EPOCH_DURATION',
59
- description: `How many L2 slots an epoch lasts (maximum AZTEC_MAX_EPOCH_DURATION).`,
60
- ...numberConfigHelper(DefaultL1ContractsConfig.aztecEpochDuration),
104
+ description: `How many L2 slots an epoch lasts (maximum MAX_CHECKPOINTS_PER_EPOCH).`,
105
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_EPOCH_DURATION),
61
106
  },
62
107
  aztecTargetCommitteeSize: {
63
108
  env: 'AZTEC_TARGET_COMMITTEE_SIZE',
64
109
  description: 'The target validator committee size.',
65
- ...numberConfigHelper(DefaultL1ContractsConfig.aztecTargetCommitteeSize),
110
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_TARGET_COMMITTEE_SIZE),
66
111
  },
67
- aztecProofSubmissionWindow: {
68
- env: 'AZTEC_PROOF_SUBMISSION_WINDOW',
69
- description:
70
- 'The number of L2 slots that a proof for an epoch can be submitted in, starting from the beginning of the epoch.',
71
- ...numberConfigHelper(DefaultL1ContractsConfig.aztecProofSubmissionWindow),
112
+ lagInEpochsForValidatorSet: {
113
+ env: 'AZTEC_LAG_IN_EPOCHS_FOR_VALIDATOR_SET',
114
+ description: 'The number of epochs to lag behind the current epoch for validator selection.',
115
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_LAG_IN_EPOCHS_FOR_VALIDATOR_SET),
116
+ },
117
+ lagInEpochsForRandao: {
118
+ env: 'AZTEC_LAG_IN_EPOCHS_FOR_RANDAO',
119
+ description: 'The number of epochs to lag behind the current epoch for randao selection.',
120
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_LAG_IN_EPOCHS_FOR_RANDAO),
72
121
  },
73
- minimumStake: {
74
- env: 'AZTEC_MINIMUM_STAKE',
122
+ inboxLag: {
123
+ env: 'AZTEC_INBOX_LAG',
124
+ description: 'The number of checkpoints to lag in the inbox (prevents sequencer DOS attacks).',
125
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_INBOX_LAG),
126
+ },
127
+ aztecProofSubmissionEpochs: {
128
+ env: 'AZTEC_PROOF_SUBMISSION_EPOCHS',
129
+ description: 'The number of epochs after an epoch ends that proofs are still accepted.',
130
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_PROOF_SUBMISSION_EPOCHS),
131
+ },
132
+ activationThreshold: {
133
+ env: 'AZTEC_ACTIVATION_THRESHOLD',
134
+ description: 'The deposit amount for a validator',
135
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_ACTIVATION_THRESHOLD)),
136
+ },
137
+ ejectionThreshold: {
138
+ env: 'AZTEC_EJECTION_THRESHOLD',
75
139
  description: 'The minimum stake for a validator.',
76
- ...bigintConfigHelper(DefaultL1ContractsConfig.minimumStake),
140
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_EJECTION_THRESHOLD)),
141
+ },
142
+ localEjectionThreshold: {
143
+ env: 'AZTEC_LOCAL_EJECTION_THRESHOLD',
144
+ description:
145
+ 'The local ejection threshold for a validator. Stricter than ejectionThreshold but local to a specific rollup',
146
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_LOCAL_EJECTION_THRESHOLD)),
147
+ },
148
+ slashingOffsetInRounds: {
149
+ env: 'AZTEC_SLASHING_OFFSET_IN_ROUNDS',
150
+ description:
151
+ 'How many slashing rounds back we slash (ie when slashing in round N, we slash for offenses committed during epochs of round N-offset)',
152
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_SLASHING_OFFSET_IN_ROUNDS),
153
+ },
154
+ slasherEnabled: {
155
+ env: 'AZTEC_SLASHER_ENABLED',
156
+ description: 'Whether to deploy a slasher proposer',
157
+ ...booleanConfigHelper(true),
158
+ },
159
+ slashAmountSmall: {
160
+ env: 'AZTEC_SLASH_AMOUNT_SMALL',
161
+ description: 'Small slashing amount for light offenses',
162
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_SLASH_AMOUNT_SMALL)),
163
+ },
164
+ slashAmountMedium: {
165
+ env: 'AZTEC_SLASH_AMOUNT_MEDIUM',
166
+ description: 'Medium slashing amount for moderate offenses',
167
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_SLASH_AMOUNT_MEDIUM)),
168
+ },
169
+ slashAmountLarge: {
170
+ env: 'AZTEC_SLASH_AMOUNT_LARGE',
171
+ description: 'Large slashing amount for severe offenses',
172
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_SLASH_AMOUNT_LARGE)),
77
173
  },
78
174
  slashingQuorum: {
79
175
  env: 'AZTEC_SLASHING_QUORUM',
80
176
  description: 'The slashing quorum',
81
- ...numberConfigHelper(DefaultL1ContractsConfig.slashingQuorum),
177
+ ...optionalNumberConfigHelper(),
82
178
  },
83
- slashingRoundSize: {
84
- env: 'AZTEC_SLASHING_ROUND_SIZE',
179
+ slashingRoundSizeInEpochs: {
180
+ env: 'AZTEC_SLASHING_ROUND_SIZE_IN_EPOCHS',
85
181
  description: 'The slashing round size',
86
- ...numberConfigHelper(DefaultL1ContractsConfig.slashingRoundSize),
182
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_SLASHING_ROUND_SIZE_IN_EPOCHS),
183
+ },
184
+ slashingLifetimeInRounds: {
185
+ env: 'AZTEC_SLASHING_LIFETIME_IN_ROUNDS',
186
+ description: 'The slashing lifetime in rounds',
187
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_SLASHING_LIFETIME_IN_ROUNDS),
188
+ },
189
+ slashingExecutionDelayInRounds: {
190
+ env: 'AZTEC_SLASHING_EXECUTION_DELAY_IN_ROUNDS',
191
+ description: 'The slashing execution delay in rounds',
192
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_SLASHING_EXECUTION_DELAY_IN_ROUNDS),
193
+ },
194
+ slashingVetoer: {
195
+ env: 'AZTEC_SLASHING_VETOER',
196
+ description: 'The slashing vetoer',
197
+ parseEnv: (val: string) => EthAddress.fromString(val),
198
+ defaultValue: EthAddress.fromString(l1ContractsDefaultEnv.AZTEC_SLASHING_VETOER),
199
+ },
200
+ slashingDisableDuration: {
201
+ env: 'AZTEC_SLASHING_DISABLE_DURATION',
202
+ description: 'How long slashing can be disabled for in seconds when vetoer disables it',
203
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_SLASHING_DISABLE_DURATION),
87
204
  },
88
205
  governanceProposerQuorum: {
89
206
  env: 'AZTEC_GOVERNANCE_PROPOSER_QUORUM',
90
207
  description: 'The governance proposing quorum',
91
- ...numberConfigHelper(DefaultL1ContractsConfig.governanceProposerQuorum),
208
+ ...optionalNumberConfigHelper(),
92
209
  },
93
210
  governanceProposerRoundSize: {
94
211
  env: 'AZTEC_GOVERNANCE_PROPOSER_ROUND_SIZE',
95
212
  description: 'The governance proposing round size',
96
- ...numberConfigHelper(DefaultL1ContractsConfig.governanceProposerRoundSize),
213
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_GOVERNANCE_PROPOSER_ROUND_SIZE),
214
+ },
215
+ governanceVotingDuration: {
216
+ env: 'AZTEC_GOVERNANCE_VOTING_DURATION',
217
+ description: 'Governance voting duration in seconds (only for local/devnet/next-net)',
218
+ ...numberConfigHelper(3600), // 1 hour default, not in generated defaults as it's deployment-time only
219
+ },
220
+ manaTarget: {
221
+ env: 'AZTEC_MANA_TARGET',
222
+ description: 'The mana target for the rollup',
223
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_MANA_TARGET)),
224
+ },
225
+ provingCostPerMana: {
226
+ env: 'AZTEC_PROVING_COST_PER_MANA',
227
+ description: 'The proving cost per mana',
228
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_PROVING_COST_PER_MANA)),
229
+ },
230
+ initialEthPerFeeAsset: {
231
+ env: 'AZTEC_INITIAL_ETH_PER_FEE_ASSET',
232
+ description: 'The initial ETH per fee asset price (with 1e12 precision)',
233
+ ...bigintConfigHelper(BigInt(l1ContractsDefaultEnv.AZTEC_INITIAL_ETH_PER_FEE_ASSET)),
234
+ },
235
+ exitDelaySeconds: {
236
+ env: 'AZTEC_EXIT_DELAY_SECONDS',
237
+ description: 'The delay before a validator can exit the set',
238
+ ...numberConfigHelper(l1ContractsDefaultEnv.AZTEC_EXIT_DELAY_SECONDS),
239
+ },
240
+ ...omitConfigMappings(l1TxUtilsConfigMappings, ['ethereumSlotDuration']),
241
+ };
242
+
243
+ /**
244
+ * Default L1 contracts configuration derived from l1ContractsConfigMappings.
245
+ * Source of truth: spartan/environments/defaults.yml -> defaults.l1-contracts
246
+ */
247
+ export const DefaultL1ContractsConfig = getDefaultConfig(l1ContractsConfigMappings);
248
+
249
+ export const genesisStateConfigMappings: ConfigMappingsType<GenesisStateConfig> = {
250
+ testAccounts: {
251
+ env: 'TEST_ACCOUNTS',
252
+ description: 'Whether to populate the genesis state with initial fee juice for the test accounts.',
253
+ ...booleanConfigHelper(false),
254
+ },
255
+ sponsoredFPC: {
256
+ env: 'SPONSORED_FPC',
257
+ description: 'Whether to populate the genesis state with initial fee juice for the sponsored FPC.',
258
+ ...booleanConfigHelper(false),
259
+ },
260
+ prefundAddresses: {
261
+ env: 'PREFUND_ADDRESSES',
262
+ description: 'Comma-separated list of Aztec addresses to prefund with fee juice at genesis (local network only).',
263
+ parseEnv: (val: string) =>
264
+ val
265
+ .split(',')
266
+ .map(a => a.trim())
267
+ .filter(a => a.length > 0),
268
+ defaultValue: [],
97
269
  },
98
- ...l1TxUtilsConfigMappings,
99
270
  };
100
271
 
101
272
  export function getL1ContractsConfigEnvVars(): L1ContractsConfig {
102
273
  return getConfigFromMappings(l1ContractsConfigMappings);
103
274
  }
275
+
276
+ export function getGenesisStateConfigEnvVars(): GenesisStateConfig {
277
+ return getConfigFromMappings(genesisStateConfigMappings);
278
+ }
@@ -0,0 +1,157 @@
1
+ # L1 Contract Wrappers
2
+
3
+ This folder contains TypeScript wrappers for L1 contracts defined in `l1-contracts/`. These wrappers are used by the node client to interact with the rollup and related contracts on Ethereum.
4
+
5
+ ## Purpose
6
+
7
+ The goal of wrapping is to shield consumers from L1-specific and viem-specific details. Clients using these wrappers interact with domain types and branded types native to the Aztec codebase, without needing to understand viem's ABI type system or deal with raw types like `Hex` and `bigint`.
8
+
9
+ ## Type Safety
10
+
11
+ ### Explicit Return Types
12
+
13
+ Every function in the contract wrappers must declare its return type explicitly. This is critical because viem's type inference over ABI types is slow and significantly impacts IDE performance.
14
+
15
+ ```typescript
16
+ // Good: Explicit return type
17
+ async getSlotNumber(): Promise<SlotNumber> {
18
+ return SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot());
19
+ }
20
+
21
+ // Bad: Inferred return type (slow)
22
+ async getSlotNumber() {
23
+ return SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot());
24
+ }
25
+ ```
26
+
27
+ ### Branded and Domain Types
28
+
29
+ Use branded types and domain-specific types instead of viem's autogenerated types for both arguments and return values:
30
+
31
+ - `CheckpointNumber`, `EpochNumber`, `SlotNumber` instead of `bigint`
32
+ - `EthAddress` instead of `` `0x${string}` `` or `Hex`
33
+ - `Fr`, `Buffer32` instead of `Hex` for hashes and field elements
34
+ - Custom domain types (e.g., `CheckpointLog`, `AttesterView`) instead of raw tuples
35
+
36
+ Type conversions happen inside wrapper methods, not at the call site:
37
+
38
+ ```typescript
39
+ async getCheckpoint(checkpointNumber: CheckpointNumber): Promise<CheckpointLog> {
40
+ const result = await this.rollup.read.getCheckpoint([BigInt(checkpointNumber)]);
41
+ return {
42
+ archive: Fr.fromString(result.archive),
43
+ headerHash: Buffer32.fromString(result.headerHash),
44
+ blockCount: result.blockCount,
45
+ };
46
+ }
47
+ ```
48
+
49
+ ## Wrapper Pattern
50
+
51
+ ### Basic Structure
52
+
53
+ Each wrapper follows a consistent structure:
54
+
55
+ ```typescript
56
+ export class FooContract {
57
+ private readonly foo: GetContractReturnType<typeof FooAbi, ViemClient>;
58
+
59
+ constructor(
60
+ public readonly client: ViemClient,
61
+ address: Hex | EthAddress,
62
+ ) {
63
+ if (address instanceof EthAddress) {
64
+ address = address.toString();
65
+ }
66
+ this.foo = getContract({ address, abi: FooAbi, client });
67
+ }
68
+
69
+ public get address(): Hex {
70
+ return this.foo.address;
71
+ }
72
+
73
+ public getContract(): GetContractReturnType<typeof FooAbi, ViemClient> {
74
+ return this.foo;
75
+ }
76
+ }
77
+ ```
78
+
79
+ The raw contract is exposed via `getContract()` for cases where direct access is needed, but most consumers should use the typed wrapper methods. Relying on `getContract()` is a code smell and should be avoided.
80
+
81
+ ### Static Factory Methods
82
+
83
+ Wrappers may provide static factory methods for common initialization patterns:
84
+
85
+ - `getFromConfig(config)` - construct from configuration object
86
+ - `getFromL1ContractsValues(deployResult)` - construct from deployment result
87
+
88
+ ### Wallet Assertions
89
+
90
+ For write operations that require a wallet, use an assertion helper:
91
+
92
+ ```typescript
93
+ private assertWallet(): GetContractReturnType<typeof FooAbi, ExtendedViemWalletClient> {
94
+ if (!isExtendedClient(this.client)) {
95
+ throw new Error('Wallet client is required for this operation');
96
+ }
97
+ return this.foo as GetContractReturnType<typeof FooAbi, ExtendedViemWalletClient>;
98
+ }
99
+ ```
100
+
101
+ ## Event Handling
102
+
103
+ ### Event Log Types
104
+
105
+ Event logs are wrapped in `L1EventLog<T>` to include L1 block context:
106
+
107
+ ```typescript
108
+ type L1EventLog<T> = {
109
+ l1BlockNumber: bigint;
110
+ l1BlockHash: Buffer32;
111
+ l1TransactionHash: Hex;
112
+ args: T;
113
+ };
114
+ ```
115
+
116
+ ### Event Fetching
117
+
118
+ Methods that fetch events convert viem's raw logs to domain types:
119
+
120
+ ```typescript
121
+ async getCheckpointProposedEvents(fromBlock: bigint, toBlock: bigint): Promise<CheckpointProposedLog[]> {
122
+ const logs = await this.rollup.getEvents.CheckpointProposed({}, { fromBlock, toBlock });
123
+ return logs.map(log => ({
124
+ l1BlockNumber: log.blockNumber!,
125
+ l1BlockHash: Buffer32.fromString(log.blockHash!),
126
+ l1TransactionHash: log.transactionHash!,
127
+ args: {
128
+ checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber!),
129
+ // ... convert other fields
130
+ },
131
+ }));
132
+ }
133
+ ```
134
+
135
+ ### Event Listeners
136
+
137
+ For reactive event handling, wrapper methods convert arguments before invoking callbacks:
138
+
139
+ ```typescript
140
+ public listenToCheckpointInvalidated(
141
+ callback: (args: { checkpointNumber: CheckpointNumber }) => unknown,
142
+ ): WatchContractEventReturnType {
143
+ return this.rollup.watchEvent.CheckpointInvalidated({}, {
144
+ onLogs: logs => {
145
+ for (const log of logs) {
146
+ if (log.args.checkpointNumber !== undefined) {
147
+ callback({ checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber) });
148
+ }
149
+ }
150
+ },
151
+ });
152
+ }
153
+ ```
154
+
155
+ ## Error Handling
156
+
157
+ Custom error classes in `errors.ts` extend `Error` and set `this.name` for proper error identification. Include relevant context as public readonly properties.
@@ -0,0 +1,200 @@
1
+ import { toHex as toPaddedHex } from '@aztec/foundation/bigint-buffer';
2
+ import type { CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
3
+ import type { Buffer32 } from '@aztec/foundation/buffer';
4
+ import { merge } from '@aztec/foundation/collection';
5
+ import type { Fr } from '@aztec/foundation/curves/bn254';
6
+
7
+ import type { StateOverride } from 'viem';
8
+
9
+ import { type FeeHeader, RollupContract } from './rollup.js';
10
+
11
+ /**
12
+ * Override values for the pending checkpoint that the simulation should treat as already applied.
13
+ * Every field is optional at plan-building time so callers can populate them incrementally; whatever
14
+ * is present at translation time is forwarded to the partial `tempCheckpointLogs` helper so the
15
+ * load-bearing `slotNumber` can land even if other fields could not be derived locally.
16
+ */
17
+ export type PendingCheckpointOverrideState = {
18
+ archive?: Fr;
19
+ feeHeader?: FeeHeader;
20
+ headerHash?: Fr;
21
+ outHash?: Fr;
22
+ payloadDigest?: Buffer32;
23
+ slotNumber?: SlotNumber;
24
+ };
25
+
26
+ export type ChainTipsOverride = {
27
+ pending?: CheckpointNumber;
28
+ proven?: CheckpointNumber;
29
+ };
30
+
31
+ /** Describes the simulated L1 rollup state that downstream calls should observe. */
32
+ export type SimulationOverridesPlan = {
33
+ chainTipsOverride?: ChainTipsOverride;
34
+ pendingCheckpointState?: PendingCheckpointOverrideState;
35
+ disableBlobCheck?: boolean;
36
+ };
37
+
38
+ /** Builds a single-checkpoint simulation plan before it is translated into a viem state override. */
39
+ export class SimulationOverridesBuilder {
40
+ private chainTipsOverride?: ChainTipsOverride;
41
+ private pendingCheckpointState?: PendingCheckpointOverrideState;
42
+ private disableBlobCheck = false;
43
+
44
+ /** Starts from an existing plan so callers can extend or specialize it. */
45
+ public static from(plan: SimulationOverridesPlan | undefined): SimulationOverridesBuilder {
46
+ return new SimulationOverridesBuilder().merge(plan);
47
+ }
48
+
49
+ /**
50
+ * Merges another plan into this builder. Later values win on a per-half basis for chain tips,
51
+ * but explicit `undefined` fields in the incoming plan are ignored so they cannot erase a
52
+ * previously-set value.
53
+ */
54
+ public merge(plan: SimulationOverridesPlan | undefined): this {
55
+ if (!plan) {
56
+ return this;
57
+ }
58
+
59
+ if (plan.chainTipsOverride) {
60
+ this.chainTipsOverride = merge(this.chainTipsOverride ?? {}, plan.chainTipsOverride);
61
+ }
62
+ if (plan.pendingCheckpointState) {
63
+ this.pendingCheckpointState = merge(this.pendingCheckpointState ?? {}, plan.pendingCheckpointState);
64
+ }
65
+ this.disableBlobCheck = this.disableBlobCheck || (plan.disableBlobCheck ?? false);
66
+
67
+ return this;
68
+ }
69
+
70
+ /**
71
+ * Sets the pending and/or proven checkpoint number overrides. Subsequent calls merge into the existing
72
+ * override on a per-half basis, so callers can set pending in one call and proven in another without
73
+ * clobbering each other.
74
+ */
75
+ public withChainTips(override: ChainTipsOverride): this {
76
+ this.chainTipsOverride = { ...(this.chainTipsOverride ?? {}), ...override };
77
+ return this;
78
+ }
79
+
80
+ /** Overrides the archive root for the configured pending checkpoint. */
81
+ public withPendingArchive(archive: Fr): this {
82
+ this.assertPendingCheckpointNumber();
83
+ this.pendingCheckpointState = { ...(this.pendingCheckpointState ?? {}), archive };
84
+ return this;
85
+ }
86
+
87
+ /** Overrides the fee header for the configured pending checkpoint. */
88
+ public withPendingFeeHeader(feeHeader: FeeHeader): this {
89
+ this.assertPendingCheckpointNumber();
90
+ this.pendingCheckpointState = { ...(this.pendingCheckpointState ?? {}), feeHeader };
91
+ return this;
92
+ }
93
+
94
+ /**
95
+ * Overrides one or more `tempCheckpointLogs` cell fields for the configured pending checkpoint.
96
+ * Fields are independent: any subset can be provided. The translator (`makeTempCheckpointLogOverride`)
97
+ * emits a stateDiff entry per field actually set, so unspecified fields stay at their on-chain
98
+ * values.
99
+ *
100
+ * `slotNumber` is load-bearing for `STFLib.canPruneAtTime`: when the simulation overrides `pending`
101
+ * to a checkpoint that has no on-chain `tempCheckpointLogs` entry yet, the missing slotNumber falls
102
+ * back to 0 and the contract treats the pending tip as belonging to epoch 0, triggering a phantom
103
+ * prune that silently undoes the `pending` override.
104
+ */
105
+ public withPendingTempCheckpointLogFields(fields: {
106
+ headerHash?: Fr;
107
+ outHash?: Fr;
108
+ payloadDigest?: Buffer32;
109
+ slotNumber?: SlotNumber;
110
+ }): this {
111
+ this.assertPendingCheckpointNumber();
112
+ this.pendingCheckpointState = { ...(this.pendingCheckpointState ?? {}), ...fields };
113
+ return this;
114
+ }
115
+
116
+ /** Disables blob checking for simulations that cannot provide DA inputs. */
117
+ public withoutBlobCheck(): this {
118
+ this.disableBlobCheck = true;
119
+ return this;
120
+ }
121
+
122
+ /** Builds the final plan, or `undefined` when no overrides were configured. */
123
+ public build(): SimulationOverridesPlan | undefined {
124
+ if (!this.pendingCheckpointState && !this.chainTipsOverride && !this.disableBlobCheck) {
125
+ return undefined;
126
+ }
127
+
128
+ return {
129
+ chainTipsOverride: this.chainTipsOverride,
130
+ pendingCheckpointState: this.pendingCheckpointState,
131
+ disableBlobCheck: this.disableBlobCheck || undefined,
132
+ };
133
+ }
134
+
135
+ private assertPendingCheckpointNumber(): void {
136
+ if (this.chainTipsOverride?.pending === undefined) {
137
+ throw new Error('withChainTips({ pending }) must be called before attaching archive or fee header overrides');
138
+ }
139
+ }
140
+ }
141
+
142
+ /** Translates a simulation plan into the viem state override shape expected by rollup calls. */
143
+ export async function buildSimulationOverridesStateOverride(
144
+ rollup: RollupContract,
145
+ plan: SimulationOverridesPlan | undefined,
146
+ ): Promise<StateOverride> {
147
+ if (!plan) {
148
+ return [];
149
+ }
150
+
151
+ const rollupStateDiff: NonNullable<StateOverride[number]['stateDiff']> = [];
152
+
153
+ if (plan.chainTipsOverride) {
154
+ rollupStateDiff.push(...extractRollupStateDiff(await rollup.makeChainTipsOverride(plan.chainTipsOverride)));
155
+ }
156
+
157
+ if (plan.pendingCheckpointState && plan.chainTipsOverride?.pending === undefined) {
158
+ throw new Error('pendingCheckpointState requires chainTipsOverride.pending to be set');
159
+ }
160
+
161
+ if (plan.pendingCheckpointState?.archive) {
162
+ rollupStateDiff.push(
163
+ ...extractRollupStateDiff(
164
+ rollup.makeArchiveOverride(plan.chainTipsOverride!.pending!, plan.pendingCheckpointState.archive),
165
+ ),
166
+ );
167
+ }
168
+
169
+ if (plan.pendingCheckpointState) {
170
+ rollupStateDiff.push(
171
+ ...extractRollupStateDiff(
172
+ await rollup.makeTempCheckpointLogOverride(plan.chainTipsOverride!.pending!, {
173
+ headerHash: plan.pendingCheckpointState.headerHash,
174
+ outHash: plan.pendingCheckpointState.outHash,
175
+ payloadDigest: plan.pendingCheckpointState.payloadDigest,
176
+ slotNumber: plan.pendingCheckpointState.slotNumber,
177
+ feeHeader: plan.pendingCheckpointState.feeHeader,
178
+ }),
179
+ ),
180
+ );
181
+ }
182
+
183
+ if (plan.disableBlobCheck) {
184
+ rollupStateDiff.push({
185
+ slot: toPaddedHex(RollupContract.checkBlobStorageSlot, true),
186
+ value: toPaddedHex(0n, true),
187
+ });
188
+ }
189
+
190
+ if (rollupStateDiff.length === 0) {
191
+ return [];
192
+ }
193
+
194
+ return [{ address: rollup.address, stateDiff: rollupStateDiff }];
195
+ }
196
+
197
+ function extractRollupStateDiff(override: StateOverride | StateOverride[number] | undefined) {
198
+ const entries = Array.isArray(override) ? override : override ? [override] : [];
199
+ return entries.flatMap(entry => entry.stateDiff ?? []);
200
+ }