diff --git a/packages/protocol/contracts/L1/TaikoL1.sol b/packages/protocol/contracts/L1/TaikoL1.sol index 04d59815355..580137155e4 100644 --- a/packages/protocol/contracts/L1/TaikoL1.sol +++ b/packages/protocol/contracts/L1/TaikoL1.sol @@ -237,7 +237,8 @@ contract TaikoL1 is EssentialContract, IHeaderSync, TaikoEvents { function getProposedBlock( uint256 id ) public view returns (TaikoData.ProposedBlock memory) { - return state.getProposedBlock(getConfig().maxNumBlocks, id); + return + LibProposing.getProposedBlock(state, getConfig().maxNumBlocks, id); } function getSyncedHeader( diff --git a/packages/protocol/contracts/L1/libs/LibProposing.sol b/packages/protocol/contracts/L1/libs/LibProposing.sol index 8525da78284..58879b3d5e2 100644 --- a/packages/protocol/contracts/L1/libs/LibProposing.sol +++ b/packages/protocol/contracts/L1/libs/LibProposing.sol @@ -140,6 +140,15 @@ library LibProposing { emit BlockProposed(state.nextBlockId++, meta); } + function getProposedBlock( + TaikoData.State storage state, + uint256 maxNumBlocks, + uint256 id + ) internal view returns (TaikoData.ProposedBlock storage) { + require(id > state.latestVerifiedId && id < state.nextBlockId, "L1:id"); + return state.getProposedBlock(maxNumBlocks, id); + } + function getBlockFee( TaikoData.State storage state, TaikoData.Config memory config diff --git a/packages/protocol/test/L1/TaikoL1.test.ts b/packages/protocol/test/L1/TaikoL1.test.ts index 5b25613a330..5a1d23f7fed 100644 --- a/packages/protocol/test/L1/TaikoL1.test.ts +++ b/packages/protocol/test/L1/TaikoL1.test.ts @@ -169,7 +169,9 @@ describe("integration:TaikoL1", function () { ); l2Signer = await l2Provider.getSigner( - (await l2Provider.listAccounts())[0] + ( + await l2Provider.listAccounts() + )[0] ); const addressManager = await ( @@ -267,11 +269,10 @@ describe("integration:TaikoL1", function () { }); describe("getProposedBlock()", function () { - it("proposed block does not exist", async function () { - const block = await taikoL1.getProposedBlock(123); - expect(block[0]).to.be.eq(ethers.constants.HashZero); - expect(block[1]).to.be.eq(ethers.constants.AddressZero); - expect(block[2]).to.be.eq(BigNumber.from(0)); + it("reverts when id is not a valid proposed block in range", async function () { + await expect(taikoL1.getProposedBlock(123)).to.be.revertedWith( + "L1:id" + ); }); }); describe("commitBlock() -> proposeBlock() integration", async function () {