Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

feat(driver): check maxBytesPerTxList for compressed txlist bytes #783

Merged
merged 10 commits into from
May 3, 2024
4 changes: 0 additions & 4 deletions driver/chain_syncer/blob/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,6 @@ func (s *Syncer) onBlockProposed(
}
}

if txListBytes, err = utils.Decompress(txListBytes); err != nil {
return fmt.Errorf("failed to decompress tx list bytes: %w", err)
}

// If the transactions list is invalid, we simply insert an empty L2 block.
if !s.txListValidator.ValidateTxList(event.BlockId, txListBytes, event.Meta.BlobUsed) {
log.Info("Invalid transactions list, insert an empty L2 block instead", "blockID", event.BlockId)
Expand Down
25 changes: 20 additions & 5 deletions pkg/txlist_validator/tx_list_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
"github.com/taikoxyz/taiko-client/internal/utils"
)

// TxListValidator is responsible for validating the transactions list in a TaikoL1.proposeBlock transaction.
Expand All @@ -29,24 +30,38 @@ func NewTxListValidator(
}

// ValidateTxList checks whether the transactions list in the TaikoL1.proposeBlock transaction's
// input data is valid.
// input data is valid, the rules are:
// - If the transaction list is empty, it's valid.
// - If the transaction list is not empty:
// 1. If the transaction list is using calldata, the compressed bytes of the transaction list must be
// less than or equal to maxBytesPerTxList.
// 2. The transaction list bytes must be able to be RLP decoded into a list of transactions.
func (v *TxListValidator) ValidateTxList(
blockID *big.Int,
txListBytes []byte,
blobUsed bool,
) (isValid bool) {
) bool {
// If the transaction list is empty, it's valid.
if len(txListBytes) == 0 {
return true
}

if !blobUsed && (len(txListBytes) > int(v.maxBytesPerTxList)) {
log.Info("Transactions list binary too large", "length", len(txListBytes), "blockID", blockID)
log.Info("Compressed transactions list binary too large", "length", len(txListBytes), "blockID", blockID)
return false
}

var txs types.Transactions
if err := rlp.DecodeBytes(txListBytes, &txs); err != nil {
var (
txs types.Transactions
err error
)

if txListBytes, err = utils.Decompress(txListBytes); err != nil {
log.Info("Failed to decompress tx list bytes", "blockID", blockID, "error", err)
return false
}

if err = rlp.DecodeBytes(txListBytes, &txs); err != nil {
davidtaikocha marked this conversation as resolved.
Show resolved Hide resolved
log.Info("Failed to decode transactions list bytes", "blockID", blockID, "error", err)
return false
}
Expand Down
Loading