@aztec/ethereum 0.0.1-commit.f2ce05ee → 0.0.1-commit.f5a9928

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 (181) hide show
  1. package/dest/client.d.ts +27 -3
  2. package/dest/client.d.ts.map +1 -1
  3. package/dest/client.js +63 -8
  4. package/dest/config.d.ts +17 -6
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +38 -10
  7. package/dest/contracts/chain_state_override.d.ts +78 -0
  8. package/dest/contracts/chain_state_override.d.ts.map +1 -0
  9. package/dest/contracts/chain_state_override.js +137 -0
  10. package/dest/contracts/fee_asset_price_oracle.d.ts +105 -0
  11. package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
  12. package/dest/contracts/fee_asset_price_oracle.js +656 -0
  13. package/dest/contracts/governance.d.ts +135 -35
  14. package/dest/contracts/governance.d.ts.map +1 -1
  15. package/dest/contracts/governance.js +229 -18
  16. package/dest/contracts/governance_proposer.d.ts +33 -2
  17. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  18. package/dest/contracts/governance_proposer.js +54 -6
  19. package/dest/contracts/gse.d.ts +4 -2
  20. package/dest/contracts/gse.d.ts.map +1 -1
  21. package/dest/contracts/gse.js +2 -2
  22. package/dest/contracts/inbox.d.ts +3 -3
  23. package/dest/contracts/inbox.d.ts.map +1 -1
  24. package/dest/contracts/inbox.js +12 -7
  25. package/dest/contracts/index.d.ts +4 -3
  26. package/dest/contracts/index.d.ts.map +1 -1
  27. package/dest/contracts/index.js +3 -2
  28. package/dest/contracts/multicall.d.ts +127 -12
  29. package/dest/contracts/multicall.d.ts.map +1 -1
  30. package/dest/contracts/multicall.js +201 -94
  31. package/dest/contracts/outbox.d.ts +27 -4
  32. package/dest/contracts/outbox.d.ts.map +1 -1
  33. package/dest/contracts/outbox.js +34 -7
  34. package/dest/contracts/registry.d.ts +3 -1
  35. package/dest/contracts/registry.d.ts.map +1 -1
  36. package/dest/contracts/registry.js +30 -1
  37. package/dest/contracts/rollup.d.ts +5437 -34
  38. package/dest/contracts/rollup.d.ts.map +1 -1
  39. package/dest/contracts/rollup.js +448 -104
  40. package/dest/contracts/slashing_proposer.d.ts +171 -0
  41. package/dest/contracts/slashing_proposer.d.ts.map +1 -0
  42. package/dest/contracts/slashing_proposer.js +753 -0
  43. package/dest/contracts/watch_event.d.ts +36 -0
  44. package/dest/contracts/watch_event.d.ts.map +1 -0
  45. package/dest/contracts/watch_event.js +66 -0
  46. package/dest/deploy_aztec_l1_contracts.d.ts +5 -9
  47. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -1
  48. package/dest/deploy_aztec_l1_contracts.js +48 -27
  49. package/dest/deploy_l1_contract.js +3 -3
  50. package/dest/foundry_binary.d.ts +13 -0
  51. package/dest/foundry_binary.d.ts.map +1 -0
  52. package/dest/foundry_binary.js +52 -0
  53. package/dest/generated/l1-contracts-defaults.d.ts +3 -3
  54. package/dest/generated/l1-contracts-defaults.js +3 -3
  55. package/dest/l1_artifacts.d.ts +15524 -15847
  56. package/dest/l1_artifacts.d.ts.map +1 -1
  57. package/dest/l1_artifacts.js +9 -24
  58. package/dest/l1_contract_addresses.d.ts +61 -65
  59. package/dest/l1_contract_addresses.d.ts.map +1 -1
  60. package/dest/l1_contract_addresses.js +101 -82
  61. package/dest/l1_reader.d.ts +5 -5
  62. package/dest/l1_reader.d.ts.map +1 -1
  63. package/dest/l1_reader.js +9 -7
  64. package/dest/l1_tx_utils/config.d.ts +7 -1
  65. package/dest/l1_tx_utils/config.d.ts.map +1 -1
  66. package/dest/l1_tx_utils/config.js +17 -4
  67. package/dest/l1_tx_utils/factory.d.ts +18 -10
  68. package/dest/l1_tx_utils/factory.d.ts.map +1 -1
  69. package/dest/l1_tx_utils/factory.js +17 -7
  70. package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +1 -1
  71. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +1 -1
  72. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +15 -15
  73. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -1
  74. package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +9 -15
  75. package/dest/l1_tx_utils/index-blobs.d.ts +3 -3
  76. package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -1
  77. package/dest/l1_tx_utils/index-blobs.js +2 -2
  78. package/dest/l1_tx_utils/index.d.ts +2 -1
  79. package/dest/l1_tx_utils/index.d.ts.map +1 -1
  80. package/dest/l1_tx_utils/index.js +1 -0
  81. package/dest/l1_tx_utils/l1_tx_utils.d.ts +26 -7
  82. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
  83. package/dest/l1_tx_utils/l1_tx_utils.js +156 -79
  84. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +1 -1
  85. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
  86. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +57 -23
  87. package/dest/l1_tx_utils/tx_delayer.d.ts +58 -0
  88. package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
  89. package/dest/{test → l1_tx_utils}/tx_delayer.js +67 -37
  90. package/dest/publisher_manager.d.ts +34 -8
  91. package/dest/publisher_manager.d.ts.map +1 -1
  92. package/dest/publisher_manager.js +119 -8
  93. package/dest/queries.d.ts +13 -2
  94. package/dest/queries.d.ts.map +1 -1
  95. package/dest/queries.js +62 -3
  96. package/dest/test/blob_kzg_warmup.d.ts +19 -0
  97. package/dest/test/blob_kzg_warmup.d.ts.map +1 -0
  98. package/dest/test/blob_kzg_warmup.js +64 -0
  99. package/dest/test/chain_monitor.d.ts +55 -4
  100. package/dest/test/chain_monitor.d.ts.map +1 -1
  101. package/dest/test/chain_monitor.js +104 -3
  102. package/dest/test/eth_cheat_codes.d.ts +31 -6
  103. package/dest/test/eth_cheat_codes.d.ts.map +1 -1
  104. package/dest/test/eth_cheat_codes.js +67 -44
  105. package/dest/test/index.d.ts +2 -3
  106. package/dest/test/index.d.ts.map +1 -1
  107. package/dest/test/index.js +1 -2
  108. package/dest/test/recording_rpc_server.d.ts +18 -0
  109. package/dest/test/recording_rpc_server.d.ts.map +1 -0
  110. package/dest/test/recording_rpc_server.js +68 -0
  111. package/dest/test/rollup_cheat_codes.d.ts +60 -3
  112. package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
  113. package/dest/test/rollup_cheat_codes.js +86 -7
  114. package/dest/test/start_anvil.d.ts +23 -3
  115. package/dest/test/start_anvil.d.ts.map +1 -1
  116. package/dest/test/start_anvil.js +182 -32
  117. package/dest/test/upgrade_utils.js +2 -2
  118. package/dest/utils.d.ts +9 -2
  119. package/dest/utils.d.ts.map +1 -1
  120. package/dest/utils.js +59 -24
  121. package/package.json +6 -8
  122. package/src/client.ts +72 -2
  123. package/src/config.ts +58 -14
  124. package/src/contracts/chain_state_override.ts +200 -0
  125. package/src/contracts/fee_asset_price_oracle.ts +285 -0
  126. package/src/contracts/governance.ts +313 -13
  127. package/src/contracts/governance_proposer.ts +58 -9
  128. package/src/contracts/gse.ts +7 -2
  129. package/src/contracts/inbox.ts +13 -5
  130. package/src/contracts/index.ts +3 -2
  131. package/src/contracts/multicall.ts +243 -105
  132. package/src/contracts/outbox.ts +42 -8
  133. package/src/contracts/registry.ts +31 -1
  134. package/src/contracts/rollup.ts +507 -109
  135. package/src/contracts/{tally_slashing_proposer.ts → slashing_proposer.ts} +119 -45
  136. package/src/contracts/watch_event.ts +110 -0
  137. package/src/deploy_aztec_l1_contracts.ts +75 -39
  138. package/src/deploy_l1_contract.ts +3 -3
  139. package/src/foundry_binary.ts +57 -0
  140. package/src/generated/l1-contracts-defaults.ts +3 -3
  141. package/src/l1_artifacts.ts +12 -35
  142. package/src/l1_contract_addresses.ts +120 -94
  143. package/src/l1_reader.ts +17 -10
  144. package/src/l1_tx_utils/config.ts +23 -3
  145. package/src/l1_tx_utils/factory.ts +31 -31
  146. package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +1 -1
  147. package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +1 -1
  148. package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +43 -54
  149. package/src/l1_tx_utils/index-blobs.ts +2 -2
  150. package/src/l1_tx_utils/index.ts +1 -0
  151. package/src/l1_tx_utils/l1_tx_utils.ts +149 -64
  152. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +57 -17
  153. package/src/{test → l1_tx_utils}/tx_delayer.ts +93 -56
  154. package/src/publisher_manager.ts +143 -12
  155. package/src/queries.ts +70 -4
  156. package/src/test/blob_kzg_warmup.ts +65 -0
  157. package/src/test/chain_monitor.ts +148 -3
  158. package/src/test/eth_cheat_codes.ts +63 -47
  159. package/src/test/index.ts +1 -2
  160. package/src/test/recording_rpc_server.ts +69 -0
  161. package/src/test/rollup_cheat_codes.ts +115 -6
  162. package/src/test/start_anvil.ts +212 -32
  163. package/src/test/upgrade_utils.ts +2 -2
  164. package/src/utils.ts +56 -29
  165. package/dest/contracts/empire_slashing_proposer.d.ts +0 -67
  166. package/dest/contracts/empire_slashing_proposer.d.ts.map +0 -1
  167. package/dest/contracts/empire_slashing_proposer.js +0 -207
  168. package/dest/contracts/tally_slashing_proposer.d.ts +0 -140
  169. package/dest/contracts/tally_slashing_proposer.d.ts.map +0 -1
  170. package/dest/contracts/tally_slashing_proposer.js +0 -320
  171. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +0 -26
  172. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +0 -1
  173. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +0 -26
  174. package/dest/test/delayed_tx_utils.d.ts +0 -13
  175. package/dest/test/delayed_tx_utils.d.ts.map +0 -1
  176. package/dest/test/delayed_tx_utils.js +0 -28
  177. package/dest/test/tx_delayer.d.ts +0 -36
  178. package/dest/test/tx_delayer.d.ts.map +0 -1
  179. package/src/contracts/empire_slashing_proposer.ts +0 -259
  180. package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +0 -77
  181. package/src/test/delayed_tx_utils.ts +0 -52
