diff --git a/ethereum/contracts/bridge/BridgeImplementation.sol b/ethereum/contracts/bridge/BridgeImplementation.sol index 8f9313024..9375d5f61 100644 --- a/ethereum/contracts/bridge/BridgeImplementation.sol +++ b/ethereum/contracts/bridge/BridgeImplementation.sol @@ -10,27 +10,6 @@ import "./Bridge.sol"; contract BridgeImplementation is Bridge { - - function initialize( - uint16 chainId, - address wormhole, - uint16 governanceChainId, - bytes32 governanceContract, - address tokenImplementation, - address WETH - ) initializer public { - setChainId(chainId); - - setWormhole(wormhole); - - setGovernanceChainId(governanceChainId); - setGovernanceContract(governanceContract); - - setTokenImplementation(tokenImplementation); - - setWETH(WETH); - } - // Beacon getter for the token contracts function implementation() public view returns (address) { return tokenImplementation(); diff --git a/ethereum/contracts/bridge/BridgeSetup.sol b/ethereum/contracts/bridge/BridgeSetup.sol new file mode 100644 index 000000000..26eb9944f --- /dev/null +++ b/ethereum/contracts/bridge/BridgeSetup.sol @@ -0,0 +1,34 @@ +// contracts/BridgeSetup.sol +// SPDX-License-Identifier: Apache 2 + +pragma solidity ^0.8.0; +pragma experimental ABIEncoderV2; + +import "./BridgeGovernance.sol"; + +import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Upgrade.sol"; + +contract BridgeSetup is BridgeSetters, ERC1967Upgrade { + function setup( + address implementation, + uint16 chainId, + address wormhole, + uint16 governanceChainId, + bytes32 governanceContract, + address tokenImplementation, + address WETH + ) public { + setChainId(chainId); + + setWormhole(wormhole); + + setGovernanceChainId(governanceChainId); + setGovernanceContract(governanceContract); + + setTokenImplementation(tokenImplementation); + + setWETH(WETH); + + _upgradeTo(implementation); + } +} diff --git a/ethereum/migrations/3_deploy_bridge.js b/ethereum/migrations/3_deploy_bridge.js index 07d80efd2..95bc787d4 100644 --- a/ethereum/migrations/3_deploy_bridge.js +++ b/ethereum/migrations/3_deploy_bridge.js @@ -2,6 +2,7 @@ require('dotenv').config({ path: "../.env" }); const TokenBridge = artifacts.require("TokenBridge"); const BridgeImplementation = artifacts.require("BridgeImplementation"); +const BridgeSetup = artifacts.require("BridgeSetup"); const TokenImplementation = artifacts.require("TokenImplementation"); const Wormhole = artifacts.require("Wormhole"); @@ -14,12 +15,16 @@ module.exports = async function (deployer) { // deploy token implementation await deployer.deploy(TokenImplementation); + // deploy setup + await deployer.deploy(BridgeSetup); + // deploy implementation await deployer.deploy(BridgeImplementation); // encode initialisation data - const impl = new web3.eth.Contract(BridgeImplementation.abi, BridgeImplementation.address); - const initData = impl.methods.initialize( + const setup = new web3.eth.Contract(BridgeSetup.abi, BridgeSetup.address); + const initData = setup.methods.setup( + BridgeImplementation.address, chainId, (await Wormhole.deployed()).address, governanceChainId, @@ -29,5 +34,5 @@ module.exports = async function (deployer) { ).encodeABI(); // deploy proxy - await deployer.deploy(TokenBridge, BridgeImplementation.address, initData); + await deployer.deploy(TokenBridge, BridgeSetup.address, initData); }; diff --git a/ethereum/test/bridge.js b/ethereum/test/bridge.js index 6ea2502a2..b79c79a9a 100644 --- a/ethereum/test/bridge.js +++ b/ethereum/test/bridge.js @@ -53,27 +53,6 @@ contract("Bridge", function () { assert.equal(governanceContract, testGovernanceContract); }) - it("initialize should be non-reentrant", async function(){ - const initialized = new web3.eth.Contract(BridgeImplementationFullABI, TokenBridge.address); - - try{ - await initialized.methods.initialize( - 1, - Wormhole.address, - 1, - testGovernanceContract, - TokenImplementation.address, - WETH - ).estimateGas(); - } catch (error) { - assert.equal(error.message, "Returned error: VM Exception while processing transaction: revert already initialized") - return - } - - assert.fail("did not fail") - }) - - it("should register a foreign bridge implementation correctly", async function() { const initialized = new web3.eth.Contract(BridgeImplementationFullABI, TokenBridge.address); const accounts = await web3.eth.getAccounts();