diff --git a/packages/taiko-client/driver/txlist_fetcher/blob.go b/packages/taiko-client/driver/txlist_fetcher/blob.go index 922e1975b86..ed45db6e653 100644 --- a/packages/taiko-client/driver/txlist_fetcher/blob.go +++ b/packages/taiko-client/driver/txlist_fetcher/blob.go @@ -3,6 +3,8 @@ package txlistdecoder import ( "context" "crypto/sha256" + "fmt" + "math/big" "github.com/ethereum-optimism/optimism/op-service/eth" "github.com/ethereum/go-ethereum/common" @@ -62,11 +64,27 @@ func (d *BlobFetcher) Fetch( } if meta.GetBlobTxListLength() == 0 { - return bytes[meta.GetBlobTxListOffset():], nil + return bytes, nil } - return bytes[meta.GetBlobTxListOffset() : meta.GetBlobTxListOffset()+meta.GetBlobTxListLength()], nil + + b, err := sliceTxList(meta.GetBlockID(), bytes, meta.GetBlobTxListOffset(), meta.GetBlobTxListLength()) + if err != nil { + log.Warn("Invalid txlist offset and size in metadata", "blockID", meta.GetBlockID(), "err", err) + return []byte{}, nil + } + return b, nil } } return nil, pkg.ErrSidecarNotFound } + +// sliceTxList returns the sliced txList bytes from the given offset and length. +func sliceTxList(id *big.Int, b []byte, offset, length uint32) ([]byte, error) { + if offset+length > uint32(len(b)) { + return nil, fmt.Errorf( + "invalid txlist offset and size in metadata (%d): offset=%d, size=%d, blobSize=%d", id, offset, length, len(b), + ) + } + return b[offset : offset+length], nil +}