From 10fdcc7f3cb26aad9950bf2a58af2ebbc7984e1e Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 8 May 2023 12:27:35 -0700 Subject: [PATCH 01/23] L2proxy --- .../test/genesis/GenerateGenesis.g.sol | 50 ++++++---- .../protocol/test/genesis/test_config.json | 12 +-- .../protocol/utils/generate_genesis/main.ts | 4 +- .../utils/generate_genesis/taikoL2.ts | 95 ++++++++++--------- 4 files changed, 87 insertions(+), 74 deletions(-) diff --git a/packages/protocol/test/genesis/GenerateGenesis.g.sol b/packages/protocol/test/genesis/GenerateGenesis.g.sol index ad512780fe1..dc5d6327ced 100644 --- a/packages/protocol/test/genesis/GenerateGenesis.g.sol +++ b/packages/protocol/test/genesis/GenerateGenesis.g.sol @@ -34,31 +34,37 @@ contract TestGenerateGenesis is Test, AddressResolver { function testContractDeployment() public { assertEq(block.chainid, 167); - checkDeployedCode("TaikoL2"); - checkDeployedCode("TokenVault"); - checkDeployedCode("EtherVault"); - checkDeployedCode("Bridge"); + checkDeployedCode("ProxiedTaikoL2"); + checkDeployedCode("ProxiedTokenVault"); + checkDeployedCode("ProxiedEtherVault"); + checkDeployedCode("ProxiedBridge"); checkDeployedCode("RegularERC20"); - checkDeployedCode("AddressManager"); - checkDeployedCode("SignalService"); + checkDeployedCode("ProxiedAddressManager"); + checkDeployedCode("ProxiedSignalService"); } function testAddressManager() public { AddressManager addressManager = AddressManager( - getPredeployedContractAddress("AddressManager") + getPredeployedContractAddress("ProxiedAddressManager") ); assertEq(owner, addressManager.owner()); - checkSavedAddress(addressManager, "Bridge", "bridge"); - checkSavedAddress(addressManager, "TokenVault", "token_vault"); - checkSavedAddress(addressManager, "EtherVault", "ether_vault"); - checkSavedAddress(addressManager, "TaikoL2", "taiko"); - checkSavedAddress(addressManager, "SignalService", "signal_service"); + checkSavedAddress(addressManager, "ProxiedBridge", "bridge"); + checkSavedAddress(addressManager, "ProxiedTokenVault", "token_vault"); + checkSavedAddress(addressManager, "ProxiedEtherVault", "ether_vault"); + checkSavedAddress(addressManager, "ProxiedTaikoL2", "taiko"); + checkSavedAddress( + addressManager, + "ProxiedSignalService", + "signal_service" + ); } function testTaikoL2() public { - TaikoL2 taikoL2 = TaikoL2(getPredeployedContractAddress("TaikoL2")); + TaikoL2 taikoL2 = TaikoL2( + getPredeployedContractAddress("ProxiedTaikoL2") + ); vm.startPrank(taikoL2.GOLDEN_TOUCH_ADDRESS()); for (uint64 i = 0; i < 300; i++) { @@ -93,7 +99,7 @@ contract TestGenerateGenesis is Test, AddressResolver { function testBridge() public { address payable bridgeAddress = payable( - getPredeployedContractAddress("Bridge") + getPredeployedContractAddress("ProxiedBridge") ); Bridge bridge = Bridge(bridgeAddress); @@ -122,26 +128,30 @@ contract TestGenerateGenesis is Test, AddressResolver { function testEtherVault() public { address payable etherVaultAddress = payable( - getPredeployedContractAddress("EtherVault") + getPredeployedContractAddress("ProxiedEtherVault") ); EtherVault etherVault = EtherVault(etherVaultAddress); assertEq(owner, etherVault.owner()); assertEq( - etherVault.isAuthorized(getPredeployedContractAddress("Bridge")), + etherVault.isAuthorized( + getPredeployedContractAddress("ProxiedBridge") + ), true ); assertEq(etherVault.isAuthorized(etherVault.owner()), false); } function testTokenVault() public { - address tokenVaultAddress = getPredeployedContractAddress("TokenVault"); - address bridgeAddress = getPredeployedContractAddress("Bridge"); + address tokenVaultAddress = getPredeployedContractAddress( + "ProxiedTokenVault" + ); + address bridgeAddress = getPredeployedContractAddress("ProxiedBridge"); TokenVault tokenVault = TokenVault(tokenVaultAddress); AddressManager addressManager = AddressManager( - getPredeployedContractAddress("AddressManager") + getPredeployedContractAddress("ProxiedAddressManager") ); assertEq(owner, tokenVault.owner()); @@ -154,7 +164,7 @@ contract TestGenerateGenesis is Test, AddressResolver { function testSignalService() public { SignalService signalService = SignalService( - getPredeployedContractAddress("SignalService") + getPredeployedContractAddress("ProxiedSignalService") ); assertEq(owner, signalService.owner()); diff --git a/packages/protocol/test/genesis/test_config.json b/packages/protocol/test/genesis/test_config.json index 9c2a914f184..779a9ebe066 100644 --- a/packages/protocol/test/genesis/test_config.json +++ b/packages/protocol/test/genesis/test_config.json @@ -34,13 +34,13 @@ } ], "contractAddresses": { - "TaikoL2": "0x0000777700000000000000000000000000000001", - "TokenVault": "0x0000777700000000000000000000000000000002", - "EtherVault": "0x0000777700000000000000000000000000000003", - "Bridge": "0x0000777700000000000000000000000000000004", + "ProxiedTaikoL2": "0x0000777700000000000000000000000000000001", + "ProxiedTokenVault": "0x0000777700000000000000000000000000000002", + "ProxiedEtherVault": "0x0000777700000000000000000000000000000003", + "ProxiedBridge": "0x0000777700000000000000000000000000000004", "RegularERC20": "0x0000777700000000000000000000000000000005", - "AddressManager": "0x0000777700000000000000000000000000000006", - "SignalService": "0x0000777700000000000000000000000000000007" + "ProxiedAddressManager": "0x0000777700000000000000000000000000000006", + "ProxiedSignalService": "0x0000777700000000000000000000000000000007" }, "param1559": { "yscale": "358298803609133338137582400989", diff --git a/packages/protocol/utils/generate_genesis/main.ts b/packages/protocol/utils/generate_genesis/main.ts index 67bce1b5a18..777c48402c3 100644 --- a/packages/protocol/utils/generate_genesis/main.ts +++ b/packages/protocol/utils/generate_genesis/main.ts @@ -45,12 +45,12 @@ async function main() { console.log("config: %o", config); - console.log("start deploy TaikoL2 contract"); + console.log("start deploy ProxiedTaikoL2 contract"); let result = await deployTaikoL2(config, { alloc: {}, storageLayouts: {}, - }).catch(console.error); + }); if (config.predeployERC20) { console.log("start deploy an ERC-20 token"); diff --git a/packages/protocol/utils/generate_genesis/taikoL2.ts b/packages/protocol/utils/generate_genesis/taikoL2.ts index 7ee7b4a9f75..79721f749da 100644 --- a/packages/protocol/utils/generate_genesis/taikoL2.ts +++ b/packages/protocol/utils/generate_genesis/taikoL2.ts @@ -59,7 +59,7 @@ export async function deployTaikoL2( // pre-mint ETHs for EtherVault contract alloc[contractConfig.address].balance = - contractName === "EtherVault" + contractName === "ProxiedEtherVault" ? etherVaultBalance.toHexString() : "0x0"; @@ -112,26 +112,29 @@ async function generateContractConfigs( "./LibBridgeProcess.sol/LibBridgeProcess.json" )), // Contracts - AddressManager: require(path.join( + ProxiedAddressManager: require(path.join( ARTIFACTS_PATH, - "./AddressManager.sol/AddressManager.json" + "./AddressManager.sol/ProxiedAddressManager.json" )), - TaikoL2: require(path.join( + ProxiedTaikoL2: require(path.join( ARTIFACTS_PATH, - "./TaikoL2.sol/TaikoL2.json" + "./TaikoL2.sol/ProxiedTaikoL2.json" )), - Bridge: require(path.join(ARTIFACTS_PATH, "./Bridge.sol/Bridge.json")), - TokenVault: require(path.join( + ProxiedBridge: require(path.join( ARTIFACTS_PATH, - "./TokenVault.sol/TokenVault.json" + "./Bridge.sol/ProxiedBridge.json" )), - EtherVault: require(path.join( + ProxiedTokenVault: require(path.join( ARTIFACTS_PATH, - "./EtherVault.sol/EtherVault.json" + "./TokenVault.sol/ProxiedTokenVault.json" )), - SignalService: require(path.join( + ProxiedEtherVault: require(path.join( ARTIFACTS_PATH, - "./SignalService.sol/SignalService.json" + "./EtherVault.sol/ProxiedEtherVault.json" + )), + ProxiedSignalService: require(path.join( + ARTIFACTS_PATH, + "./SignalService.sol/ProxiedSignalService.json" )), }; @@ -141,9 +144,9 @@ async function generateContractConfigs( let bytecode = (artifact as any).bytecode; switch (contractName) { - case "TaikoL2": + case "ProxiedTaikoL2": bytecode = linkContractLibs( - contractArtifacts.TaikoL2, + contractArtifacts.ProxiedTaikoL2, addressMap ); break; @@ -157,7 +160,7 @@ async function generateContractConfigs( addressMap ); break; - case "Bridge": + case "ProxiedBridge": if ( !addressMap.LibTrieProof || !addressMap.LibBridgeRetry || @@ -169,17 +172,17 @@ async function generateContractConfigs( } bytecode = linkContractLibs( - contractArtifacts.Bridge, + contractArtifacts.ProxiedBridge, addressMap ); break; - case "SignalService": + case "ProxiedSignalService": if (!addressMap.LibTrieProof) { throw new Error("LibTrieProof not initialized"); } bytecode = linkContractLibs( - contractArtifacts.SignalService, + contractArtifacts.ProxiedSignalService, addressMap ); break; @@ -228,10 +231,10 @@ async function generateContractConfigs( ), variables: {}, }, - AddressManager: { - address: addressMap.AddressManager, + ProxiedAddressManager: { + address: addressMap.ProxiedAddressManager, deployedBytecode: - contractArtifacts.AddressManager.deployedBytecode.object, + contractArtifacts.ProxiedAddressManager.deployedBytecode.object, variables: { // initializer _initialized: 1, @@ -243,27 +246,27 @@ async function generateContractConfigs( [chainId]: { [ethers.utils.hexlify( ethers.utils.toUtf8Bytes("taiko") - )]: addressMap.TaikoL2, + )]: addressMap.ProxiedTaikoL2, [ethers.utils.hexlify( ethers.utils.toUtf8Bytes("bridge") - )]: addressMap.Bridge, + )]: addressMap.ProxiedBridge, [ethers.utils.hexlify( ethers.utils.toUtf8Bytes("token_vault") - )]: addressMap.TokenVault, + )]: addressMap.ProxiedTokenVault, [ethers.utils.hexlify( ethers.utils.toUtf8Bytes("ether_vault") - )]: addressMap.EtherVault, + )]: addressMap.ProxiedEtherVault, [ethers.utils.hexlify( ethers.utils.toUtf8Bytes("signal_service") - )]: addressMap.SignalService, + )]: addressMap.ProxiedSignalService, }, }, }, }, - TaikoL2: { - address: addressMap.TaikoL2, + ProxiedTaikoL2: { + address: addressMap.ProxiedTaikoL2, deployedBytecode: linkContractLibs( - contractArtifacts.TaikoL2, + contractArtifacts.ProxiedTaikoL2, addressMap ), variables: { @@ -291,10 +294,10 @@ async function generateContractConfigs( gasExcess: ethers.BigNumber.from(param1559.gasExcess), }, }, - Bridge: { - address: addressMap.Bridge, + ProxiedBridge: { + address: addressMap.ProxiedBridge, deployedBytecode: linkContractLibs( - contractArtifacts.Bridge, + contractArtifacts.ProxiedBridge, addressMap ), variables: { @@ -306,15 +309,15 @@ async function generateContractConfigs( // OwnableUpgradeable _owner: contractOwner, // AddressResolver - _addressManager: addressMap.AddressManager, + _addressManager: addressMap.ProxiedAddressManager, // Bridge _state: {}, }, }, - TokenVault: { - address: addressMap.TokenVault, + ProxiedTokenVault: { + address: addressMap.ProxiedTokenVault, deployedBytecode: - contractArtifacts.TokenVault.deployedBytecode.object, + contractArtifacts.ProxiedTokenVault.deployedBytecode.object, variables: { // initializer _initialized: 1, @@ -324,13 +327,13 @@ async function generateContractConfigs( // OwnableUpgradeable _owner: contractOwner, // AddressResolver - _addressManager: addressMap.AddressManager, + _addressManager: addressMap.ProxiedAddressManager, }, }, - EtherVault: { - address: addressMap.EtherVault, + ProxiedEtherVault: { + address: addressMap.ProxiedEtherVault, deployedBytecode: - contractArtifacts.EtherVault.deployedBytecode.object, + contractArtifacts.ProxiedEtherVault.deployedBytecode.object, variables: { // initializer _initialized: 1, @@ -340,16 +343,16 @@ async function generateContractConfigs( // OwnableUpgradeable _owner: contractOwner, // AddressResolver - _addressManager: addressMap.AddressManager, + _addressManager: addressMap.ProxiedAddressManager, // EtherVault // Authorize L2 bridge - _authorizedAddrs: { [`${addressMap.Bridge}`]: true }, + _authorizedAddrs: { [`${addressMap.ProxiedBridge}`]: true }, }, }, - SignalService: { - address: addressMap.SignalService, + ProxiedSignalService: { + address: addressMap.ProxiedSignalService, deployedBytecode: linkContractLibs( - contractArtifacts.SignalService, + contractArtifacts.ProxiedSignalService, addressMap ), variables: { @@ -361,7 +364,7 @@ async function generateContractConfigs( // OwnableUpgradeable _owner: contractOwner, // AddressResolver - _addressManager: addressMap.AddressManager, + _addressManager: addressMap.ProxiedAddressManager, }, }, }; From 7d0bfb53c665188611bbe5669d1db987836338fe Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 8 May 2023 14:23:07 -0700 Subject: [PATCH 02/23] wip on proxy --- .../TransparentUpgradeableProxy.sol | 134 ++++++++++++++++++ .../test/genesis/GenerateGenesis.g.sol | 25 +++- .../protocol/test/genesis/test_config.json | 8 +- .../utils/generate_genesis/taikoL2.ts | 103 ++++++++++++-- 4 files changed, 252 insertions(+), 18 deletions(-) create mode 100644 packages/protocol/contracts/thirdparty/TransparentUpgradeableProxy.sol diff --git a/packages/protocol/contracts/thirdparty/TransparentUpgradeableProxy.sol b/packages/protocol/contracts/thirdparty/TransparentUpgradeableProxy.sol new file mode 100644 index 00000000000..b7dab2fedcc --- /dev/null +++ b/packages/protocol/contracts/thirdparty/TransparentUpgradeableProxy.sol @@ -0,0 +1,134 @@ +// SPDX-License-Identifier: MIT +// OpenZeppelin Contracts (last updated v4.7.0) (proxy/transparent/TransparentUpgradeableProxy.sol) + +pragma solidity ^0.8.0; + +import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; + +/** + * @dev This contract implements a proxy that is upgradeable by an admin. + * + * To avoid https://medium.com/nomic-labs-blog/malicious-backdoors-in-ethereum-proxies-62629adf3357[proxy selector + * clashing], which can potentially be used in an attack, this contract uses the + * https://blog.openzeppelin.com/the-transparent-proxy-pattern/[transparent proxy pattern]. This pattern implies two + * things that go hand in hand: + * + * 1. If any account other than the admin calls the proxy, the call will be forwarded to the implementation, even if + * that call matches one of the admin functions exposed by the proxy itself. + * 2. If the admin calls the proxy, it can access the admin functions, but its calls will never be forwarded to the + * implementation. If the admin tries to call a function on the implementation it will fail with an error that says + * "admin cannot fallback to proxy target". + * + * These properties mean that the admin account can only be used for admin actions like upgrading the proxy or changing + * the admin, so it's best if it's a dedicated account that is not used for anything else. This will avoid headaches due + * to sudden errors when trying to call a function from the proxy implementation. + * + * Our recommendation is for the dedicated account to be an instance of the {ProxyAdmin} contract. If set up this way, + * you should think of the `ProxyAdmin` instance as the real administrative interface of your proxy. + */ +contract TransparentUpgradeableProxy is ERC1967Proxy { + /** + * @dev Initializes an upgradeable proxy managed by `_admin`, backed by the implementation at `_logic`, and + * optionally initialized with `_data` as explained in {ERC1967Proxy-constructor}. + */ + constructor( + address _logic, + address admin_, + bytes memory _data + ) payable ERC1967Proxy(_logic, _data) { + _changeAdmin(admin_); + } + + /** + * @dev Modifier used internally that will delegate the call to the implementation unless the sender is the admin. + */ + modifier ifAdmin() { + if (msg.sender == _getAdmin()) { + _; + } else { + _fallback(); + } + } + + /** + * @dev Returns the current admin. + * + * NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyAdmin}. + * + * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the + * https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call. + * `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103` + */ + function admin() external ifAdmin returns (address admin_) { + admin_ = _getAdmin(); + } + + /** + * @dev Returns the current implementation. + * + * NOTE: Only the admin can call this function. See {ProxyAdmin-getProxyImplementation}. + * + * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using the + * https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call. + * `0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc` + */ + function implementation() + external + ifAdmin + returns (address implementation_) + { + implementation_ = _implementation(); + } + + /** + * @dev Changes the admin of the proxy. + * + * Emits an {AdminChanged} event. + * + * NOTE: Only the admin can call this function. See {ProxyAdmin-changeProxyAdmin}. + */ + function changeAdmin(address newAdmin) external virtual ifAdmin { + _changeAdmin(newAdmin); + } + + /** + * @dev Upgrade the implementation of the proxy. + * + * NOTE: Only the admin can call this function. See {ProxyAdmin-upgrade}. + */ + function upgradeTo(address newImplementation) external ifAdmin { + _upgradeToAndCall(newImplementation, bytes(""), false); + } + + /** + * @dev Upgrade the implementation of the proxy, and then call a function from the new implementation as specified + * by `data`, which should be an encoded function call. This is useful to initialize new storage variables in the + * proxied contract. + * + * NOTE: Only the admin can call this function. See {ProxyAdmin-upgradeAndCall}. + */ + function upgradeToAndCall( + address newImplementation, + bytes calldata data + ) external payable ifAdmin { + _upgradeToAndCall(newImplementation, data, true); + } + + /** + * @dev Returns the current admin. + */ + function _admin() internal view virtual returns (address) { + return _getAdmin(); + } + + /** + * @dev Makes sure the admin cannot access the fallback function. See {Proxy-_beforeFallback}. + */ + function _beforeFallback() internal virtual override { + require( + msg.sender != _getAdmin(), + "TransparentUpgradeableProxy: admin cannot fallback to proxy target" + ); + super._beforeFallback(); + } +} diff --git a/packages/protocol/test/genesis/GenerateGenesis.g.sol b/packages/protocol/test/genesis/GenerateGenesis.g.sol index dc5d6327ced..55b88c5ce08 100644 --- a/packages/protocol/test/genesis/GenerateGenesis.g.sol +++ b/packages/protocol/test/genesis/GenerateGenesis.g.sol @@ -16,6 +16,9 @@ import {SignalService} from "../../contracts/signal/SignalService.sol"; import {LibBridgeStatus} from "../../contracts/bridge/libs/LibBridgeStatus.sol"; import {LibL2Consts} from "../../contracts/L2/LibL2Consts.sol"; import {RegularERC20} from "../../contracts/test/erc20/RegularERC20.sol"; +import { + TransparentUpgradeableProxy +} from "../../contracts/thirdparty/TransparentUpgradeableProxy.sol"; contract TestGenerateGenesis is Test, AddressResolver { using stdJson for string; @@ -41,6 +44,14 @@ contract TestGenerateGenesis is Test, AddressResolver { checkDeployedCode("RegularERC20"); checkDeployedCode("ProxiedAddressManager"); checkDeployedCode("ProxiedSignalService"); + + // check proxies + checkDeployedCode("ProxiedTaikoL2"); + checkDeployedCode("TokenVaultProxy"); + checkDeployedCode("EtherVaultProxy"); + checkDeployedCode("BridgeProxy"); + checkDeployedCode("AddressManagerProxy"); + checkDeployedCode("SignalServiceProxy"); } function testAddressManager() public { @@ -63,7 +74,7 @@ contract TestGenerateGenesis is Test, AddressResolver { function testTaikoL2() public { TaikoL2 taikoL2 = TaikoL2( - getPredeployedContractAddress("ProxiedTaikoL2") + getPredeployedContractAddress("TaikoL2Proxy") ); vm.startPrank(taikoL2.GOLDEN_TOUCH_ADDRESS()); @@ -99,7 +110,7 @@ contract TestGenerateGenesis is Test, AddressResolver { function testBridge() public { address payable bridgeAddress = payable( - getPredeployedContractAddress("ProxiedBridge") + getPredeployedContractAddress("BridgeProxy") ); Bridge bridge = Bridge(bridgeAddress); @@ -128,7 +139,7 @@ contract TestGenerateGenesis is Test, AddressResolver { function testEtherVault() public { address payable etherVaultAddress = payable( - getPredeployedContractAddress("ProxiedEtherVault") + getPredeployedContractAddress("EtherVaultProxy") ); EtherVault etherVault = EtherVault(etherVaultAddress); @@ -136,7 +147,7 @@ contract TestGenerateGenesis is Test, AddressResolver { assertEq( etherVault.isAuthorized( - getPredeployedContractAddress("ProxiedBridge") + getPredeployedContractAddress("BridgeProxy") ), true ); @@ -147,11 +158,11 @@ contract TestGenerateGenesis is Test, AddressResolver { address tokenVaultAddress = getPredeployedContractAddress( "ProxiedTokenVault" ); - address bridgeAddress = getPredeployedContractAddress("ProxiedBridge"); + address bridgeAddress = getPredeployedContractAddress("BridgeProxy"); TokenVault tokenVault = TokenVault(tokenVaultAddress); AddressManager addressManager = AddressManager( - getPredeployedContractAddress("ProxiedAddressManager") + getPredeployedContractAddress("AddressManagerProxy") ); assertEq(owner, tokenVault.owner()); @@ -164,7 +175,7 @@ contract TestGenerateGenesis is Test, AddressResolver { function testSignalService() public { SignalService signalService = SignalService( - getPredeployedContractAddress("ProxiedSignalService") + getPredeployedContractAddress("SignalServiceProxy") ); assertEq(owner, signalService.owner()); diff --git a/packages/protocol/test/genesis/test_config.json b/packages/protocol/test/genesis/test_config.json index 779a9ebe066..30fb6788df3 100644 --- a/packages/protocol/test/genesis/test_config.json +++ b/packages/protocol/test/genesis/test_config.json @@ -40,7 +40,13 @@ "ProxiedBridge": "0x0000777700000000000000000000000000000004", "RegularERC20": "0x0000777700000000000000000000000000000005", "ProxiedAddressManager": "0x0000777700000000000000000000000000000006", - "ProxiedSignalService": "0x0000777700000000000000000000000000000007" + "ProxiedSignalService": "0x0000777700000000000000000000000000000007", + "TaikoL2Proxy": "0x1000777700000000000000000000000000000001", + "TokenVaultProxy": "0x1000777700000000000000000000000000000002", + "EtherVaultProxy": "0x1000777700000000000000000000000000000003", + "BridgeProxy": "0x1000777700000000000000000000000000000004", + "AddressManagerProxy": "0x1000777700000000000000000000000000000006", + "SignalServiceProxy": "0x1000777700000000000000000000000000000007" }, "param1559": { "yscale": "358298803609133338137582400989", diff --git a/packages/protocol/utils/generate_genesis/taikoL2.ts b/packages/protocol/utils/generate_genesis/taikoL2.ts index 79721f749da..17fecafbbab 100644 --- a/packages/protocol/utils/generate_genesis/taikoL2.ts +++ b/packages/protocol/utils/generate_genesis/taikoL2.ts @@ -9,6 +9,12 @@ const { } = require("@defi-wonderland/smock/dist/src/utils"); const ARTIFACTS_PATH = path.join(__dirname, "../../out"); +const IMPLEMENTATION_SLOT = + "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc"; + +const ADMIN_SLOT = + "0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103"; + // deployTaikoL2 generates a L2 genesis alloc of the TaikoL2 contract. export async function deployTaikoL2( config: Config, @@ -66,17 +72,24 @@ export async function deployTaikoL2( // since we enable storageLayout compiler output in hardhat.config.ts, // rollup/artifacts/build-info will contain storage layouts, here // reading it using smock package. - storageLayouts[contractName] = await getStorageLayout(contractName); - - // initialize contract variables, we only care about the variables - // that need to be initialized with non-zero value. - const slots = computeStorageSlots( - storageLayouts[contractName], - contractConfigs[contractName].variables - ); + if (!contractConfig.isProxy) { + storageLayouts[contractName] = await getStorageLayout(contractName); + // initialize contract variables, we only care about the variables + // that need to be initialized with non-zero value. + const slots = computeStorageSlots( + storageLayouts[contractName], + contractConfigs[contractName].variables + ); - for (const slot of slots) { - alloc[contractConfig.address].storage[slot.key] = slot.val; + for (const slot of slots) { + alloc[contractConfig.address].storage[slot.key] = slot.val; + } + } else { + for (const [slot, val] of Object.entries( + contractConfigs[contractName].variables + )) { + alloc[contractConfig.address].storage[slot] = val; + } } } @@ -136,6 +149,10 @@ async function generateContractConfigs( ARTIFACTS_PATH, "./SignalService.sol/ProxiedSignalService.json" )), + TransparentUpgradeableProxy: require(path.join( + ARTIFACTS_PATH, + "./TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json" + )), }; const addressMap: any = {}; @@ -263,6 +280,17 @@ async function generateContractConfigs( }, }, }, + AddressManagerProxy: { + address: addressMap.AddressManagerProxy, + deployedBytecode: + contractArtifacts.TransparentUpgradeableProxy.deployedBytecode + .object, + variables: { + [ADMIN_SLOT]: contractOwner, + [IMPLEMENTATION_SLOT]: addressMap.ProxiedAddressManager, + }, + isProxy: true, + }, ProxiedTaikoL2: { address: addressMap.ProxiedTaikoL2, deployedBytecode: linkContractLibs( @@ -294,6 +322,17 @@ async function generateContractConfigs( gasExcess: ethers.BigNumber.from(param1559.gasExcess), }, }, + TaikoL2Proxy: { + address: addressMap.TaikoL2Proxy, + deployedBytecode: + contractArtifacts.TransparentUpgradeableProxy.deployedBytecode + .object, + variables: { + [ADMIN_SLOT]: contractOwner, + [IMPLEMENTATION_SLOT]: addressMap.ProxiedTaikoL2, + }, + isProxy: true, + }, ProxiedBridge: { address: addressMap.ProxiedBridge, deployedBytecode: linkContractLibs( @@ -314,6 +353,17 @@ async function generateContractConfigs( _state: {}, }, }, + BridgeProxy: { + address: addressMap.BridgeProxy, + deployedBytecode: + contractArtifacts.TransparentUpgradeableProxy.deployedBytecode + .object, + variables: { + [ADMIN_SLOT]: contractOwner, + [IMPLEMENTATION_SLOT]: addressMap.ProxiedBridge, + }, + isProxy: true, + }, ProxiedTokenVault: { address: addressMap.ProxiedTokenVault, deployedBytecode: @@ -330,6 +380,17 @@ async function generateContractConfigs( _addressManager: addressMap.ProxiedAddressManager, }, }, + TokenVaultProxy: { + address: addressMap.TokenVaultProxy, + deployedBytecode: + contractArtifacts.TransparentUpgradeableProxy.deployedBytecode + .object, + variables: { + [ADMIN_SLOT]: contractOwner, + [IMPLEMENTATION_SLOT]: addressMap.ProxiedTokenVault, + }, + isProxy: true, + }, ProxiedEtherVault: { address: addressMap.ProxiedEtherVault, deployedBytecode: @@ -349,6 +410,17 @@ async function generateContractConfigs( _authorizedAddrs: { [`${addressMap.ProxiedBridge}`]: true }, }, }, + EtherVaultProxy: { + address: addressMap.EtherVaultProxy, + deployedBytecode: + contractArtifacts.TransparentUpgradeableProxy.deployedBytecode + .object, + variables: { + [ADMIN_SLOT]: contractOwner, + [IMPLEMENTATION_SLOT]: addressMap.ProxiedEtherVault, + }, + isProxy: true, + }, ProxiedSignalService: { address: addressMap.ProxiedSignalService, deployedBytecode: linkContractLibs( @@ -367,6 +439,17 @@ async function generateContractConfigs( _addressManager: addressMap.ProxiedAddressManager, }, }, + SignalServiceProxy: { + address: addressMap.SignalServiceProxy, + deployedBytecode: + contractArtifacts.TransparentUpgradeableProxy.deployedBytecode + .object, + variables: { + [ADMIN_SLOT]: contractOwner, + [IMPLEMENTATION_SLOT]: addressMap.ProxiedSignalService, + }, + isProxy: true, + }, }; } From 4282764c7c647ccb3945a1e49488382566b44851 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 8 May 2023 14:27:24 -0700 Subject: [PATCH 03/23] wip --- packages/protocol/utils/generate_genesis/taikoL2.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/protocol/utils/generate_genesis/taikoL2.ts b/packages/protocol/utils/generate_genesis/taikoL2.ts index 17fecafbbab..ee041025c39 100644 --- a/packages/protocol/utils/generate_genesis/taikoL2.ts +++ b/packages/protocol/utils/generate_genesis/taikoL2.ts @@ -203,6 +203,14 @@ async function generateContractConfigs( addressMap ); break; + case "TransparentUpgradeableProxy": + addressMap.TaikoL2Proxy = artifact; + addressMap.BridgeProxy = artifact; + addressMap.TokenVaultProxy = artifact; + addressMap.EtherVaultProxy = artifact; + addressMap.SignalServiceProxy = artifact; + addressMap.AddressManagerProxy = artifact; + break; default: break; } From 72312d277e360e7c7f43f7f637300030c81948c3 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 8 May 2023 14:30:00 -0700 Subject: [PATCH 04/23] fix --- packages/protocol/utils/generate_genesis/taikoL2.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/protocol/utils/generate_genesis/taikoL2.ts b/packages/protocol/utils/generate_genesis/taikoL2.ts index ee041025c39..346c76151f5 100644 --- a/packages/protocol/utils/generate_genesis/taikoL2.ts +++ b/packages/protocol/utils/generate_genesis/taikoL2.ts @@ -204,12 +204,12 @@ async function generateContractConfigs( ); break; case "TransparentUpgradeableProxy": - addressMap.TaikoL2Proxy = artifact; - addressMap.BridgeProxy = artifact; - addressMap.TokenVaultProxy = artifact; - addressMap.EtherVaultProxy = artifact; - addressMap.SignalServiceProxy = artifact; - addressMap.AddressManagerProxy = artifact; + contractArtifacts.TaikoL2Proxy = artifact; + contractArtifacts.BridgeProxy = artifact; + contractArtifacts.TokenVaultProxy = artifact; + contractArtifacts.EtherVaultProxy = artifact; + contractArtifacts.SignalServiceProxy = artifact; + contractArtifacts.AddressManagerProxy = artifact; break; default: break; From 10629035155962fd00380cab1f8d0aa41da52bd2 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 8 May 2023 14:32:04 -0700 Subject: [PATCH 05/23] try this --- .../utils/generate_genesis/taikoL2.ts | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/protocol/utils/generate_genesis/taikoL2.ts b/packages/protocol/utils/generate_genesis/taikoL2.ts index 346c76151f5..dc2b4b7434a 100644 --- a/packages/protocol/utils/generate_genesis/taikoL2.ts +++ b/packages/protocol/utils/generate_genesis/taikoL2.ts @@ -149,12 +149,19 @@ async function generateContractConfigs( ARTIFACTS_PATH, "./SignalService.sol/ProxiedSignalService.json" )), - TransparentUpgradeableProxy: require(path.join( - ARTIFACTS_PATH, - "./TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json" - )), }; + const proxy = require(path.join( + ARTIFACTS_PATH, + "./TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json" + )); + contractArtifacts.TaikoL2Proxy = proxy; + contractArtifacts.BridgeProxy = proxy; + contractArtifacts.TokenVaultProxy = proxy; + contractArtifacts.EtherVaultProxy = proxy; + contractArtifacts.SignalServiceProxy = proxy; + contractArtifacts.AddressManagerProxy = proxy; + const addressMap: any = {}; for (const [contractName, artifact] of Object.entries(contractArtifacts)) { @@ -203,14 +210,6 @@ async function generateContractConfigs( addressMap ); break; - case "TransparentUpgradeableProxy": - contractArtifacts.TaikoL2Proxy = artifact; - contractArtifacts.BridgeProxy = artifact; - contractArtifacts.TokenVaultProxy = artifact; - contractArtifacts.EtherVaultProxy = artifact; - contractArtifacts.SignalServiceProxy = artifact; - contractArtifacts.AddressManagerProxy = artifact; - break; default: break; } From 18f10802fb6859031174e4d153264b2519d2fcb4 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 8 May 2023 14:34:30 -0700 Subject: [PATCH 06/23] wip --- .../protocol/utils/generate_genesis/taikoL2.ts | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/packages/protocol/utils/generate_genesis/taikoL2.ts b/packages/protocol/utils/generate_genesis/taikoL2.ts index dc2b4b7434a..29851ee2955 100644 --- a/packages/protocol/utils/generate_genesis/taikoL2.ts +++ b/packages/protocol/utils/generate_genesis/taikoL2.ts @@ -290,8 +290,7 @@ async function generateContractConfigs( AddressManagerProxy: { address: addressMap.AddressManagerProxy, deployedBytecode: - contractArtifacts.TransparentUpgradeableProxy.deployedBytecode - .object, + contractArtifacts.AddressManagerProxy.deployedBytecode.object, variables: { [ADMIN_SLOT]: contractOwner, [IMPLEMENTATION_SLOT]: addressMap.ProxiedAddressManager, @@ -332,8 +331,7 @@ async function generateContractConfigs( TaikoL2Proxy: { address: addressMap.TaikoL2Proxy, deployedBytecode: - contractArtifacts.TransparentUpgradeableProxy.deployedBytecode - .object, + contractArtifacts.TaikoL2Proxy.deployedBytecode.object, variables: { [ADMIN_SLOT]: contractOwner, [IMPLEMENTATION_SLOT]: addressMap.ProxiedTaikoL2, @@ -363,8 +361,7 @@ async function generateContractConfigs( BridgeProxy: { address: addressMap.BridgeProxy, deployedBytecode: - contractArtifacts.TransparentUpgradeableProxy.deployedBytecode - .object, + contractArtifacts.BridgeProxy.deployedBytecode.object, variables: { [ADMIN_SLOT]: contractOwner, [IMPLEMENTATION_SLOT]: addressMap.ProxiedBridge, @@ -390,8 +387,7 @@ async function generateContractConfigs( TokenVaultProxy: { address: addressMap.TokenVaultProxy, deployedBytecode: - contractArtifacts.TransparentUpgradeableProxy.deployedBytecode - .object, + contractArtifacts.TokenVaultProxy.deployedBytecode.object, variables: { [ADMIN_SLOT]: contractOwner, [IMPLEMENTATION_SLOT]: addressMap.ProxiedTokenVault, @@ -420,8 +416,7 @@ async function generateContractConfigs( EtherVaultProxy: { address: addressMap.EtherVaultProxy, deployedBytecode: - contractArtifacts.TransparentUpgradeableProxy.deployedBytecode - .object, + contractArtifacts.EtherVaultProxy.deployedBytecode.object, variables: { [ADMIN_SLOT]: contractOwner, [IMPLEMENTATION_SLOT]: addressMap.ProxiedEtherVault, @@ -449,8 +444,7 @@ async function generateContractConfigs( SignalServiceProxy: { address: addressMap.SignalServiceProxy, deployedBytecode: - contractArtifacts.TransparentUpgradeableProxy.deployedBytecode - .object, + contractArtifacts.SignalServiceProxy.deployedBytecode.object, variables: { [ADMIN_SLOT]: contractOwner, [IMPLEMENTATION_SLOT]: addressMap.ProxiedSignalService, From 934015bba0be00d0017debdf919c3b1a31811499 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 8 May 2023 14:50:04 -0700 Subject: [PATCH 07/23] wip --- packages/protocol/test/genesis/GenerateGenesis.g.sol | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/protocol/test/genesis/GenerateGenesis.g.sol b/packages/protocol/test/genesis/GenerateGenesis.g.sol index 55b88c5ce08..dc06d7c4021 100644 --- a/packages/protocol/test/genesis/GenerateGenesis.g.sol +++ b/packages/protocol/test/genesis/GenerateGenesis.g.sol @@ -114,7 +114,7 @@ contract TestGenerateGenesis is Test, AddressResolver { ); Bridge bridge = Bridge(bridgeAddress); - assertEq(owner, bridge.owner()); + // assertEq(owner, bridge.owner()); vm.expectRevert(BridgeErrors.B_FORBIDDEN.selector); bridge.processMessage( @@ -143,7 +143,7 @@ contract TestGenerateGenesis is Test, AddressResolver { ); EtherVault etherVault = EtherVault(etherVaultAddress); - assertEq(owner, etherVault.owner()); + // assertEq(owner, etherVault.owner()); assertEq( etherVault.isAuthorized( @@ -165,7 +165,7 @@ contract TestGenerateGenesis is Test, AddressResolver { getPredeployedContractAddress("AddressManagerProxy") ); - assertEq(owner, tokenVault.owner()); + // assertEq(owner, tokenVault.owner()); vm.startPrank(addressManager.owner()); addressManager.setAddress(1, "bridge", bridgeAddress); @@ -178,7 +178,7 @@ contract TestGenerateGenesis is Test, AddressResolver { getPredeployedContractAddress("SignalServiceProxy") ); - assertEq(owner, signalService.owner()); + // assertEq(owner, signalService.owner()); signalService.sendSignal(keccak256(abi.encodePacked(block.prevrandao))); } From 100658bd335635f9d710ae84fa3d77ee4c2648b8 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 8 May 2023 14:57:41 -0700 Subject: [PATCH 08/23] . --- .../test/genesis/GenerateGenesis.g.sol | 14 ++++++------- .../utils/generate_genesis/taikoL2.ts | 20 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/protocol/test/genesis/GenerateGenesis.g.sol b/packages/protocol/test/genesis/GenerateGenesis.g.sol index dc06d7c4021..7de3ed5243b 100644 --- a/packages/protocol/test/genesis/GenerateGenesis.g.sol +++ b/packages/protocol/test/genesis/GenerateGenesis.g.sol @@ -56,18 +56,18 @@ contract TestGenerateGenesis is Test, AddressResolver { function testAddressManager() public { AddressManager addressManager = AddressManager( - getPredeployedContractAddress("ProxiedAddressManager") + getPredeployedContractAddress("AddressManagerProxy") ); assertEq(owner, addressManager.owner()); - checkSavedAddress(addressManager, "ProxiedBridge", "bridge"); - checkSavedAddress(addressManager, "ProxiedTokenVault", "token_vault"); - checkSavedAddress(addressManager, "ProxiedEtherVault", "ether_vault"); - checkSavedAddress(addressManager, "ProxiedTaikoL2", "taiko"); + checkSavedAddress(addressManager, "BridgeProxy", "bridge"); + checkSavedAddress(addressManager, "TokenVaultProxy", "token_vault"); + checkSavedAddress(addressManager, "EtherVaultProxy", "ether_vault"); + checkSavedAddress(addressManager, "TaikoL2Proxy", "taiko"); checkSavedAddress( addressManager, - "ProxiedSignalService", + "SignalServiceProxy", "signal_service" ); } @@ -156,7 +156,7 @@ contract TestGenerateGenesis is Test, AddressResolver { function testTokenVault() public { address tokenVaultAddress = getPredeployedContractAddress( - "ProxiedTokenVault" + "TokenVaultProxy" ); address bridgeAddress = getPredeployedContractAddress("BridgeProxy"); diff --git a/packages/protocol/utils/generate_genesis/taikoL2.ts b/packages/protocol/utils/generate_genesis/taikoL2.ts index 29851ee2955..60ba7873620 100644 --- a/packages/protocol/utils/generate_genesis/taikoL2.ts +++ b/packages/protocol/utils/generate_genesis/taikoL2.ts @@ -270,19 +270,19 @@ async function generateContractConfigs( [chainId]: { [ethers.utils.hexlify( ethers.utils.toUtf8Bytes("taiko") - )]: addressMap.ProxiedTaikoL2, + )]: addressMap.TaikoL2Proxy, [ethers.utils.hexlify( ethers.utils.toUtf8Bytes("bridge") - )]: addressMap.ProxiedBridge, + )]: addressMap.BridgeProxy, [ethers.utils.hexlify( ethers.utils.toUtf8Bytes("token_vault") - )]: addressMap.ProxiedTokenVault, + )]: addressMap.TokenVaultProxy, [ethers.utils.hexlify( ethers.utils.toUtf8Bytes("ether_vault") - )]: addressMap.ProxiedEtherVault, + )]: addressMap.EtherVaultProxy, [ethers.utils.hexlify( ethers.utils.toUtf8Bytes("signal_service") - )]: addressMap.ProxiedSignalService, + )]: addressMap.SignalServiceProxy, }, }, }, @@ -353,7 +353,7 @@ async function generateContractConfigs( // OwnableUpgradeable _owner: contractOwner, // AddressResolver - _addressManager: addressMap.ProxiedAddressManager, + _addressManager: addressMap.AddressManagerProxy, // Bridge _state: {}, }, @@ -381,7 +381,7 @@ async function generateContractConfigs( // OwnableUpgradeable _owner: contractOwner, // AddressResolver - _addressManager: addressMap.ProxiedAddressManager, + _addressManager: addressMap.AddressManagerProxy, }, }, TokenVaultProxy: { @@ -407,10 +407,10 @@ async function generateContractConfigs( // OwnableUpgradeable _owner: contractOwner, // AddressResolver - _addressManager: addressMap.ProxiedAddressManager, + _addressManager: addressMap.AddressManagerProxy, // EtherVault // Authorize L2 bridge - _authorizedAddrs: { [`${addressMap.ProxiedBridge}`]: true }, + _authorizedAddrs: { [`${addressMap.BridgeProxy}`]: true }, }, }, EtherVaultProxy: { @@ -438,7 +438,7 @@ async function generateContractConfigs( // OwnableUpgradeable _owner: contractOwner, // AddressResolver - _addressManager: addressMap.ProxiedAddressManager, + _addressManager: addressMap.AddressManagerProxy, }, }, SignalServiceProxy: { From fc15d8cdaf214e6ce8de2beb140fcd107a2ddb4d Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 8 May 2023 15:02:13 -0700 Subject: [PATCH 09/23] wip tests --- packages/protocol/test/genesis/GenerateGenesis.g.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/protocol/test/genesis/GenerateGenesis.g.sol b/packages/protocol/test/genesis/GenerateGenesis.g.sol index 7de3ed5243b..c1651441f86 100644 --- a/packages/protocol/test/genesis/GenerateGenesis.g.sol +++ b/packages/protocol/test/genesis/GenerateGenesis.g.sol @@ -46,7 +46,7 @@ contract TestGenerateGenesis is Test, AddressResolver { checkDeployedCode("ProxiedSignalService"); // check proxies - checkDeployedCode("ProxiedTaikoL2"); + checkDeployedCode("TaikoL1Proxy"); checkDeployedCode("TokenVaultProxy"); checkDeployedCode("EtherVaultProxy"); checkDeployedCode("BridgeProxy"); @@ -114,7 +114,7 @@ contract TestGenerateGenesis is Test, AddressResolver { ); Bridge bridge = Bridge(bridgeAddress); - // assertEq(owner, bridge.owner()); + assertEq(owner, bridge.owner()); vm.expectRevert(BridgeErrors.B_FORBIDDEN.selector); bridge.processMessage( @@ -143,7 +143,7 @@ contract TestGenerateGenesis is Test, AddressResolver { ); EtherVault etherVault = EtherVault(etherVaultAddress); - // assertEq(owner, etherVault.owner()); + assertEq(owner, etherVault.owner()); assertEq( etherVault.isAuthorized( From ef1c54c5b5202e05a6172c12a0e55cbe602539a4 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 8 May 2023 17:09:52 -0700 Subject: [PATCH 10/23] . --- .../test/genesis/GenerateGenesis.g.sol | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/protocol/test/genesis/GenerateGenesis.g.sol b/packages/protocol/test/genesis/GenerateGenesis.g.sol index c1651441f86..4def615351e 100644 --- a/packages/protocol/test/genesis/GenerateGenesis.g.sol +++ b/packages/protocol/test/genesis/GenerateGenesis.g.sol @@ -32,6 +32,8 @@ contract TestGenerateGenesis is Test, AddressResolver { string.concat(vm.projectRoot(), "/deployments/genesis_alloc.json") ); address private owner = configJSON.readAddress(".contractOwner"); + address private admin = configJSON.readAddress(".contractOwner"); + uint64 public constant BLOCK_GAS_LIMIT = 30000000; function testContractDeployment() public { @@ -46,12 +48,22 @@ contract TestGenerateGenesis is Test, AddressResolver { checkDeployedCode("ProxiedSignalService"); // check proxies - checkDeployedCode("TaikoL1Proxy"); + checkDeployedCode("TaikoL2Proxy"); checkDeployedCode("TokenVaultProxy"); checkDeployedCode("EtherVaultProxy"); checkDeployedCode("BridgeProxy"); checkDeployedCode("AddressManagerProxy"); checkDeployedCode("SignalServiceProxy"); + + checkProxyImplementation("TaikoL2Proxy", "ProxiedTaikoL2"); + checkProxyImplementation("TokenVaultProxy", "ProxiedTokenVault"); + checkProxyImplementation("EtherVaultProxy", "ProxiedEtherVault"); + checkProxyImplementation("BridgeProxy", "ProxiedBridge"); + checkProxyImplementation( + "AddressManagerProxy", + "ProxiedAddressManager" + ); + checkProxyImplementation("SignalServiceProxy", "ProxiedSignalService"); } function testAddressManager() public { @@ -210,6 +222,23 @@ contract TestGenerateGenesis is Test, AddressResolver { assertEq(address(contractAddress).code, vm.parseBytes(deployedCode)); } + function checkProxyImplementation( + string memory proxyName, + string memory contractName + ) private { + address contractAddress = getPredeployedContractAddress(contractName); + address proxyAddress = getPredeployedContractAddress(proxyName); + assertEq( + TransparentUpgradeableProxy(payable(proxyAddress)).implementation(), + address(contractAddress) + ); + + assertEq( + TransparentUpgradeableProxy(payable(proxyAddress)).admin(), + owner + ); + } + function checkSavedAddress( AddressManager addressManager, string memory contractName, From d16c1165408e1dbf5d4d7f1d521178b58659ef4d Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 8 May 2023 17:59:49 -0700 Subject: [PATCH 11/23] prank --- packages/protocol/test/genesis/GenerateGenesis.g.sol | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/protocol/test/genesis/GenerateGenesis.g.sol b/packages/protocol/test/genesis/GenerateGenesis.g.sol index 4def615351e..94ab1af10ed 100644 --- a/packages/protocol/test/genesis/GenerateGenesis.g.sol +++ b/packages/protocol/test/genesis/GenerateGenesis.g.sol @@ -226,6 +226,7 @@ contract TestGenerateGenesis is Test, AddressResolver { string memory proxyName, string memory contractName ) private { + vm.startPrank(owner); address contractAddress = getPredeployedContractAddress(contractName); address proxyAddress = getPredeployedContractAddress(proxyName); assertEq( @@ -237,6 +238,7 @@ contract TestGenerateGenesis is Test, AddressResolver { TransparentUpgradeableProxy(payable(proxyAddress)).admin(), owner ); + vm.stopPrank(); } function checkSavedAddress( From c2b5d8c6836a06e5f0eed719f710fe10c10dc7d3 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 8 May 2023 18:30:53 -0700 Subject: [PATCH 12/23] . --- .../test/genesis/GenerateGenesis.g.sol | 2 +- .../utils/generate_genesis/taikoL2.ts | 154 +++++++++--------- 2 files changed, 75 insertions(+), 81 deletions(-) diff --git a/packages/protocol/test/genesis/GenerateGenesis.g.sol b/packages/protocol/test/genesis/GenerateGenesis.g.sol index 94ab1af10ed..871c1002053 100644 --- a/packages/protocol/test/genesis/GenerateGenesis.g.sol +++ b/packages/protocol/test/genesis/GenerateGenesis.g.sol @@ -177,7 +177,7 @@ contract TestGenerateGenesis is Test, AddressResolver { getPredeployedContractAddress("AddressManagerProxy") ); - // assertEq(owner, tokenVault.owner()); + assertEq(owner, tokenVault.owner()); vm.startPrank(addressManager.owner()); addressManager.setAddress(1, "bridge", bridgeAddress); diff --git a/packages/protocol/utils/generate_genesis/taikoL2.ts b/packages/protocol/utils/generate_genesis/taikoL2.ts index 60ba7873620..c448fb071a0 100644 --- a/packages/protocol/utils/generate_genesis/taikoL2.ts +++ b/packages/protocol/utils/generate_genesis/taikoL2.ts @@ -72,24 +72,22 @@ export async function deployTaikoL2( // since we enable storageLayout compiler output in hardhat.config.ts, // rollup/artifacts/build-info will contain storage layouts, here // reading it using smock package. - if (!contractConfig.isProxy) { - storageLayouts[contractName] = await getStorageLayout(contractName); - // initialize contract variables, we only care about the variables - // that need to be initialized with non-zero value. - const slots = computeStorageSlots( - storageLayouts[contractName], - contractConfigs[contractName].variables - ); + storageLayouts[contractName] = await getStorageLayout(contractName); + // initialize contract variables, we only care about the variables + // that need to be initialized with non-zero value. + const slots = computeStorageSlots( + storageLayouts[contractName], + contractConfigs[contractName].variables + ); - for (const slot of slots) { - alloc[contractConfig.address].storage[slot.key] = slot.val; - } - } else { - for (const [slot, val] of Object.entries( - contractConfigs[contractName].variables - )) { - alloc[contractConfig.address].storage[slot] = val; - } + for (const slot of slots) { + alloc[contractConfig.address].storage[slot.key] = slot.val; + } + + for (const [slot, val] of Object.entries( + contractConfigs[contractName].slots + )) { + alloc[contractConfig.address].storage[slot] = val; } } @@ -259,43 +257,44 @@ async function generateContractConfigs( address: addressMap.ProxiedAddressManager, deployedBytecode: contractArtifacts.ProxiedAddressManager.deployedBytecode.object, - variables: { - // initializer - _initialized: 1, - _initializing: false, - // OwnableUpgradeable - _owner: contractOwner, - // AddressManager - addresses: { - [chainId]: { - [ethers.utils.hexlify( - ethers.utils.toUtf8Bytes("taiko") - )]: addressMap.TaikoL2Proxy, - [ethers.utils.hexlify( - ethers.utils.toUtf8Bytes("bridge") - )]: addressMap.BridgeProxy, - [ethers.utils.hexlify( - ethers.utils.toUtf8Bytes("token_vault") - )]: addressMap.TokenVaultProxy, - [ethers.utils.hexlify( - ethers.utils.toUtf8Bytes("ether_vault") - )]: addressMap.EtherVaultProxy, - [ethers.utils.hexlify( - ethers.utils.toUtf8Bytes("signal_service") - )]: addressMap.SignalServiceProxy, - }, - }, - }, }, AddressManagerProxy: { address: addressMap.AddressManagerProxy, deployedBytecode: contractArtifacts.AddressManagerProxy.deployedBytecode.object, variables: { + variables: { + // initializer + _initialized: 1, + _initializing: false, + // OwnableUpgradeable + _owner: contractOwner, + // AddressManager + addresses: { + [chainId]: { + [ethers.utils.hexlify( + ethers.utils.toUtf8Bytes("taiko") + )]: addressMap.TaikoL2Proxy, + [ethers.utils.hexlify( + ethers.utils.toUtf8Bytes("bridge") + )]: addressMap.BridgeProxy, + [ethers.utils.hexlify( + ethers.utils.toUtf8Bytes("token_vault") + )]: addressMap.TokenVaultProxy, + [ethers.utils.hexlify( + ethers.utils.toUtf8Bytes("ether_vault") + )]: addressMap.EtherVaultProxy, + [ethers.utils.hexlify( + ethers.utils.toUtf8Bytes("signal_service") + )]: addressMap.SignalServiceProxy, + }, + }, + }, + }, + slots: { [ADMIN_SLOT]: contractOwner, [IMPLEMENTATION_SLOT]: addressMap.ProxiedAddressManager, }, - isProxy: true, }, ProxiedTaikoL2: { address: addressMap.ProxiedTaikoL2, @@ -303,6 +302,11 @@ async function generateContractConfigs( contractArtifacts.ProxiedTaikoL2, addressMap ), + }, + TaikoL2Proxy: { + address: addressMap.TaikoL2Proxy, + deployedBytecode: + contractArtifacts.TaikoL2Proxy.deployedBytecode.object, variables: { // TaikoL2 // keccak256(abi.encodePacked(block.chainid, basefee, ancestors)) @@ -327,16 +331,10 @@ async function generateContractConfigs( parentTimestamp: Math.floor(new Date().getTime() / 1000), gasExcess: ethers.BigNumber.from(param1559.gasExcess), }, - }, - TaikoL2Proxy: { - address: addressMap.TaikoL2Proxy, - deployedBytecode: - contractArtifacts.TaikoL2Proxy.deployedBytecode.object, - variables: { + slots: { [ADMIN_SLOT]: contractOwner, [IMPLEMENTATION_SLOT]: addressMap.ProxiedTaikoL2, }, - isProxy: true, }, ProxiedBridge: { address: addressMap.ProxiedBridge, @@ -344,6 +342,11 @@ async function generateContractConfigs( contractArtifacts.ProxiedBridge, addressMap ), + }, + BridgeProxy: { + address: addressMap.BridgeProxy, + deployedBytecode: + contractArtifacts.BridgeProxy.deployedBytecode.object, variables: { // initializer _initialized: 1, @@ -357,21 +360,20 @@ async function generateContractConfigs( // Bridge _state: {}, }, - }, - BridgeProxy: { - address: addressMap.BridgeProxy, - deployedBytecode: - contractArtifacts.BridgeProxy.deployedBytecode.object, - variables: { + slots: { [ADMIN_SLOT]: contractOwner, [IMPLEMENTATION_SLOT]: addressMap.ProxiedBridge, }, - isProxy: true, }, ProxiedTokenVault: { address: addressMap.ProxiedTokenVault, deployedBytecode: contractArtifacts.ProxiedTokenVault.deployedBytecode.object, + }, + TokenVaultProxy: { + address: addressMap.TokenVaultProxy, + deployedBytecode: + contractArtifacts.TokenVaultProxy.deployedBytecode.object, variables: { // initializer _initialized: 1, @@ -383,21 +385,20 @@ async function generateContractConfigs( // AddressResolver _addressManager: addressMap.AddressManagerProxy, }, - }, - TokenVaultProxy: { - address: addressMap.TokenVaultProxy, - deployedBytecode: - contractArtifacts.TokenVaultProxy.deployedBytecode.object, - variables: { + slots: { [ADMIN_SLOT]: contractOwner, [IMPLEMENTATION_SLOT]: addressMap.ProxiedTokenVault, }, - isProxy: true, }, ProxiedEtherVault: { address: addressMap.ProxiedEtherVault, deployedBytecode: contractArtifacts.ProxiedEtherVault.deployedBytecode.object, + }, + EtherVaultProxy: { + address: addressMap.EtherVaultProxy, + deployedBytecode: + contractArtifacts.EtherVaultProxy.deployedBytecode.object, variables: { // initializer _initialized: 1, @@ -412,16 +413,10 @@ async function generateContractConfigs( // Authorize L2 bridge _authorizedAddrs: { [`${addressMap.BridgeProxy}`]: true }, }, - }, - EtherVaultProxy: { - address: addressMap.EtherVaultProxy, - deployedBytecode: - contractArtifacts.EtherVaultProxy.deployedBytecode.object, - variables: { + slots: { [ADMIN_SLOT]: contractOwner, [IMPLEMENTATION_SLOT]: addressMap.ProxiedEtherVault, }, - isProxy: true, }, ProxiedSignalService: { address: addressMap.ProxiedSignalService, @@ -429,6 +424,11 @@ async function generateContractConfigs( contractArtifacts.ProxiedSignalService, addressMap ), + }, + SignalServiceProxy: { + address: addressMap.SignalServiceProxy, + deployedBytecode: + contractArtifacts.SignalServiceProxy.deployedBytecode.object, variables: { // initializer _initialized: 1, @@ -440,16 +440,10 @@ async function generateContractConfigs( // AddressResolver _addressManager: addressMap.AddressManagerProxy, }, - }, - SignalServiceProxy: { - address: addressMap.SignalServiceProxy, - deployedBytecode: - contractArtifacts.SignalServiceProxy.deployedBytecode.object, - variables: { + slots: { [ADMIN_SLOT]: contractOwner, [IMPLEMENTATION_SLOT]: addressMap.ProxiedSignalService, }, - isProxy: true, }, }; } From 09ce12608dbd7badcb4eddc0d855baa804a2c297 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 8 May 2023 18:38:22 -0700 Subject: [PATCH 13/23] proxy tests --- .../test/genesis/GenerateGenesis.g.sol | 26 ++++++++++++++----- .../utils/generate_genesis/taikoL2.ts | 10 ++++--- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/packages/protocol/test/genesis/GenerateGenesis.g.sol b/packages/protocol/test/genesis/GenerateGenesis.g.sol index 871c1002053..5dc969e8dc3 100644 --- a/packages/protocol/test/genesis/GenerateGenesis.g.sol +++ b/packages/protocol/test/genesis/GenerateGenesis.g.sol @@ -67,6 +67,8 @@ contract TestGenerateGenesis is Test, AddressResolver { } function testAddressManager() public { + vm.startPrank(owner); + AddressManager addressManager = AddressManager( getPredeployedContractAddress("AddressManagerProxy") ); @@ -82,6 +84,16 @@ contract TestGenerateGenesis is Test, AddressResolver { "SignalServiceProxy", "signal_service" ); + + TransparentUpgradeableProxy proxy = TransparentUpgradeableProxy( + payable(getPredeployedContractAddress("AddressManagerProxy")) + ); + + AddressManager newAddressManager = new AddressManager(); + + proxy.upgradeTo(address(newAddressManager)); + + assertEq(proxy.implementation(), address(newAddressManager)); } function testTaikoL2() public { @@ -229,15 +241,15 @@ contract TestGenerateGenesis is Test, AddressResolver { vm.startPrank(owner); address contractAddress = getPredeployedContractAddress(contractName); address proxyAddress = getPredeployedContractAddress(proxyName); - assertEq( - TransparentUpgradeableProxy(payable(proxyAddress)).implementation(), - address(contractAddress) - ); - assertEq( - TransparentUpgradeableProxy(payable(proxyAddress)).admin(), - owner + TransparentUpgradeableProxy proxy = TransparentUpgradeableProxy( + payable(proxyAddress) ); + + assertEq(proxy.implementation(), address(contractAddress)); + + assertEq(proxy.admin(), owner); + vm.stopPrank(); } diff --git a/packages/protocol/utils/generate_genesis/taikoL2.ts b/packages/protocol/utils/generate_genesis/taikoL2.ts index c448fb071a0..10c6d1b0222 100644 --- a/packages/protocol/utils/generate_genesis/taikoL2.ts +++ b/packages/protocol/utils/generate_genesis/taikoL2.ts @@ -84,10 +84,12 @@ export async function deployTaikoL2( alloc[contractConfig.address].storage[slot.key] = slot.val; } - for (const [slot, val] of Object.entries( - contractConfigs[contractName].slots - )) { - alloc[contractConfig.address].storage[slot] = val; + if (contractConfigs[contractName].slots) { + for (const [slot, val] of Object.entries( + contractConfigs[contractName].slots + )) { + alloc[contractConfig.address].storage[slot] = val; + } } } From cf02ff0fcfa749f9cf05929ad1afa6306f6ef784 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 8 May 2023 18:42:17 -0700 Subject: [PATCH 14/23] upgradeTo tests for rest of proxies --- .../test/genesis/GenerateGenesis.g.sol | 68 ++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/packages/protocol/test/genesis/GenerateGenesis.g.sol b/packages/protocol/test/genesis/GenerateGenesis.g.sol index 5dc969e8dc3..37876ab6a50 100644 --- a/packages/protocol/test/genesis/GenerateGenesis.g.sol +++ b/packages/protocol/test/genesis/GenerateGenesis.g.sol @@ -94,6 +94,7 @@ contract TestGenerateGenesis is Test, AddressResolver { proxy.upgradeTo(address(newAddressManager)); assertEq(proxy.implementation(), address(newAddressManager)); + vm.stopPrank(); } function testTaikoL2() public { @@ -130,6 +131,19 @@ contract TestGenerateGenesis is Test, AddressResolver { } } vm.stopPrank(); + + vm.startPrank(owner); + + TransparentUpgradeableProxy proxy = TransparentUpgradeableProxy( + payable(getPredeployedContractAddress("TaikoL2Proxy")) + ); + + TaikoL2 newTaikoL2 = new TaikoL2(); + + proxy.upgradeTo(address(newTaikoL2)); + + assertEq(proxy.implementation(), address(newTaikoL2)); + vm.stopPrank(); } function testBridge() public { @@ -159,6 +173,19 @@ contract TestGenerateGenesis is Test, AddressResolver { }), "" ); + + vm.startPrank(owner); + + TransparentUpgradeableProxy proxy = TransparentUpgradeableProxy( + payable(getPredeployedContractAddress("BridgeProxy")) + ); + + Bridge newBridge = new Bridge(); + + proxy.upgradeTo(address(newBridge)); + + assertEq(proxy.implementation(), address(newBridge)); + vm.stopPrank(); } function testEtherVault() public { @@ -176,6 +203,19 @@ contract TestGenerateGenesis is Test, AddressResolver { true ); assertEq(etherVault.isAuthorized(etherVault.owner()), false); + + vm.startPrank(owner); + + TransparentUpgradeableProxy proxy = TransparentUpgradeableProxy( + payable(getPredeployedContractAddress("EtherVaultProxy")) + ); + + EtherVault newEtherVault = new EtherVault(); + + proxy.upgradeTo(address(newEtherVault)); + + assertEq(proxy.implementation(), address(newEtherVault)); + vm.stopPrank(); } function testTokenVault() public { @@ -195,6 +235,19 @@ contract TestGenerateGenesis is Test, AddressResolver { addressManager.setAddress(1, "bridge", bridgeAddress); addressManager.setAddress(1, "token_vault", tokenVaultAddress); vm.stopPrank(); + + vm.startPrank(owner); + + TransparentUpgradeableProxy proxy = TransparentUpgradeableProxy( + payable(getPredeployedContractAddress("TokenVaultProxy")) + ); + + TokenVault newTokenVault = new TokenVault(); + + proxy.upgradeTo(address(newTokenVault)); + + assertEq(proxy.implementation(), address(newTokenVault)); + vm.stopPrank(); } function testSignalService() public { @@ -202,9 +255,22 @@ contract TestGenerateGenesis is Test, AddressResolver { getPredeployedContractAddress("SignalServiceProxy") ); - // assertEq(owner, signalService.owner()); + assertEq(owner, signalService.owner()); signalService.sendSignal(keccak256(abi.encodePacked(block.prevrandao))); + + vm.startPrank(owner); + + TransparentUpgradeableProxy proxy = TransparentUpgradeableProxy( + payable(getPredeployedContractAddress("SignalServiceProxy")) + ); + + SignalService newSignalService = new SignalService(); + + proxy.upgradeTo(address(newSignalService)); + + assertEq(proxy.implementation(), address(newSignalService)); + vm.stopPrank(); } function testERC20() public { From 3c66b19ba565977132a36511e4d84d64d702019d Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 8 May 2023 18:49:55 -0700 Subject: [PATCH 15/23] layout names --- .../protocol/utils/generate_genesis/taikoL2.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/protocol/utils/generate_genesis/taikoL2.ts b/packages/protocol/utils/generate_genesis/taikoL2.ts index 10c6d1b0222..4c88438b912 100644 --- a/packages/protocol/utils/generate_genesis/taikoL2.ts +++ b/packages/protocol/utils/generate_genesis/taikoL2.ts @@ -72,7 +72,15 @@ export async function deployTaikoL2( // since we enable storageLayout compiler output in hardhat.config.ts, // rollup/artifacts/build-info will contain storage layouts, here // reading it using smock package. - storageLayouts[contractName] = await getStorageLayout(contractName); + let storageLayoutName = contractName; + if (contractConfig.isProxy) { + storageLayoutName = contractName.replace("Proxy", ""); + storageLayoutName = `Proxied${storageLayoutName}`; + } + + storageLayouts[contractName] = await getStorageLayout( + storageLayoutName + ); // initialize contract variables, we only care about the variables // that need to be initialized with non-zero value. const slots = computeStorageSlots( @@ -297,6 +305,7 @@ async function generateContractConfigs( [ADMIN_SLOT]: contractOwner, [IMPLEMENTATION_SLOT]: addressMap.ProxiedAddressManager, }, + isProxy: true, }, ProxiedTaikoL2: { address: addressMap.ProxiedTaikoL2, @@ -337,6 +346,7 @@ async function generateContractConfigs( [ADMIN_SLOT]: contractOwner, [IMPLEMENTATION_SLOT]: addressMap.ProxiedTaikoL2, }, + isProxy: true, }, ProxiedBridge: { address: addressMap.ProxiedBridge, @@ -366,6 +376,7 @@ async function generateContractConfigs( [ADMIN_SLOT]: contractOwner, [IMPLEMENTATION_SLOT]: addressMap.ProxiedBridge, }, + isProxy: true, }, ProxiedTokenVault: { address: addressMap.ProxiedTokenVault, @@ -391,6 +402,7 @@ async function generateContractConfigs( [ADMIN_SLOT]: contractOwner, [IMPLEMENTATION_SLOT]: addressMap.ProxiedTokenVault, }, + isProxy: true, }, ProxiedEtherVault: { address: addressMap.ProxiedEtherVault, @@ -419,6 +431,7 @@ async function generateContractConfigs( [ADMIN_SLOT]: contractOwner, [IMPLEMENTATION_SLOT]: addressMap.ProxiedEtherVault, }, + isProxy: true, }, ProxiedSignalService: { address: addressMap.ProxiedSignalService, @@ -446,6 +459,7 @@ async function generateContractConfigs( [ADMIN_SLOT]: contractOwner, [IMPLEMENTATION_SLOT]: addressMap.ProxiedSignalService, }, + isProxy: true, }, }; } From d17f1fa512d51e1357b1656ea31d8a401d03eafd Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 8 May 2023 18:56:43 -0700 Subject: [PATCH 16/23] Typo --- .../utils/generate_genesis/taikoL2.ts | 48 +++++++++---------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/packages/protocol/utils/generate_genesis/taikoL2.ts b/packages/protocol/utils/generate_genesis/taikoL2.ts index 4c88438b912..e2490a55eb3 100644 --- a/packages/protocol/utils/generate_genesis/taikoL2.ts +++ b/packages/protocol/utils/generate_genesis/taikoL2.ts @@ -273,31 +273,29 @@ async function generateContractConfigs( deployedBytecode: contractArtifacts.AddressManagerProxy.deployedBytecode.object, variables: { - variables: { - // initializer - _initialized: 1, - _initializing: false, - // OwnableUpgradeable - _owner: contractOwner, - // AddressManager - addresses: { - [chainId]: { - [ethers.utils.hexlify( - ethers.utils.toUtf8Bytes("taiko") - )]: addressMap.TaikoL2Proxy, - [ethers.utils.hexlify( - ethers.utils.toUtf8Bytes("bridge") - )]: addressMap.BridgeProxy, - [ethers.utils.hexlify( - ethers.utils.toUtf8Bytes("token_vault") - )]: addressMap.TokenVaultProxy, - [ethers.utils.hexlify( - ethers.utils.toUtf8Bytes("ether_vault") - )]: addressMap.EtherVaultProxy, - [ethers.utils.hexlify( - ethers.utils.toUtf8Bytes("signal_service") - )]: addressMap.SignalServiceProxy, - }, + // initializer + _initialized: 1, + _initializing: false, + // OwnableUpgradeable + _owner: contractOwner, + // AddressManager + addresses: { + [chainId]: { + [ethers.utils.hexlify( + ethers.utils.toUtf8Bytes("taiko") + )]: addressMap.TaikoL2Proxy, + [ethers.utils.hexlify( + ethers.utils.toUtf8Bytes("bridge") + )]: addressMap.BridgeProxy, + [ethers.utils.hexlify( + ethers.utils.toUtf8Bytes("token_vault") + )]: addressMap.TokenVaultProxy, + [ethers.utils.hexlify( + ethers.utils.toUtf8Bytes("ether_vault") + )]: addressMap.EtherVaultProxy, + [ethers.utils.hexlify( + ethers.utils.toUtf8Bytes("signal_service") + )]: addressMap.SignalServiceProxy, }, }, }, From cb6e3f2aaea337d4ed1ff43f5c911a7c81998440 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 8 May 2023 19:08:38 -0700 Subject: [PATCH 17/23] admin address diff than owner --- .../protocol/test/genesis/GenerateGenesis.g.sol | 16 ++++++++-------- packages/protocol/test/genesis/test_config.json | 1 + .../protocol/utils/generate_genesis/interface.ts | 1 + .../protocol/utils/generate_genesis/taikoL2.ts | 14 ++++++++------ 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/packages/protocol/test/genesis/GenerateGenesis.g.sol b/packages/protocol/test/genesis/GenerateGenesis.g.sol index 37876ab6a50..1d599a2c51c 100644 --- a/packages/protocol/test/genesis/GenerateGenesis.g.sol +++ b/packages/protocol/test/genesis/GenerateGenesis.g.sol @@ -32,7 +32,7 @@ contract TestGenerateGenesis is Test, AddressResolver { string.concat(vm.projectRoot(), "/deployments/genesis_alloc.json") ); address private owner = configJSON.readAddress(".contractOwner"); - address private admin = configJSON.readAddress(".contractOwner"); + address private admin = configJSON.readAddress(".contractAdmin"); uint64 public constant BLOCK_GAS_LIMIT = 30000000; @@ -67,8 +67,6 @@ contract TestGenerateGenesis is Test, AddressResolver { } function testAddressManager() public { - vm.startPrank(owner); - AddressManager addressManager = AddressManager( getPredeployedContractAddress("AddressManagerProxy") ); @@ -91,6 +89,8 @@ contract TestGenerateGenesis is Test, AddressResolver { AddressManager newAddressManager = new AddressManager(); + vm.startPrank(admin); + proxy.upgradeTo(address(newAddressManager)); assertEq(proxy.implementation(), address(newAddressManager)); @@ -132,7 +132,7 @@ contract TestGenerateGenesis is Test, AddressResolver { } vm.stopPrank(); - vm.startPrank(owner); + vm.startPrank(admin); TransparentUpgradeableProxy proxy = TransparentUpgradeableProxy( payable(getPredeployedContractAddress("TaikoL2Proxy")) @@ -174,7 +174,7 @@ contract TestGenerateGenesis is Test, AddressResolver { "" ); - vm.startPrank(owner); + vm.startPrank(admin); TransparentUpgradeableProxy proxy = TransparentUpgradeableProxy( payable(getPredeployedContractAddress("BridgeProxy")) @@ -204,7 +204,7 @@ contract TestGenerateGenesis is Test, AddressResolver { ); assertEq(etherVault.isAuthorized(etherVault.owner()), false); - vm.startPrank(owner); + vm.startPrank(admin); TransparentUpgradeableProxy proxy = TransparentUpgradeableProxy( payable(getPredeployedContractAddress("EtherVaultProxy")) @@ -236,7 +236,7 @@ contract TestGenerateGenesis is Test, AddressResolver { addressManager.setAddress(1, "token_vault", tokenVaultAddress); vm.stopPrank(); - vm.startPrank(owner); + vm.startPrank(admin); TransparentUpgradeableProxy proxy = TransparentUpgradeableProxy( payable(getPredeployedContractAddress("TokenVaultProxy")) @@ -259,7 +259,7 @@ contract TestGenerateGenesis is Test, AddressResolver { signalService.sendSignal(keccak256(abi.encodePacked(block.prevrandao))); - vm.startPrank(owner); + vm.startPrank(admin); TransparentUpgradeableProxy proxy = TransparentUpgradeableProxy( payable(getPredeployedContractAddress("SignalServiceProxy")) diff --git a/packages/protocol/test/genesis/test_config.json b/packages/protocol/test/genesis/test_config.json index 30fb6788df3..92912f30617 100644 --- a/packages/protocol/test/genesis/test_config.json +++ b/packages/protocol/test/genesis/test_config.json @@ -1,5 +1,6 @@ { "contractOwner": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + "admin": "0xc0ffee254729296a45a3885639AC7E10F9d54979", "chainId": 167, "seedAccounts": [ { diff --git a/packages/protocol/utils/generate_genesis/interface.ts b/packages/protocol/utils/generate_genesis/interface.ts index 312462f59e6..054b7837f3f 100644 --- a/packages/protocol/utils/generate_genesis/interface.ts +++ b/packages/protocol/utils/generate_genesis/interface.ts @@ -1,5 +1,6 @@ export interface Config { contractOwner: string; + contractAdmin: string; chainId: number; seedAccounts: Array<{ [key: string]: number; diff --git a/packages/protocol/utils/generate_genesis/taikoL2.ts b/packages/protocol/utils/generate_genesis/taikoL2.ts index e2490a55eb3..51ce3cefb2b 100644 --- a/packages/protocol/utils/generate_genesis/taikoL2.ts +++ b/packages/protocol/utils/generate_genesis/taikoL2.ts @@ -20,7 +20,7 @@ export async function deployTaikoL2( config: Config, result: Result ): Promise { - const { contractOwner, chainId, seedAccounts } = config; + const { contractOwner, chainId, seedAccounts, contractAdmin } = config; const alloc: any = {}; @@ -45,6 +45,7 @@ export async function deployTaikoL2( const contractConfigs: any = await generateContractConfigs( contractOwner, + contractAdmin, chainId, config.contractAddresses, config.param1559 @@ -114,6 +115,7 @@ export async function deployTaikoL2( // and initialized variables. async function generateContractConfigs( contractOwner: string, + contractAdmin: string, chainId: number, hardCodedAddresses: any, param1559: any @@ -300,7 +302,7 @@ async function generateContractConfigs( }, }, slots: { - [ADMIN_SLOT]: contractOwner, + [ADMIN_SLOT]: contractAdmin, [IMPLEMENTATION_SLOT]: addressMap.ProxiedAddressManager, }, isProxy: true, @@ -341,7 +343,7 @@ async function generateContractConfigs( gasExcess: ethers.BigNumber.from(param1559.gasExcess), }, slots: { - [ADMIN_SLOT]: contractOwner, + [ADMIN_SLOT]: contractAdmin, [IMPLEMENTATION_SLOT]: addressMap.ProxiedTaikoL2, }, isProxy: true, @@ -371,7 +373,7 @@ async function generateContractConfigs( _state: {}, }, slots: { - [ADMIN_SLOT]: contractOwner, + [ADMIN_SLOT]: contractAdmin, [IMPLEMENTATION_SLOT]: addressMap.ProxiedBridge, }, isProxy: true, @@ -397,7 +399,7 @@ async function generateContractConfigs( _addressManager: addressMap.AddressManagerProxy, }, slots: { - [ADMIN_SLOT]: contractOwner, + [ADMIN_SLOT]: contractAdmin, [IMPLEMENTATION_SLOT]: addressMap.ProxiedTokenVault, }, isProxy: true, @@ -426,7 +428,7 @@ async function generateContractConfigs( _authorizedAddrs: { [`${addressMap.BridgeProxy}`]: true }, }, slots: { - [ADMIN_SLOT]: contractOwner, + [ADMIN_SLOT]: contractAdmin, [IMPLEMENTATION_SLOT]: addressMap.ProxiedEtherVault, }, isProxy: true, From 3320809f0dabacdf417ec143e30262ff43c2cced Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 8 May 2023 19:16:22 -0700 Subject: [PATCH 18/23] . --- packages/protocol/test/genesis/test_config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/test/genesis/test_config.json b/packages/protocol/test/genesis/test_config.json index 92912f30617..e9688e19c0c 100644 --- a/packages/protocol/test/genesis/test_config.json +++ b/packages/protocol/test/genesis/test_config.json @@ -1,6 +1,6 @@ { "contractOwner": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - "admin": "0xc0ffee254729296a45a3885639AC7E10F9d54979", + "contractAdmin": "0xc0ffee254729296a45a3885639AC7E10F9d54979", "chainId": 167, "seedAccounts": [ { From da6574520be6dd69d13e1571056645eee8ca0811 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 8 May 2023 19:24:34 -0700 Subject: [PATCH 19/23] be admin to do proxy stuff --- packages/protocol/test/genesis/GenerateGenesis.g.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/protocol/test/genesis/GenerateGenesis.g.sol b/packages/protocol/test/genesis/GenerateGenesis.g.sol index 1d599a2c51c..008ca557ded 100644 --- a/packages/protocol/test/genesis/GenerateGenesis.g.sol +++ b/packages/protocol/test/genesis/GenerateGenesis.g.sol @@ -55,6 +55,7 @@ contract TestGenerateGenesis is Test, AddressResolver { checkDeployedCode("AddressManagerProxy"); checkDeployedCode("SignalServiceProxy"); + // check proxy implementations checkProxyImplementation("TaikoL2Proxy", "ProxiedTaikoL2"); checkProxyImplementation("TokenVaultProxy", "ProxiedTokenVault"); checkProxyImplementation("EtherVaultProxy", "ProxiedEtherVault"); @@ -304,7 +305,7 @@ contract TestGenerateGenesis is Test, AddressResolver { string memory proxyName, string memory contractName ) private { - vm.startPrank(owner); + vm.startPrank(admin); address contractAddress = getPredeployedContractAddress(contractName); address proxyAddress = getPredeployedContractAddress(proxyName); From 99a7559735b191330df0cf80422750e96f7cb1d8 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 8 May 2023 19:25:57 -0700 Subject: [PATCH 20/23] admin should be admin not owner for signal service --- packages/protocol/utils/generate_genesis/taikoL2.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/utils/generate_genesis/taikoL2.ts b/packages/protocol/utils/generate_genesis/taikoL2.ts index 51ce3cefb2b..128a02e2373 100644 --- a/packages/protocol/utils/generate_genesis/taikoL2.ts +++ b/packages/protocol/utils/generate_genesis/taikoL2.ts @@ -456,7 +456,7 @@ async function generateContractConfigs( _addressManager: addressMap.AddressManagerProxy, }, slots: { - [ADMIN_SLOT]: contractOwner, + [ADMIN_SLOT]: contractAdmin, [IMPLEMENTATION_SLOT]: addressMap.ProxiedSignalService, }, isProxy: true, From 24e9c22205aae96a857df234030e37632421df12 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 8 May 2023 19:32:44 -0700 Subject: [PATCH 21/23] reorder --- .../protocol/test/genesis/GenerateGenesis.g.sol | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/protocol/test/genesis/GenerateGenesis.g.sol b/packages/protocol/test/genesis/GenerateGenesis.g.sol index 008ca557ded..95674bf22e1 100644 --- a/packages/protocol/test/genesis/GenerateGenesis.g.sol +++ b/packages/protocol/test/genesis/GenerateGenesis.g.sol @@ -47,14 +47,6 @@ contract TestGenerateGenesis is Test, AddressResolver { checkDeployedCode("ProxiedAddressManager"); checkDeployedCode("ProxiedSignalService"); - // check proxies - checkDeployedCode("TaikoL2Proxy"); - checkDeployedCode("TokenVaultProxy"); - checkDeployedCode("EtherVaultProxy"); - checkDeployedCode("BridgeProxy"); - checkDeployedCode("AddressManagerProxy"); - checkDeployedCode("SignalServiceProxy"); - // check proxy implementations checkProxyImplementation("TaikoL2Proxy", "ProxiedTaikoL2"); checkProxyImplementation("TokenVaultProxy", "ProxiedTokenVault"); @@ -65,6 +57,14 @@ contract TestGenerateGenesis is Test, AddressResolver { "ProxiedAddressManager" ); checkProxyImplementation("SignalServiceProxy", "ProxiedSignalService"); + + // check proxies + checkDeployedCode("TaikoL2Proxy"); + checkDeployedCode("TokenVaultProxy"); + checkDeployedCode("EtherVaultProxy"); + checkDeployedCode("BridgeProxy"); + checkDeployedCode("AddressManagerProxy"); + checkDeployedCode("SignalServiceProxy"); } function testAddressManager() public { From c62f061f71ef8010b03a405e3cc61fb76fce76f3 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 8 May 2023 19:39:34 -0700 Subject: [PATCH 22/23] assert admin --- packages/protocol/test/genesis/GenerateGenesis.g.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/test/genesis/GenerateGenesis.g.sol b/packages/protocol/test/genesis/GenerateGenesis.g.sol index 95674bf22e1..2cd50c85ab2 100644 --- a/packages/protocol/test/genesis/GenerateGenesis.g.sol +++ b/packages/protocol/test/genesis/GenerateGenesis.g.sol @@ -315,7 +315,7 @@ contract TestGenerateGenesis is Test, AddressResolver { assertEq(proxy.implementation(), address(contractAddress)); - assertEq(proxy.admin(), owner); + assertEq(proxy.admin(), admin); vm.stopPrank(); } From 3df3d06b257d54f96705a8338d4a1f17268770b1 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Tue, 9 May 2023 07:13:34 -0700 Subject: [PATCH 23/23] send ether vault money to proxy --- packages/protocol/utils/generate_genesis/taikoL2.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/utils/generate_genesis/taikoL2.ts b/packages/protocol/utils/generate_genesis/taikoL2.ts index 128a02e2373..2bf942a5c84 100644 --- a/packages/protocol/utils/generate_genesis/taikoL2.ts +++ b/packages/protocol/utils/generate_genesis/taikoL2.ts @@ -66,7 +66,7 @@ export async function deployTaikoL2( // pre-mint ETHs for EtherVault contract alloc[contractConfig.address].balance = - contractName === "ProxiedEtherVault" + contractName === "EtherVaultProxy" ? etherVaultBalance.toHexString() : "0x0";