From 2fe76b63f23c2250dcdbe962cdffd8133d4dca66 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Tue, 28 May 2024 16:58:19 +0800 Subject: [PATCH] core: fix pre-check for account balance under EIP-1559 (#23244) --- core/state_processor_test.go | 2 +- core/state_transition.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/core/state_processor_test.go b/core/state_processor_test.go index c07d3c50656d..cce40167528d 100644 --- a/core/state_processor_test.go +++ b/core/state_processor_test.go @@ -120,7 +120,7 @@ func TestStateProcessorErrors(t *testing.T) { txs: []*types.Transaction{ makeTx(0, common.Address{}, big.NewInt(1000000000000000000), params.TxGas, big.NewInt(875000000), nil), }, - want: "insufficient funds for transfer: address xdc71562b71999873DB5b286dF957af199Ec94617F7", + want: "insufficient funds for gas * price + value: address xdc71562b71999873DB5b286dF957af199Ec94617F7", }, { // ErrInsufficientFunds txs: []*types.Transaction{ diff --git a/core/state_transition.go b/core/state_transition.go index cf4e5f26606c..fa9c501c1296 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -186,6 +186,7 @@ func (st *StateTransition) buyGas() error { if st.gasFeeCap != nil { balanceCheck = new(big.Int).SetUint64(st.msg.Gas()) balanceCheck = balanceCheck.Mul(balanceCheck, st.gasFeeCap) + balanceCheck.Add(balanceCheck, st.value) } if have, want := st.state.GetBalance(st.msg.From()), balanceCheck; have.Cmp(want) < 0 { return fmt.Errorf("%w: address %v have %v want %v", ErrInsufficientFunds, st.msg.From().Hex(), have, want)