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

Commit

Permalink
feat(driver): check maxBytesPerTxList for compressed txlist bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Apr 30, 2024
1 parent b4167fe commit 6c0bd93
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
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
18 changes: 14 additions & 4 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 Down Expand Up @@ -34,19 +35,28 @@ 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 {
log.Info("Failed to decode transactions list bytes", "blockID", blockID, "error", err)
return false
}
Expand Down

0 comments on commit 6c0bd93

Please sign in to comment.