Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: prevent negative fee during RPC calls #25214

Merged
merged 4 commits into from
Jul 15, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,12 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
if rules.IsLondon {
effectiveTip = cmath.BigMin(st.gasTipCap, new(big.Int).Sub(st.gasFeeCap, st.evm.Context.BaseFee))
}
st.state.AddBalance(st.evm.Context.Coinbase, new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), effectiveTip))
// effectiveTip may be negative during RPC calls such as eth_call and eth_estimateGas.
// In these circumstances, we don't want to subtract balance from the coinbase,
// which would otherwise result in a potentially negative balance.
if effectiveTip.Sign() > 0 {
lightclient marked this conversation as resolved.
Show resolved Hide resolved
st.state.AddBalance(st.evm.Context.Coinbase, new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), effectiveTip))
}

return &ExecutionResult{
UsedGas: st.gasUsed(),
Expand Down