From 7436bae9660cfcf1d430ca111df8c75d50908eae Mon Sep 17 00:00:00 2001 From: Daniel Wang <99078276+dantaik@users.noreply.github.com> Date: Mon, 28 Oct 2024 18:04:23 +0800 Subject: [PATCH] fix(protocol): fix a new bug in LibProposing (#18328) --- .../contracts/layer1/based/LibProposing.sol | 13 ++++++------- .../protocol/contracts/layer1/based/TaikoL1.sol | 2 -- .../test/layer1/based/TaikoL1testGroupA1.t.sol | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/protocol/contracts/layer1/based/LibProposing.sol b/packages/protocol/contracts/layer1/based/LibProposing.sol index a3437d8368..8ea6711dbd 100644 --- a/packages/protocol/contracts/layer1/based/LibProposing.sol +++ b/packages/protocol/contracts/layer1/based/LibProposing.sol @@ -180,15 +180,14 @@ library LibProposing { local.params.coinbase = local.params.proposer; } - if (local.params.anchorBlockId == 0) { - unchecked { - local.params.anchorBlockId = - local.postFork ? uint64(block.number - 1) : uint64(block.number); + unchecked { + if (local.params.anchorBlockId == 0) { + local.params.anchorBlockId = uint64(block.number - 1); } - } - if (local.params.timestamp == 0) { - local.params.timestamp = uint64(block.timestamp); + if (local.params.timestamp == 0) { + local.params.timestamp = uint64(block.timestamp); + } } // Verify params against the parent block. diff --git a/packages/protocol/contracts/layer1/based/TaikoL1.sol b/packages/protocol/contracts/layer1/based/TaikoL1.sol index 4b0f364efb..a7a33982dc 100644 --- a/packages/protocol/contracts/layer1/based/TaikoL1.sol +++ b/packages/protocol/contracts/layer1/based/TaikoL1.sol @@ -189,14 +189,12 @@ contract TaikoL1 is EssentialContract, ITaikoL1, TaikoEvents { /// @param _blockId Index of the block. /// @return blk_ The block. function getBlock(uint64 _blockId) external view returns (TaikoData.Block memory blk_) { - require(_blockId < getConfig().ontakeForkHeight, L1_INVALID_PARAMS()); (TaikoData.BlockV2 memory blk,) = LibUtils.getBlock(state, getConfig(), _blockId); blk_ = LibData.blockV2toV1(blk); } /// @inheritdoc ITaikoL1 function getBlockV2(uint64 _blockId) external view returns (TaikoData.BlockV2 memory blk_) { - require(_blockId >= getConfig().ontakeForkHeight, L1_INVALID_PARAMS()); (blk_,) = LibUtils.getBlock(state, getConfig(), _blockId); } diff --git a/packages/protocol/test/layer1/based/TaikoL1testGroupA1.t.sol b/packages/protocol/test/layer1/based/TaikoL1testGroupA1.t.sol index 1aa4a34452..12c7e272bd 100644 --- a/packages/protocol/test/layer1/based/TaikoL1testGroupA1.t.sol +++ b/packages/protocol/test/layer1/based/TaikoL1testGroupA1.t.sol @@ -46,7 +46,7 @@ contract TaikoL1TestGroupA1 is TaikoL1TestGroupBase { assertTrue(blk.livenessBond > 0); assertEq(blk.assignedProver, address(0)); assertEq(blk.proposedAt, block.timestamp); - assertEq(blk.proposedIn, block.number); + assertEq(blk.proposedIn, block.number - 1); // Prove the block bytes32 blockHash = bytes32(uint256(10_000 + i));