-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(protocol): extract an IBlockHash interface from TaikoL2 (#18045
) Co-authored-by: dantaik <[email protected]>
- Loading branch information
Showing
5 changed files
with
952 additions
and
2,124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.27; | ||
|
||
/// @title IBlockHash | ||
/// @notice Interface for retrieving block hashes. | ||
interface IBlockHash { | ||
/// @notice Retrieves the block hash for a given block ID. | ||
/// @param _blockId The ID of the block whose hash is being requested. | ||
/// @return The block hash of the specified block ID, or 0 if no hash is found. | ||
function getBlockHash(uint256 _blockId) external view returns (bytes32); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import "../libs/LibAddress.sol"; | |
import "../signal/ISignalService.sol"; | ||
import "./Lib1559Math.sol"; | ||
import "./LibL2Config.sol"; | ||
import "./IBlockHash.sol"; | ||
|
||
/// @title TaikoL2 | ||
/// @notice Taiko L2 is a smart contract that handles cross-layer message | ||
|
@@ -19,7 +20,7 @@ import "./LibL2Config.sol"; | |
/// communication, manage EIP-1559 parameters for gas pricing, and store | ||
/// verified L1 block information. | ||
/// @custom:security-contact [email protected] | ||
contract TaikoL2 is EssentialContract { | ||
contract TaikoL2 is EssentialContract, IBlockHash { | ||
using LibAddress for address; | ||
using SafeERC20 for IERC20; | ||
|
||
|
@@ -28,7 +29,7 @@ contract TaikoL2 is EssentialContract { | |
|
||
/// @notice Mapping from L2 block numbers to their block hashes. All L2 block hashes will | ||
/// be saved in this mapping. | ||
mapping(uint256 blockId => bytes32 blockHash) public l2Hashes; | ||
mapping(uint256 blockId => bytes32 blockHash) private _blockhashes; | ||
|
||
/// @notice A hash to check the integrity of public inputs. | ||
/// @dev Slot 2. | ||
|
@@ -95,7 +96,7 @@ contract TaikoL2 is EssentialContract { | |
} else if (block.number == 1) { | ||
// This is the case in tests | ||
uint256 parentHeight = block.number - 1; | ||
l2Hashes[parentHeight] = blockhash(parentHeight); | ||
_blockhashes[parentHeight] = blockhash(parentHeight); | ||
} else { | ||
revert L2_TOO_LATE(); | ||
} | ||
|
@@ -150,7 +151,7 @@ contract TaikoL2 is EssentialContract { | |
|
||
// Update state variables | ||
bytes32 parentHash = blockhash(parentId); | ||
l2Hashes[parentId] = parentHash; | ||
_blockhashes[parentId] = parentHash; | ||
|
||
publicInputHash = newPublicInputHash; | ||
parentGasExcess = newGasExcess; | ||
|
@@ -223,7 +224,7 @@ contract TaikoL2 is EssentialContract { | |
|
||
// Update state variables | ||
bytes32 parentHash = blockhash(parentId); | ||
l2Hashes[parentId] = parentHash; | ||
_blockhashes[parentId] = parentHash; | ||
parentTimestamp = uint64(block.timestamp); | ||
|
||
emit Anchored(parentHash, parentGasExcess); | ||
|
@@ -276,14 +277,11 @@ contract TaikoL2 is EssentialContract { | |
); | ||
} | ||
|
||
/// @notice Retrieves the block hash for the given L2 block number. | ||
/// @param _blockId The L2 block number to retrieve the block hash for. | ||
/// @return The block hash for the specified L2 block id, or zero if the | ||
/// block id is greater than or equal to the current block number. | ||
function getBlockHash(uint64 _blockId) public view returns (bytes32) { | ||
/// @inheritdoc IBlockHash | ||
function getBlockHash(uint256 _blockId) public view returns (bytes32) { | ||
if (_blockId >= block.number) return 0; | ||
if (_blockId + 256 >= block.number) return blockhash(_blockId); | ||
return l2Hashes[_blockId]; | ||
return _blockhashes[_blockId]; | ||
} | ||
|
||
/// @notice Returns EIP1559 related configurations. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.