mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 21:56:43 +00:00
feat: reject txs with max l1 data fee (#1203)
* feat: reject txs with max l1 data fee * hide mutable constant using getter function * nit
This commit is contained in:
parent
5148229082
commit
cf3d22ef87
3 changed files with 15 additions and 3 deletions
|
|
@ -842,6 +842,11 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to calculate L1 data fee, err: %w", err)
|
return fmt.Errorf("failed to calculate L1 data fee, err: %w", err)
|
||||||
}
|
}
|
||||||
|
// Reject transactions that require the max data fee amount.
|
||||||
|
// This can only happen if the L1 gas oracle is updated incorrectly.
|
||||||
|
if l1DataFee.Cmp(fees.MaxL1DataFee()) >= 0 {
|
||||||
|
return errors.New("invalid transaction: invalid L1 data fee")
|
||||||
|
}
|
||||||
// Transactor should have enough funds to cover the costs
|
// Transactor should have enough funds to cover the costs
|
||||||
// cost == L1 data fee + V + GP * GL
|
// cost == L1 data fee + V + GP * GL
|
||||||
if b := pool.currentState.GetBalance(from); b.Cmp(new(big.Int).Add(tx.Cost(), l1DataFee)) < 0 {
|
if b := pool.currentState.GetBalance(from); b.Cmp(new(big.Int).Add(tx.Cost(), l1DataFee)) < 0 {
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import (
|
||||||
const (
|
const (
|
||||||
VersionMajor = 5 // Major version component of the current release
|
VersionMajor = 5 // Major version component of the current release
|
||||||
VersionMinor = 8 // Minor version component of the current release
|
VersionMinor = 8 // Minor version component of the current release
|
||||||
VersionPatch = 54 // Patch version component of the current release
|
VersionPatch = 55 // Patch version component of the current release
|
||||||
VersionMeta = "mainnet" // Version metadata to append to the version string
|
VersionMeta = "mainnet" // Version metadata to append to the version string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,15 @@ var (
|
||||||
// to be non-zero.
|
// to be non-zero.
|
||||||
// - tx length prefix: 4 bytes
|
// - tx length prefix: 4 bytes
|
||||||
txExtraDataBytes = uint64(4)
|
txExtraDataBytes = uint64(4)
|
||||||
|
|
||||||
|
// L1 data fee cap.
|
||||||
|
l1DataFeeCap = new(big.Int).SetUint64(math.MaxUint64)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func MaxL1DataFee() *big.Int {
|
||||||
|
return new(big.Int).Set(l1DataFeeCap)
|
||||||
|
}
|
||||||
|
|
||||||
// Message represents the interface of a message.
|
// Message represents the interface of a message.
|
||||||
// It should be a subset of the methods found on
|
// It should be a subset of the methods found on
|
||||||
// types.Message
|
// types.Message
|
||||||
|
|
@ -248,8 +255,8 @@ func CalculateL1DataFee(tx *types.Transaction, state StateDB, config *params.Cha
|
||||||
|
|
||||||
// ensure l1DataFee fits into uint64 for circuit compatibility
|
// ensure l1DataFee fits into uint64 for circuit compatibility
|
||||||
// (note: in practice this value should never be this big)
|
// (note: in practice this value should never be this big)
|
||||||
if !l1DataFee.IsUint64() {
|
if l1DataFee.Cmp(l1DataFeeCap) > 0 {
|
||||||
l1DataFee.SetUint64(math.MaxUint64)
|
l1DataFee = new(big.Int).Set(l1DataFeeCap)
|
||||||
}
|
}
|
||||||
|
|
||||||
return l1DataFee, nil
|
return l1DataFee, nil
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue