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

fix(protocol): set initial owner in the init() function without acceptOwnership #16071

Merged
merged 16 commits into from
Feb 26, 2024
28 changes: 17 additions & 11 deletions packages/protocol/contracts/L1/TaikoL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,19 @@ contract TaikoL1 is EssentialContract, ITaikoL1, ITierProvider, TaikoEvents, Tai
if (!_inNonReentrant()) revert L1_RECEIVE_DISABLED();
}

/// @notice Initializes the rollup.
/// @param _addressManager The {AddressManager} address.
/// @notice Initializes the contract.
/// @param _owner The owner of this contract. msg.sender will be used if this value is zero.
/// @param _addressManager The address of the {AddressManager} contract.
/// @param _genesisBlockHash The block hash of the genesis block.
function init(address _addressManager, bytes32 _genesisBlockHash) external initializer {
__Essential_init(_addressManager);
function init(
address _owner,
address _addressManager,
bytes32 _genesisBlockHash
)
external
initializer
{
__Essential_init(_owner, _addressManager);
LibVerifying.init(state, getConfig(), _genesisBlockHash);
}

Expand All @@ -70,8 +78,7 @@ contract TaikoL1 is EssentialContract, ITaikoL1, ITierProvider, TaikoEvents, Tai
{
TaikoData.Config memory config = getConfig();

(meta, depositsProcessed) =
LibProposing.proposeBlock(state, config, AddressResolver(this), params, txList);
(meta, depositsProcessed) = LibProposing.proposeBlock(state, config, this, params, txList);

if (!state.slotB.provingPaused) {
_verifyBlocks(config, config.maxBlocksToVerifyPerProposal);
Expand All @@ -98,8 +105,7 @@ contract TaikoL1 is EssentialContract, ITaikoL1, ITierProvider, TaikoEvents, Tai

TaikoData.Config memory config = getConfig();

uint8 maxBlocksToVerify =
LibProving.proveBlock(state, config, AddressResolver(this), meta, tran, proof);
uint8 maxBlocksToVerify = LibProving.proveBlock(state, config, this, meta, tran, proof);

_verifyBlocks(config, maxBlocksToVerify);
}
Expand All @@ -120,11 +126,11 @@ contract TaikoL1 is EssentialContract, ITaikoL1, ITierProvider, TaikoEvents, Tai
/// @param recipient Address of the recipient for the deposited Ether on
/// Layer 2.
function depositEtherToL2(address recipient) external payable nonReentrant whenNotPaused {
LibDepositing.depositEtherToL2(state, getConfig(), AddressResolver(this), recipient);
LibDepositing.depositEtherToL2(state, getConfig(), this, recipient);
}

function unpause() public override {
OwnerUUPSUpgradable.unpause(); // permission checked inside
super.unpause(); // permission checked inside
state.slotB.lastUnpausedAt = uint64(block.timestamp);
}

Expand Down Expand Up @@ -252,7 +258,7 @@ contract TaikoL1 is EssentialContract, ITaikoL1, ITierProvider, TaikoEvents, Tai
internal
whenProvingNotPaused
{
LibVerifying.verifyBlocks(state, config, AddressResolver(this), maxBlocksToVerify);
LibVerifying.verifyBlocks(state, config, this, maxBlocksToVerify);
}

function _authorizePause(address)
Expand Down
6 changes: 4 additions & 2 deletions packages/protocol/contracts/L1/TaikoToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,21 @@ contract TaikoToken is EssentialContract, ERC20SnapshotUpgradeable, ERC20VotesUp

error TKO_INVALID_ADDR();

/// @notice Initializes the TaikoToken contract and mints initial tokens.
/// @notice Initializes the contract.
/// @param _owner The owner of this contract. msg.sender will be used if this value is zero.
/// @param _name The name of the token.
/// @param _symbol The symbol of the token.
/// @param _recipient The address to receive initial token minting.
function init(
address _owner,
string calldata _name,
string calldata _symbol,
address _recipient
)
public
initializer
{
__Essential_init();
__Essential_init(_owner);
__ERC20_init(_name, _symbol);
__ERC20Snapshot_init();
__ERC20Votes_init();
Expand Down
11 changes: 8 additions & 3 deletions packages/protocol/contracts/L1/gov/TaikoGovernor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import
"@openzeppelin/contracts-upgradeable/governance/extensions/GovernorVotesQuorumFractionUpgradeable.sol";
import
"@openzeppelin/contracts-upgradeable/governance/extensions/GovernorTimelockControlUpgradeable.sol";
import "../../common/OwnerUUPSUpgradable.sol";
import "../../common/EssentialContract.sol";

contract TaikoGovernor is
OwnerUUPSUpgradable,
EssentialContract,
GovernorCompatibilityBravoUpgradeable,
GovernorVotesUpgradeable,
GovernorVotesQuorumFractionUpgradeable,
Expand All @@ -35,14 +35,19 @@ contract TaikoGovernor is

error TG_INVALID_SIGNATURES_LENGTH();

/// @notice Initializes the contract.
/// @param _owner The owner of this contract. msg.sender will be used if this value is zero.
/// @param _token The Taiko token.
/// @param _timelock The timelock contract address.
function init(
address _owner,
IVotesUpgradeable _token,
TimelockControllerUpgradeable _timelock
)
external
initializer
{
__OwnerUUPSUpgradable_init();
__Essential_init(_owner);
__Governor_init("TaikoGovernor");
__GovernorCompatibilityBravo_init();
__GovernorVotes_init(_token);
Expand Down
11 changes: 7 additions & 4 deletions packages/protocol/contracts/L1/gov/TaikoTimelockController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
pragma solidity 0.8.24;

import "@openzeppelin/contracts-upgradeable/governance/TimelockControllerUpgradeable.sol";
import "../../common/OwnerUUPSUpgradable.sol";
import "../../common/EssentialContract.sol";

contract TaikoTimelockController is OwnerUUPSUpgradable, TimelockControllerUpgradeable {
contract TaikoTimelockController is EssentialContract, TimelockControllerUpgradeable {
uint256[50] private __gap;

function init(uint256 minDelay) external initializer {
__OwnerUUPSUpgradable_init();
/// @notice Initializes the contract.
/// @param _owner The owner of this contract. msg.sender will be used if this value is zero.
/// @param minDelay The minimal delay.
function init(address _owner, uint256 minDelay) external initializer {
__Essential_init(_owner);
address[] memory nil = new address[](0);
__TimelockController_init(minDelay, nil, nil, owner());
}
Expand Down
7 changes: 5 additions & 2 deletions packages/protocol/contracts/L1/hooks/AssignmentHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ contract AssignmentHook is EssentialContract, IHook {
error HOOK_ASSIGNMENT_INSUFFICIENT_FEE();
error HOOK_TIER_NOT_FOUND();

function init(address _addressManager) external initializer {
__Essential_init(_addressManager);
/// @notice Initializes the contract.
/// @param _owner The owner of this contract. msg.sender will be used if this value is zero.
/// @param _addressManager The address of the {AddressManager} contract.
function init(address _owner, address _addressManager) external initializer {
__Essential_init(_owner, _addressManager);
}

function onBlockProposed(
Expand Down
4 changes: 2 additions & 2 deletions packages/protocol/contracts/L1/libs/LibDepositing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

pragma solidity 0.8.24;

import "../../common/AddressResolver.sol";
import "../../common/IAddressResolver.sol";
import "../../libs/LibAddress.sol";
import "../../libs/LibMath.sol";
import "../TaikoData.sol";
Expand All @@ -36,7 +36,7 @@ library LibDepositing {
function depositEtherToL2(
TaikoData.State storage state,
TaikoData.Config memory config,
AddressResolver resolver,
IAddressResolver resolver,
address recipient
)
external
Expand Down
6 changes: 3 additions & 3 deletions packages/protocol/contracts/L1/libs/LibProposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
pragma solidity 0.8.24;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../../common/AddressResolver.sol";
import "../../common/IAddressResolver.sol";
import "../../libs/LibAddress.sol";
import "../hooks/IHook.sol";
import "../tiers/ITierProvider.sol";
Expand Down Expand Up @@ -62,7 +62,7 @@ library LibProposing {
function proposeBlock(
TaikoData.State storage state,
TaikoData.Config memory config,
AddressResolver resolver,
IAddressResolver resolver,
bytes calldata data,
bytes calldata txList
)
Expand Down Expand Up @@ -291,7 +291,7 @@ library LibProposing {

function _isProposerPermitted(
TaikoData.SlotB memory slotB,
AddressResolver resolver
IAddressResolver resolver
)
private
view
Expand Down
4 changes: 2 additions & 2 deletions packages/protocol/contracts/L1/libs/LibProving.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
pragma solidity 0.8.24;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../../common/AddressResolver.sol";
import "../../common/IAddressResolver.sol";
import "../../libs/LibMath.sol";
import "../../verifiers/IVerifier.sol";
import "../tiers/ITierProvider.sol";
Expand Down Expand Up @@ -78,7 +78,7 @@ library LibProving {
function proveBlock(
TaikoData.State storage state,
TaikoData.Config memory config,
AddressResolver resolver,
IAddressResolver resolver,
TaikoData.BlockMetadata memory meta,
TaikoData.Transition memory tran,
TaikoData.TierProof memory proof
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/libs/LibUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

pragma solidity 0.8.24;

import "../../common/AddressResolver.sol";
import "../../common/IAddressResolver.sol";
import "../../signal/ISignalService.sol";
import "../../signal/LibSignals.sol";
import "../TaikoData.sol";
Expand Down
6 changes: 3 additions & 3 deletions packages/protocol/contracts/L1/libs/LibVerifying.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
pragma solidity 0.8.24;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../../common/AddressResolver.sol";
import "../../common/IAddressResolver.sol";
import "../../libs/LibMath.sol";
import "../../signal/ISignalService.sol";
import "../../signal/LibSignals.sol";
Expand Down Expand Up @@ -108,7 +108,7 @@ library LibVerifying {
function verifyBlocks(
TaikoData.State storage state,
TaikoData.Config memory config,
AddressResolver resolver,
IAddressResolver resolver,
uint64 maxBlocksToVerify
)
internal
Expand Down Expand Up @@ -246,7 +246,7 @@ library LibVerifying {

function _syncChainData(
TaikoData.Config memory config,
AddressResolver resolver,
IAddressResolver resolver,
uint64 lastVerifiedBlockId,
bytes32 stateRoot
)
Expand Down
9 changes: 5 additions & 4 deletions packages/protocol/contracts/L1/provers/GuardianProver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ contract GuardianProver is Guardians {
address indexed addr, uint256 indexed blockId, bytes32 blockHash, bool approved
);

/// @notice Initializes the contract with the provided address manager.
/// @param _addressManager The address of the address manager contract.
function init(address _addressManager) external initializer {
__Essential_init(_addressManager);
/// @notice Initializes the contract.
/// @param _owner The owner of this contract. msg.sender will be used if this value is zero.
/// @param _addressManager The address of the {AddressManager} contract.
function init(address _owner, address _addressManager) external initializer {
__Essential_init(_owner, _addressManager);
}

/// @dev Called by guardians to approve a guardian proof
Expand Down
7 changes: 4 additions & 3 deletions packages/protocol/contracts/L1/tiers/DevnetTierProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import "./ITierProvider.sol";
contract DevnetTierProvider is EssentialContract, ITierProvider {
uint256[50] private __gap;

/// @notice Initializes the contract with the provided address manager.
function init() external initializer {
__Essential_init();
/// @notice Initializes the contract.
/// @param _owner The owner of this contract. msg.sender will be used if this value is zero.
function init(address _owner) external initializer {
__Essential_init(_owner);
}

function getTier(uint16 tierId) public pure override returns (ITierProvider.Tier memory) {
Expand Down
7 changes: 4 additions & 3 deletions packages/protocol/contracts/L1/tiers/MainnetTierProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import "./ITierProvider.sol";
contract MainnetTierProvider is EssentialContract, ITierProvider {
uint256[50] private __gap;

/// @notice Initializes the contract with the provided address manager.
function init() external initializer {
__Essential_init();
/// @notice Initializes the contract.
/// @param _owner The owner of this contract. msg.sender will be used if this value is zero.
function init(address _owner) external initializer {
__Essential_init(_owner);
}

function getTier(uint16 tierId) public pure override returns (ITierProvider.Tier memory) {
Expand Down
7 changes: 4 additions & 3 deletions packages/protocol/contracts/L1/tiers/TestnetTierProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import "./ITierProvider.sol";
contract TestnetTierProvider is EssentialContract, ITierProvider {
uint256[50] private __gap;

/// @notice Initializes the contract with the provided address manager.
function init() external initializer {
__Essential_init();
/// @notice Initializes the contract.
/// @param _owner The owner of this contract. msg.sender will be used if this value is zero.
function init(address _owner) external initializer {
__Essential_init(_owner);
}

function getTier(uint16 tierId) public pure override returns (ITierProvider.Tier memory) {
Expand Down
7 changes: 4 additions & 3 deletions packages/protocol/contracts/L2/CrossChainOwned.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,20 @@ abstract contract CrossChainOwned is EssentialContract, IMessageInvocable {
}

/// @notice Initializes the contract.
/// @param _addressManager The address of the address manager.
/// @param _owner The owner of this contract. msg.sender will be used if this value is zero.
/// @param _addressManager The address of the {AddressManager} contract.
/// @param _ownerChainId The owner's deployment chain ID.
// solhint-disable-next-line func-name-mixedcase
function __CrossChainOwned_init(
address _owner,
address _addressManager,
uint64 _ownerChainId
)
internal
virtual
onlyInitializing
{
__Essential_init(_addressManager);

__Essential_init(_owner, _addressManager);
if (_ownerChainId == 0 || _ownerChainId == block.chainid) {
revert XCO_INVALID_OWNER_CHAINID();
}
Expand Down
8 changes: 5 additions & 3 deletions packages/protocol/contracts/L2/TaikoL2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,21 @@ contract TaikoL2 is CrossChainOwned {
error L2_PUBLIC_INPUT_HASH_MISMATCH();
error L2_TOO_LATE();

/// @notice Initializes the TaikoL2 contract.
/// @param _addressManager Address of the AddressManager contract.
/// @notice Initializes the contract.
/// @param _owner The owner of this contract. msg.sender will be used if this value is zero.
/// @param _addressManager The address of the {AddressManager} contract.
/// @param _l1ChainId The ID of the base layer.
/// @param _gasExcess The initial gasExcess.
function init(
address _owner,
address _addressManager,
uint64 _l1ChainId,
uint64 _gasExcess
)
external
initializer
{
__CrossChainOwned_init(_addressManager, _l1ChainId);
__CrossChainOwned_init(_owner, _addressManager, _l1ChainId);

if (block.chainid <= 1 || block.chainid > type(uint64).max) {
revert L2_INVALID_CHAIN_ID();
Expand Down
5 changes: 3 additions & 2 deletions packages/protocol/contracts/bridge/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ contract Bridge is EssentialContract, IBridge {
receive() external payable { }

/// @notice Initializes the contract.
/// @param _owner The owner of this contract. msg.sender will be used if this value is zero.
/// @param _addressManager The address of the {AddressManager} contract.
function init(address _addressManager) external initializer {
__Essential_init(_addressManager);
function init(address _owner, address _addressManager) external initializer {
__Essential_init(_owner, _addressManager);
}

/// @notice Suspend or unsuspend invocation for a list of messages.
Expand Down
Loading
Loading