From 8bf31bcd2b0bddea114db05310ffb662f0551a0a Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Mon, 13 Jan 2025 10:44:18 +0800 Subject: [PATCH] rebase --- .../contracts/layer1/based/TaikoInbox.sol | 2 +- .../contracts/layer1/fork/ForkManager.sol | 63 ------------------- .../layer1/fork/PacayaForkManager.sol | 32 ---------- 3 files changed, 1 insertion(+), 96 deletions(-) delete mode 100644 packages/protocol/contracts/layer1/fork/ForkManager.sol delete mode 100644 packages/protocol/contracts/layer1/fork/PacayaForkManager.sol diff --git a/packages/protocol/contracts/layer1/based/TaikoInbox.sol b/packages/protocol/contracts/layer1/based/TaikoInbox.sol index 2048e561d70..1dbc92e3389 100644 --- a/packages/protocol/contracts/layer1/based/TaikoInbox.sol +++ b/packages/protocol/contracts/layer1/based/TaikoInbox.sol @@ -371,7 +371,7 @@ abstract contract TaikoInbox is EssentialContract, ITaikoInbox, ITaiko, IFork { } function isForkActive() external view override returns (bool) { - return state.stats2.numBlocks >= getConfigV3().forkHeights.pacaya; + return state.stats2.numBatches >= getConfig().forkHeights.pacaya; } // Public functions ------------------------------------------------------------------------- diff --git a/packages/protocol/contracts/layer1/fork/ForkManager.sol b/packages/protocol/contracts/layer1/fork/ForkManager.sol deleted file mode 100644 index 585d0251a6a..00000000000 --- a/packages/protocol/contracts/layer1/fork/ForkManager.sol +++ /dev/null @@ -1,63 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -import "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol"; -import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol"; - -import "../based/IFork.sol"; - -/// @title ForkManager -/// @custom:security-contact security@taiko.xyz -/// @notice This contract serves as a base contract for managing up to two forks within the Taiko -/// protocol. By default, all function calls are routed to the newFork address. -/// Sub-contracts should override the shouldRouteToOldFork function to route specific function calls -/// to the old fork address. -/// These sub-contracts should be placed between a proxy and the actual fork implementations. When -/// calling upgradeTo, the proxy should always upgrade to a new ForkManager implementation, not an -/// actual fork implementation. -/// It is strongly advised to name functions differently for the same functionality across the two -/// forks, as it is not possible to route the same function to two different forks. -/// -/// +--> newFork -/// PROXY -> FORK_MANAGER --| -/// +--> oldFork -contract ForkManager is UUPSUpgradeable, Ownable2StepUpgradeable { - address public immutable oldFork; - address public immutable newFork; - - error InvalidParams(); - - constructor(address _oldFork, address _currFork) { - require(_currFork != address(0) && _currFork != _oldFork, InvalidParams()); - oldFork = _oldFork; - newFork = _currFork; - } - - fallback() external payable virtual { - _fallback(); - } - - receive() external payable virtual { - _fallback(); - } - - function isForkRouter() public pure returns (bool) { - return true; - } - - function _fallback() internal virtual { - address fork = IFork(newFork).isForkActive() ? newFork : oldFork; - - assembly { - calldatacopy(0, 0, calldatasize()) - let result := delegatecall(gas(), fork, 0, calldatasize(), 0, 0) - returndatacopy(0, 0, returndatasize()) - - switch result - case 0 { revert(0, returndatasize()) } - default { return(0, returndatasize()) } - } - } - - function _authorizeUpgrade(address) internal virtual override onlyOwner { } -} diff --git a/packages/protocol/contracts/layer1/fork/PacayaForkManager.sol b/packages/protocol/contracts/layer1/fork/PacayaForkManager.sol deleted file mode 100644 index 51fa5d1e2a3..00000000000 --- a/packages/protocol/contracts/layer1/fork/PacayaForkManager.sol +++ /dev/null @@ -1,32 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.24; - -import "./ForkManager.sol"; - -/// @title OntakeSelectors -/// @custom:security-contact security@taiko.xyz -/// @notice This interface is used to route specific transactions to the v2 version of the contract. -/// @dev Function selectors are calculated independently of the return type. Therefore, -/// we have omitted the `returns` statements from all functions to avoid maintaining -/// the return struct definitions. -interface OntakeSelectors { - function proposeBlocksV2(bytes[] calldata, bytes[] calldata) external; - function proveBlocks(uint64[] calldata, bytes[] calldata, bytes calldata) external; - function getBlockV2(uint64) external; - function getTransition(uint64, uint32) external; - function getConfig() external; -} - -/// @title PacayaForkManager (Ontake -> Pacaya) -/// @custom:security-contact security@taiko.xyz -contract PacayaForkManager is ForkManager { - constructor(address _ontakeFork, address _pacayaFork) ForkManager(_ontakeFork, _pacayaFork) { } - - function shouldRouteToOldFork(bytes4 _selector) internal pure override returns (bool) { - return _selector == OntakeSelectors.proposeBlocksV2.selector - || _selector == OntakeSelectors.proveBlocks.selector - || _selector == OntakeSelectors.getBlockV2.selector - || _selector == OntakeSelectors.getTransition.selector - || _selector == OntakeSelectors.getConfig.selector; - } -}