Skip to content

Commit e396190

Browse files
PlasmaPowerlightclientfjl
authored andcommitted
core: prevent negative fee during RPC calls (ethereum#25214)
During RPC calls such as eth_call and eth_estimateGas, st.evm.Config.NoBaseFee is set which allows the gas price to be below the base fee. This results the tip being negative, and balance being subtracted from the coinbase instead of added to it, which results in a potentially negative coinbase balance interestingly. This can't happen during normal chain processing as outside of RPC calls the gas price is required to be at least the base fee, as NoBaseFee is false. This change prevents this behavior by disabling fee payment when the fee is not set. Co-authored-by: [email protected] <[email protected]> Co-authored-by: Felix Lange <[email protected]>
1 parent 1e68254 commit e396190

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

core/state_transition.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,16 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
344344
if rules.IsLondon {
345345
effectiveTip = cmath.BigMin(st.gasTipCap, new(big.Int).Sub(st.gasFeeCap, st.evm.Context.BaseFee))
346346
}
347-
st.state.AddBalance(st.evm.Context.Coinbase, new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), effectiveTip))
347+
348+
if st.evm.Config.NoBaseFee && st.gasFeeCap.Sign() == 0 && st.gasTipCap.Sign() == 0 {
349+
// Skip fee payment when NoBaseFee is set and the fee fields
350+
// are 0. This avoids a negative effectiveTip being applied to
351+
// the coinbase when simulating calls.
352+
} else {
353+
fee := new(big.Int).SetUint64(st.gasUsed())
354+
fee.Mul(fee, effectiveTip)
355+
st.state.AddBalance(st.evm.Context.Coinbase, fee)
356+
}
348357

349358
return &ExecutionResult{
350359
UsedGas: st.gasUsed(),

0 commit comments

Comments
 (0)