From 6d1abf7bd8565bf0377a42b823a6ad98959c340a Mon Sep 17 00:00:00 2001 From: David <104078303+davidtaikocha@users.noreply.github.com> Date: Fri, 9 Dec 2022 23:56:49 +0800 Subject: [PATCH] feat(protocol): allow empty L2 blocks (#406) * feat(protocol): allow empty blocks by updating `LibTxDecoder` * test: update test_genesis * feat: allow txList with zero byte --- packages/protocol/contracts/L1/v1/V1Proposing.sol | 2 +- packages/protocol/contracts/libs/LibTxDecoder.sol | 4 +++- .../test/genesis/generate_genesis.test.ts | 8 +++++--- packages/protocol/test/libs/LibTxDecoder.test.ts | 15 +++++++++++---- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/packages/protocol/contracts/L1/v1/V1Proposing.sol b/packages/protocol/contracts/L1/v1/V1Proposing.sol index 6add00c3b10..0ef68db1b5d 100644 --- a/packages/protocol/contracts/L1/v1/V1Proposing.sol +++ b/packages/protocol/contracts/L1/v1/V1Proposing.sol @@ -77,7 +77,7 @@ library V1Proposing { bytes calldata txList = inputs[1]; // perform validation and populate some fields require( - txList.length > 0 && + txList.length >= 0 && txList.length <= LibConstants.K_TXLIST_MAX_BYTES && meta.txListHash == txList.hashTxList(), "L1:txList" diff --git a/packages/protocol/contracts/libs/LibTxDecoder.sol b/packages/protocol/contracts/libs/LibTxDecoder.sol index 9c10316f7d9..9dff797f56a 100644 --- a/packages/protocol/contracts/libs/LibTxDecoder.sol +++ b/packages/protocol/contracts/libs/LibTxDecoder.sol @@ -78,8 +78,10 @@ library LibTxDecoder { function decodeTxList( bytes calldata encoded ) public pure returns (TxList memory txList) { + if (encoded.length == 0) { + return txList; + } LibRLPReader.RLPItem[] memory txs = LibRLPReader.readList(encoded); - require(txs.length > 0, "empty txList"); Tx[] memory _txList = new Tx[](txs.length); for (uint256 i = 0; i < txs.length; i++) { diff --git a/packages/protocol/test/genesis/generate_genesis.test.ts b/packages/protocol/test/genesis/generate_genesis.test.ts index 4abe3611ab1..05503c8872e 100644 --- a/packages/protocol/test/genesis/generate_genesis.test.ts +++ b/packages/protocol/test/genesis/generate_genesis.test.ts @@ -142,9 +142,11 @@ action("Generate Genesis", function () { signer ) - await expect( - LibTxDecoder.decodeTxList(ethers.utils.RLP.encode([])) - ).to.be.revertedWith("empty txList") + const decoded = await LibTxDecoder.callStatic.decodeTxList( + ethers.utils.RLP.encode([]) + ) + + expect(decoded.items.length).to.be.eql(0) }) it("TaikoL2", async function () { diff --git a/packages/protocol/test/libs/LibTxDecoder.test.ts b/packages/protocol/test/libs/LibTxDecoder.test.ts index 10ab421264b..6e46b66bd4a 100644 --- a/packages/protocol/test/libs/LibTxDecoder.test.ts +++ b/packages/protocol/test/libs/LibTxDecoder.test.ts @@ -30,12 +30,19 @@ describe("LibTxDecoder", function () { } describe("decodeTxList", function () { - it("should revert if tx list is empty", async function () { + it("should not revert if tx list is empty", async function () { const txList: string[] = [] const txListBytes = await rlpEncodeTxList(txList) - await expect( - libTxDecoder.callStatic.decodeTxList(txListBytes) - ).to.be.revertedWith("empty txList") + + let decoded = await libTxDecoder.callStatic.decodeTxList( + txListBytes + ) + + expect(decoded.items.length).to.be.eql(0) + + decoded = await libTxDecoder.callStatic.decodeTxList([]) + + expect(decoded.items.length).to.be.eql(0) }) it("should revert with random bytes", async function () {