@aztec/ethereum 0.0.1-commit.fce3e4f → 0.0.1-commit.ff7989d6c

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 (199) hide show
  1. package/dest/client.js +6 -2
  2. package/dest/config.d.ts +19 -68
  3. package/dest/config.d.ts.map +1 -1
  4. package/dest/config.js +55 -380
  5. package/dest/contracts/empire_base.d.ts +4 -1
  6. package/dest/contracts/empire_base.d.ts.map +1 -1
  7. package/dest/contracts/empire_slashing_proposer.d.ts +4 -1
  8. package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -1
  9. package/dest/contracts/empire_slashing_proposer.js +31 -15
  10. package/dest/contracts/fee_asset_handler.d.ts +6 -5
  11. package/dest/contracts/fee_asset_handler.d.ts.map +1 -1
  12. package/dest/contracts/fee_asset_handler.js +11 -9
  13. package/dest/contracts/fee_asset_price_oracle.d.ts +101 -0
  14. package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
  15. package/dest/contracts/fee_asset_price_oracle.js +651 -0
  16. package/dest/contracts/governance.d.ts +3 -1
  17. package/dest/contracts/governance.d.ts.map +1 -1
  18. package/dest/contracts/governance.js +14 -4
  19. package/dest/contracts/governance_proposer.d.ts +4 -1
  20. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  21. package/dest/contracts/governance_proposer.js +404 -9
  22. package/dest/contracts/inbox.d.ts +24 -3
  23. package/dest/contracts/inbox.d.ts.map +1 -1
  24. package/dest/contracts/inbox.js +36 -1
  25. package/dest/contracts/index.d.ts +4 -1
  26. package/dest/contracts/index.d.ts.map +1 -1
  27. package/dest/contracts/index.js +3 -0
  28. package/dest/contracts/log.d.ts +13 -0
  29. package/dest/contracts/log.d.ts.map +1 -0
  30. package/dest/contracts/log.js +1 -0
  31. package/dest/contracts/multicall.d.ts +1 -1
  32. package/dest/contracts/multicall.d.ts.map +1 -1
  33. package/dest/contracts/multicall.js +2 -1
  34. package/dest/contracts/outbox.d.ts +41 -0
  35. package/dest/contracts/outbox.d.ts.map +1 -0
  36. package/dest/contracts/outbox.js +86 -0
  37. package/dest/contracts/rollup.d.ts +177 -96
  38. package/dest/contracts/rollup.d.ts.map +1 -1
  39. package/dest/contracts/rollup.js +707 -144
  40. package/dest/contracts/tally_slashing_proposer.d.ts +3 -2
  41. package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -1
  42. package/dest/contracts/tally_slashing_proposer.js +8 -1
  43. package/dest/deploy_aztec_l1_contracts.d.ts +259 -0
  44. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
  45. package/dest/deploy_aztec_l1_contracts.js +413 -0
  46. package/dest/deploy_l1_contract.d.ts +68 -0
  47. package/dest/deploy_l1_contract.d.ts.map +1 -0
  48. package/dest/deploy_l1_contract.js +312 -0
  49. package/dest/forwarder_proxy.d.ts +32 -0
  50. package/dest/forwarder_proxy.d.ts.map +1 -0
  51. package/dest/forwarder_proxy.js +93 -0
  52. package/dest/generated/l1-contracts-defaults.d.ts +30 -0
  53. package/dest/generated/l1-contracts-defaults.d.ts.map +1 -0
  54. package/dest/generated/l1-contracts-defaults.js +30 -0
  55. package/dest/l1_artifacts.d.ts +5975 -1575
  56. package/dest/l1_artifacts.d.ts.map +1 -1
  57. package/dest/l1_contract_addresses.d.ts +1 -1
  58. package/dest/l1_contract_addresses.d.ts.map +1 -1
  59. package/dest/l1_contract_addresses.js +3 -3
  60. package/dest/l1_reader.d.ts +3 -1
  61. package/dest/l1_reader.d.ts.map +1 -1
  62. package/dest/l1_reader.js +6 -0
  63. package/dest/l1_tx_utils/config.d.ts +9 -3
  64. package/dest/l1_tx_utils/config.d.ts.map +1 -1
  65. package/dest/l1_tx_utils/config.js +31 -4
  66. package/dest/l1_tx_utils/constants.d.ts +8 -2
  67. package/dest/l1_tx_utils/constants.d.ts.map +1 -1
  68. package/dest/l1_tx_utils/constants.js +27 -2
  69. package/dest/l1_tx_utils/factory.d.ts +18 -10
  70. package/dest/l1_tx_utils/factory.d.ts.map +1 -1
  71. package/dest/l1_tx_utils/factory.js +17 -7
  72. package/dest/l1_tx_utils/fee-strategies/index.d.ts +10 -0
  73. package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -0
  74. package/dest/l1_tx_utils/fee-strategies/index.js +12 -0
  75. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +8 -0
  76. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -0
  77. package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +129 -0
  78. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +23 -0
  79. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -0
  80. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +191 -0
  81. package/dest/l1_tx_utils/fee-strategies/types.d.ts +51 -0
  82. package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -0
  83. package/dest/l1_tx_utils/fee-strategies/types.js +3 -0
  84. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +41 -0
  85. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -0
  86. package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +42 -0
  87. package/dest/l1_tx_utils/index-blobs.d.ts +3 -0
  88. package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -0
  89. package/dest/l1_tx_utils/index-blobs.js +2 -0
  90. package/dest/l1_tx_utils/index.d.ts +4 -1
  91. package/dest/l1_tx_utils/index.d.ts.map +1 -1
  92. package/dest/l1_tx_utils/index.js +3 -0
  93. package/dest/l1_tx_utils/interfaces.d.ts +2 -2
  94. package/dest/l1_tx_utils/interfaces.d.ts.map +1 -1
  95. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +233 -0
  96. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
  97. package/dest/l1_tx_utils/l1_fee_analyzer.js +506 -0
  98. package/dest/l1_tx_utils/l1_tx_utils.d.ts +15 -5
  99. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
  100. package/dest/l1_tx_utils/l1_tx_utils.js +64 -17
  101. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +4 -15
  102. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
  103. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +53 -160
  104. package/dest/l1_tx_utils/tx_delayer.d.ts +56 -0
  105. package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
  106. package/dest/{test → l1_tx_utils}/tx_delayer.js +65 -36
  107. package/dest/publisher_manager.d.ts +3 -2
  108. package/dest/publisher_manager.d.ts.map +1 -1
  109. package/dest/publisher_manager.js +2 -2
  110. package/dest/queries.d.ts +2 -2
  111. package/dest/queries.d.ts.map +1 -1
  112. package/dest/queries.js +12 -4
  113. package/dest/test/chain_monitor.d.ts +15 -13
  114. package/dest/test/chain_monitor.d.ts.map +1 -1
  115. package/dest/test/chain_monitor.js +7 -9
  116. package/dest/test/eth_cheat_codes.d.ts +13 -1
  117. package/dest/test/eth_cheat_codes.d.ts.map +1 -1
  118. package/dest/test/eth_cheat_codes.js +4 -2
  119. package/dest/test/index.d.ts +1 -3
  120. package/dest/test/index.d.ts.map +1 -1
  121. package/dest/test/index.js +0 -2
  122. package/dest/test/rollup_cheat_codes.d.ts +9 -6
  123. package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
  124. package/dest/test/rollup_cheat_codes.js +32 -6
  125. package/dest/test/start_anvil.d.ts +3 -1
  126. package/dest/test/start_anvil.d.ts.map +1 -1
  127. package/dest/test/start_anvil.js +1 -1
  128. package/dest/test/upgrade_utils.js +2 -2
  129. package/dest/types.d.ts +57 -2
  130. package/dest/types.d.ts.map +1 -1
  131. package/dest/utils.d.ts +16 -3
  132. package/dest/utils.d.ts.map +1 -1
  133. package/dest/utils.js +64 -0
  134. package/package.json +33 -14
  135. package/src/client.ts +2 -2
  136. package/src/config.ts +65 -459
  137. package/src/contracts/README.md +157 -0
  138. package/src/contracts/empire_base.ts +3 -1
  139. package/src/contracts/empire_slashing_proposer.ts +28 -28
  140. package/src/contracts/fee_asset_handler.ts +10 -7
  141. package/src/contracts/fee_asset_price_oracle.ts +280 -0
  142. package/src/contracts/governance.ts +13 -4
  143. package/src/contracts/governance_proposer.ts +16 -2
  144. package/src/contracts/inbox.ts +55 -3
  145. package/src/contracts/index.ts +3 -0
  146. package/src/contracts/log.ts +13 -0
  147. package/src/contracts/multicall.ts +5 -2
  148. package/src/contracts/outbox.ts +98 -0
  149. package/src/contracts/rollup.ts +390 -118
  150. package/src/contracts/tally_slashing_proposer.ts +7 -1
  151. package/src/deploy_aztec_l1_contracts.ts +650 -0
  152. package/src/deploy_l1_contract.ts +362 -0
  153. package/src/forwarder_proxy.ts +108 -0
  154. package/src/generated/l1-contracts-defaults.ts +32 -0
  155. package/src/l1_contract_addresses.ts +22 -20
  156. package/src/l1_reader.ts +8 -0
  157. package/src/l1_tx_utils/config.ts +44 -6
  158. package/src/l1_tx_utils/constants.ts +13 -2
  159. package/src/l1_tx_utils/factory.ts +31 -31
  160. package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
  161. package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +163 -0
  162. package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +245 -0
  163. package/src/l1_tx_utils/fee-strategies/types.ts +56 -0
  164. package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +108 -0
  165. package/src/l1_tx_utils/index-blobs.ts +2 -0
  166. package/src/l1_tx_utils/index.ts +3 -0
  167. package/src/l1_tx_utils/interfaces.ts +1 -1
  168. package/src/l1_tx_utils/l1_fee_analyzer.ts +803 -0
  169. package/src/l1_tx_utils/l1_tx_utils.ts +76 -21
  170. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +67 -206
  171. package/src/{test → l1_tx_utils}/tx_delayer.ts +82 -52
  172. package/src/publisher_manager.ts +4 -2
  173. package/src/queries.ts +11 -3
  174. package/src/test/chain_monitor.ts +18 -16
  175. package/src/test/eth_cheat_codes.ts +2 -2
  176. package/src/test/index.ts +0 -2
  177. package/src/test/rollup_cheat_codes.ts +32 -9
  178. package/src/test/start_anvil.ts +3 -1
  179. package/src/test/upgrade_utils.ts +2 -2
  180. package/src/types.ts +62 -0
  181. package/src/utils.ts +83 -1
  182. package/dest/deploy_l1_contracts.d.ts +0 -673
  183. package/dest/deploy_l1_contracts.d.ts.map +0 -1
  184. package/dest/deploy_l1_contracts.js +0 -1491
  185. package/dest/index.d.ts +0 -18
  186. package/dest/index.d.ts.map +0 -1
  187. package/dest/index.js +0 -17
  188. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +0 -26
  189. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +0 -1
  190. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +0 -26
  191. package/dest/test/delayed_tx_utils.d.ts +0 -13
  192. package/dest/test/delayed_tx_utils.d.ts.map +0 -1
  193. package/dest/test/delayed_tx_utils.js +0 -28
  194. package/dest/test/tx_delayer.d.ts +0 -36
  195. package/dest/test/tx_delayer.d.ts.map +0 -1
  196. package/src/deploy_l1_contracts.ts +0 -1869
  197. package/src/index.ts +0 -17
  198. package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +0 -77
  199. package/src/test/delayed_tx_utils.ts +0 -52
