From e8c40ea225c3e49e1bceedd0bc0c841c8c0449f8 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 c07d3c50656d0..cce40167528d2 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 f24a03cf29e28..12239e0d3f13c 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -195,6 +195,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)