Skip to content

Commit cf3d22e

Browse files
authored
feat: reject txs with max l1 data fee (#1203)
* feat: reject txs with max l1 data fee * hide mutable constant using getter function * nit
1 parent 5148229 commit cf3d22e

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

core/tx_pool.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,11 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
842842
if err != nil {
843843
return fmt.Errorf("failed to calculate L1 data fee, err: %w", err)
844844
}
845+
// Reject transactions that require the max data fee amount.
846+
// This can only happen if the L1 gas oracle is updated incorrectly.
847+
if l1DataFee.Cmp(fees.MaxL1DataFee()) >= 0 {
848+
return errors.New("invalid transaction: invalid L1 data fee")
849+
}
845850
// Transactor should have enough funds to cover the costs
846851
// cost == L1 data fee + V + GP * GL
847852
if b := pool.currentState.GetBalance(from); b.Cmp(new(big.Int).Add(tx.Cost(), l1DataFee)) < 0 {

params/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
const (
2525
VersionMajor = 5 // Major version component of the current release
2626
VersionMinor = 8 // Minor version component of the current release
27-
VersionPatch = 54 // Patch version component of the current release
27+
VersionPatch = 55 // Patch version component of the current release
2828
VersionMeta = "mainnet" // Version metadata to append to the version string
2929
)
3030

rollup/fees/rollup_fee.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,15 @@ var (
2020
// to be non-zero.
2121
// - tx length prefix: 4 bytes
2222
txExtraDataBytes = uint64(4)
23+
24+
// L1 data fee cap.
25+
l1DataFeeCap = new(big.Int).SetUint64(math.MaxUint64)
2326
)
2427

28+
func MaxL1DataFee() *big.Int {
29+
return new(big.Int).Set(l1DataFeeCap)
30+
}
31+
2532
// Message represents the interface of a message.
2633
// It should be a subset of the methods found on
2734
// types.Message
@@ -248,8 +255,8 @@ func CalculateL1DataFee(tx *types.Transaction, state StateDB, config *params.Cha
248255

249256
// ensure l1DataFee fits into uint64 for circuit compatibility
250257
// (note: in practice this value should never be this big)
251-
if !l1DataFee.IsUint64() {
252-
l1DataFee.SetUint64(math.MaxUint64)
258+
if l1DataFee.Cmp(l1DataFeeCap) > 0 {
259+
l1DataFee = new(big.Int).Set(l1DataFeeCap)
253260
}
254261

255262
return l1DataFee, nil

0 commit comments

Comments
 (0)