Skip to content

Commit 8f6c1f8

Browse files
authored
Merge pull request #54 from OffchainLabs/init-logic-contracts
Init logic contracts
2 parents 41df4f4 + 127c1f3 commit 8f6c1f8

File tree

2 files changed

+117
-6
lines changed

2 files changed

+117
-6
lines changed

contracts/tokenbridge/arbitrum/L2AtomicTokenBridgeFactory.sol

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";
2525
contract L2AtomicTokenBridgeFactory {
2626
error L2AtomicTokenBridgeFactory_AlreadyExists();
2727

28+
// In order to avoid having uninitialized logic contracts, `initialize` function will be called
29+
// on all logic contracts which don't have initializers disabled. This dummy non-zero address
30+
// will be provided to those initializers, as values written to the logic contract's storage
31+
// are not used.
32+
address private constant ADDRESS_DEAD = address(0x000000000000000000000000000000000000dEaD);
33+
2834
function deployL2Contracts(
2935
L2RuntimeCode calldata l2Code,
3036
address l1Router,
@@ -86,7 +92,8 @@ contract L2AtomicTokenBridgeFactory {
8692
proxyAdmin, _getL2Salt(OrbitSalts.L2_EXECUTOR), _getL2Salt(OrbitSalts.L2_EXECUTOR_LOGIC)
8793
);
8894

89-
// create UpgradeExecutor logic and upgrade to it
95+
// Create UpgradeExecutor logic and upgrade to it.
96+
// Note: UpgradeExecutor logic has initializer disabled so no need to call it.
9097
address upExecutorLogic = Create2.deploy(
9198
0, _getL2Salt(OrbitSalts.L2_EXECUTOR_LOGIC), _creationCodeFor(runtimeCode)
9299
);
@@ -119,6 +126,9 @@ contract L2AtomicTokenBridgeFactory {
119126
Create2.deploy(0, _getL2Salt(OrbitSalts.L2_ROUTER_LOGIC), _creationCodeFor(runtimeCode));
120127
ProxyAdmin(proxyAdmin).upgrade(ITransparentUpgradeableProxy(canonicalRouter), routerLogic);
121128

129+
// init logic contract with dummy values.
130+
L2GatewayRouter(routerLogic).initialize(ADDRESS_DEAD, ADDRESS_DEAD);
131+
122132
// init
123133
L2GatewayRouter(canonicalRouter).initialize(l1Router, l2StandardGatewayCanonicalAddress);
124134

@@ -147,6 +157,9 @@ contract L2AtomicTokenBridgeFactory {
147157
ITransparentUpgradeableProxy(canonicalStdGateway), stdGatewayLogic
148158
);
149159

160+
// init logic contract with dummy values
161+
L2ERC20Gateway(stdGatewayLogic).initialize(ADDRESS_DEAD, ADDRESS_DEAD, ADDRESS_DEAD);
162+
150163
// create beacon
151164
StandardArbERC20 standardArbERC20 = new StandardArbERC20{
152165
salt: _getL2Salt(OrbitSalts.L2_STANDARD_ERC20)
@@ -189,8 +202,11 @@ contract L2AtomicTokenBridgeFactory {
189202
ITransparentUpgradeableProxy(canonicalCustomGateway), customGatewayLogicAddress
190203
);
191204

205+
// init logic contract with dummy values
206+
L2CustomGateway(customGatewayLogicAddress).initialize(ADDRESS_DEAD, ADDRESS_DEAD);
207+
192208
// init
193-
L2GatewayRouter(canonicalCustomGateway).initialize(l1CustomGateway, router);
209+
L2CustomGateway(canonicalCustomGateway).initialize(l1CustomGateway, router);
194210
}
195211

196212
function _deployWethGateway(
@@ -206,7 +222,7 @@ contract L2AtomicTokenBridgeFactory {
206222
proxyAdmin, _getL2Salt(OrbitSalts.L2_WETH), _getL2Salt(OrbitSalts.L2_WETH_LOGIC)
207223
);
208224

209-
// create L2WETH logic and upgrade
225+
// Create L2WETH logic and upgrade. Note: L2WETH logic has initializer disabled so no need to call it.
210226
address l2WethLogic = Create2.deploy(
211227
0, _getL2Salt(OrbitSalts.L2_WETH_LOGIC), _creationCodeFor(aeWethRuntimeCode)
212228
);
@@ -229,6 +245,11 @@ contract L2AtomicTokenBridgeFactory {
229245
ITransparentUpgradeableProxy(canonicalL2WethGateway), l2WethGatewayLogic
230246
);
231247

248+
// init logic contract with dummy values
249+
L2WethGateway(payable(l2WethGatewayLogic)).initialize(
250+
ADDRESS_DEAD, ADDRESS_DEAD, ADDRESS_DEAD, ADDRESS_DEAD
251+
);
252+
232253
// init gateway
233254
L2WethGateway(payable(canonicalL2WethGateway)).initialize(
234255
l1WethGateway, router, l1Weth, address(canonicalL2Weth)

scripts/atomicTokenBridgeDeployer.ts

Lines changed: 93 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ import { getBaseFee } from '@arbitrum/sdk/dist/lib/utils/lib'
4141
import { RollupAdminLogic__factory } from '@arbitrum/sdk/dist/lib/abi/factories/RollupAdminLogic__factory'
4242
import { ContractVerifier } from './contractVerifier'
4343

44+
/**
45+
* Dummy non-zero address which is provided to logic contracts initializers
46+
*/
47+
const ADDRESS_DEAD = '0x000000000000000000000000000000000000dEaD'
48+
4449
/**
4550
* Use already deployed L1TokenBridgeCreator to create and init token bridge contracts.
4651
* Function first gets estimates for 2 retryable tickets - one for deploying L2 factory and
@@ -237,7 +242,7 @@ export const createTokenBridge = async (
237242
l2Weth,
238243
beaconProxyFactory,
239244
l2ProxyAdmin,
240-
l2Multicall
245+
l2Multicall,
241246
}
242247
}
243248

@@ -304,40 +309,104 @@ export const deployL1TokenBridgeCreator = async (
304309
l1Deployer
305310
)
306311

312+
// initialize retryable sender logic contract
313+
await (await retryableSenderLogic.initialize()).wait()
314+
307315
/// init creator
308316
await (await l1TokenBridgeCreator.initialize(retryableSender.address)).wait()
309317

310-
/// deploy L1 logic contracts
318+
/// deploy L1 logic contracts. Initialize them with dummy data
311319
const routerTemplate = await new L1GatewayRouter__factory(l1Deployer).deploy()
312320
await routerTemplate.deployed()
321+
await (
322+
await routerTemplate.initialize(
323+
ADDRESS_DEAD,
324+
ADDRESS_DEAD,
325+
ADDRESS_DEAD,
326+
ADDRESS_DEAD,
327+
ADDRESS_DEAD
328+
)
329+
).wait()
313330

314331
const standardGatewayTemplate = await new L1ERC20Gateway__factory(
315332
l1Deployer
316333
).deploy()
317334
await standardGatewayTemplate.deployed()
335+
await (
336+
await standardGatewayTemplate.initialize(
337+
ADDRESS_DEAD,
338+
ADDRESS_DEAD,
339+
ADDRESS_DEAD,
340+
ethers.utils.hexZeroPad('0x01', 32),
341+
ADDRESS_DEAD
342+
)
343+
).wait()
318344

319345
const customGatewayTemplate = await new L1CustomGateway__factory(
320346
l1Deployer
321347
).deploy()
322348
await customGatewayTemplate.deployed()
349+
await (
350+
await customGatewayTemplate.initialize(
351+
ADDRESS_DEAD,
352+
ADDRESS_DEAD,
353+
ADDRESS_DEAD,
354+
ADDRESS_DEAD
355+
)
356+
).wait()
323357

324358
const wethGatewayTemplate = await new L1WethGateway__factory(
325359
l1Deployer
326360
).deploy()
327361
await wethGatewayTemplate.deployed()
362+
await (
363+
await wethGatewayTemplate.initialize(
364+
ADDRESS_DEAD,
365+
ADDRESS_DEAD,
366+
ADDRESS_DEAD,
367+
ADDRESS_DEAD,
368+
ADDRESS_DEAD
369+
)
370+
).wait()
328371

329372
const feeTokenBasedRouterTemplate = await new L1OrbitGatewayRouter__factory(
330373
l1Deployer
331374
).deploy()
332375
await feeTokenBasedRouterTemplate.deployed()
376+
await (
377+
await feeTokenBasedRouterTemplate.initialize(
378+
ADDRESS_DEAD,
379+
ADDRESS_DEAD,
380+
ADDRESS_DEAD,
381+
ADDRESS_DEAD,
382+
ADDRESS_DEAD
383+
)
384+
).wait()
333385

334386
const feeTokenBasedStandardGatewayTemplate =
335387
await new L1OrbitERC20Gateway__factory(l1Deployer).deploy()
336388
await feeTokenBasedStandardGatewayTemplate.deployed()
389+
await (
390+
await feeTokenBasedStandardGatewayTemplate.initialize(
391+
ADDRESS_DEAD,
392+
ADDRESS_DEAD,
393+
ADDRESS_DEAD,
394+
ethers.utils.hexZeroPad('0x01', 32),
395+
ADDRESS_DEAD
396+
)
397+
).wait()
337398

338399
const feeTokenBasedCustomGatewayTemplate =
339400
await new L1OrbitCustomGateway__factory(l1Deployer).deploy()
340401
await feeTokenBasedCustomGatewayTemplate.deployed()
402+
await (
403+
await feeTokenBasedCustomGatewayTemplate.initialize(
404+
ADDRESS_DEAD,
405+
ADDRESS_DEAD,
406+
ADDRESS_DEAD,
407+
ADDRESS_DEAD
408+
)
409+
).wait()
341410

342411
const upgradeExecutorFactory = new ethers.ContractFactory(
343412
UpgradeExecutorABI,
@@ -359,7 +428,7 @@ export const deployL1TokenBridgeCreator = async (
359428
upgradeExecutor: upgradeExecutor.address,
360429
}
361430

362-
/// deploy L2 contracts as placeholders on L1
431+
/// deploy L2 contracts as placeholders on L1. Initialize them with dummy data
363432
const l2TokenBridgeFactoryOnL1 =
364433
await new L2AtomicTokenBridgeFactory__factory(l1Deployer).deploy()
365434
await l2TokenBridgeFactoryOnL1.deployed()
@@ -368,21 +437,42 @@ export const deployL1TokenBridgeCreator = async (
368437
l1Deployer
369438
).deploy()
370439
await l2GatewayRouterOnL1.deployed()
440+
await (
441+
await l2GatewayRouterOnL1.initialize(ADDRESS_DEAD, ADDRESS_DEAD)
442+
).wait()
371443

372444
const l2StandardGatewayAddressOnL1 = await new L2ERC20Gateway__factory(
373445
l1Deployer
374446
).deploy()
375447
await l2StandardGatewayAddressOnL1.deployed()
448+
await (
449+
await l2StandardGatewayAddressOnL1.initialize(
450+
ADDRESS_DEAD,
451+
ADDRESS_DEAD,
452+
ADDRESS_DEAD
453+
)
454+
).wait()
376455

377456
const l2CustomGatewayAddressOnL1 = await new L2CustomGateway__factory(
378457
l1Deployer
379458
).deploy()
380459
await l2CustomGatewayAddressOnL1.deployed()
460+
await (
461+
await l2CustomGatewayAddressOnL1.initialize(ADDRESS_DEAD, ADDRESS_DEAD)
462+
).wait()
381463

382464
const l2WethGatewayAddressOnL1 = await new L2WethGateway__factory(
383465
l1Deployer
384466
).deploy()
385467
await l2WethGatewayAddressOnL1.deployed()
468+
await (
469+
await l2WethGatewayAddressOnL1.initialize(
470+
ADDRESS_DEAD,
471+
ADDRESS_DEAD,
472+
ADDRESS_DEAD,
473+
ADDRESS_DEAD
474+
)
475+
).wait()
386476

387477
const l2WethAddressOnL1 = await new AeWETH__factory(l1Deployer).deploy()
388478
await l2WethAddressOnL1.deployed()

0 commit comments

Comments
 (0)