Skip to content

Commit

Permalink
Merge branch 'main' into release-please--branches--main--components--…
Browse files Browse the repository at this point in the history
…protocol
  • Loading branch information
dantaik authored Sep 9, 2024
2 parents 3af058d + bff481e commit eadc4fe
Show file tree
Hide file tree
Showing 5 changed files with 952 additions and 2,124 deletions.
2 changes: 1 addition & 1 deletion packages/protocol/contract_layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
| __paused | uint8 | 201 | 1 | 1 | contracts/L2/TaikoL2.sol:TaikoL2 |
| lastUnpausedAt | uint64 | 201 | 2 | 8 | contracts/L2/TaikoL2.sol:TaikoL2 |
| __gap | uint256[49] | 202 | 0 | 1568 | contracts/L2/TaikoL2.sol:TaikoL2 |
| l2Hashes | mapping(uint256 => bytes32) | 251 | 0 | 32 | contracts/L2/TaikoL2.sol:TaikoL2 |
| _blockhashes | mapping(uint256 => bytes32) | 251 | 0 | 32 | contracts/L2/TaikoL2.sol:TaikoL2 |
| publicInputHash | bytes32 | 252 | 0 | 32 | contracts/L2/TaikoL2.sol:TaikoL2 |
| parentGasExcess | uint64 | 253 | 0 | 8 | contracts/L2/TaikoL2.sol:TaikoL2 |
| lastSyncedBlock | uint64 | 253 | 8 | 8 | contracts/L2/TaikoL2.sol:TaikoL2 |
Expand Down
11 changes: 11 additions & 0 deletions packages/protocol/contracts/L2/IBlockHash.sol
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);
}
20 changes: 9 additions & 11 deletions packages/protocol/contracts/L2/TaikoL2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand All @@ -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.
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract contract AddressCache {
function getAddress(
uint64 _chainId,
bytes32 _name,
function (uint64, bytes32) view returns (address) _fallbackFunc
function (uint64, bytes32) view returns (address) _fallbackFunc
)
internal
view
Expand Down
Loading

0 comments on commit eadc4fe

Please sign in to comment.