Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(protocol): improve the usage of initializer and reinitializer #18319

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/protocol/contracts/layer1/based/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents {
bool _toPause
)
external
reinitializer(2)
initializer
{
__Essential_init(_owner, _rollupAddressManager);
LibUtils.init(state, getConfig(), _genesisBlockHash);
if (_toPause) _pause();
}

/// @notice This function shall be called by previously deployed contracts.
function init2() external onlyOwner reinitializer(2) {
// reset some previously used slots for future reuse
state.slotB.__reservedB1 = 0;
Expand Down
3 changes: 2 additions & 1 deletion packages/protocol/contracts/shared/bridge/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ contract Bridge is EssentialContract, IBridge {
/// @notice Initializes the contract.
/// @param _owner The owner of this contract. msg.sender will be used if this value is zero.
/// @param _sharedAddressManager The address of the {AddressManager} contract.
function init(address _owner, address _sharedAddressManager) external reinitializer(2) {
function init(address _owner, address _sharedAddressManager) external initializer {
__Essential_init(_owner, _sharedAddressManager);
}

/// @notice This function shall be called by previously deployed contracts.
function init2() external onlyOwner reinitializer(2) {
// reset some previously used slots for future reuse
__reserved1 = 0;
Expand Down
3 changes: 2 additions & 1 deletion packages/protocol/contracts/shared/common/AddressManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ contract AddressManager is EssentialContract, IAddressManager {

/// @notice Initializes the contract.
/// @param _owner The owner of this contract.
function init(address _owner) external reinitializer(2) {
function init(address _owner) external initializer {
__Essential_init(_owner, address(this));
}

/// @notice This function shall be called by previously deployed contracts.
function init2() external onlyOwner reinitializer(2) {
addressManager = address(this);
}
Expand Down
32 changes: 12 additions & 20 deletions packages/protocol/contracts/shared/tokenvault/BridgedERC20V2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ contract BridgedERC20V2 is BridgedERC20, IERC20PermitUpgradeable, EIP712Upgradea
error BTOKEN_INVALID_SIG();

/// @inheritdoc IBridgedERC20Initializable
/// @dev Calling this function will change the initialized version to 2.
/// @dev This function is called when the bridge deploys a new bridged ERC20 token, so this
/// function must also cover the logic in init2(), we use
/// `reinitializer(2)` instead of `initializer`.
function init(
address _owner,
address _sharedAddressManager,
Expand All @@ -48,31 +50,27 @@ contract BridgedERC20V2 is BridgedERC20, IERC20PermitUpgradeable, EIP712Upgradea
LibBridgedToken.validateInputs(_srcToken, _srcChainId);
__Essential_init(_owner, _sharedAddressManager);
__ERC20_init(_name, _symbol);
__EIP712_init_unchained(_name, "1");

// Set contract properties
srcToken = _srcToken;
srcChainId = _srcChainId;
__srcDecimals = _decimals;

// Cover logics from `init2()`
__EIP712_init_unchained(_name, "1");
}

/// @dev This function shall be called when upgrading a deployed contract from {BridgedERC20} to
/// {BridgedERC20V2}.
/// @notice This function shall be called by previously deployed contracts.
function init2() external reinitializer(2) {
__EIP712_init_unchained(name(), "1");
}
/**
* @inheritdoc IERC20PermitUpgradeable
*/
// solhint-disable-next-line func-name-mixedcase

/// @inheritdoc IERC20PermitUpgradeable
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view override returns (bytes32) {
return _domainSeparatorV4();
}

/**
* @inheritdoc IERC20PermitUpgradeable
*/
/// @inheritdoc IERC20PermitUpgradeable
function permit(
address owner,
address spender,
Expand Down Expand Up @@ -100,9 +98,7 @@ contract BridgedERC20V2 is BridgedERC20, IERC20PermitUpgradeable, EIP712Upgradea
_approve(owner, spender, value);
}

/**
* @inheritdoc IERC20PermitUpgradeable
*/
/// @inheritdoc IERC20PermitUpgradeable
function nonces(address owner) public view virtual override returns (uint256) {
return _nonces[owner].current();
}
Expand All @@ -113,11 +109,7 @@ contract BridgedERC20V2 is BridgedERC20, IERC20PermitUpgradeable, EIP712Upgradea
|| super.supportsInterface(_interfaceId);
}

/**
* @dev "Consume a nonce": return the current value and increment.
*
* _Available since v4.1._
*/
/// @dev "Consume a nonce": return the current value and increment.
function _useNonce(address owner) internal virtual returns (uint256 current) {
CountersUpgradeable.Counter storage nonce = _nonces[owner];
current = nonce.current();
Expand Down
4 changes: 0 additions & 4 deletions packages/protocol/test/shared/thirdparty/Multicall3.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* Submitted for verification at taikoscan.io on 2024-05-30
*/

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

Expand Down