From e7422624fe9311ada455d3a5d7aa7d40a8a54023 Mon Sep 17 00:00:00 2001 From: d1onys1us <13951458+d1onys1us@users.noreply.github.com> Date: Sun, 18 Feb 2024 22:56:21 -0500 Subject: [PATCH] feat(protocol): revert revert update open-zeppelin contracts (#15896)" This reverts commit 994e29e67f68b2478c2e79ce28c9542fd048dc3c. --- .../contracts/L1/gov/TaikoGovernor.sol | 27 ++++++++++++++----- packages/protocol/package.json | 4 +-- .../protocol/test/L1/gov/TaikoGovernor.t.sol | 2 +- .../test/common/EssentialContract.t.sol | 21 +++++++-------- pnpm-lock.yaml | 16 +++++------ 5 files changed, 40 insertions(+), 30 deletions(-) diff --git a/packages/protocol/contracts/L1/gov/TaikoGovernor.sol b/packages/protocol/contracts/L1/gov/TaikoGovernor.sol index c146bb42c6f..ad2e3d0bc3e 100644 --- a/packages/protocol/contracts/L1/gov/TaikoGovernor.sol +++ b/packages/protocol/contracts/L1/gov/TaikoGovernor.sol @@ -14,10 +14,8 @@ pragma solidity 0.8.24; -import "@openzeppelin/contracts-upgradeable/governance/GovernorUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/governance/compatibility/GovernorCompatibilityBravoUpgradeable.sol"; -import "@openzeppelin/contracts-upgradeable/governance/extensions/GovernorVotesUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/governance/extensions/GovernorVotesQuorumFractionUpgradeable.sol"; import @@ -26,9 +24,7 @@ import "../../common/OwnerUUPSUpgradable.sol"; contract TaikoGovernor is OwnerUUPSUpgradable, - GovernorUpgradeable, GovernorCompatibilityBravoUpgradeable, - GovernorVotesUpgradeable, GovernorVotesQuorumFractionUpgradeable, GovernorTimelockControlUpgradeable { @@ -42,8 +38,7 @@ contract TaikoGovernor is initializer { __OwnerUUPSUpgradable_init(); - __Governor_init("TaikoGovernor"); - __GovernorCompatibilityBravo_init(); + __Governor_init("Taiko"); __GovernorVotes_init(_token); __GovernorVotesQuorumFraction_init(4); __GovernorTimelockControl_init(_timelock); @@ -68,7 +63,8 @@ contract TaikoGovernor is override(GovernorUpgradeable, GovernorTimelockControlUpgradeable, IERC165Upgradeable) returns (bool) { - return super.supportsInterface(interfaceId); + return interfaceId == type(IGovernorUpgradeable).interfaceId + || super.supportsInterface(interfaceId); } function state(uint256 proposalId) @@ -96,6 +92,23 @@ contract TaikoGovernor is return 1_000_000_000 ether / 10_000; // 0.01% of Taiko Token } + /** + * @dev See {IGovernor-cancel}. + */ + function cancel( + address[] memory targets, + uint256[] memory values, + bytes[] memory calldatas, + bytes32 descriptionHash + ) + public + virtual + override(IGovernorUpgradeable, GovernorUpgradeable, GovernorCompatibilityBravoUpgradeable) + returns (uint256) + { + return super.cancel(targets, values, calldatas, descriptionHash); + } + function _execute( uint256 proposalId, address[] memory targets, diff --git a/packages/protocol/package.json b/packages/protocol/package.json index 552d105e431..a537bde6525 100644 --- a/packages/protocol/package.json +++ b/packages/protocol/package.json @@ -62,8 +62,8 @@ "typescript": "^5.2.2" }, "dependencies": { - "@openzeppelin/contracts-upgradeable": "4.8.2", - "@openzeppelin/contracts": "4.8.2", + "@openzeppelin/contracts-upgradeable": "4.9.5", + "@openzeppelin/contracts": "4.9.5", "forge-std": "github:foundry-rs/forge-std#v1.7.5", "ds-test": "github:dapphub/ds-test#e282159d5170298eb2455a6c05280ab5a73a4ef0", "solady": "github:Vectorized/solady#v0.0.167", diff --git a/packages/protocol/test/L1/gov/TaikoGovernor.t.sol b/packages/protocol/test/L1/gov/TaikoGovernor.t.sol index 1839017ad4a..b52a1eb50d5 100644 --- a/packages/protocol/test/L1/gov/TaikoGovernor.t.sol +++ b/packages/protocol/test/L1/gov/TaikoGovernor.t.sol @@ -91,7 +91,7 @@ contract TestTaikoGovernor is TaikoL1TestBase { assertEq(taikoGovernor.quorumDenominator(), 100, "Incorrect quorum denominator"); // GovernorUpgradeable - assertEq(taikoGovernor.name(), "TaikoGovernor", "Incorrect name"); + assertEq(taikoGovernor.name(), "Taiko", "Incorrect name"); assertEq(taikoGovernor.version(), "1", "Incorrect version"); // GovernorVotesUpgradeable diff --git a/packages/protocol/test/common/EssentialContract.t.sol b/packages/protocol/test/common/EssentialContract.t.sol index db68fe03815..4a707fb4e87 100644 --- a/packages/protocol/test/common/EssentialContract.t.sol +++ b/packages/protocol/test/common/EssentialContract.t.sol @@ -27,6 +27,11 @@ contract Target2 is Target1 { } contract TestOwnerUUPSUpgradable is TaikoTest { + /// @dev This is how we can query the admin - because from v.4.9.5 external admin() function + /// does not exist anymore. + bytes32 internal constant _ADMIN_SLOT = + 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; + function test_essential_behind_1967_proxy() external { bytes memory data = abi.encodeCall(Target1.init, ()); vm.startPrank(Alice); @@ -80,18 +85,10 @@ contract TestOwnerUUPSUpgradable is TaikoTest { vm.prank(Carol); assertEq(target.owner(), Alice); - // Only Bob can call admin() - vm.prank(Bob); - assertEq(proxy.admin(), Bob); - - // Other people, including Alice, cannot call admin() - vm.prank(Alice); - vm.expectRevert(); - proxy.admin(); - - vm.prank(Carol); - vm.expectRevert(); - proxy.admin(); + // Admin can be queried via storage slot only - no other way. + bytes32 adminSlotValue = vm.load(address(proxy), _ADMIN_SLOT); + address admin = address(uint160(uint256(adminSlotValue))); + assertEq(admin, Bob); // Alice can adjust(); vm.prank(Alice); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 52ce5b68732..d4af2c5f307 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -262,11 +262,11 @@ importers: packages/protocol: dependencies: '@openzeppelin/contracts': - specifier: 4.8.2 - version: 4.8.2 + specifier: 4.9.5 + version: 4.9.5 '@openzeppelin/contracts-upgradeable': - specifier: 4.8.2 - version: 4.8.2 + specifier: 4.9.5 + version: 4.9.5 ds-test: specifier: github:dapphub/ds-test#e282159d5170298eb2455a6c05280ab5a73a4ef0 version: github.com/dapphub/ds-test/e282159d5170298eb2455a6c05280ab5a73a4ef0 @@ -4127,12 +4127,12 @@ packages: rimraf: 3.0.2 dev: true - /@openzeppelin/contracts-upgradeable@4.8.2: - resolution: {integrity: sha512-zIggnBwemUmmt9IS73qxi+tumALxCY4QEs3zLCII78k0Gfse2hAOdAkuAeLUzvWUpneMUfFE5sGHzEUSTvn4Ag==} + /@openzeppelin/contracts-upgradeable@4.9.5: + resolution: {integrity: sha512-f7L1//4sLlflAN7fVzJLoRedrf5Na3Oal5PZfIq55NFcVZ90EpV1q5xOvL4lFvg3MNICSDr2hH0JUBxwlxcoPg==} dev: false - /@openzeppelin/contracts@4.8.2: - resolution: {integrity: sha512-kEUOgPQszC0fSYWpbh2kT94ltOJwj1qfT2DWo+zVttmGmf97JZ99LspePNaeeaLhCImaHVeBbjaQFZQn7+Zc5g==} + /@openzeppelin/contracts@4.9.5: + resolution: {integrity: sha512-ZK+W5mVhRppff9BE6YdR8CC52C8zAvsVAiWhEtQ5+oNxFE6h1WdeWo+FJSF8KKvtxxVYZ7MTP/5KoVpAU3aSWg==} dev: false /@parcel/watcher-android-arm64@2.3.0: