Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(protocol): allow empty L2 blocks #406

Merged
merged 3 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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