From 460432f154d9c0f3a5dfd85ce354e430d75f331f Mon Sep 17 00:00:00 2001 From: jangko Date: Tue, 28 Sep 2021 22:16:15 +0700 Subject: [PATCH] fixes EIP1559 tx gasCost validation pre EIP1559 max(gasCost) is tx.gasLimit * tx.gasPrice the new EIP1559 max(gasCost) before the transaction can be executed is tx.gasLimit * tx.maxFeePerGas --- nimbus/p2p/validate.nim | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/nimbus/p2p/validate.nim b/nimbus/p2p/validate.nim index ca386ffc6..b2f031775 100644 --- a/nimbus/p2p/validate.nim +++ b/nimbus/p2p/validate.nim @@ -153,7 +153,7 @@ proc validateHeader(db: BaseChainDB; header, parentHeader: BlockHeader; if header.gasUsed < 0 or header.gasUsed > header.gasLimit: return err("gasUsed should be non negative and smaller or equal gasLimit") - + if header.blockNumber != parentHeader.blockNumber + 1: return err("Blocks must be numbered consecutively") @@ -304,7 +304,12 @@ proc validateTransaction*(vmState: BaseVMState, tx: Transaction, maxPriorityFee=tx.maxPriorityFee return - let gasCost = tx.gasLimit.u256 * tx.gasPrice.u256 + # the signer must be able to afford the transaction + let gasCost = if tx.txType >= TxEip1559: + tx.gasLimit.u256 * tx.maxFee.u256 + else: + tx.gasLimit.u256 * tx.gasPrice.u256 + if gasCost > balance: debug "invalid tx: not enough cash for gas", available=balance,