@@ -1,9 +1,42 @@
1
1
  import { createLogger } from '@aztec/foundation/log';
2
2
  import { makeBackoff, retry } from '@aztec/foundation/retry';
3
- import { fileURLToPath } from '@aztec/foundation/url';
3
+ import type { TestDateProvider } from '@aztec/foundation/timer';
4
4
 
5
- import { type Anvil, createAnvil } from '@viem/anvil';
6
- import { dirname, resolve } from 'path';
5
+ import { type ChildProcess, spawn } from 'child_process';
6
+
7
+ import { resolveFoundryBinary } from '../foundry_binary.js';
8
+
9
+ /** Minimal interface matching the @viem/anvil Anvil shape used by callers. */
10
+ export interface Anvil {
11
+ readonly port: number;
12
+ readonly host: string;
13
+ readonly status: 'listening' | 'idle';
14
+ stop(): Promise<void>;
15
+ }
16
+
17
+ // Watchdog wrapper: instead of spawning anvil directly, we spawn a small bash supervisor that runs
18
+ // anvil as a background child and polls its own parent (this node process). If the parent dies for
19
+ // ANY reason — including SIGKILL / crash / OOM, where node's own exit handlers never run — the poll
20
+ // loop ends and the EXIT trap reaps anvil. The script is inlined (rather than shipped as a `.sh`) so
21
+ // it works from the published npm tarball too, and the resolved anvil binary is passed via
22
+ // `$ANVIL_BIN` so it works without `anvil` on PATH.
23
+ //
24
+ // `$@` is the anvil argv; `bash -c <script> bash <...args>` puts the args in `$@` and `$0` = 'bash'.
25
+ //
26
+ // The EXIT trap reaps anvil; INT/TERM just `exit` (which fires the EXIT trap) so a signal terminates
27
+ // the supervisor promptly instead of being swallowed — a trapped TERM does NOT terminate the shell,
28
+ // so trapping the kill directly on TERM would leave the poll loop running and the caller's teardown
29
+ // hanging until its SIGKILL escalation. `sleep & wait` makes the poll interruptible, so INT/TERM are
30
+ // handled immediately rather than after the current `sleep` returns.
31
+ const ANVIL_WATCHDOG = `
32
+ set -u
33
+ parent=$PPID
34
+ "$ANVIL_BIN" "$@" &
35
+ anvil_pid=$!
36
+ trap 'kill "$anvil_pid" 2>/dev/null' EXIT
37
+ trap 'exit 0' INT TERM
38
+ while kill -0 "$parent" 2>/dev/null; do sleep 1 & wait $!; done
39
+ `;
7
40
 
