diff --git a/ethereum/contracts/Implementation.sol b/ethereum/contracts/Implementation.sol index d61293ad..474cc2d6 100644 --- a/ethereum/contracts/Implementation.sol +++ b/ethereum/contracts/Implementation.sol @@ -30,23 +30,6 @@ contract Implementation is Governance { setNextSequence(emitter, sequence + 1); } - function initialize(address[] memory initialGuardians, uint16 chainId, uint16 governanceChainId, bytes32 governanceContract) initializer public { - require(initialGuardians.length > 0, "no guardians specified"); - - Structs.GuardianSet memory initialGuardianSet = Structs.GuardianSet({ - keys : initialGuardians, - expirationTime : 0 - }); - - storeGuardianSet(initialGuardianSet, 0); - // initial guardian set index is 0, which is the default value of the storage slot anyways - - setChainId(chainId); - - setGovernanceChainId(governanceChainId); - setGovernanceContract(governanceContract); - } - modifier initializer() { address implementation = ERC1967Upgrade._getImplementation(); diff --git a/ethereum/contracts/Setup.sol b/ethereum/contracts/Setup.sol new file mode 100644 index 00000000..989ffd6f --- /dev/null +++ b/ethereum/contracts/Setup.sol @@ -0,0 +1,36 @@ +// contracts/Implementation.sol +// SPDX-License-Identifier: Apache 2 + +pragma solidity ^0.8.0; +pragma experimental ABIEncoderV2; + +import "./Governance.sol"; + +import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Upgrade.sol"; + +contract Setup is Setters, ERC1967Upgrade { + function setup( + address implementation, + address[] memory initialGuardians, + uint16 chainId, + uint16 governanceChainId, + bytes32 governanceContract + ) public { + require(initialGuardians.length > 0, "no guardians specified"); + + Structs.GuardianSet memory initialGuardianSet = Structs.GuardianSet({ + keys : initialGuardians, + expirationTime : 0 + }); + + storeGuardianSet(initialGuardianSet, 0); + // initial guardian set index is 0, which is the default value of the storage slot anyways + + setChainId(chainId); + + setGovernanceChainId(governanceChainId); + setGovernanceContract(governanceContract); + + _upgradeTo(implementation); + } +} diff --git a/ethereum/contracts/Wormhole.sol b/ethereum/contracts/Wormhole.sol index da749745..a0917894 100644 --- a/ethereum/contracts/Wormhole.sol +++ b/ethereum/contracts/Wormhole.sol @@ -6,8 +6,8 @@ pragma solidity ^0.8.0; import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; contract Wormhole is ERC1967Proxy { - constructor (address implementation, bytes memory initData) ERC1967Proxy( - implementation, + constructor (address setup, bytes memory initData) ERC1967Proxy( + setup, initData ) { } } \ No newline at end of file diff --git a/ethereum/migrations/2_deploy_wormhole.js b/ethereum/migrations/2_deploy_wormhole.js index 8eb981b6..fbc6dbef 100644 --- a/ethereum/migrations/2_deploy_wormhole.js +++ b/ethereum/migrations/2_deploy_wormhole.js @@ -1,5 +1,6 @@ require('dotenv').config({ path: "../.env" }); +const Setup = artifacts.require("Setup"); const Implementation = artifacts.require("Implementation"); const Wormhole = artifacts.require("Wormhole"); @@ -10,20 +11,22 @@ const governanceChainId = process.env.INIT_GOV_CHAIN_ID; const governanceContract = process.env.INIT_GOV_CONTRACT; // bytes32 module.exports = async function (deployer) { + // deploy setup + await deployer.deploy(Setup); + // deploy implementation await deployer.deploy(Implementation); // encode initialisation data - const impl = new web3.eth.Contract(Implementation.abi, Implementation.address); - const initData = impl.methods.initialize( + const setup = new web3.eth.Contract(Setup.abi, Setup.address); + const initData = setup.methods.setup( + Implementation.address, initialSigners, chainId, governanceChainId, governanceContract ).encodeABI(); - // console.log(initData) - // deploy proxy - await deployer.deploy(Wormhole, Implementation.address, initData); + await deployer.deploy(Wormhole, Setup.address, initData); }; diff --git a/ethereum/test/wormhole.js b/ethereum/test/wormhole.js index ce6f59c1..a2a45b79 100644 --- a/ethereum/test/wormhole.js +++ b/ethereum/test/wormhole.js @@ -85,21 +85,6 @@ contract("Wormhole", function () { assert.equal(governanceContract, testGovernanceContract); }) - it("initialize should be non-reentrant", async function () { - const initialized = new web3.eth.Contract(ImplementationFullABI, Wormhole.address); - - try { - await initialized.methods.initialize([ - testSigner1.address - ], testChainId, testGovernanceChainId, testGovernanceContract).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 log a published message correctly", async function () { const initialized = new web3.eth.Contract(ImplementationFullABI, Wormhole.address); const accounts = await web3.eth.getAccounts();