core: add new eip-1559 tx constraints (#22970)

This PR adds the new consensus constraints of EIP-1559 transactions as specified in https://github.com/ethereum/EIPs#3594
This commit is contained in:
Felföldi Zsolt
2021-05-30 19:37:52 +02:00
committed by GitHub
parent 966ee3ae6d
commit 2d716c4b01
5 changed files with 102 additions and 12 deletions

View File

@ -83,10 +83,6 @@ var (
// than some meaningful limit a user might use. This is not a consensus error
// making the transaction invalid, rather a DOS protection.
ErrOversizedData = errors.New("oversized data")
// ErrTipAboveFeeCap is a sanity error to ensure no one is able to specify a
// transaction with a tip higher than the total fee cap.
ErrTipAboveFeeCap = errors.New("tip higher than fee cap")
)
var (
@ -559,6 +555,13 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
if pool.currentMaxGas < tx.Gas() {
return ErrGasLimit
}
// Sanity check for extremely large numbers
if tx.FeeCap().BitLen() > 256 {
return ErrFeeCapVeryHigh
}
if tx.Tip().BitLen() > 256 {
return ErrTipVeryHigh
}
// Ensure feeCap is less than or equal to tip.
if tx.FeeCapIntCmp(tx.Tip()) < 0 {
return ErrTipAboveFeeCap