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

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 (229) 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/client.d.ts +5 -3
  5. package/dest/client.d.ts.map +1 -1
  6. package/dest/client.js +16 -2
  7. package/dest/config.d.ts +107 -16
  8. package/dest/config.d.ts.map +1 -1
  9. package/dest/config.js +456 -22
  10. package/dest/contracts/empire_base.d.ts +21 -6
  11. package/dest/contracts/empire_base.d.ts.map +1 -1
  12. package/dest/contracts/empire_base.js +75 -2
  13. package/dest/contracts/empire_slashing_proposer.d.ts +65 -0
  14. package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -0
  15. package/dest/contracts/empire_slashing_proposer.js +194 -0
  16. package/dest/contracts/errors.d.ts +7 -0
  17. package/dest/contracts/errors.d.ts.map +1 -0
  18. package/dest/contracts/errors.js +12 -0
  19. package/dest/contracts/fee_asset_handler.d.ts +19 -0
  20. package/dest/contracts/fee_asset_handler.d.ts.map +1 -0
  21. package/dest/contracts/fee_asset_handler.js +57 -0
  22. package/dest/contracts/fee_juice.d.ts +5 -6
  23. package/dest/contracts/fee_juice.d.ts.map +1 -1
  24. package/dest/contracts/fee_juice.js +27 -20
  25. package/dest/contracts/governance.d.ts +36 -25
  26. package/dest/contracts/governance.d.ts.map +1 -1
  27. package/dest/contracts/governance.js +87 -84
  28. package/dest/contracts/governance_proposer.d.ts +13 -11
  29. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  30. package/dest/contracts/governance_proposer.js +32 -18
  31. package/dest/contracts/gse.d.ts +32 -0
  32. package/dest/contracts/gse.d.ts.map +1 -0
  33. package/dest/contracts/gse.js +72 -0
  34. package/dest/contracts/inbox.d.ts +26 -0
  35. package/dest/contracts/inbox.d.ts.map +1 -0
  36. package/dest/contracts/inbox.js +45 -0
  37. package/dest/contracts/index.d.ts +8 -2
  38. package/dest/contracts/index.d.ts.map +1 -1
  39. package/dest/contracts/index.js +8 -2
  40. package/dest/contracts/multicall.d.ts +21 -0
  41. package/dest/contracts/multicall.d.ts.map +1 -0
  42. package/dest/contracts/multicall.js +156 -0
  43. package/dest/contracts/registry.d.ts +9 -4
  44. package/dest/contracts/registry.d.ts.map +1 -1
  45. package/dest/contracts/registry.js +44 -16
  46. package/dest/contracts/rollup.d.ts +202 -29
  47. package/dest/contracts/rollup.d.ts.map +1 -1
  48. package/dest/contracts/rollup.js +500 -55
  49. package/dest/contracts/slasher_contract.d.ts +44 -0
  50. package/dest/contracts/slasher_contract.d.ts.map +1 -0
  51. package/dest/contracts/slasher_contract.js +75 -0
  52. package/dest/contracts/tally_slashing_proposer.d.ts +138 -0
  53. package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -0
  54. package/dest/contracts/tally_slashing_proposer.js +313 -0
  55. package/dest/contracts/utils.d.ts +3 -0
  56. package/dest/contracts/utils.d.ts.map +1 -0
  57. package/dest/contracts/utils.js +11 -0
  58. package/dest/deploy_l1_contracts.d.ts +128 -21112
  59. package/dest/deploy_l1_contracts.d.ts.map +1 -1
  60. package/dest/deploy_l1_contracts.js +1204 -418
  61. package/dest/eth-signer/eth-signer.d.ts +21 -0
  62. package/dest/eth-signer/eth-signer.d.ts.map +1 -0
  63. package/dest/eth-signer/eth-signer.js +5 -0
  64. package/dest/eth-signer/index.d.ts +2 -0
  65. package/dest/eth-signer/index.d.ts.map +1 -0
  66. package/dest/eth-signer/index.js +1 -0
  67. package/dest/index.d.ts +6 -2
  68. package/dest/index.d.ts.map +1 -1
  69. package/dest/index.js +6 -2
  70. package/dest/l1_artifacts.d.ts +76184 -0
  71. package/dest/l1_artifacts.d.ts.map +1 -0
  72. package/dest/l1_artifacts.js +166 -0
  73. package/dest/l1_contract_addresses.d.ts +21 -1
  74. package/dest/l1_contract_addresses.d.ts.map +1 -1
  75. package/dest/l1_contract_addresses.js +22 -18
  76. package/dest/l1_reader.d.ts +1 -1
  77. package/dest/l1_reader.d.ts.map +1 -1
  78. package/dest/l1_reader.js +8 -8
  79. package/dest/l1_tx_utils/config.d.ts +59 -0
  80. package/dest/l1_tx_utils/config.d.ts.map +1 -0
  81. package/dest/l1_tx_utils/config.js +73 -0
  82. package/dest/l1_tx_utils/constants.d.ts +6 -0
  83. package/dest/l1_tx_utils/constants.d.ts.map +1 -0
  84. package/dest/l1_tx_utils/constants.js +14 -0
  85. package/dest/l1_tx_utils/factory.d.ts +24 -0
  86. package/dest/l1_tx_utils/factory.d.ts.map +1 -0
  87. package/dest/l1_tx_utils/factory.js +12 -0
  88. package/dest/l1_tx_utils/index.d.ts +10 -0
  89. package/dest/l1_tx_utils/index.d.ts.map +1 -0
  90. package/dest/l1_tx_utils/index.js +10 -0
  91. package/dest/l1_tx_utils/interfaces.d.ts +76 -0
  92. package/dest/l1_tx_utils/interfaces.d.ts.map +1 -0
  93. package/dest/l1_tx_utils/interfaces.js +4 -0
  94. package/dest/l1_tx_utils/l1_tx_utils.d.ts +95 -0
  95. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -0
  96. package/dest/l1_tx_utils/l1_tx_utils.js +610 -0
  97. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +26 -0
  98. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +1 -0
  99. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +26 -0
  100. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +94 -0
  101. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -0
  102. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +431 -0
  103. package/dest/l1_tx_utils/signer.d.ts +4 -0
  104. package/dest/l1_tx_utils/signer.d.ts.map +1 -0
  105. package/dest/l1_tx_utils/signer.js +16 -0
  106. package/dest/l1_tx_utils/types.d.ts +67 -0
  107. package/dest/l1_tx_utils/types.d.ts.map +1 -0
  108. package/dest/l1_tx_utils/types.js +26 -0
  109. package/dest/l1_tx_utils/utils.d.ts +4 -0
  110. package/dest/l1_tx_utils/utils.d.ts.map +1 -0
  111. package/dest/l1_tx_utils/utils.js +14 -0
  112. package/dest/l1_types.d.ts +6 -0
  113. package/dest/l1_types.d.ts.map +1 -0
  114. package/dest/l1_types.js +1 -0
  115. package/dest/publisher_manager.d.ts +15 -0
  116. package/dest/publisher_manager.d.ts.map +1 -0
  117. package/dest/publisher_manager.js +88 -0
  118. package/dest/queries.d.ts +3 -1
  119. package/dest/queries.d.ts.map +1 -1
  120. package/dest/queries.js +51 -12
  121. package/dest/test/chain_monitor.d.ts +72 -0
  122. package/dest/test/chain_monitor.d.ts.map +1 -0
  123. package/dest/test/chain_monitor.js +216 -0
  124. package/dest/test/delayed_tx_utils.d.ts +7 -2
  125. package/dest/test/delayed_tx_utils.d.ts.map +1 -1
  126. package/dest/test/delayed_tx_utils.js +13 -6
  127. package/dest/{eth_cheat_codes.d.ts → test/eth_cheat_codes.d.ts} +87 -13
  128. package/dest/test/eth_cheat_codes.d.ts.map +1 -0
  129. package/dest/test/eth_cheat_codes.js +552 -0
  130. package/dest/test/eth_cheat_codes_with_state.d.ts +1 -1
  131. package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -1
  132. package/dest/test/eth_cheat_codes_with_state.js +1 -1
  133. package/dest/test/index.d.ts +3 -0
  134. package/dest/test/index.d.ts.map +1 -1
  135. package/dest/test/index.js +3 -0
  136. package/dest/test/rollup_cheat_codes.d.ts +86 -0
  137. package/dest/test/rollup_cheat_codes.d.ts.map +1 -0
  138. package/dest/test/rollup_cheat_codes.js +268 -0
  139. package/dest/test/start_anvil.d.ts +5 -0
  140. package/dest/test/start_anvil.d.ts.map +1 -1
  141. package/dest/test/start_anvil.js +15 -7
  142. package/dest/test/tx_delayer.d.ts +17 -6
  143. package/dest/test/tx_delayer.d.ts.map +1 -1
  144. package/dest/test/tx_delayer.js +95 -19
  145. package/dest/test/upgrade_utils.d.ts +5 -4
  146. package/dest/test/upgrade_utils.d.ts.map +1 -1
  147. package/dest/test/upgrade_utils.js +23 -16
  148. package/dest/types.d.ts +6 -7
  149. package/dest/types.d.ts.map +1 -1
  150. package/dest/types.js +3 -1
  151. package/dest/utils.d.ts +1 -0
  152. package/dest/utils.d.ts.map +1 -1
  153. package/dest/utils.js +43 -88
  154. package/dest/zkPassportVerifierAddress.d.ts +15 -0
  155. package/dest/zkPassportVerifierAddress.d.ts.map +1 -0
  156. package/dest/zkPassportVerifierAddress.js +11 -0
  157. package/package.json +24 -16
  158. package/src/account.ts +5 -0
  159. package/src/client.ts +42 -4
  160. package/src/config.ts +584 -31
  161. package/src/contracts/empire_base.ts +75 -6
  162. package/src/contracts/empire_slashing_proposer.ts +259 -0
  163. package/src/contracts/errors.ts +13 -0
  164. package/src/contracts/fee_asset_handler.ts +63 -0
  165. package/src/contracts/fee_juice.ts +29 -15
  166. package/src/contracts/governance.ts +80 -77
  167. package/src/contracts/governance_proposer.ts +60 -24
  168. package/src/contracts/gse.ts +88 -0
  169. package/src/contracts/inbox.ts +63 -0
  170. package/src/contracts/index.ts +8 -2
  171. package/src/contracts/multicall.ts +155 -0
  172. package/src/contracts/registry.ts +51 -26
  173. package/src/contracts/rollup.ts +585 -56
  174. package/src/contracts/slasher_contract.ts +89 -0
  175. package/src/contracts/tally_slashing_proposer.ts +315 -0
  176. package/src/contracts/utils.ts +14 -0
  177. package/src/deploy_l1_contracts.ts +1467 -566
  178. package/src/eth-signer/eth-signer.ts +25 -0
  179. package/src/eth-signer/index.ts +1 -0
  180. package/src/index.ts +6 -2
  181. package/src/l1_artifacts.ts +254 -0
  182. package/src/l1_contract_addresses.ts +32 -19
  183. package/src/l1_reader.ts +9 -9
  184. package/src/l1_tx_utils/README.md +177 -0
  185. package/src/l1_tx_utils/config.ts +140 -0
  186. package/src/l1_tx_utils/constants.ts +18 -0
  187. package/src/l1_tx_utils/factory.ts +64 -0
  188. package/src/l1_tx_utils/index.ts +12 -0
  189. package/src/l1_tx_utils/interfaces.ts +86 -0
  190. package/src/l1_tx_utils/l1_tx_utils.ts +718 -0
  191. package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +77 -0
  192. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +559 -0
  193. package/src/l1_tx_utils/signer.ts +28 -0
  194. package/src/l1_tx_utils/types.ts +85 -0
  195. package/src/l1_tx_utils/utils.ts +16 -0
  196. package/src/l1_types.ts +6 -0
  197. package/src/publisher_manager.ts +106 -0
  198. package/src/queries.ts +70 -15
  199. package/src/test/chain_monitor.ts +243 -0
  200. package/src/test/delayed_tx_utils.ts +34 -6
  201. package/src/test/eth_cheat_codes.ts +582 -0
  202. package/src/test/eth_cheat_codes_with_state.ts +1 -1
  203. package/src/test/index.ts +3 -0
  204. package/src/test/rollup_cheat_codes.ts +310 -0
  205. package/src/test/start_anvil.ts +20 -5
  206. package/src/test/tx_delayer.ts +127 -26
  207. package/src/test/upgrade_utils.ts +30 -21
  208. package/src/types.ts +10 -8
  209. package/src/utils.ts +49 -90
  210. package/src/zkPassportVerifierAddress.ts +15 -0
  211. package/dest/contracts/forwarder.d.ts +0 -24
  212. package/dest/contracts/forwarder.d.ts.map +0 -1
  213. package/dest/contracts/forwarder.js +0 -101
  214. package/dest/contracts/slashing_proposer.d.ts +0 -21
  215. package/dest/contracts/slashing_proposer.d.ts.map +0 -1
  216. package/dest/contracts/slashing_proposer.js +0 -47
  217. package/dest/eth_cheat_codes.d.ts.map +0 -1
  218. package/dest/eth_cheat_codes.js +0 -303
  219. package/dest/l1_tx_utils.d.ts +0 -192
  220. package/dest/l1_tx_utils.d.ts.map +0 -1
  221. package/dest/l1_tx_utils.js +0 -641
  222. package/dest/l1_tx_utils_with_blobs.d.ts +0 -12
  223. package/dest/l1_tx_utils_with_blobs.d.ts.map +0 -1
  224. package/dest/l1_tx_utils_with_blobs.js +0 -64
  225. package/src/contracts/forwarder.ts +0 -132
  226. package/src/contracts/slashing_proposer.ts +0 -51
  227. package/src/eth_cheat_codes.ts +0 -314
  228. package/src/l1_tx_utils.ts +0 -847
  229. package/src/l1_tx_utils_with_blobs.ts +0 -86
