From eb002d75e0cc514c4d5978d8196bf696df71f302 Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Tue, 23 Apr 2024 11:17:05 +0800 Subject: [PATCH 1/6] remove ERC20SnapshotUpgradeable --- packages/protocol/contracts/L1/TaikoToken.sol | 53 ++---------- .../contracts/tokenvault/BridgedERC20.sol | 82 +++---------------- 2 files changed, 21 insertions(+), 114 deletions(-) diff --git a/packages/protocol/contracts/L1/TaikoToken.sol b/packages/protocol/contracts/L1/TaikoToken.sol index 5363ce6afb6..40300ec94bc 100644 --- a/packages/protocol/contracts/L1/TaikoToken.sol +++ b/packages/protocol/contracts/L1/TaikoToken.sol @@ -2,18 +2,24 @@ pragma solidity 0.8.24; import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol"; -import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20SnapshotUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20VotesUpgradeable.sol"; import "../common/EssentialContract.sol"; import "../common/LibStrings.sol"; +/// @notice TaikoToken was `EssentialContract, ERC20SnapshotUpgradeable, ERC20VotesUpgradeable`. +/// We use this contract to take 50 more slots to remove `ERC20SnapshotUpgradeable` from the parent +/// contract list. +abstract contract EssentialContract_ is EssentialContract { + uint256[50] private __gap; +} + /// @title TaikoToken /// @notice The TaikoToken (TKO), in the protocol is used for prover collateral /// in the form of bonds. It is an ERC20 token with 18 decimal places of /// precision. /// @dev Labeled in AddressResolver as "taiko_token" /// @custom:security-contact security@taiko.xyz -contract TaikoToken is EssentialContract, ERC20SnapshotUpgradeable, ERC20VotesUpgradeable { +contract TaikoToken is EssentialContract_, ERC20VotesUpgradeable { uint256[50] private __gap; error TKO_INVALID_ADDR(); @@ -37,7 +43,6 @@ contract TaikoToken is EssentialContract, ERC20SnapshotUpgradeable, ERC20VotesUp __Essential_init(_owner, _addressManager); __Context_init_unchained(); __ERC20_init(_name, _symbol); - __ERC20Snapshot_init(); __ERC20Votes_init(); __ERC20Permit_init(_name); @@ -78,46 +83,4 @@ contract TaikoToken is EssentialContract, ERC20SnapshotUpgradeable, ERC20VotesUp if (_to == address(this)) revert TKO_INVALID_ADDR(); return super.transferFrom(_from, _to, _amount); } - - function _beforeTokenTransfer( - address _from, - address _to, - uint256 _amount - ) - internal - override(ERC20Upgradeable, ERC20SnapshotUpgradeable) - { - return super._beforeTokenTransfer(_from, _to, _amount); - } - - function _afterTokenTransfer( - address _from, - address _to, - uint256 _amount - ) - internal - override(ERC20Upgradeable, ERC20VotesUpgradeable) - { - return super._afterTokenTransfer(_from, _to, _amount); - } - - function _mint( - address _to, - uint256 _amount - ) - internal - override(ERC20Upgradeable, ERC20VotesUpgradeable) - { - return super._mint(_to, _amount); - } - - function _burn( - address _from, - uint256 _amount - ) - internal - override(ERC20Upgradeable, ERC20VotesUpgradeable) - { - return super._burn(_from, _amount); - } } diff --git a/packages/protocol/contracts/tokenvault/BridgedERC20.sol b/packages/protocol/contracts/tokenvault/BridgedERC20.sol index 98e40f864dc..b4516865845 100644 --- a/packages/protocol/contracts/tokenvault/BridgedERC20.sol +++ b/packages/protocol/contracts/tokenvault/BridgedERC20.sol @@ -1,22 +1,22 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.24; -import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol"; -import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20SnapshotUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20VotesUpgradeable.sol"; import "./LibBridgedToken.sol"; import "./BridgedERC20Base.sol"; +/// @notice BridgedERC20 was `BridgedERC20Base, ERC20SnapshotUpgradeable, ERC20VotesUpgradeable`. +/// We use this contract to take 50 more slots to remove `ERC20SnapshotUpgradeable` from the parent +/// contract list. +abstract contract BridgedERC20Base_ is BridgedERC20Base { + uint256[50] private __gap; +} + /// @title BridgedERC20 /// @notice An upgradeable ERC20 contract that represents tokens bridged from /// another chain. /// @custom:security-contact security@taiko.xyz -contract BridgedERC20 is - BridgedERC20Base, - IERC20MetadataUpgradeable, - ERC20SnapshotUpgradeable, - ERC20VotesUpgradeable -{ +contract BridgedERC20 is BridgedERC20Base_, ERC20VotesUpgradeable { /// @dev Slot 1. address public srcToken; @@ -26,7 +26,7 @@ contract BridgedERC20 is uint256 public srcChainId; /// @dev Slot 3. - address public snapshooter; + address private __reserved1; uint256[47] private __gap; @@ -56,7 +56,6 @@ contract BridgedERC20 is LibBridgedToken.validateInputs(_srcToken, _srcChainId, _symbol, _name); __Essential_init(_owner, _addressManager); __ERC20_init(_name, _symbol); - __ERC20Snapshot_init(); __ERC20Votes_init(); __ERC20Permit_init(_name); @@ -68,34 +67,19 @@ contract BridgedERC20 is /// @notice Gets the name of the token. /// @return The name. - function name() - public - view - override(ERC20Upgradeable, IERC20MetadataUpgradeable) - returns (string memory) - { + function name() public view override returns (string memory) { return LibBridgedToken.buildName(super.name(), srcChainId); } /// @notice Gets the symbol of the bridged token. /// @return The symbol. - function symbol() - public - view - override(ERC20Upgradeable, IERC20MetadataUpgradeable) - returns (string memory) - { + function symbol() public view override returns (string memory) { return LibBridgedToken.buildSymbol(super.symbol()); } /// @notice Gets the number of decimal places of the token. /// @return The number of decimal places of the token. - function decimals() - public - view - override(ERC20Upgradeable, IERC20MetadataUpgradeable) - returns (uint8) - { + function decimals() public view override returns (uint8) { return __srcDecimals; } @@ -114,49 +98,9 @@ contract BridgedERC20 is return _burn(_from, _amount); } - /// @dev For ERC20SnapshotUpgradeable and ERC20VotesUpgradeable, need to implement the following - /// functions - function _beforeTokenTransfer( - address _from, - address _to, - uint256 _amount - ) - internal - override(ERC20Upgradeable, ERC20SnapshotUpgradeable) - { + function _beforeTokenTransfer(address _from, address _to, uint256 _amount) internal override { if (_to == address(this)) revert BTOKEN_CANNOT_RECEIVE(); if (paused()) revert INVALID_PAUSE_STATUS(); return super._beforeTokenTransfer(_from, _to, _amount); } - - function _afterTokenTransfer( - address _from, - address _to, - uint256 _amount - ) - internal - override(ERC20Upgradeable, ERC20VotesUpgradeable) - { - return super._afterTokenTransfer(_from, _to, _amount); - } - - function _mint( - address _to, - uint256 _amount - ) - internal - override(ERC20Upgradeable, ERC20VotesUpgradeable) - { - return super._mint(_to, _amount); - } - - function _burn( - address _from, - uint256 _amount - ) - internal - override(ERC20Upgradeable, ERC20VotesUpgradeable) - { - return super._burn(_from, _amount); - } } From 17381e47613d1f5fc31be9c83713d4c6fddb0929 Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Tue, 23 Apr 2024 11:19:21 +0800 Subject: [PATCH 2/6] Update BridgedERC20.sol --- packages/protocol/contracts/tokenvault/BridgedERC20.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/contracts/tokenvault/BridgedERC20.sol b/packages/protocol/contracts/tokenvault/BridgedERC20.sol index b4516865845..e081b3c24d7 100644 --- a/packages/protocol/contracts/tokenvault/BridgedERC20.sol +++ b/packages/protocol/contracts/tokenvault/BridgedERC20.sol @@ -26,7 +26,7 @@ contract BridgedERC20 is BridgedERC20Base_, ERC20VotesUpgradeable { uint256 public srcChainId; /// @dev Slot 3. - address private __reserved1; + address private __deprecated1; uint256[47] private __gap; From cf007b8ee5c7a167da8e67e41ce96acd4163a1ae Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Tue, 23 Apr 2024 12:06:28 +0800 Subject: [PATCH 3/6] Update BridgedERC721.sol --- packages/protocol/contracts/tokenvault/BridgedERC721.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/protocol/contracts/tokenvault/BridgedERC721.sol b/packages/protocol/contracts/tokenvault/BridgedERC721.sol index 57ed0aacf9a..3d9eb0c1968 100644 --- a/packages/protocol/contracts/tokenvault/BridgedERC721.sol +++ b/packages/protocol/contracts/tokenvault/BridgedERC721.sol @@ -84,13 +84,13 @@ contract BridgedERC721 is EssentialContract, ERC721Upgradeable { /// @notice Gets the name of the token. /// @return The name. - function name() public view override(ERC721Upgradeable) returns (string memory) { + function name() public view override returns (string memory) { return LibBridgedToken.buildName(super.name(), srcChainId); } /// @notice Gets the symbol of the bridged token. /// @return The symbol. - function symbol() public view override(ERC721Upgradeable) returns (string memory) { + function symbol() public view override returns (string memory) { return LibBridgedToken.buildSymbol(super.symbol()); } From 9ad70c9aa58f18ec38f8e6e29901067bddf96960 Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Tue, 23 Apr 2024 12:47:56 +0800 Subject: [PATCH 4/6] Update BridgedERC20.sol --- .../contracts/tokenvault/BridgedERC20.sol | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/protocol/contracts/tokenvault/BridgedERC20.sol b/packages/protocol/contracts/tokenvault/BridgedERC20.sol index 8023b97017d..fd47ab3f51f 100644 --- a/packages/protocol/contracts/tokenvault/BridgedERC20.sol +++ b/packages/protocol/contracts/tokenvault/BridgedERC20.sol @@ -95,4 +95,24 @@ contract BridgedERC20 is BridgedERC20Base_, ERC20VotesUpgradeable { if (paused()) revert INVALID_PAUSE_STATUS(); return super._beforeTokenTransfer(_from, _to, _amount); } + + function _mint( + address _to, + uint256 _amount + ) + internal + override(BridgedERC20Base, ERC20VotesUpgradeable) + { + return super._mint(_to, _amount); + } + + function _burn( + address _from, + uint256 _amount + ) + internal + override(BridgedERC20Base, ERC20VotesUpgradeable) + { + return super._burn(_from, _amount); + } } From 38de3db13aa8d05a93d88e8cb858163b4984f404 Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Tue, 23 Apr 2024 12:51:08 +0800 Subject: [PATCH 5/6] fix --- packages/protocol/contracts/L1/TaikoToken.sol | 2 +- packages/protocol/contracts/tokenvault/BridgedERC20.sol | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/protocol/contracts/L1/TaikoToken.sol b/packages/protocol/contracts/L1/TaikoToken.sol index 40300ec94bc..8caff3bf839 100644 --- a/packages/protocol/contracts/L1/TaikoToken.sol +++ b/packages/protocol/contracts/L1/TaikoToken.sol @@ -10,7 +10,7 @@ import "../common/LibStrings.sol"; /// We use this contract to take 50 more slots to remove `ERC20SnapshotUpgradeable` from the parent /// contract list. abstract contract EssentialContract_ is EssentialContract { - uint256[50] private __gap; + uint256[50] private __slots_previously_used_by_ERC20SnapshotUpgradeable; } /// @title TaikoToken diff --git a/packages/protocol/contracts/tokenvault/BridgedERC20.sol b/packages/protocol/contracts/tokenvault/BridgedERC20.sol index fd47ab3f51f..37f15b9a416 100644 --- a/packages/protocol/contracts/tokenvault/BridgedERC20.sol +++ b/packages/protocol/contracts/tokenvault/BridgedERC20.sol @@ -9,7 +9,7 @@ import "./BridgedERC20Base.sol"; /// We use this contract to take 50 more slots to remove `ERC20SnapshotUpgradeable` from the parent /// contract list. abstract contract BridgedERC20Base_ is BridgedERC20Base { - uint256[50] private __gap; + uint256[50] private __slots_previously_used_by_ERC20SnapshotUpgradeable; } /// @title BridgedERC20 From 9688fa979e2cc097b5b482837a373a791b0d19a4 Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Tue, 23 Apr 2024 15:33:13 +0800 Subject: [PATCH 6/6] add a comment --- packages/protocol/contracts/L1/TaikoToken.sol | 1 + packages/protocol/contracts/tokenvault/BridgedERC20.sol | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/protocol/contracts/L1/TaikoToken.sol b/packages/protocol/contracts/L1/TaikoToken.sol index 8caff3bf839..6557e040ee7 100644 --- a/packages/protocol/contracts/L1/TaikoToken.sol +++ b/packages/protocol/contracts/L1/TaikoToken.sol @@ -9,6 +9,7 @@ import "../common/LibStrings.sol"; /// @notice TaikoToken was `EssentialContract, ERC20SnapshotUpgradeable, ERC20VotesUpgradeable`. /// We use this contract to take 50 more slots to remove `ERC20SnapshotUpgradeable` from the parent /// contract list. +/// We can simplify the code since we no longer need to maintain upgradability with Hekla. abstract contract EssentialContract_ is EssentialContract { uint256[50] private __slots_previously_used_by_ERC20SnapshotUpgradeable; } diff --git a/packages/protocol/contracts/tokenvault/BridgedERC20.sol b/packages/protocol/contracts/tokenvault/BridgedERC20.sol index 37f15b9a416..be981e07593 100644 --- a/packages/protocol/contracts/tokenvault/BridgedERC20.sol +++ b/packages/protocol/contracts/tokenvault/BridgedERC20.sol @@ -8,6 +8,7 @@ import "./BridgedERC20Base.sol"; /// @notice BridgedERC20 was `BridgedERC20Base, ERC20SnapshotUpgradeable, ERC20VotesUpgradeable`. /// We use this contract to take 50 more slots to remove `ERC20SnapshotUpgradeable` from the parent /// contract list. +/// We can simplify the code since we no longer need to maintain upgradability with Hekla. abstract contract BridgedERC20Base_ is BridgedERC20Base { uint256[50] private __slots_previously_used_by_ERC20SnapshotUpgradeable; }