Skip to content

Commit

Permalink
feat(protocol): allow empty L2 blocks (#406)
Browse files Browse the repository at this point in the history
* feat(protocol): allow empty blocks by updating `LibTxDecoder`

* test: update test_genesis

* feat: allow txList with zero byte
  • Loading branch information
davidtaikocha committed Dec 9, 2022
1 parent 3681483 commit 6d1abf7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/v1/V1Proposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion packages/protocol/contracts/libs/LibTxDecoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
8 changes: 5 additions & 3 deletions packages/protocol/test/genesis/generate_genesis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
15 changes: 11 additions & 4 deletions packages/protocol/test/libs/LibTxDecoder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 6d1abf7

Please sign in to comment.