From d2498fcf4a51504eba63dc9cf0f6a9a59ed1de84 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 1 May 2024 01:12:00 +0800 Subject: [PATCH] feat(driver): check `maxBytesPerTxList` for compressed txlist bytes --- driver/chain_syncer/blob/syncer.go | 4 ---- pkg/txlist_validator/tx_list_validator.go | 18 ++++++++++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/driver/chain_syncer/blob/syncer.go b/driver/chain_syncer/blob/syncer.go index 3db1945b1..70f62977e 100644 --- a/driver/chain_syncer/blob/syncer.go +++ b/driver/chain_syncer/blob/syncer.go @@ -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) diff --git a/pkg/txlist_validator/tx_list_validator.go b/pkg/txlist_validator/tx_list_validator.go index 1d1801a77..b660a823b 100644 --- a/pkg/txlist_validator/tx_list_validator.go +++ b/pkg/txlist_validator/tx_list_validator.go @@ -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. @@ -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 }