@@ -1,9 +1,12 @@
1
- import { type L1TxRequest, type ViemClient, tryExtractEvent } from '@aztec/ethereum';
1
+ import type { L1TxRequest } from '@aztec/ethereum/l1-tx-utils';
2
+ import type { ViemClient } from '@aztec/ethereum/types';
3
+ import { mergeAbis, tryExtractEvent } from '@aztec/ethereum/utils';
2
4
  import { SlotNumber } from '@aztec/foundation/branded-types';
3
5
  import { Buffer32 } from '@aztec/foundation/buffer';
4
6
  import { EthAddress } from '@aztec/foundation/eth-address';
5
7
  import { Signature } from '@aztec/foundation/eth-signature';
6
8
  import { hexToBuffer } from '@aztec/foundation/string';
9
+ import { SlasherAbi } from '@aztec/l1-artifacts/SlasherAbi';
7
10
  import { TallySlashingProposerAbi } from '@aztec/l1-artifacts/TallySlashingProposerAbi';
8
11
 
9
12
  import {
@@ -158,6 +161,7 @@ export class TallySlashingProposerContract {
158
161
 
159
162
  return {
160
163
  to: this.contract.address,
164
+ abi: TallySlashingProposerAbi,
161
165
  data: encodeFunctionData({
162
166
  abi: TallySlashingProposerAbi,
163
167
  functionName: 'vote',
@@ -205,6 +209,7 @@ export class TallySlashingProposerContract {
205
209
  public buildVoteRequestWithSignature(votes: Hex, signature: { v: number; r: Hex; s: Hex }): L1TxRequest {
206
210
  return {
207
211
  to: this.contract.address,
212
+ abi: TallySlashingProposerAbi,
208
213
  data: encodeFunctionData({
209
214
  abi: TallySlashingProposerAbi,
210
215
  functionName: 'vote',
@@ -222,6 +227,7 @@ export class TallySlashingProposerContract {
222
227
  public buildExecuteRoundRequest(round: bigint, committees: EthAddress[][]): L1TxRequest {
223
228
  return {
224
229
  to: this.contract.address,
230
+ abi: mergeAbis([TallySlashingProposerAbi, SlasherAbi]),
225
231
  data: encodeFunctionData({
226
232
  abi: TallySlashingProposerAbi,
227
233
  functionName: 'executeRound',
@@ -0,0 +1,650 @@
1
+ import { SlotNumber } from '@aztec/foundation/branded-types';
2
+ import { SecretValue, getActiveNetworkName } from '@aztec/foundation/config';
3
+ import { EthAddress } from '@aztec/foundation/eth-address';
4
+ import { jsonStringify } from '@aztec/foundation/json-rpc';
5
+ import { createLogger } from '@aztec/foundation/log';
6
+ import { promiseWithResolvers } from '@aztec/foundation/promise';
7
+ import type { Fr } from '@aztec/foundation/schemas';
8
+ import { fileURLToPath } from '@aztec/foundation/url';
9
+
10
+ import { bn254 } from '@noble/curves/bn254';
11
+ import type { Abi, Narrow } from 'abitype';
12
+ import { spawn } from 'child_process';
13
+ import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs';
14
+ import { tmpdir } from 'os';
15
+ import { dirname, join, resolve } from 'path';
16
+ import readline from 'readline';
17
+ import type { Hex } from 'viem';
18
+ import { mainnet, sepolia } from 'viem/chains';
19
+
20
+ import { createEthereumChain, isAnvilTestChain } from './chain.js';
21
+ import { createExtendedL1Client } from './client.js';
22
+ import type { L1ContractsConfig } from './config.js';
23
+ import { deployMulticall3 } from './contracts/multicall.js';
24
+ import { RollupContract } from './contracts/rollup.js';
25
+ import type { L1ContractAddresses } from './l1_contract_addresses.js';
26
+ import type { ExtendedViemWalletClient } from './types.js';
27
+
28
+ const logger = createLogger('ethereum:deploy_aztec_l1_contracts');
29
+
30
+ const JSON_DEPLOY_RESULT_PREFIX = 'JSON DEPLOY RESULT:';
31
+
32
+ /**
33
+ * Runs a process and parses JSON deploy results from stdout.
34
+ * Lines starting with JSON_DEPLOY_RESULT_PREFIX are parsed and returned.
35
+ * All other stdout goes to logger.info, stderr goes to logger.warn.
36
+ */
37
+ function runProcess<T>(
38
+ command: string,
39
+ args: string[],
40
+ env: Record<string, string | undefined>,
41
+ cwd: string,
42
+ ): Promise<T | undefined> {
43
+ const { promise, resolve, reject } = promiseWithResolvers<T | undefined>();
44
+ const proc = spawn(command, args, {
45
+ cwd,
46
+ env: { ...process.env, ...env },
47
+ stdio: ['ignore', 'pipe', 'pipe'],
48
+ });
49
+
50
+ let result: T | undefined;
51
+ let parseError: Error | undefined;
52
+ let settled = false;
53
+
54
+ readline.createInterface({ input: proc.stdout }).on('line', line => {
55
+ const trimmedLine = line.trim();
56
+ if (trimmedLine.startsWith(JSON_DEPLOY_RESULT_PREFIX)) {
57
+ const jsonStr = trimmedLine.slice(JSON_DEPLOY_RESULT_PREFIX.length).trim();
58
+ try {
59
+ result = JSON.parse(jsonStr);
60
+ } catch {
61
+ parseError = new Error(`Failed to parse deploy result JSON: ${jsonStr.slice(0, 200)}`);
62
+ }
63
+ } else {
64
+ logger.info(line);
65
+ }
66
+ });
67
+ readline.createInterface({ input: proc.stderr }).on('line', logger.warn.bind(logger));
68
+
69
+ proc.on('error', error => {
70
+ if (settled) {
71
+ return;
72
+ }
73
+ settled = true;
74
+ reject(new Error(`Failed to spawn ${command}: ${error.message}`));
75
+ });
76
+
77
+ proc.on('close', code => {
78
+ if (settled) {
79
+ return;
80
+ }
81
+ settled = true;
82
+ if (code !== 0) {
83
+ reject(new Error(`${command} exited with code ${code}`));
84
+ } else if (parseError) {
85
+ reject(parseError);
86
+ } else {
87
+ resolve(result);
88
+ }
89
+ });
90
+
91
+ return promise;
92
+ }
93
+
94
+ // Covers an edge where where we may have a cached BlobLib that is not meant for production.
95
+ // Despite the profile apparently sometimes cached code remains (so says Lasse after his ignition-monorepo arc).
96
+ async function maybeForgeForceProductionBuild(l1ContractsPath: string, script: string, chainId: number) {
97
+ if (chainId === mainnet.id) {
98
+ logger.info(`Recompiling ${script} with production profile for mainnet deployment`);
99
+ logger.info('This may take a minute but ensures production BlobLib is used.');
100
+ await runProcess('forge', ['build', script, '--force'], { FOUNDRY_PROFILE: 'production' }, l1ContractsPath);
101
+ }
102
+ }
103
+
104
+ // Validator types for initial validator setup
105
+ export interface G2PointJson {
106
+ x0: string;
107
+ x1: string;
108
+ y0: string;
109
+ y1: string;
110
+ }
111
+
112
+ /**
113
+ * Validator data passed to Solidity for registration.
114
+ * Solidity will derive publicKeyG1 and proofOfPossession from the privateKey.
115
+ */
116
+ export interface ValidatorJson {
117
+ attester: string;
118
+ withdrawer: string;
119
+ /** BN254 secret key (private key) */
120
+ privateKey: string;
121
+ /** Pre-computed G2 public key (cannot be computed in Solidity) */
122
+ publicKeyInG2: G2PointJson;
123
+ }
124
+
125
+ /**
126
+ * Gets the path to the l1-contracts foundry artifacts directory.
127
+ * These are copied from l1-contracts to yarn-project/l1-artifacts/l1-contracts
128
+ * during build to make yarn-project self-contained.
129
+ */
130
+ export function getL1ContractsPath(): string {
131
+ const currentDir = dirname(fileURLToPath(import.meta.url));
132
+ // Go up from yarn-project/ethereum/dest to yarn-project, then to l1-artifacts/l1-contracts
133
+ const l1ContractsPath = resolve(currentDir, '..', '..', 'l1-artifacts', 'l1-contracts');
134
+ return l1ContractsPath;
135
+ }
136
+
137
+ // Cached deployment directory
138
+ let preparedDeployDir: string | undefined;
139
+
140
+ function cleanupDeployDir() {
141
+ if (preparedDeployDir) {
142
+ try {
143
+ rmSync(preparedDeployDir, { recursive: true, force: true });
144
+ } catch {
145
+ // ignore cleanup errors
146
+ }
147
+ preparedDeployDir = undefined;
148
+ }
149
+ }
150
+
151
+ /**
152
+ * Prepares a temp directory for forge deployment.
153
+ * Copies all artifacts with preserved timestamps (required for forge cache validity).
154
+ * A fresh broadcast/ directory is created for deployment outputs.
155
+ */
156
+ export function prepareL1ContractsForDeployment(): string {
157
+ if (preparedDeployDir && existsSync(preparedDeployDir)) {
158
+ logger.verbose(`Using cached deployment directory: ${preparedDeployDir}`);
159
+ return preparedDeployDir;
160
+ }
161
+
162
+ const basePath = getL1ContractsPath();
163
+ logger.verbose(`Preparing L1 contracts from: ${basePath}`);
164
+ const tempDir = mkdtempSync(join(tmpdir(), '.foundry-deploy-'));
165
+ logger.verbose(`Created temp directory for deployment: ${tempDir}`);
166
+ preparedDeployDir = tempDir;
167
+ process.on('exit', cleanupDeployDir);
168
+
169
+ // Copy all dirs with preserved timestamps (required for forge cache validity)
170
+ const copyOpts = { recursive: true, preserveTimestamps: true };
171
+ cpSync(join(basePath, 'out'), join(tempDir, 'out'), copyOpts);
172
+ cpSync(join(basePath, 'lib'), join(tempDir, 'lib'), copyOpts);
173
+ cpSync(join(basePath, 'cache'), join(tempDir, 'cache'), copyOpts);
174
+ cpSync(join(basePath, 'src'), join(tempDir, 'src'), copyOpts);
175
+ cpSync(join(basePath, 'script'), join(tempDir, 'script'), copyOpts);
176
+ cpSync(join(basePath, 'generated'), join(tempDir, 'generated'), copyOpts);
177
+ // Kludge: copy test/ to appease forge cache which references test/shouting.t.sol
178
+ cpSync(join(basePath, 'test'), join(tempDir, 'test'), copyOpts);
179
+ cpSync(join(basePath, 'foundry.lock'), join(tempDir, 'foundry.lock'));
180
+
181
+ // Update foundry.toml to use absolute path to solc binary (avoids copying to noexec tmpfs)
182
+ const foundryTomlPath = join(basePath, 'foundry.toml');
183
+ let foundryToml = readFileSync(foundryTomlPath, 'utf-8');
184
+ const solcPathMatch = foundryToml.match(/solc\s*=\s*"\.\/solc-([^"]+)"/);
185
+ // Did we find a hardcoded solc path that we need to make absolute?
186
+ // This code path happens in CI currently as we bundle solc there to avoid race conditions when
187
+ // downloading solc.
188
+ if (solcPathMatch) {
189
+ const solcVersion = solcPathMatch[1];
190
+ const absoluteSolcPath = join(basePath, `solc-${solcVersion}`);
191
+ foundryToml = foundryToml.replace(/solc\s*=\s*"\.\/solc-[^"]+"/, `solc = "${absoluteSolcPath}"`);
192
+ logger.verbose(`Updated solc path in foundry.toml to: ${absoluteSolcPath}`);
193
+ }
194
+ writeFileSync(join(tempDir, 'foundry.toml'), foundryToml);
195
+
196
+ mkdirSync(join(tempDir, 'broadcast'));
197
+ return tempDir;
198
+ }
199
+
200
+ /**
201
+ * Computes the validator data for passing to Solidity.
202
+ * Only computes the G2 public key (which requires scalar multiplication on G2, not available in EVM).
203
+ * Solidity will derive G1 public key and proof of possession from the private key.
204
+ */
205
+ export function computeValidatorData(operator: Operator): ValidatorJson {
206
+ const privateKey = operator.bn254SecretKey.getValue();
207
+
208
+ // Compute G2 public key: pk2 = privateKey * G2
209
+ // This is the only computation we need to do in TypeScript since G2 scalar mul
210
+ // is not available as an EVM precompile
211
+ const publicKeyG2 = bn254.G2.ProjectivePoint.BASE.multiply(privateKey);
212
+ const publicKeyG2Affine = publicKeyG2.toAffine();
213
+
214
+ return {
215
+ attester: operator.attester.toString(),
216
+ withdrawer: operator.withdrawer.toString(),
217
+ privateKey: privateKey.toString(),
218
+ publicKeyInG2: {
219
+ x0: publicKeyG2Affine.x.c0.toString(),
220
+ x1: publicKeyG2Affine.x.c1.toString(),
221
+ y0: publicKeyG2Affine.y.c0.toString(),
222
+ y1: publicKeyG2Affine.y.c1.toString(),
223
+ },
224
+ };
225
+ }
226
+
227
+ /**
228
+ * Deployed addresses from the rollup upgrade deployment.
229
+ */
230
+ export interface RollupUpgradeAddresses {
231
+ rollupAddress: string;
232
+ verifierAddress: string;
233
+ slashFactoryAddress: string;
234
+ inboxAddress: string;
235
+ outboxAddress: string;
236
+ feeJuicePortalAddress: string;
237
+ rollupVersion: number;
238
+ }
239
+
240
+ /**
241
+ * Return type for rollup upgrade via forge.
242
+ */
243
+ export interface ForgeRollupUpgradeResult {
244
+ rollupAddress: Hex;
245
+ verifierAddress: Hex;
246
+ slashFactoryAddress: Hex;
247
+ inboxAddress: Hex;
248
+ outboxAddress: Hex;
249
+ feeJuicePortalAddress: Hex;
250
+ rollupVersion: number;
251
+ }
252
+
253
+ export interface ForgeL1ContractsDeployResult extends ForgeRollupUpgradeResult {
254
+ registryAddress: Hex;
255
+ feeAssetAddress: Hex;
256
+ stakingAssetAddress: Hex;
257
+ gseAddress?: Hex;
258
+ rewardDistributorAddress: Hex;
259
+ coinIssuerAddress: Hex;
260
+ governanceProposerAddress: Hex;
261
+ governanceAddress: Hex;
262
+ dateGatedRelayerAddress?: Hex;
263
+ feeAssetHandlerAddress?: Hex;
264
+ stakingAssetHandlerAddress?: Hex;
265
+ zkPassportVerifierAddress?: Hex;
266
+ }
267
+
268
+ /**
269
+ * Deploys L1 contracts using forge and returns a result compatible with the TypeScript deployAztecL1Contracts function.
270
+ * This queries the Rollup contract to get the inbox, outbox, and feeJuicePortal addresses.
271
+ *
272
+ * All configuration is passed via environment variables to the forge script. The DeploymentConfiguration.sol
273
+ * contract reads these values and applies defaults for any unspecified parameters.
274
+ *
275
+ * @param rpcUrl - The RPC URL to use
276
+ * @param privateKey - The private key for the deployer (with 0x prefix)
277
+ * @param options - Additional deployment options (all optional with sensible defaults)
278
+ * @returns The deployment result with all contract addresses and an l1Client
279
+ */
280
+ export async function deployAztecL1Contracts(
281
+ rpcUrl: string,
282
+ privateKey: `0x${string}`,
283
+ chainId: number,
284
+ args: DeployAztecL1ContractsArgs,
285
+ ): Promise<DeployAztecL1ContractsReturnType> {
286
+ logger.info(`Deploying L1 contracts with config: ${jsonStringify(args)}`);
287
+ if (args.initialValidators && args.initialValidators.length > 0 && args.existingTokenAddress) {
288
+ throw new Error(
289
+ 'Cannot deploy with both initialValidators and existingTokenAddress. ' +
290
+ 'Initial validator funding requires minting tokens, which is not possible with an external token.',
291
+ );
292
+ }
293
+ const chain = createEthereumChain([rpcUrl], chainId);
294
+
295
+ const l1Client = createExtendedL1Client([rpcUrl], privateKey, chain.chainInfo);
296
+ const rpcCall = async (method: string, params: any[]) => {
297
+ logger.info(`Calling ${method} with params: ${JSON.stringify(params)}`);
298
+ return (await l1Client.transport.request({
299
+ method,
300
+ params,
301
+ })) as any;
302
+ };
303
+
304
+ logger.verbose(`Deploying contracts from ${l1Client.account.address.toString()}`);
305
+
306
+ // Deploy multicall3 if it does not exist in this network
307
+ // Sepolia and mainnet will have this.
308
+ await deployMulticall3(l1Client, logger);
309
+
310
+ if (isAnvilTestChain(chainId)) {
311
+ try {
312
+ // We are assuming that you are running this on a local anvil node which have 1s block times
313
+ // To align better with actual deployment, we update the block interval to 12s
314
+ await rpcCall('anvil_setBlockTimestampInterval', [args.ethereumSlotDuration]);
315
+ logger.warn(`Set block interval to ${args.ethereumSlotDuration}`);
316
+ } catch (e) {
317
+ logger.error(`Error setting block interval: ${e}`);
318
+ }
319
+ }
320
+
321
+ // Use foundry-artifacts from l1-artifacts package
322
+ const l1ContractsPath = prepareL1ContractsForDeployment();
323
+
324
+ const FORGE_SCRIPT = 'script/deploy/DeployAztecL1Contracts.s.sol';
325
+ await maybeForgeForceProductionBuild(l1ContractsPath, FORGE_SCRIPT, chainId);
326
+
327
+ // Verify contracts on Etherscan when on mainnet/sepolia and ETHERSCAN_API_KEY is available.
328
+ const isVerifiableChain = chainId === mainnet.id || chainId === sepolia.id;
329
+ const shouldVerify = isVerifiableChain && !!process.env.ETHERSCAN_API_KEY;
330
+
331
+ if (isVerifiableChain && !process.env.ETHERSCAN_API_KEY) {
332
+ logger.warn(
333
+ `Deploying to chain ${chainId} (${chainId === mainnet.id ? 'mainnet' : 'sepolia'}) without ETHERSCAN_API_KEY. ` +
334
+ `Contracts will NOT be verified on Etherscan. Set ETHERSCAN_API_KEY environment variable to enable verification.`,
335
+ );
336
+ }
337
+
338
+ const scriptPath = join(getL1ContractsPath(), 'scripts', 'forge_broadcast.js');
339
+ const forgeArgs = [
340
+ FORGE_SCRIPT,
341
+ '--sig',
342
+ 'run()',
343
+ '--private-key',
344
+ privateKey,
345
+ '--rpc-url',
346
+ rpcUrl,
347
+ ...(shouldVerify ? ['--verify'] : []),
348
+ ];
349
+ const forgeEnv = {
350
+ // Env vars required by l1-contracts/script/deploy/DeploymentConfiguration.sol.
351
+ NETWORK: getActiveNetworkName(),
352
+ FOUNDRY_PROFILE: chainId === mainnet.id ? 'production' : undefined,
353
+ ...getDeployAztecL1ContractsEnvVars(args),
354
+ };
355
+ const result = await runProcess<ForgeL1ContractsDeployResult>(
356
+ process.execPath,
357
+ [scriptPath, ...forgeArgs],
358
+ forgeEnv,
359
+ l1ContractsPath,
360
+ );
361
+ if (!result) {
362
+ throw new Error('Forge script did not output deployment result');
363
+ }
364
+ logger.info(`Deployed L1 contracts with L1 addresses: ${jsonStringify(result)}`);
365
+
366
+ const rollup = new RollupContract(l1Client, result.rollupAddress);
367
+
368
+ if (isAnvilTestChain(chainId)) {
369
+ // @note We make a time jump PAST the very first slot to not have to deal with the edge case of the first slot.
370
+ // The edge case being that the genesis block is already occupying slot 0, so we cannot have another block.
371
+ try {
372
+ // Need to get the time
373
+ const currentSlot = await rollup.getSlotNumber();
374
+
375
+ if (currentSlot === 0) {
376
+ const ts = Number(await rollup.getTimestampForSlot(SlotNumber(1)));
377
+ await rpcCall('evm_setNextBlockTimestamp', [ts]);
378
+ await rpcCall('hardhat_mine', [1]);
379
+ const currentSlot = await rollup.getSlotNumber();
380
+
381
+ if (currentSlot !== 1) {
382
+ throw new Error(`Error jumping time: current slot is ${currentSlot}`);
383
+ }
384
+ logger.info(`Jumped to slot 1`);
385
+ }
386
+ } catch (e) {
387
+ throw new Error(`Error jumping time: ${e}`);
388
+ }
389
+ }
390
+
391
+ return {
392
+ l1Client,
393
+ rollupVersion: result.rollupVersion,
394
+ l1ContractAddresses: {
395
+ rollupAddress: EthAddress.fromString(result.rollupAddress),
396
+ registryAddress: EthAddress.fromString(result.registryAddress),
397
+ inboxAddress: EthAddress.fromString(result.inboxAddress),
398
+ outboxAddress: EthAddress.fromString(result.outboxAddress),
399
+ feeJuiceAddress: EthAddress.fromString(result.feeAssetAddress),
400
+ feeJuicePortalAddress: EthAddress.fromString(result.feeJuicePortalAddress),
401
+ coinIssuerAddress: EthAddress.fromString(result.coinIssuerAddress),
402
+ rewardDistributorAddress: EthAddress.fromString(result.rewardDistributorAddress),
403
+ governanceProposerAddress: EthAddress.fromString(result.governanceProposerAddress),
404
+ governanceAddress: EthAddress.fromString(result.governanceAddress),
405
+ stakingAssetAddress: EthAddress.fromString(result.stakingAssetAddress),
406
+ slashFactoryAddress: result.slashFactoryAddress ? EthAddress.fromString(result.slashFactoryAddress) : undefined,
407
+ feeAssetHandlerAddress: result.feeAssetHandlerAddress
408
+ ? EthAddress.fromString(result.feeAssetHandlerAddress)
409
+ : undefined,
410
+ stakingAssetHandlerAddress: result.stakingAssetHandlerAddress
411
+ ? EthAddress.fromString(result.stakingAssetHandlerAddress)
412
+ : undefined,
413
+ zkPassportVerifierAddress: result.zkPassportVerifierAddress
414
+ ? EthAddress.fromString(result.zkPassportVerifierAddress)
415
+ : undefined,
416
+ gseAddress: result.gseAddress ? EthAddress.fromString(result.gseAddress) : undefined,
417
+ dateGatedRelayerAddress: result.dateGatedRelayerAddress
418
+ ? EthAddress.fromString(result.dateGatedRelayerAddress)
419
+ : undefined,
420
+ },
421
+ };
422
+ }
423
+
424
+ export const DEPLOYER_ADDRESS: Hex = '0x4e59b44847b379578588920cA78FbF26c0B4956C';
425
+
426
+ export type Operator = {
427
+ attester: EthAddress;
428
+ withdrawer: EthAddress;
429
+ bn254SecretKey: SecretValue<bigint>;
430
+ };
431
+
432
+ /**
433
+ * Return type of the deployAztecL1Contracts function.
434
+ */
435
+ export type DeployAztecL1ContractsReturnType = {
436
+ /** Extended Wallet Client Type. */
437
+ l1Client: ExtendedViemWalletClient;
438
+ /** The currently deployed l1 contract addresses */
439
+ l1ContractAddresses: L1ContractAddresses;
440
+ /** Version of the current rollup contract. */
441
+ rollupVersion: number;
442
+ };
443
+
444
+ export interface LinkReferences {
445
+ [fileName: string]: {
446
+ [contractName: string]: ReadonlyArray<{
447
+ start: number;
448
+ length: number;
449
+ }>;
450
+ };
451
+ }
452
+
453
+ export interface Libraries {
454
+ linkReferences: LinkReferences;
455
+ libraryCode: Record<string, ContractArtifacts>;
456
+ }
457
+
458
+ /**
459
+ * Contract artifacts
460
+ */
461
+ export interface ContractArtifacts<TAbi extends Abi | readonly unknown[] = Abi> {
462
+ /**
463
+ * The contract name.
464
+ */
465
+ name: string;
466
+ /**
467
+ * The contract abi.
468
+ */
469
+ contractAbi: Narrow<TAbi>;
470
+ /**
471
+ * The contract bytecode
472
+ */
473
+ contractBytecode: Hex;
474
+ /**
475
+ * The contract libraries
476
+ */
477
+ libraries?: Libraries;
478
+ }
479
+
480
+ export type VerificationLibraryEntry = {
481
+ file: string;
482
+ contract: string;
483
+ address: string;
484
+ };
485
+
486
+ export type VerificationRecord = {
487
+ name: string;
488
+ address: string;
489
+ constructorArgsHex: Hex;
490
+ libraries: VerificationLibraryEntry[];
491
+ };
492
+
493
+ export interface DeployAztecL1ContractsArgs
494
+ extends Omit<
495
+ L1ContractsConfig,
496
+ | 'gasLimitBufferPercentage'
497
+ | 'maxGwei'
498
+ | 'maxBlobGwei'
499
+ | 'priorityFeeBumpPercentage'
500
+ | 'priorityFeeRetryBumpPercentage'
501
+ | 'minimumPriorityFeePerGas'
502
+ | 'maxSpeedUpAttempts'
503
+ | 'checkIntervalMs'
504
+ | 'stallTimeMs'
505
+ | 'txTimeoutMs'
506
+ | 'cancelTxOnTimeout'
507
+ | 'txCancellationFinalTimeoutMs'
508
+ | 'txUnseenConsideredDroppedMs'
509
+ | 'enableDelayer'
510
+ | 'txDelayerMaxInclusionTimeIntoSlot'
511
+ > {
512
+ /** The vk tree root. */
513
+ vkTreeRoot: Fr;
514
+ /** The hash of the protocol contracts. */
515
+ protocolContractsHash: Fr;
516
+ /** The genesis root of the archive tree. */
517
+ genesisArchiveRoot: Fr;
518
+ /** The initial validators for the rollup contract. */
519
+ initialValidators?: Operator[];
520
+ /** The initial balance of the fee juice portal. This is the amount of fee juice that is prefunded to accounts */
521
+ feeJuicePortalInitialBalance?: bigint;
522
+ /** Whether to deploy the real verifier or the mock verifier */
523
+ realVerifier?: boolean;
524
+ /** The zk passport args */
525
+ zkPassportArgs?: ZKPassportArgs;
526
+ /** If provided, use this token for BOTH fee and staking assets (skip deployments) */
527
+ existingTokenAddress?: EthAddress;
528
+ }
529
+
530
+ export interface ZKPassportArgs {
531
+ /** The domain of the zk passport (url) */
532
+ zkPassportDomain?: string;
533
+ /** The scope of the zk passport (personhood, etc) */
534
+ zkPassportScope?: string;
535
+ }
536
+
537
+ // picked up by l1-contracts DeploymentConfiguration.sol
538
+ export function getDeployAztecL1ContractsEnvVars(args: DeployAztecL1ContractsArgs) {
539
+ return {
540
+ ...getDeployRollupForUpgradeEnvVars(args), // parsed by RollupConfiguration.sol
541
+ EXISTING_TOKEN_ADDRESS: args.existingTokenAddress?.toString(),
542
+ AZTEC_ACTIVATION_THRESHOLD: args.activationThreshold?.toString(),
543
+ AZTEC_EJECTION_THRESHOLD: args.ejectionThreshold?.toString(),
544
+ AZTEC_GOVERNANCE_PROPOSER_ROUND_SIZE: args.governanceProposerRoundSize?.toString(),
545
+ AZTEC_GOVERNANCE_PROPOSER_QUORUM: args.governanceProposerQuorum?.toString(),
546
+ AZTEC_GOVERNANCE_VOTING_DURATION: args.governanceVotingDuration?.toString(),
547
+ ZKPASSPORT_DOMAIN: args.zkPassportArgs?.zkPassportDomain,
548
+ ZKPASSPORT_SCOPE: args.zkPassportArgs?.zkPassportScope,
549
+ } as const;
550
+ }
551
+
552
+ // picked up by l1-contracts RollupConfiguration.sol
553
+ export function getDeployRollupForUpgradeEnvVars(
554
+ args: Omit<
555
+ DeployAztecL1ContractsArgs,
556
+ | 'governanceProposerQuorum'
557
+ | 'governanceProposerRoundSize'
558
+ | 'ejectionThreshold'
559
+ | 'activationThreshold'
560
+ | 'getZkPassportArgs'
561
+ >,
562
+ ) {
563
+ return {
564
+ INITIAL_VALIDATORS: JSON.stringify((args.initialValidators ?? []).map(computeValidatorData)),
565
+ REAL_VERIFIER: args.realVerifier ? 'true' : 'false',
566
+ FEE_JUICE_PORTAL_INITIAL_BALANCE: (args.feeJuicePortalInitialBalance ?? 0n).toString(),
567
+ // Genesis state
568
+ VK_TREE_ROOT: args.vkTreeRoot.toString(),
569
+ PROTOCOL_CONTRACTS_HASH: args.protocolContractsHash.toString(),
570
+ GENESIS_ARCHIVE_ROOT: args.genesisArchiveRoot.toString(),
571
+ // Rollup config
572
+ AZTEC_SLOT_DURATION: args.aztecSlotDuration.toString(),
573
+ AZTEC_EPOCH_DURATION: args.aztecEpochDuration.toString(),
574
+ AZTEC_TARGET_COMMITTEE_SIZE: args.aztecTargetCommitteeSize.toString(),
575
+ AZTEC_LAG_IN_EPOCHS_FOR_VALIDATOR_SET: args.lagInEpochsForValidatorSet.toString(),
576
+ AZTEC_LAG_IN_EPOCHS_FOR_RANDAO: args.lagInEpochsForRandao.toString(),
577
+ AZTEC_INBOX_LAG: args.inboxLag?.toString(),
578
+ AZTEC_PROOF_SUBMISSION_EPOCHS: args.aztecProofSubmissionEpochs.toString(),
579
+ AZTEC_LOCAL_EJECTION_THRESHOLD: args.localEjectionThreshold.toString(),
580
+ AZTEC_SLASHING_LIFETIME_IN_ROUNDS: args.slashingLifetimeInRounds.toString(),
581
+ AZTEC_SLASHING_EXECUTION_DELAY_IN_ROUNDS: args.slashingExecutionDelayInRounds.toString(),
582
+ AZTEC_SLASHING_VETOER: args.slashingVetoer.toString(),
583
+ AZTEC_SLASHING_DISABLE_DURATION: args.slashingDisableDuration.toString(),
584
+ AZTEC_MANA_TARGET: args.manaTarget.toString(),
585
+ AZTEC_EXIT_DELAY_SECONDS: args.exitDelaySeconds.toString(),
586
+ AZTEC_PROVING_COST_PER_MANA: args.provingCostPerMana.toString(),
587
+ AZTEC_INITIAL_ETH_PER_FEE_ASSET: args.initialEthPerFeeAsset.toString(),
588
+ AZTEC_SLASHER_FLAVOR: args.slasherFlavor,
589
+ AZTEC_SLASHING_ROUND_SIZE_IN_EPOCHS: args.slashingRoundSizeInEpochs.toString(),
590
+ AZTEC_SLASHING_QUORUM: args.slashingQuorum?.toString(),
591
+ AZTEC_SLASHING_OFFSET_IN_ROUNDS: args.slashingOffsetInRounds.toString(),
592
+ AZTEC_SLASH_AMOUNT_SMALL: args.slashAmountSmall.toString(),
593
+ AZTEC_SLASH_AMOUNT_MEDIUM: args.slashAmountMedium.toString(),
594
+ AZTEC_SLASH_AMOUNT_LARGE: args.slashAmountLarge.toString(),
595
+ } as const;
596
+ }
597
+
598
+ /**
599
+ * Deploys a new rollup, using the existing canonical version to derive certain values (addresses of assets etc).
600
+ */
601
+ export const deployRollupForUpgrade = async (
602
+ privateKey: `0x${string}`,
603
+ rpcUrl: string,
604
+ chainId: number,
605
+ registryAddress: EthAddress,
606
+ args: Omit<
607
+ DeployAztecL1ContractsArgs,
608
+ | 'governanceProposerQuorum'
609
+ | 'governanceProposerRoundSize'
610
+ | 'ejectionThreshold'
611
+ | 'activationThreshold'
612
+ | 'zkPassportArgs'
613
+ >,
614
+ ) => {
615
+ // Use foundry-artifacts from l1-artifacts package
616
+ const l1ContractsPath = prepareL1ContractsForDeployment();
617
+
618
+ const FORGE_SCRIPT = 'script/deploy/DeployRollupForUpgrade.s.sol';
619
+ await maybeForgeForceProductionBuild(l1ContractsPath, FORGE_SCRIPT, chainId);
620
+
621
+ const scriptPath = join(getL1ContractsPath(), 'scripts', 'forge_broadcast.js');
622
+ const forgeArgs = [FORGE_SCRIPT, '--sig', 'run()', '--private-key', privateKey, '--rpc-url', rpcUrl];
623
+ const forgeEnv = {
624
+ FOUNDRY_PROFILE: chainId === mainnet.id ? 'production' : undefined,
625
+ // Env vars required by l1-contracts/script/deploy/RollupConfiguration.sol.
626
+ REGISTRY_ADDRESS: registryAddress.toString(),
627
+ NETWORK: getActiveNetworkName(),
628
+ ...getDeployRollupForUpgradeEnvVars(args),
629
+ };
630
+
631
+ const result = await runProcess<ForgeRollupUpgradeResult>(
632
+ process.execPath,
633
+ [scriptPath, ...forgeArgs],
634
+ forgeEnv,
635
+ l1ContractsPath,
636
+ );
637
+ if (!result) {
638
+ throw new Error('Forge script did not output deployment result');
639
+ }
640
+
641
+ const extendedClient = createExtendedL1Client([rpcUrl], privateKey);
642
+
643
+ // Create RollupContract wrapper for the deployed rollup
644
+ const rollup = new RollupContract(extendedClient, result.rollupAddress);
645
+
646
+ return {
647
+ rollup,
648
+ slashFactoryAddress: result.slashFactoryAddress,
649
+ };
650
+ };