diff --git a/contracts/utility/Upgradeable.sol b/contracts/utility/Upgradeable.sol index 27d24e91..15b89c0d 100644 --- a/contracts/utility/Upgradeable.sol +++ b/contracts/utility/Upgradeable.sol @@ -81,18 +81,17 @@ abstract contract Upgradeable is IUpgradeable, AccessControlEnumerableUpgradeabl * * - this must and can be called only once per-upgrade */ - function postUpgrade(bytes calldata data) external { + function postUpgrade(bool checkVersion, bytes calldata data) external { uint16 initializations = _initializations + 1; uint16 _version = version(); - if (initializations < _version) { - initializations = _version; - } - if (initializations != _version) { + if (checkVersion && initializations != _version) { revert AlreadyInitialized(); + } else if (!checkVersion) { + initializations = _version; + } else { + initializations = initializations; } - _initializations = initializations; - _postUpgrade(data); } diff --git a/deploy/scripts/network/0002-Voucher.ts b/deploy/scripts/network/0002-Voucher.ts index 2d278d80..326ae69c 100644 --- a/deploy/scripts/network/0002-Voucher.ts +++ b/deploy/scripts/network/0002-Voucher.ts @@ -20,7 +20,7 @@ const func: DeployFunction = async ({ getNamedAccounts }: HardhatRuntimeEnvironm await execute({ name: InstanceName.Voucher, methodName: 'postUpgrade', - args: ["0x"], + args: ['0x'], from: deployer }); diff --git a/deploy/tests/mainnet/carbon.ts b/deploy/tests/mainnet/carbon.ts index d118d180..c96f409a 100644 --- a/deploy/tests/mainnet/carbon.ts +++ b/deploy/tests/mainnet/carbon.ts @@ -77,7 +77,10 @@ import { ethers, getNamedAccounts } from 'hardhat'; await expectRoleMembers(carbonVortex, Roles.Upgradeable.ROLE_ADMIN, [daoMultisig.address]); // expect carbon vortex to have fee manager role in Carbon - await expectRoleMembers(carbonController, Roles.CarbonController.ROLE_FEES_MANAGER, [oldVortex, carbonVortex.address]); + await expectRoleMembers(carbonController, Roles.CarbonController.ROLE_FEES_MANAGER, [ + oldVortex, + carbonVortex.address + ]); // expect carbonController to have minter role in voucher await expectRoleMembers(voucher, Roles.Voucher.ROLE_MINTER, [carbonController.address]); diff --git a/deploy/tests/network/0002-voucher.ts b/deploy/tests/network/0002-voucher.ts index 5a2183c0..1370839e 100644 --- a/deploy/tests/network/0002-voucher.ts +++ b/deploy/tests/network/0002-voucher.ts @@ -27,7 +27,7 @@ describeDeployment(__filename, () => { it('cannot call postUpgrade on voucher', async () => { // hardcoding gas limit to avoid gas estimation attempts (which get rejected instead of reverted) - const tx = await voucher.postUpgrade("0x", { gasLimit: 6000000 }); + const tx = await voucher.postUpgrade('0x', { gasLimit: 6000000 }); await expect(tx.wait()).to.be.reverted; }); }); diff --git a/deploy/tests/network/0003-carbon-controller.ts b/deploy/tests/network/0003-carbon-controller.ts index 2d22469e..3cc541d7 100644 --- a/deploy/tests/network/0003-carbon-controller.ts +++ b/deploy/tests/network/0003-carbon-controller.ts @@ -30,7 +30,7 @@ describeDeployment(__filename, () => { it('cannot call postUpgrade on carbon controller', async () => { // hardcoding gas limit to avoid gas estimation attempts (which get rejected instead of reverted) - const tx = await carbonController.postUpgrade("0x", { gasLimit: 6000000 }); + const tx = await carbonController.postUpgrade('0x', { gasLimit: 6000000 }); await expect(tx.wait()).to.be.reverted; }); }); diff --git a/lib/forge-std b/lib/forge-std index e4aef94c..3d8086d4 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit e4aef94c1768803a16fe19f7ce8b65defd027cfd +Subproject commit 3d8086d4911b36c1874531ce8c367e6cfd028e80 diff --git a/utils/Deploy.ts b/utils/Deploy.ts index baa35649..c0a097b6 100644 --- a/utils/Deploy.ts +++ b/utils/Deploy.ts @@ -329,6 +329,7 @@ export const deployProxy = async (options: DeployOptions, proxy: ProxyOptions = // ] interface UpgradeProxyOptions extends DeployOptions { postUpgradeArgs?: TypedParam[]; + checkVersion?: boolean; } export const upgradeProxy = async (options: UpgradeProxyOptions) => { @@ -351,16 +352,17 @@ export const upgradeProxy = async (options: UpgradeProxyOptions) => { const values = postUpgradeArgs.map(({ value }) => value); const abiCoder = new AbiCoder(); - upgradeCallData = [abiCoder.encode(types, values)]; + upgradeCallData = abiCoder.encode(types, values); } else { - upgradeCallData = [ZERO_BYTES]; + upgradeCallData = ZERO_BYTES; } + const checkVersion = options.checkVersion ?? true; const proxyOptions = { proxyContract: PROXY_CONTRACT, owner: await proxyAdmin.owner(), viaAdminContract: InstanceName.ProxyAdmin, - execute: { onUpgrade: { methodName: POST_UPGRADE, args: upgradeCallData } } + execute: { onUpgrade: { methodName: POST_UPGRADE, args: [checkVersion, upgradeCallData] } } }; Logger.log(` upgrading proxy ${contractName} V${prevVersion}`);