@@ -0,0 +1,552 @@
1
+ import { toBigIntBE, toHex } from '@aztec/foundation/bigint-buffer';
2
+ import { keccak256 } from '@aztec/foundation/crypto';
3
+ import { jsonStringify } from '@aztec/foundation/json-rpc';
4
+ import { createLogger } from '@aztec/foundation/log';
5
+ import { pluralize } from '@aztec/foundation/string';
6
+ import { createPublicClient, fallback, hexToNumber, http } from 'viem';
7
+ /**
8
+ * A class that provides utility functions for interacting with ethereum (L1).
9
+ */ export class EthCheatCodes {
10
+ rpcUrls;
11
+ dateProvider;
12
+ logger;
13
+ publicClient;
14
+ constructor(/**
15
+ * The RPC URL to use for interacting with the chain
16
+ */ rpcUrls, /**
17
+ * The date provider to use for time operations
18
+ */ dateProvider, /**
19
+ * The logger to use for the eth cheatcodes
20
+ */ logger = createLogger('ethereum:cheat_codes')){
21
+ this.rpcUrls = rpcUrls;
22
+ this.dateProvider = dateProvider;
23
+ this.logger = logger;
24
+ this.publicClient = createPublicClient({
25
+ transport: fallback(this.rpcUrls.map((url)=>http(url)))
26
+ });
27
+ }
28
+ rpcCall(method, params) {
29
+ this.logger.debug(`Calling ${method} with params: ${jsonStringify(params)} on ${this.rpcUrls.join(', ')}`);
30
+ return this.doRpcCall(method, params);
31
+ }
32
+ async doRpcCall(method, params) {
33
+ return await this.publicClient.transport.request({
34
+ method,
35
+ params
36
+ });
37
+ }
38
+ /**
39
+ * Get the auto mine status of the underlying chain
40
+ * @returns True if automine is on, false otherwise
41
+ */ async isAutoMining() {
42
+ try {
43
+ const res = await this.doRpcCall('anvil_getAutomine', []);
44
+ return res;
45
+ } catch (err) {
46
+ this.logger.error(`Calling "anvil_getAutomine" failed with:`, err);
47
+ }
48
+ return false;
49
+ }
50
+ /**
51
+ * Get the current blocknumber
52
+ * @returns The current block number
53
+ */ async blockNumber() {
54
+ const res = await this.doRpcCall('eth_blockNumber', []);
55
+ return parseInt(res, 16);
56
+ }
57
+ /**
58
+ * Get the current chainId
59
+ * @returns The current chainId
60
+ */ async chainId() {
61
+ const res = await this.doRpcCall('eth_chainId', []);
62
+ return parseInt(res, 16);
63
+ }
64
+ /**
65
+ * Get the current timestamp
66
+ * @returns The current timestamp
67
+ */ async timestamp() {
68
+ const res = await this.doRpcCall('eth_getBlockByNumber', [
69
+ 'latest',
70
+ true
71
+ ]);
72
+ return parseInt(res.timestamp, 16);
73
+ }
74
+ /**
75
+ * Advance the chain by a number of blocks
76
+ * @param numberOfBlocks - The number of blocks to mine
77
+ */ async mine(numberOfBlocks = 1) {
78
+ await this.doMine(Number(numberOfBlocks));
79
+ this.logger.warn(`Mined ${numberOfBlocks} L1 blocks`);
80
+ }
81
+ async doMine(numberOfBlocks = 1) {
82
+ try {
83
+ await this.doRpcCall('hardhat_mine', [
84
+ numberOfBlocks
85
+ ]);
86
+ } catch (err) {
87
+ throw new Error(`Error mining: ${err}`);
88
+ }
89
+ }
90
+ /**
91
+ * Mines a single block with evm_mine
92
+ */ async evmMine() {
93
+ try {
94
+ await this.doRpcCall('evm_mine', []);
95
+ this.logger.warn(`Mined 1 L1 block with evm_mine`);
96
+ } catch (err) {
97
+ throw new Error(`Error mining: ${err}`);
98
+ }
99
+ }
100
+ /**
101
+ * Set the balance of an account
102
+ * @param account - The account to set the balance for
103
+ * @param balance - The balance to set
104
+ */ async setBalance(account, balance) {
105
+ try {
106
+ await this.rpcCall('anvil_setBalance', [
107
+ account.toString(),
108
+ toHex(balance)
109
+ ]);
110
+ } catch (err) {
111
+ throw new Error(`Error setting balance for ${account}: ${err}`);
112
+ }
113
+ this.logger.warn(`Set balance for ${account} to ${balance}`);
114
+ }
115
+ async getBalance(account) {
116
+ const res = await this.doRpcCall('eth_getBalance', [
117
+ account.toString(),
118
+ 'latest'
119
+ ]);
120
+ return BigInt(res);
121
+ }
122
+ /**
123
+ * Set the interval between successive blocks (block time). This does NOT enable interval mining.
124
+ * @param interval - The interval to use between blocks
125
+ */ async setBlockInterval(interval) {
126
+ try {
127
+ await this.rpcCall('anvil_setBlockTimestampInterval', [
128
+ interval
129
+ ]);
130
+ } catch (err) {
131
+ throw new Error(`Error setting block interval: ${err}`);
132
+ }
133
+ this.logger.warn(`Set L1 block interval to ${interval}`);
134
+ }
135
+ /**
136
+ * Set the next block base fee per gas
137
+ * @param baseFee - The base fee to set
138
+ */ async setNextBlockBaseFeePerGas(baseFee) {
139
+ try {
140
+ await this.rpcCall('anvil_setNextBlockBaseFeePerGas', [
141
+ baseFee.toString()
142
+ ]);
143
+ } catch (err) {
144
+ throw new Error(`Error setting next block base fee per gas: ${err}`);
145
+ }
146
+ this.logger.warn(`Set L1 next block base fee per gas to ${baseFee}`);
147
+ }
148
+ /**
149
+ * Get interval mining if set.
150
+ * @param seconds - The interval to use between blocks
151
+ */ getIntervalMining() {
152
+ try {
153
+ return this.doRpcCall('anvil_getIntervalMining', []);
154
+ } catch (err) {
155
+ throw new Error(`Error getting interval mining: ${err}`);
156
+ }
157
+ }
158
+ /**
159
+ * Enable interval mining at the given interval (block time)
160
+ * @param seconds - The interval to use between blocks
161
+ */ async setIntervalMining(seconds, opts = {}) {
162
+ try {
163
+ await this.rpcCall('anvil_setIntervalMining', [
164
+ seconds
165
+ ]);
166
+ } catch (err) {
167
+ throw new Error(`Error setting interval mining: ${err}`);
168
+ }
169
+ if (!opts.silent) {
170
+ this.logger.warn(`Set L1 interval mining to ${seconds} seconds`);
171
+ }
172
+ }
173
+ /**
174
+ * Set the automine status of the underlying anvil chain
175
+ * @param automine - The automine status to set
176
+ */ async setAutomine(automine, opts = {}) {
177
+ try {
178
+ await this.rpcCall('anvil_setAutomine', [
179
+ automine
180
+ ]);
181
+ } catch (err) {
182
+ throw new Error(`Error setting automine: ${err}`);
183
+ }
184
+ if (!opts.silent) {
185
+ this.logger.warn(`Set L1 automine to ${automine}`);
186
+ }
187
+ }
188
+ /**
189
+ * Drop a transaction from the mempool
190
+ * @param txHash - The transaction hash
191
+ */ async dropTransaction(txHash) {
192
+ try {
193
+ await this.rpcCall('anvil_dropTransaction', [
194
+ txHash
195
+ ]);
196
+ } catch (err) {
197
+ throw new Error(`Error dropping transaction: ${err}`);
198
+ }
199
+ this.logger.warn(`Dropped transaction ${txHash}`);
200
+ }
201
+ /**
202
+ * Set the next block timestamp
203
+ * @param timestamp - The timestamp to set the next block to
204
+ */ async setNextBlockTimestamp(timestamp) {
205
+ try {
206
+ await this.rpcCall('evm_setNextBlockTimestamp', [
207
+ timestamp instanceof Date ? Math.floor(timestamp.getTime() / 1000) : timestamp
208
+ ]);
209
+ } catch (err) {
210
+ throw new Error(`Error setting next block timestamp: ${err.message}`);
211
+ }
212
+ this.logger.warn(`Set L1 next block timestamp to ${timestamp}`);
213
+ }
214
+ /**
215
+ * Set the next block timestamp and mines the block.
216
+ * Optionally resets interval mining so the next block is mined in `blockInterval` seconds from now.
217
+ * Always updates the injected date provider to follow L1 time.
218
+ * @param timestamp - The timestamp to set the next block to
219
+ */ async warp(timestamp, opts = {}) {
220
+ let blockInterval = null;
221
+ try {
222
+ // Load current block interval and disable it
223
+ if (opts.resetBlockInterval) {
224
+ blockInterval = await this.getIntervalMining();
225
+ if (blockInterval !== null) {
226
+ await this.setIntervalMining(0, {
227
+ silent: true
228
+ });
229
+ }
230
+ }
231
+ // Set the timestamp of the next block to be mined
232
+ await this.rpcCall('evm_setNextBlockTimestamp', [
233
+ Number(timestamp)
234
+ ]);
235
+ // And mine a block so the timestamp goes into effect now
236
+ await this.doMine();
237
+ // Update the injected date provider so it follows L1 time
238
+ if ('setTime' in this.dateProvider) {
239
+ this.dateProvider.setTime(Number(timestamp) * 1000);
240
+ }
241
+ } catch (err) {
242
+ throw new Error(`Error warping: ${err}`);
243
+ } finally{
244
+ // Restore interval mining so the next block is mined in `blockInterval` seconds from this one
245
+ if (opts.resetBlockInterval && blockInterval !== null && blockInterval > 0) {
246
+ await this.setIntervalMining(blockInterval, {
247
+ silent: true
248
+ });
249
+ }
250
+ }
251
+ if (!opts.silent) {
252
+ this.logger.warn(`Warped L1 timestamp to ${timestamp}`);
253
+ }
254
+ }
255
+ /**
256
+ * Load the value at a storage slot of a contract address on eth
257
+ * @param contract - The contract address
258
+ * @param slot - The storage slot
259
+ * @returns - The value at the storage slot
260
+ */ async load(contract, slot) {
261
+ const res = await this.rpcCall('eth_getStorageAt', [
262
+ contract.toString(),
263
+ toHex(slot),
264
+ 'latest'
265
+ ]);
266
+ return BigInt(res);
267
+ }
268
+ /**
269
+ * Set the value at a storage slot of a contract address on eth
270
+ * @param contract - The contract address
271
+ * @param slot - The storage slot
272
+ * @param value - The value to set the storage slot to
273
+ */ async store(contract, slot, value, opts = {}) {
274
+ // for the rpc call, we need to change value to be a 32 byte hex string.
275
+ try {
276
+ await this.rpcCall('hardhat_setStorageAt', [
277
+ contract.toString(),
278
+ toHex(slot),
279
+ toHex(value, true)
280
+ ]);
281
+ } catch (err) {
282
+ throw new Error(`Error setting storage for contract ${contract} at ${slot}: ${err}`);
283
+ }
284
+ if (!opts.silent) {
285
+ this.logger.warn(`Set L1 storage for contract ${contract} at ${slot} to ${value}`);
286
+ }
287
+ }
288
+ /**
289
+ * Computes the slot value for a given map and key.
290
+ * @param baseSlot - The base slot of the map (specified in Aztec.nr contract)
291
+ * @param key - The key to lookup in the map
292
+ * @returns The storage slot of the value in the map
293
+ */ keccak256(baseSlot, key) {
294
+ // abi encode (removing the 0x) - concat key and baseSlot (both padded to 32 bytes)
295
+ const abiEncoded = toHex(key, true).substring(2) + toHex(baseSlot, true).substring(2);
296
+ return toBigIntBE(keccak256(Buffer.from(abiEncoded, 'hex')));
297
+ }
298
+ /**
299
+ * Send transactions impersonating an externally owned account or contract.
300
+ * @param who - The address to impersonate
301
+ */ async startImpersonating(who) {
302
+ try {
303
+ // Since the `who` impersonated will sometimes be a contract without funds, we fund it if needed.
304
+ if (await this.getBalance(who) === 0n) {
305
+ await this.setBalance(who, 10n * 10n ** 18n);
306
+ }
307
+ await this.rpcCall('hardhat_impersonateAccount', [
308
+ who.toString()
309
+ ]);
310
+ } catch (err) {
311
+ throw new Error(`Error impersonating ${who}: ${err}`);
312
+ }
313
+ this.logger.warn(`Impersonating ${who}`);
314
+ }
315
+ /**
316
+ * Stop impersonating an account that you are currently impersonating.
317
+ * @param who - The address to stop impersonating
318
+ */ async stopImpersonating(who) {
319
+ try {
320
+ await this.rpcCall('hardhat_stopImpersonatingAccount', [
321
+ who.toString()
322
+ ]);
323
+ } catch (err) {
324
+ throw new Error(`Error when stopping the impersonation of ${who}: ${err}`);
325
+ }
326
+ this.logger.warn(`Stopped impersonating ${who}`);
327
+ }
328
+ /**
329
+ * Set the bytecode for a contract
330
+ * @param contract - The contract address
331
+ * @param bytecode - The bytecode to set
332
+ */ async etch(contract, bytecode) {
333
+ try {
334
+ await this.rpcCall('hardhat_setCode', [
335
+ contract.toString(),
336
+ bytecode
337
+ ]);
338
+ } catch (err) {
339
+ throw new Error(`Error setting bytecode for ${contract}: ${err}`);
340
+ }
341
+ this.logger.warn(`Set bytecode for ${contract} to ${bytecode}`);
342
+ }
343
+ /**
344
+ * Get the bytecode for a contract
345
+ * @param contract - The contract address
346
+ * @returns The bytecode for the contract
347
+ */ async getBytecode(contract) {
348
+ return await this.doRpcCall('eth_getCode', [
349
+ contract.toString(),
350
+ 'latest'
351
+ ]);
352
+ }
353
+ /**
354
+ * Get the raw transaction object for a given transaction hash
355
+ * @param txHash - The transaction hash
356
+ * @returns The raw transaction
357
+ */ async getRawTransaction(txHash) {
358
+ return await this.doRpcCall('debug_getRawTransaction', [
359
+ txHash
360
+ ]);
361
+ }
362
+ /**
363
+ * Get the trace for a given transaction hash
364
+ * @param txHash - The transaction hash
365
+ * @returns The trace
366
+ */ async debugTraceTransaction(txHash) {
367
+ return await this.doRpcCall('debug_traceTransaction', [
368
+ txHash
369
+ ]);
370
+ }
371
+ /**
372
+ * Triggers a reorg of the given depth, removing those blocks from the chain.
373
+ * @param depth - The depth of the reorg
374
+ */ reorg(depth) {
375
+ return this.execWithPausedAnvil(()=>{
376
+ return this.rpcCall('anvil_rollback', [
377
+ depth
378
+ ]);
379
+ });
380
+ }
381
+ /**
382
+ * Causes Anvil to reorg until the given block number is the new tip
383
+ * @param blockNumber - The block number that's going to be the new tip
384
+ */ reorgTo(blockNumber) {
385
+ if (blockNumber <= 0) {
386
+ throw new Error(`Can't reorg to block before genesis: ${blockNumber}`);
387
+ }
388
+ return this.execWithPausedAnvil(async ()=>{
389
+ const currentTip = await this.publicClient.getBlockNumber();
390
+ if (currentTip < BigInt(blockNumber)) {
391
+ this.logger.warn(`Can't call anvil_rollback, chain tip is behind target block: ${currentTip} < ${BigInt(blockNumber)}`);
392
+ return;
393
+ }
394
+ const depth = Number(currentTip - BigInt(blockNumber) + 1n);
395
+ await this.rpcCall('anvil_rollback', [
396
+ depth
397
+ ]);
398
+ this.logger.warn(`Reorged L1 chain to block number ${blockNumber} (depth ${depth})`);
399
+ });
400
+ }
401
+ /**
402
+ * Triggers a reorg of the given depth, optionally replacing it with new blocks.
403
+ * The resulting block height will be the same as the original chain.
404
+ * @param depth - The depth of the reorg
405
+ * @param newBlocks - The blocks to replace the old ones with, each represented as a list of txs.
406
+ */ async reorgWithReplacement(depth, newBlocks = []) {
407
+ this.logger.verbose(`Preparing L1 reorg with depth ${depth}`);
408
+ try {
409
+ await this.rpcCall('anvil_reorg', [
410
+ depth,
411
+ newBlocks.flatMap((txs, index)=>txs.map((tx)=>[
412
+ typeof tx === 'string' ? tx : {
413
+ value: 0,
414
+ ...tx
415
+ },
416
+ index
417
+ ]))
418
+ ]);
419
+ } catch (err) {
420
+ throw new Error(`Error reorging: ${err}`);
421
+ }
422
+ this.logger.warn(`Reorged L1 chain with depth ${depth} and ${newBlocks.length} new blocks`, {
423
+ depth,
424
+ newBlocks
425
+ });
426
+ }
427
+ traceTransaction(txHash) {
428
+ return this.doRpcCall('trace_transaction', [
429
+ txHash
430
+ ]);
431
+ }
432
+ async getTxPoolStatus() {
433
+ const { pending, queued } = await this.doRpcCall('txpool_status', []);
434
+ return {
435
+ pending: hexToNumber(pending),
436
+ queued: hexToNumber(queued)
437
+ };
438
+ }
439
+ async getTxPoolContents() {
440
+ const txpoolContent = await this.doRpcCall('txpool_content', []);
441
+ return mapTxPoolContent(txpoolContent);
442
+ }
443
+ /**
444
+ * Mines an empty block by temporarily removing all pending transactions from the mempool,
445
+ * mining a block, and then re-adding the transactions back to the pool.
446
+ */ async mineEmptyBlock(blockCount = 1) {
447
+ await this.execWithPausedAnvil(async ()=>{
448
+ // Get all pending and queued transactions from the pool
449
+ const txs = await this.getTxPoolContents();
450
+ this.logger.debug(`Found ${txs.length} transactions in pool`);
451
+ // Get raw transactions before dropping them
452
+ const rawTxs = [];
453
+ for (const tx of txs){
454
+ try {
455
+ const rawTx = await this.doRpcCall('debug_getRawTransaction', [
456
+ tx.hash
457
+ ]);
458
+ if (rawTx) {
459
+ rawTxs.push(rawTx);
460
+ this.logger.debug(`Got raw tx for ${tx.hash}`);
461
+ } else {
462
+ this.logger.warn(`No raw tx found for ${tx.hash}`);
463
+ }
464
+ } catch {
465
+ this.logger.warn(`Failed to get raw transaction for ${tx.hash}`);
466
+ }
467
+ }
468
+ this.logger.debug(`Retrieved ${rawTxs.length} raw transactions`);
469
+ // Drop all transactions from the mempool
470
+ await this.doRpcCall('anvil_dropAllTransactions', []);
471
+ // Mine an empty block
472
+ await this.doMine(blockCount);
473
+ // Re-add the transactions to the pool
474
+ for (const rawTx of rawTxs){
475
+ try {
476
+ const txHash = await this.doRpcCall('eth_sendRawTransaction', [
477
+ rawTx
478
+ ]);
479
+ this.logger.debug(`Re-added transaction ${txHash}`);
480
+ } catch (err) {
481
+ this.logger.warn(`Failed to re-add transaction: ${err}`);
482
+ }
483
+ }
484
+ if (rawTxs.length !== txs.length) {
485
+ this.logger.warn(`Failed to add all txs back: had ${txs.length} but re-added ${rawTxs.length}`);
486
+ }
487
+ });
488
+ this.logger.warn(`Mined ${blockCount} empty L1 ${pluralize('block', blockCount)}`);
489
+ }
490
+ async execWithPausedAnvil(fn) {
491
+ const [blockInterval, wasAutoMining] = await Promise.all([
492
+ this.getIntervalMining(),
493
+ this.isAutoMining()
494
+ ]);
495
+ try {
496
+ if (blockInterval !== null) {
497
+ await this.setIntervalMining(0, {
498
+ silent: true
499
+ });
500
+ }
501
+ if (wasAutoMining) {
502
+ await this.setAutomine(false, {
503
+ silent: true
504
+ });
505
+ }
506
+ return await fn();
507
+ } finally{
508
+ try {
509
+ // restore automine if necessary
510
+ if (wasAutoMining) {
511
+ await this.setAutomine(true, {
512
+ silent: true
513
+ });
514
+ }
515
+ } catch (err) {
516
+ this.logger.warn(`Failed to reenable automining: ${err}`);
517
+ }
518
+ try {
519
+ // restore automine if necessary
520
+ if (blockInterval !== null) {
521
+ await this.setIntervalMining(blockInterval, {
522
+ silent: true
523
+ });
524
+ }
525
+ } catch (err) {
526
+ this.logger.warn(`Failed to reenable interval mining: ${err}`);
527
+ }
528
+ }
529
+ }
530
+ async syncDateProvider() {
531
+ const timestamp = await this.timestamp();
532
+ if ('setTime' in this.dateProvider) {
533
+ this.dateProvider.setTime(timestamp * 1000);
534
+ }
535
+ }
536
+ }
537
+ function mapTxPoolContent(content) {
538
+ const result = [];
539
+ const processPool = (pool, poolState)=>{
540
+ for (const txsByNonce of Object.values(pool)){
541
+ for (const tx of Object.values(txsByNonce)){
542
+ result.push({
543
+ ...tx,
544
+ poolState
545
+ });
546
+ }
547
+ }
548
+ };
549
+ processPool(content.pending, 'pending');
550
+ processPool(content.queued, 'queued');
551
+ return result;
552
+ }
@@ -1,4 +1,4 @@
1
- import { EthCheatCodes } from '../eth_cheat_codes.js';
1
+ import { EthCheatCodes } from './eth_cheat_codes.js';
2
2
  /**
3
3
  * A class that provides utility functions for interacting with ethereum (L1) dumping/loading state to/from a file.
4
4
  * It is separated to avoid importing fs in the main EthCheatCodes class, which might be used in the browser.
@@ -1 +1 @@
1
- {"version":3,"file":"eth_cheat_codes_with_state.d.ts","sourceRoot":"","sources":["../../src/test/eth_cheat_codes_with_state.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD;;;GAGG;AACH,qBAAa,sBAAuB,SAAQ,aAAa;IACvD;;;OAGG;IACU,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAW5D;;;OAGG;IACU,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAS7D"}
1
+ {"version":3,"file":"eth_cheat_codes_with_state.d.ts","sourceRoot":"","sources":["../../src/test/eth_cheat_codes_with_state.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;GAGG;AACH,qBAAa,sBAAuB,SAAQ,aAAa;IACvD;;;OAGG;IACU,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAW5D;;;OAGG;IACU,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAS7D"}
@@ -1,5 +1,5 @@
1
1
  import fs from 'fs';
2
- import { EthCheatCodes } from '../eth_cheat_codes.js';
2
+ import { EthCheatCodes } from './eth_cheat_codes.js';
3
3
  /**
4
4
  * A class that provides utility functions for interacting with ethereum (L1) dumping/loading state to/from a file.
5
5
  * It is separated to avoid importing fs in the main EthCheatCodes class, which might be used in the browser.
@@ -1,6 +1,9 @@
1
1
  export * from './delayed_tx_utils.js';
2
+ export * from './eth_cheat_codes.js';
2
3
  export * from './eth_cheat_codes_with_state.js';
3
4
  export * from './start_anvil.js';
4
5
  export * from './tx_delayer.js';
5
6
  export * from './upgrade_utils.js';
7
+ export * from './chain_monitor.js';
8
+ export * from './rollup_cheat_codes.js';
6
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,iCAAiC,CAAC;AAChD,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iCAAiC,CAAC;AAChD,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC"}
@@ -1,5 +1,8 @@
1
1
  export * from './delayed_tx_utils.js';
2
+ export * from './eth_cheat_codes.js';
2
3
  export * from './eth_cheat_codes_with_state.js';
3
4
  export * from './start_anvil.js';
4
5
  export * from './tx_delayer.js';
5
6
  export * from './upgrade_utils.js';
7
+ export * from './chain_monitor.js';
8
+ export * from './rollup_cheat_codes.js';
@@ -0,0 +1,86 @@
1
+ import { type ViemPublicClient } from '@aztec/ethereum';
2
+ import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
3
+ import type { DateProvider } from '@aztec/foundation/timer';
4
+ import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
5
+ import { type GetContractReturnType, type Hex } from 'viem';
6
+ import { EthCheatCodes } from './eth_cheat_codes.js';
7
+ /** Cheat codes for the L1 rollup contract. */
8
+ export declare class RollupCheatCodes {
9
+ private ethCheatCodes;
10
+ private client;
11
+ private rollup;
12
+ private logger;
13
+ constructor(ethCheatCodes: EthCheatCodes, addresses: Pick<L1ContractAddresses, 'rollupAddress'>);
14
+ static create(rpcUrls: string[], addresses: Pick<L1ContractAddresses, 'rollupAddress'>, dateProvider: DateProvider): RollupCheatCodes;
15
+ /** Returns the current slot */
16
+ getSlot(): Promise<bigint>;
17
+ /** Returns the current epoch */
18
+ getEpoch(): Promise<bigint>;
19
+ /**
20
+ * Returns the pending and proven chain tips
21
+ * @returns The pending and proven chain tips
22
+ */
23
+ getTips(): Promise<{
24
+ /** The pending chain tip */ pending: bigint;
25
+ /** The proven chain tip */ proven: bigint;
26
+ }>;
27
+ /**
28
+ * Logs the current state of the rollup contract.
29
+ */
30
+ debugRollup(): Promise<void>;
31
+ /** Fetches the epoch and slot duration config from the rollup contract */
32
+ getConfig(): Promise<{
33
+ /** Epoch duration */ epochDuration: bigint;
34
+ /** Slot duration */ slotDuration: bigint;
35
+ }>;
36
+ /**
37
+ * Advances time to the beginning of the given epoch
38
+ * @param epoch - The epoch to advance to
39
+ * @param opts - Options
40
+ */
41
+ advanceToEpoch(epoch: bigint | number, opts?: {
42
+ /** Offset in seconds */
43
+ offset?: number;
44
+ }): Promise<bigint>;
45
+ /** Warps time in L1 until the next epoch */
46
+ advanceToNextEpoch(): Promise<void>;
47
+ /** Warps time in L1 until the beginning of the next slot. */
48
+ advanceToNextSlot(): Promise<bigint[]>;
49
+ /**
50
+ * Warps time in L1 equivalent to however many slots.
51
+ * @param howMany - The number of slots to advance.
52
+ */
53
+ advanceSlots(howMany: number): Promise<void>;
54
+ /**
55
+ * Marks the specified block (or latest if none) as proven
56
+ * @param maybeBlockNumber - The block number to mark as proven (defaults to latest pending)
57
+ */
58
+ markAsProven(maybeBlockNumber?: number | bigint): Promise<void>;
59
+ /**
60
+ * Overrides the inProgress field of the Inbox contract state
61
+ * @param howMuch - How many blocks to move it forward
62
+ */
63
+ advanceInboxInProgress(howMuch: number | bigint): Promise<bigint>;
64
+ /**
65
+ * Executes an action impersonated as the owner of the Rollup contract.
66
+ * @param action - The action to execute
67
+ */
68
+ asOwner(action: (owner: Hex, rollup: GetContractReturnType<typeof RollupAbi, ViemPublicClient>) => Promise<void>): Promise<void>;
69
+ /**
70
+ * Sets up the epoch.
71
+ */
72
+ setupEpoch(): Promise<void>;
73
+ /** Directly calls the L1 gas fee oracle. */
74
+ updateL1GasFeeOracle(): Promise<void>;
75
+ /**
76
+ * Bumps proving cost per mana.
77
+ * @param bumper - Callback to calculate the new proving cost per mana based on current value.
78
+ */
79
+ bumpProvingCostPerMana(bumper: (before: bigint) => bigint): Promise<void>;
80
+ /**
81
+ * Directly updates proving cost per mana.
82
+ * @param ethValue - The new proving cost per mana in ETH
83
+ */
84
+ setProvingCostPerMana(ethValue: bigint): Promise<void>;
85
+ }
86
+ //# sourceMappingURL=rollup_cheat_codes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rollup_cheat_codes.d.ts","sourceRoot":"","sources":["../../src/test/rollup_cheat_codes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAGjF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE1D,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,GAAG,EAMT,MAAM,MAAM,CAAC;AAGd,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,8CAA8C;AAC9C,qBAAa,gBAAgB;IAOzB,OAAO,CAAC,aAAa;IANvB,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,MAAM,CAA4D;IAE1E,OAAO,CAAC,MAAM,CAAuC;gBAG3C,aAAa,EAAE,aAAa,EACpC,SAAS,EAAE,IAAI,CAAC,mBAAmB,EAAE,eAAe,CAAC;IAavD,MAAM,CAAC,MAAM,CACX,OAAO,EAAE,MAAM,EAAE,EACjB,SAAS,EAAE,IAAI,CAAC,mBAAmB,EAAE,eAAe,CAAC,EACrD,YAAY,EAAE,YAAY,GACzB,gBAAgB;IAKnB,+BAA+B;IAClB,OAAO;IAKpB,gCAAgC;IACnB,QAAQ;IAKrB;;;OAGG;IACU,OAAO,IAAI,OAAO,CAAC;QAC9B,4BAA4B,CAAC,OAAO,EAAE,MAAM,CAAC;QAC7C,2BAA2B,CAAC,MAAM,EAAE,MAAM,CAAC;KAC5C,CAAC;IAQF;;OAEG;IACU,WAAW;IAmBxB,0EAA0E;IAC7D,SAAS,IAAI,OAAO,CAAC;QAChC,qBAAqB,CAAC,aAAa,EAAE,MAAM,CAAC;QAC5C,oBAAoB,CAAC,YAAY,EAAE,MAAM,CAAC;KAC3C,CAAC;IAQF;;;;OAIG;IACU,cAAc,CACzB,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,IAAI,GAAE;QACJ,wBAAwB;QACxB,MAAM,CAAC,EAAE,MAAM,CAAC;KACZ;IAcR,4CAA4C;IAC/B,kBAAkB;IAa/B,6DAA6D;IAChD,iBAAiB;IAQ9B;;;OAGG;IACU,YAAY,CAAC,OAAO,EAAE,MAAM;IASzC;;;OAGG;IACI,YAAY,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM;IAiCtD;;;OAGG;IACI,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAqCxE;;;OAGG;IACU,OAAO,CAClB,MAAM,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,qBAAqB,CAAC,OAAO,SAAS,EAAE,gBAAgB,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC;IAQ1G;;OAEG;IACU,UAAU;IASvB,4CAA4C;IAC/B,oBAAoB;IAQjC;;;OAGG;IACU,sBAAsB,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM;IAMtE;;;OAGG;IACU,qBAAqB,CAAC,QAAQ,EAAE,MAAM;CAWpD"}