From ba1a9a08850c08e6676a937614c96feffc67a60e Mon Sep 17 00:00:00 2001 From: David Date: Fri, 9 Dec 2022 19:06:37 +0800 Subject: [PATCH 1/3] feat(protocol): allow empty blocks by updating `LibTxDecoder` --- packages/protocol/contracts/libs/LibTxDecoder.sol | 1 - packages/protocol/test/libs/LibTxDecoder.test.ts | 11 +++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/protocol/contracts/libs/LibTxDecoder.sol b/packages/protocol/contracts/libs/LibTxDecoder.sol index 9c10316f7d9..a6c0d6e5db2 100644 --- a/packages/protocol/contracts/libs/LibTxDecoder.sol +++ b/packages/protocol/contracts/libs/LibTxDecoder.sol @@ -79,7 +79,6 @@ library LibTxDecoder { bytes calldata encoded ) public pure returns (TxList memory 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/libs/LibTxDecoder.test.ts b/packages/protocol/test/libs/LibTxDecoder.test.ts index 10ab421264b..83a0ee0d43f 100644 --- a/packages/protocol/test/libs/LibTxDecoder.test.ts +++ b/packages/protocol/test/libs/LibTxDecoder.test.ts @@ -30,12 +30,15 @@ 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") + + const decoded = await libTxDecoder.callStatic.decodeTxList( + txListBytes + ) + + expect(decoded.items.length).to.be.eql(0) }) it("should revert with random bytes", async function () { From 37992fda636c40957d693181cfcfbfa284091174 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 9 Dec 2022 19:15:04 +0800 Subject: [PATCH 2/3] test: update test_genesis --- packages/protocol/test/genesis/generate_genesis.test.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 () { From 7c408681e3672b614a18862dbe31c905bba52262 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 9 Dec 2022 21:10:05 +0800 Subject: [PATCH 3/3] feat: allow txList with zero byte --- packages/protocol/contracts/L1/v1/V1Proposing.sol | 2 +- packages/protocol/contracts/libs/LibTxDecoder.sol | 3 +++ packages/protocol/test/libs/LibTxDecoder.test.ts | 6 +++++- 3 files changed, 9 insertions(+), 2 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 a6c0d6e5db2..9dff797f56a 100644 --- a/packages/protocol/contracts/libs/LibTxDecoder.sol +++ b/packages/protocol/contracts/libs/LibTxDecoder.sol @@ -78,6 +78,9 @@ 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); Tx[] memory _txList = new Tx[](txs.length); diff --git a/packages/protocol/test/libs/LibTxDecoder.test.ts b/packages/protocol/test/libs/LibTxDecoder.test.ts index 83a0ee0d43f..6e46b66bd4a 100644 --- a/packages/protocol/test/libs/LibTxDecoder.test.ts +++ b/packages/protocol/test/libs/LibTxDecoder.test.ts @@ -34,11 +34,15 @@ describe("LibTxDecoder", function () { const txList: string[] = [] const txListBytes = await rlpEncodeTxList(txList) - const decoded = await libTxDecoder.callStatic.decodeTxList( + 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 () {