Skip to content

Commit

Permalink
Merge pull request ethereum-optimism#85 from ethstorage/fix_L1Block
Browse files Browse the repository at this point in the history
fix "just build"
  • Loading branch information
blockchaindevsh authored Nov 4, 2024
2 parents 409ef8b + 89849bb commit 688a875
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
9 changes: 7 additions & 2 deletions packages/contracts-bedrock/src/L2/L1Block.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ contract L1Block is ISemver, IGasToken {
}

/// @notice size of historyHashes.
uint256 public constant HISTORY_SIZE = 8192;
uint256 internal constant HISTORY_SIZE = 8192;
/// @notice The 8191 history L1 blockhashes and 1 latest L1 blockhash.
bytes32[HISTORY_SIZE] public historyHashes;
bytes32[HISTORY_SIZE] internal historyHashes;

/// @custom:legacy
/// @notice Updates the L1 block values.
Expand Down Expand Up @@ -207,4 +207,9 @@ contract L1Block is ISemver, IGasToken {

emit GasPayingTokenSet({ token: _token, decimals: _decimals, name: _name, symbol: _symbol });
}

/// @notice Returns the size of history hashes.
function historySize() external view returns (uint256) {
return HISTORY_SIZE;
}
}
3 changes: 3 additions & 0 deletions packages/contracts-bedrock/src/L2/interfaces/IL1Block.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ interface IL1Block {
function version() external pure returns (string memory);

function __constructor__() external;

function historySize() external view returns (uint256);
function blockHash(uint256 _historyNumber) external view returns (bytes32);
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,7 @@ interface IL1BlockInterop {
function version() external pure returns (string memory);

function __constructor__() external;

function historySize() external view returns (uint256);
function blockHash(uint256 _historyNumber) external view returns (bytes32);
}
14 changes: 7 additions & 7 deletions packages/contracts-bedrock/test/L2/L1Block.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,14 @@ contract L1BlockEcotone_Test is L1BlockTest {
)
external
{
if (number > type(uint64).max - uint64(l1Block.HISTORY_SIZE()) - 1) {
number = type(uint64).max - uint64(l1Block.HISTORY_SIZE()) - 1;
if (number > type(uint64).max - uint64(l1Block.historySize()) - 1) {
number = type(uint64).max - uint64(l1Block.historySize()) - 1;
}
if (uint256(hash) > type(uint256).max - l1Block.HISTORY_SIZE() - 1) {
hash = bytes32(type(uint256).max - l1Block.HISTORY_SIZE() - 1);
if (uint256(hash) > type(uint256).max - l1Block.historySize() - 1) {
hash = bytes32(type(uint256).max - l1Block.historySize() - 1);
}

for (uint256 i = 1; i <= l1Block.HISTORY_SIZE() + 1; i++) {
for (uint256 i = 1; i <= l1Block.historySize() + 1; i++) {
bytes memory functionCallDataPacked = Encoding.encodeSetL1BlockValuesEcotone(
baseFeeScalar,
blobBaseFeeScalar,
Expand All @@ -208,11 +208,11 @@ contract L1BlockEcotone_Test is L1BlockTest {
}

assertTrue(
l1Block.blockHash(number + l1Block.HISTORY_SIZE() + 1) == bytes32(0),
l1Block.blockHash(number + l1Block.historySize() + 1) == bytes32(0),
"should return bytes32(0) for the latest L1 block"
);
assertTrue(l1Block.blockHash(number + 1) == bytes32(0), "should return bytes32(0) for blocks out of range");
for (uint256 i = 2; i <= l1Block.HISTORY_SIZE(); i++) {
for (uint256 i = 2; i <= l1Block.historySize(); i++) {
assertTrue(
l1Block.blockHash(number + i) == bytes32(uint256(hash) + i),
"blockHash's return value should match the value set"
Expand Down

0 comments on commit 688a875

Please sign in to comment.