This repository has been archived by the owner on May 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(driver): check
maxBytesPerTxList
for compressed txlist bytes (#…
…783) Co-authored-by: Roger <50648015+RogerLamTd@users.noreply.github.com> Co-authored-by: RogerLamTd <bob.rogerbob1@gmail.com>
- Loading branch information
1 parent
d2e9667
commit b41379e
Showing
5 changed files
with
108 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package txlistdecompressor | ||
|
||
import ( | ||
"math/big" | ||
|
||
"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" | ||
) | ||
|
||
// TxListDecompressor is responsible for validating and decompressing | ||
// the transactions list in a TaikoL1.proposeBlock transaction. | ||
type TxListDecompressor struct { | ||
blockMaxGasLimit uint64 | ||
maxBytesPerTxList uint64 | ||
chainID *big.Int | ||
} | ||
|
||
// NewTxListDecompressor creates a new TxListDecompressor instance based on giving configurations. | ||
func NewTxListDecompressor( | ||
blockMaxGasLimit uint64, | ||
maxBytesPerTxList uint64, | ||
chainID *big.Int, | ||
) *TxListDecompressor { | ||
return &TxListDecompressor{ | ||
blockMaxGasLimit: blockMaxGasLimit, | ||
maxBytesPerTxList: maxBytesPerTxList, | ||
chainID: chainID, | ||
} | ||
} | ||
|
||
// TryDecompress validates and decompresses whether the transactions list in the TaikoL1.proposeBlock transaction's | ||
// 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 *TxListDecompressor) TryDecompress( | ||
blockID *big.Int, | ||
txListBytes []byte, | ||
blobUsed bool, | ||
) []byte { | ||
// If the transaction list is empty, it's valid. | ||
if len(txListBytes) == 0 { | ||
return []byte{} | ||
} | ||
|
||
// If calldata is used, the compressed bytes of the transaction list must be | ||
// less than or equal to maxBytesPerTxList. | ||
if !blobUsed && (len(txListBytes) > int(v.maxBytesPerTxList)) { | ||
log.Info("Compressed transactions list binary too large", "length", len(txListBytes), "blockID", blockID) | ||
return []byte{} | ||
} | ||
|
||
var ( | ||
txs types.Transactions | ||
err error | ||
) | ||
|
||
// Decompress the transaction list bytes. | ||
if txListBytes, err = utils.Decompress(txListBytes); err != nil { | ||
log.Info("Failed to decompress tx list bytes", "blockID", blockID, "error", err) | ||
return []byte{} | ||
} | ||
|
||
// Try to RLP decode the transaction list bytes. | ||
if err = rlp.DecodeBytes(txListBytes, &txs); err != nil { | ||
log.Info("Failed to decode transactions list bytes", "blockID", blockID, "error", err) | ||
return []byte{} | ||
} | ||
|
||
log.Info("Transaction list is valid", "blockID", blockID) | ||
return txListBytes | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.