Skip to content

Commit 39f5023

Browse files
authored
internal/ethapi: don't set sender-balance to maxuint, fixes #16999 (#20783)
Prior to this change, eth_call changed the balance of the sender account in the EVM environment to 2^256 wei to cover the gas cost of the call execution. We've had this behavior for a long time even though it's super confusing. This commit sets the default call gasprice to zero instead of updating the balance, which is better because it makes eth_call semantics less surprising. Removing the built-in balance assignment also makes balance overrides work as expected.
1 parent 0734c4b commit 39f5023

3 files changed

Lines changed: 1 addition & 9 deletions

File tree

‎eth/api_backend.go‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323

2424
"github.com/ethereum/go-ethereum/accounts"
2525
"github.com/ethereum/go-ethereum/common"
26-
"github.com/ethereum/go-ethereum/common/math"
2726
"github.com/ethereum/go-ethereum/core"
2827
"github.com/ethereum/go-ethereum/core/bloombits"
2928
"github.com/ethereum/go-ethereum/core/rawdb"
@@ -191,7 +190,6 @@ func (b *EthAPIBackend) GetTd(blockHash common.Hash) *big.Int {
191190
}
192191

193192
func (b *EthAPIBackend) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header) (*vm.EVM, func() error, error) {
194-
state.SetBalance(msg.From(), math.MaxBig256)
195193
vmError := func() error { return nil }
196194

197195
context := core.NewEVMContext(msg, header, b.eth.BlockChain(), nil)

‎internal/ethapi/api.go‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ import (
4747
"github.com/tyler-smith/go-bip39"
4848
)
4949

50-
const (
51-
defaultGasPrice = params.GWei
52-
)
53-
5450
// PublicEthereumAPI provides an API to access Ethereum related information.
5551
// It offers only methods that operate on public data that is freely available to anyone.
5652
type PublicEthereumAPI struct {
@@ -808,7 +804,7 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo
808804
log.Warn("Caller gas above allowance, capping", "requested", gas, "cap", globalGasCap)
809805
gas = globalGasCap.Uint64()
810806
}
811-
gasPrice := new(big.Int).SetUint64(defaultGasPrice)
807+
gasPrice := new(big.Int)
812808
if args.GasPrice != nil {
813809
gasPrice = args.GasPrice.ToInt()
814810
}

‎les/api_backend.go‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323

2424
"github.com/ethereum/go-ethereum/accounts"
2525
"github.com/ethereum/go-ethereum/common"
26-
"github.com/ethereum/go-ethereum/common/math"
2726
"github.com/ethereum/go-ethereum/core"
2827
"github.com/ethereum/go-ethereum/core/bloombits"
2928
"github.com/ethereum/go-ethereum/core/rawdb"
@@ -168,7 +167,6 @@ func (b *LesApiBackend) GetTd(hash common.Hash) *big.Int {
168167
}
169168

170169
func (b *LesApiBackend) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header) (*vm.EVM, func() error, error) {
171-
state.SetBalance(msg.From(), math.MaxBig256)
172170
context := core.NewEVMContext(msg, header, b.eth.blockchain, nil)
173171
return vm.NewEVM(context, state, b.eth.chainConfig, vm.Config{}), state.Error, nil
174172
}

0 commit comments

Comments
 (0)