8
41
  /**
9
42
  * Ensures there's a running Anvil instance and returns the RPC URL.
@@ -16,56 +49,203 @@ export async function startAnvil(
16
49
  captureMethodCalls?: boolean;
17
50
  accounts?: number;
18
51
  chainId?: number;
19
- /** The hardfork to use - note: @viem/anvil types are out of date but 'cancun' and 'latest' work */
52
+ /** The hardfork to use (e.g. 'cancun', 'latest'). */
20
53
  hardfork?: string;
54
+ /**
55
+ * Number of slots per epoch used by anvil to compute the 'finalized' and 'safe' block tags.
56
+ * Anvil reports `finalized = latest - slotsInAnEpoch * 2`.
57
+ * Defaults to 1 so the finalized block advances immediately, making tests that check
58
+ * L1-finality-based logic work without needing hundreds of mined blocks.
59
+ */
60
+ slotsInAnEpoch?: number;
61
+ /**
62
+ * If provided, the date provider will be synced to anvil's block time on every mined block.
63
+ * This keeps the dateProvider in lockstep with anvil's chain time, avoiding drift between
64
+ * the wall clock and the L1 chain when computing L1 slot timestamps.
65
+ */
66
+ dateProvider?: TestDateProvider;
21
67
  } = {},
22
68
  ): Promise<{ anvil: Anvil; methodCalls?: string[]; rpcUrl: string; stop: () => Promise<void> }> {
23
- const anvilBinary = resolve(dirname(fileURLToPath(import.meta.url)), '../../', 'scripts/anvil_kill_wrapper.sh');
69
+ const anvilBinary = resolveFoundryBinary('anvil');
24
70
  const logger = opts.log ? createLogger('ethereum:anvil') : undefined;
25
71
  const methodCalls = opts.captureMethodCalls ? ([] as string[]) : undefined;
26
72
 
27
- let port: number | undefined;
73
+ let detectedPort: number | undefined;
28
74
 
29
- // Start anvil.
30
- // We go via a wrapper script to ensure if the parent dies, anvil dies.
31
75
  const anvil = await retry(
32
76
  async () => {
33
- const anvil = createAnvil({
34
- anvilBinary,
35
- host: '127.0.0.1',
36
- port: opts.port ?? (process.env.ANVIL_PORT ? parseInt(process.env.ANVIL_PORT) : 8545),
37
- blockTime: opts.l1BlockTime,
38
- stopTimeout: 1000,
39
- accounts: opts.accounts ?? 20,
40
- gasLimit: 45_000_000n,
41
- chainId: opts.chainId ?? 31337,
77
+ // `--port 0` lets anvil bind an OS-assigned ephemeral port; the actual port is read back from
78
+ // its "Listening on host:port" stdout below, so independent suites can spawn their own anvil
79
+ // in parallel without fighting over a fixed port.
80
+ const port = opts.port ?? (process.env.ANVIL_PORT ? parseInt(process.env.ANVIL_PORT) : 8545);
81
+ const args: string[] = [
82
+ '--host',
83
+ '127.0.0.1',
84
+ '--port',
85
+ String(port),
86
+ '--accounts',
87
+ String(opts.accounts ?? 20),
88
+ '--gas-limit',
89
+ String(45_000_000),
90
+ '--chain-id',
91
+ String(opts.chainId ?? 31337),
92
+ ];
93
+ if (opts.l1BlockTime !== undefined) {
94
+ args.push('--block-time', String(opts.l1BlockTime));
95
+ }
96
+ if (opts.hardfork !== undefined) {
97
+ args.push('--hardfork', opts.hardfork);
98
+ }
99
+ args.push('--slots-in-an-epoch', String(opts.slotsInAnEpoch ?? 1));
100
+
101
+ // Spawn the watchdog (see ANVIL_WATCHDOG). It launches anvil with these args and reaps it if we
102
+ // die; `$0` is 'bash' and `$@` is the anvil argv.
103
+ const child = spawn('bash', ['-c', ANVIL_WATCHDOG, 'bash', ...args], {
104
+ stdio: ['ignore', 'pipe', 'pipe'],
105
+ env: { ...process.env, ANVIL_BIN: anvilBinary, RAYON_NUM_THREADS: '1' },
42
106
  });
43
107
 
44
- // Listen to the anvil output to get the port.
45
- const removeHandler = anvil.on('message', (message: string) => {
46
- logger?.debug(message.trim());
108
+ // Wait for "Listening on" or an early exit.
109
+ await new Promise<void>((resolve, reject) => {
110
+ let stderr = '';
111
+
112
+ const onStdout = (data: Buffer) => {
113
+ const text = data.toString();
114
+ logger?.debug(text.trim());
115
+ methodCalls?.push(...(text.match(/eth_[^\s]+/g) || []));
47
116
 
48
- methodCalls?.push(...(message.match(/eth_[^\s]+/g) || []));
49
- if (port === undefined && message.includes('Listening on')) {
50
- port = parseInt(message.match(/Listening on ([^:]+):(\d+)/)![2]);
51
- }
117
+ if (detectedPort === undefined && text.includes('Listening on')) {
118
+ const match = text.match(/Listening on ([^:]+):(\d+)/);
119
+ if (match) {
120
+ detectedPort = parseInt(match[2]);
121
+ }
122
+ }
123
+ if (detectedPort !== undefined) {
124
+ child.stdout?.removeListener('data', onStdout);
125
+ child.stderr?.removeListener('data', onStderr);
126
+ child.removeListener('close', onClose);
127
+ resolve();
128
+ }
129
+ };
130
+
131
+ const onStderr = (data: Buffer) => {
132
+ stderr += data.toString();
133
+ logger?.debug(data.toString().trim());
134
+ };
135
+
136
+ const onClose = (code: number | null) => {
137
+ child.stdout?.removeListener('data', onStdout);
138
+ child.stderr?.removeListener('data', onStderr);
139
+ reject(new Error(`Anvil exited with code ${code} before listening. stderr: ${stderr}`));
140
+ };
141
+
142
+ child.stdout?.on('data', onStdout);
143
+ child.stderr?.on('data', onStderr);
144
+ child.once('close', onClose);
52
145
  });
53
- await anvil.start();
54
- if (!logger && !opts.captureMethodCalls) {
55
- removeHandler();
146
+
147
+ // Continue piping for logging, method-call capture, and/or dateProvider sync after startup.
148
+ if (logger || opts.captureMethodCalls || opts.dateProvider) {
149
+ child.stdout?.on('data', (data: Buffer) => {
150
+ const text = data.toString();
151
+ logger?.debug(text.trim());
152
+ methodCalls?.push(...(text.match(/eth_[^\s]+/g) || []));
153
+ if (opts.dateProvider) {
154
+ syncDateProviderFromAnvilOutput(text, opts.dateProvider);
155
+ }
156
+ });
157
+ child.stderr?.on('data', (data: Buffer) => {
158
+ logger?.debug(data.toString().trim());
159
+ });
160
+ } else {
161
+ // Consume streams so the child process doesn't block on full pipe buffers.
162
+ child.stdout?.resume();
163
+ child.stderr?.resume();
56
164
  }
57
165
 
58
- return anvil;
166
+ return child;
59
167
  },
60
168
  'Start anvil',
61
169
  makeBackoff([5, 5, 5]),
62
170
  );
63
171
 
64
- if (!port) {
172
+ if (!detectedPort) {
65
173
  throw new Error('Failed to start anvil');
66
174
  }
67
175
 
68
- // Monkeypatch the anvil instance to include the actually assigned port
69
- // Object.defineProperty(anvil, 'port', { value: port, writable: false });
70
- return { anvil, methodCalls, stop: () => anvil.stop(), rpcUrl: `http://127.0.0.1:${port}` };
176
+ const port = detectedPort;
177
+ let status: 'listening' | 'idle' = 'listening';
178
+
179
+ anvil.once('close', () => {
180
+ status = 'idle';
181
+ });
182
+
183
+ const stop = async () => {
184
+ if (status === 'idle') {
185
+ return;
186
+ }
187
+ await killChild(anvil);
188
+ };
189
+
190
+ const anvilObj: Anvil = {
191
+ port,
192
+ host: '127.0.0.1',
193
+ get status() {
194
+ return status;
195
+ },
196
+ stop,
197
+ };
198
+
199
+ return { anvil: anvilObj, methodCalls, stop, rpcUrl: `http://127.0.0.1:${port}` };
200
+ }
201
+
202
+ /** Extracts block time from anvil stdout and syncs the dateProvider. */
203
+ function syncDateProviderFromAnvilOutput(text: string, dateProvider: TestDateProvider): void {
204
+ // Anvil logs mined blocks as:
205
+ // Block Time: "Fri, 20 Mar 2026 02:10:46 +0000"
206
+ const match = text.match(/Block Time:\s*"([^"]+)"/);
207
+ if (match) {
208
+ const blockTimeMs = new Date(match[1]).getTime();
209
+ if (!isNaN(blockTimeMs)) {
210
+ dateProvider.setTime(blockTimeMs);
211
+ }
212
+ }
213
+ }
214
+
215
+ /**
216
+ * Send SIGTERM to the watchdog, wait up to 5 s, then SIGKILL. The watchdog's trap forwards the
217
+ * signal to anvil, so terminating it tears down anvil too. All timers are always cleared.
218
+ */
219
+ function killChild(child: ChildProcess): Promise<void> {
220
+ return new Promise<void>(resolve => {
221
+ if (child.exitCode !== null || child.killed) {
222
+ child.stdout?.destroy();
223
+ child.stderr?.destroy();
224
+ resolve();
225
+ return;
226
+ }
227
+
228
+ let killTimer: NodeJS.Timeout | undefined;
229
+
230
+ const onClose = () => {
231
+ if (killTimer !== undefined) {
232
+ clearTimeout(killTimer);
233
+ }
234
+ // Destroy stdio streams so their PipeWrap handles don't keep the event loop alive.
235
+ child.stdout?.destroy();
236
+ child.stderr?.destroy();
237
+ resolve();
238
+ };
239
+
240
+ child.once('close', onClose);
241
+ child.kill('SIGTERM');
242
+
243
+ killTimer = setTimeout(() => {
244
+ killTimer = undefined;
245
+ child.kill('SIGKILL');
246
+ }, 5000);
247
+
248
+ // Ensure the timer does not prevent Node from exiting.
249
+ killTimer.unref();
250
+ });
71
251
  }
@@ -7,7 +7,7 @@ import { type GetContractReturnType, type PrivateKeyAccount, getContract } from
7
7
 
8
8
  import { extractProposalIdFromLogs } from '../contracts/governance.js';
9
9
  import type { L1ContractAddresses } from '../l1_contract_addresses.js';
10
- import { createL1TxUtilsFromViemWallet } from '../l1_tx_utils/index.js';
10
+ import { createL1TxUtils } from '../l1_tx_utils/index.js';
11
11
  import type { ExtendedViemWalletClient, ViemPublicClient } from '../types.js';
12
12
  import { EthCheatCodes } from './eth_cheat_codes.js';
13
13
 
@@ -22,7 +22,7 @@ export async function executeGovernanceProposal(
22
22
  ) {
23
23
  const proposal = await governance.read.getProposal([proposalId]);
24
24
 
25
- const l1TxUtils = createL1TxUtilsFromViemWallet(l1Client);
25
+ const l1TxUtils = createL1TxUtils(l1Client);
26
26
 
27
27
  const waitL1Block = async () => {
28
28
  await l1TxUtils.sendAndMonitorTransaction({
package/src/utils.ts CHANGED
@@ -27,8 +27,8 @@ export interface L2Claim {
27
27
  export class FormattedViemError extends Error {
28
28
  metaMessages?: any[];
29
29
 
30
- constructor(message: string, metaMessages?: any[]) {
31
- super(message);
30
+ constructor(message: string, metaMessages?: any[], options?: ErrorOptions) {
31
+ super(message, options);
32
32
  this.name = 'FormattedViemError';
33
33
  this.metaMessages = metaMessages;
34
34
  }
@@ -170,6 +170,21 @@ function getNestedErrorData(error: unknown): string | undefined {
170
170
  return undefined;
171
171
  }
172
172
 
173
+ /**
174
+ * Truncates an error message to a safe length for log renderers.
175
+ * LogExplorer can only render up to 2500 characters in its summary view.
176
+ * We cap at 2000 to leave room for decorating context added by callers.
177
+ */
178
+ function truncateErrorMessage(message: string): string {
179
+ const MAX = 2000;
180
+ const CHUNK = 950;
181
+ if (message.length <= MAX) {
182
+ return message;
183
+ }
184
+ const truncated = message.length - 2 * CHUNK;
185
+ return message.slice(0, CHUNK) + `...${truncated} characters truncated...` + message.slice(-CHUNK);
186
+ }
187
+
173
188
  /**
174
189
  * Formats a Viem error into a FormattedViemError instance.
175
190
  * @param error - The error to format.
@@ -182,6 +197,8 @@ export function formatViemError(error: any, abi: Abi = ErrorsAbi): FormattedViem
182
197
  return error;
183
198
  }
184
199
 
200
+ const originalError = error;
201
+
185
202
  // First try to decode as a custom error using the ABI
186
203
  try {
187
204
  const data = getNestedErrorData(error);
@@ -192,7 +209,9 @@ export function formatViemError(error: any, abi: Abi = ErrorsAbi): FormattedViem
192
209
  data: data as Hex,
193
210
  });
194
211
  if (decoded) {
195
- return new FormattedViemError(`${decoded.errorName}(${decoded.args?.join(', ') ?? ''})`, error?.metaMessages);
212
+ return new FormattedViemError(`${decoded.errorName}(${decoded.args?.join(', ') ?? ''})`, error?.metaMessages, {
213
+ cause: originalError,
214
+ });
196
215
  }
197
216
  }
198
217
 
@@ -209,45 +228,35 @@ export function formatViemError(error: any, abi: Abi = ErrorsAbi): FormattedViem
209
228
  revertError.metaMessages && revertError.metaMessages?.length > 1
210
229
  ? revertError.metaMessages[1].trimStart()
211
230
  : '';
212
- return new FormattedViemError(`${errorName}${args}`, error?.metaMessages);
231
+ return new FormattedViemError(`${errorName}${args}`, error?.metaMessages, { cause: originalError });
213
232
  }
214
233
  }
215
234
  } catch {
216
235
  // If decoding fails, we fall back to the original formatting
217
236
  }
218
237
 
219
- // Strip ABI from the error object before formatting
238
+ // Strip ABI from the error object before formatting. We clone first to avoid mutating the
239
+ // caller's error, but structuredClone throws DataCloneError on values it cannot clone (e.g.
240
+ // viem RPC errors carrying function-valued request context). If cloning fails, fall back to
241
+ // formatting the original error untouched rather than letting the clone failure mask it.
220
242
  if (error && typeof error === 'object') {
221
- // Create a clone to avoid modifying the original
222
- const errorClone = structuredClone(error);
223
-
224
- // Helper function to recursively remove ABI properties
225
-
226
- // Strip ABIs from the clone
227
- stripAbis(errorClone);
228
-
229
- // Use the cleaned clone for further processing
230
- error = errorClone;
243
+ try {
244
+ const errorClone = structuredClone(error);
245
+ stripAbis(errorClone);
246
+ error = errorClone;
247
+ } catch {
248
+ // Leave `error` as the original; we skip stripAbis to avoid mutating the caller's object.
249
+ }
231
250
  }
232
251
 
233
252
  // If it's a regular Error instance, return it with its message
234
253
  if (error instanceof Error) {
235
- return new FormattedViemError(error.message, (error as any)?.metaMessages);
236
- }
237
-
238
- const body = String(error);
239
- const length = body.length;
240
- // LogExplorer can only render up to 2500 characters in it's summary view. Try to keep the whole message below this number
241
- // Limit the error to 2000 chacaters in order to allow code higher up to decorate this error with extra details (up to 500 characters)
242
- if (length > 2000) {
243
- const chunk = 950;
244
- const truncated = length - 2 * chunk;
245
- return new FormattedViemError(
246
- body.slice(0, chunk) + `...${truncated} characters truncated...` + body.slice(-1 * chunk),
247
- );
254
+ return new FormattedViemError(truncateErrorMessage(error.message), (error as any)?.metaMessages, {
255
+ cause: originalError,
256
+ });
248
257
  }
249
258
 
250
- return new FormattedViemError(body);
259
+ return new FormattedViemError(truncateErrorMessage(String(error)), undefined, { cause: originalError });
251
260
  }
252
261
 
253
262
  function stripAbis(obj: any) {
@@ -273,6 +282,24 @@ function stripAbis(obj: any) {
273
282
  });
274
283
  }
275
284
 
285
+ /**
286
+ * Best-effort decode of a raw revert payload (`0x...`) against an ABI.
287
+ * Returns a human-readable `ErrorName(arg1, arg2, ...)` string, or `undefined` if the selector
288
+ * is unknown or the payload is empty. Use to surface decoded error names alongside the raw
289
+ * payload in log lines for operators.
290
+ */
291
+ export function tryDecodeRevertReason(data: Hex | undefined, abi: Abi): string | undefined {
292
+ if (!data || data === '0x') {
293
+ return undefined;
294
+ }
295
+ try {
296
+ const decoded = decodeErrorResult({ abi, data });
297
+ return `${decoded.errorName}(${decoded.args?.join(', ') ?? ''})`;
298
+ } catch {
299
+ return undefined;
300
+ }
301
+ }
302
+
276
303
  export function tryGetCustomErrorName(err: any) {
277
304
  try {
278
305
  // See https://viem.sh/docs/contract/simulateContract#handling-custom-errors
@@ -1,67 +0,0 @@
1
- import { SlotNumber } from '@aztec/foundation/branded-types';
2
- import { EthAddress } from '@aztec/foundation/eth-address';
3
- import EventEmitter from 'events';
4
- import { type Hex, type Log, type TypedDataDefinition } from 'viem';
5
- import type { L1TxRequest, L1TxUtils } from '../l1_tx_utils/index.js';
6
- import type { ViemClient } from '../types.js';
7
- import { type IEmpireBase } from './empire_base.js';
8
- export declare class ProposalAlreadyExecutedError extends Error {
9
- constructor(round: bigint);
10
- }
11
- export declare class EmpireSlashingProposerContract extends EventEmitter implements IEmpireBase {
12
- readonly client: ViemClient;
13
- private readonly logger;
14
- private readonly proposer;
15
- readonly type: "empire";
16
- constructor(client: ViemClient, address: Hex | EthAddress);
17
- get address(): EthAddress;
18
- getQuorumSize(): Promise<bigint>;
19
- getRoundSize(): Promise<bigint>;
20
- getLifetimeInRounds(): Promise<bigint>;
21
- getExecutionDelayInRounds(): Promise<bigint>;
22
- getCurrentRound(): Promise<bigint>;
23
- computeRound(slot: SlotNumber): Promise<bigint>;
24
- getInstance(): Promise<`0x${string}`>;
25
- getRoundInfo(rollupAddress: Hex, round: bigint): Promise<{
26
- lastSignalSlot: SlotNumber;
27
- payloadWithMostSignals: Hex;
28
- quorumReached: boolean;
29
- executed: boolean;
30
- }>;
31
- getPayloadSignals(rollupAddress: Hex, round: bigint, payload: Hex): Promise<bigint>;
32
- createSignalRequest(payload: Hex): L1TxRequest;
33
- createSignalRequestWithSignature(payload: Hex, slot: SlotNumber, chainId: number, signerAddress: Hex, signer: (msg: TypedDataDefinition) => Promise<Hex>): Promise<L1TxRequest>;
34
- listenToSubmittablePayloads(callback: (args: {
35
- payload: `0x${string}`;
36
- round: bigint;
37
- }) => unknown): import("viem").WatchContractEventReturnType;
38
- listenToPayloadSubmitted(callback: (args: {
39
- round: bigint;
40
- payload: `0x${string}`;
41
- }) => unknown): import("viem").WatchContractEventReturnType;
42
- listenToSignalCasted(callback: (args: {
43
- round: bigint;
44
- payload: `0x${string}`;
45
- signaler: `0x${string}`;
46
- }) => unknown): import("viem").WatchContractEventReturnType;
47
- /** Creates an L1TxRequest to submit the round winner for the given round. */
48
- buildExecuteRoundRequest(round: bigint): L1TxRequest;
49
- /** Tries to extract a PayloadSubmitted event from the given logs. */
50
- tryExtractPayloadSubmittedEvent(logs: Log[]): {
51
- eventName: "PayloadSubmitted";
52
- args: {
53
- payload: `0x${string}`;
54
- round: bigint;
55
- };
56
- } | undefined;
57
- /**
58
- * Wait for a round to be reached.
59
- *
60
- * @param round - The round to wait for.
61
- * @param pollingIntervalSeconds - The interval in seconds to poll for the round.
62
- * @returns True if the round was reached, false otherwise.
63
- */
64
- waitForRound(round: bigint, pollingIntervalSeconds?: number): Promise<boolean>;
65
- executeRound(txUtils: L1TxUtils, round: bigint | number): ReturnType<typeof txUtils.sendAndMonitorTransaction>;
66
- }
67
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZW1waXJlX3NsYXNoaW5nX3Byb3Bvc2VyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY29udHJhY3RzL2VtcGlyZV9zbGFzaGluZ19wcm9wb3Nlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDN0QsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLCtCQUErQixDQUFDO0FBSzNELE9BQU8sWUFBWSxNQUFNLFFBQVEsQ0FBQztBQUNsQyxPQUFPLEVBRUwsS0FBSyxHQUFHLEVBQ1IsS0FBSyxHQUFHLEVBQ1IsS0FBSyxtQkFBbUIsRUFHekIsTUFBTSxNQUFNLENBQUM7QUFFZCxP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