Skip to content

Commit

Permalink
feat(protocol): enforce initializer call with onlyInitializing modifi…
Browse files Browse the repository at this point in the history
  • Loading branch information
arularmstrong authored Feb 25, 2024
1 parent b9ee868 commit f3d7d82
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L2/CrossChainOwned.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
pragma solidity 0.8.24;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import "../common/EssentialContract.sol";
import "../bridge/IBridge.sol";

Expand Down Expand Up @@ -66,6 +65,7 @@ abstract contract CrossChainOwned is EssentialContract, IMessageInvocable {
)
internal
virtual
onlyInitializing
{
__Essential_init(_addressManager);

Expand Down
5 changes: 3 additions & 2 deletions packages/protocol/contracts/common/AddressResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

pragma solidity 0.8.24;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "./AddressManager.sol";

/// @title AddressResolver
Expand All @@ -25,7 +26,7 @@ import "./AddressManager.sol";
/// Note that the address manager should be changed using upgradability, there
/// is no setAddressManager() function go guarantee atomicness across all
/// contracts that are resolvers.
abstract contract AddressResolver {
abstract contract AddressResolver is Initializable {
address public addressManager;
uint256[49] private __gap;

Expand Down Expand Up @@ -93,7 +94,7 @@ abstract contract AddressResolver {
/// @dev Initialization method for setting up AddressManager reference.
/// @param _addressManager Address of the AddressManager.
// solhint-disable-next-line func-name-mixedcase
function __AddressResolver_init(address _addressManager) internal virtual {
function __AddressResolver_init(address _addressManager) internal virtual onlyInitializing {
if (block.chainid > type(uint64).max) {
revert RESOLVER_UNEXPECTED_CHAINID();
}
Expand Down
4 changes: 2 additions & 2 deletions packages/protocol/contracts/common/EssentialContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ abstract contract Essential1StepContract is OwnerUUPSUpgradable, AddressResolver
/// @notice Initializes the contract with an address manager.
/// @param _addressManager The address of the address manager.
// solhint-disable-next-line func-name-mixedcase
function __Essential_init(address _addressManager) internal virtual {
function __Essential_init(address _addressManager) internal virtual onlyInitializing {
__OwnerUUPSUpgradable_init();
__AddressResolver_init(_addressManager);
}

/// @notice Initializes the contract without an address manager.
// solhint-disable-next-line func-name-mixedcase
function __Essential_init() internal virtual {
function __Essential_init() internal virtual onlyInitializing {
__Essential_init(address(0));
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/common/OwnerUUPSUpgradable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ abstract contract OwnerUUPSUpgradable is UUPSUpgradeable, OwnableUpgradeable {

/// @notice Initializes the contract with an address manager.
// solhint-disable-next-line func-name-mixedcase
function __OwnerUUPSUpgradable_init() internal virtual {
function __OwnerUUPSUpgradable_init() internal virtual onlyInitializing {
__Ownable_init();
_paused = _FALSE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ abstract contract MerkleClaimable is EssentialContract {
bytes32 _merkleRoot
)
internal
onlyInitializing
{
_setConfig(_claimStart, _claimEnd, _merkleRoot);
}
Expand Down

0 comments on commit f3d7d82

Please sign in to comment.