From 39f502329fac4640cfb71959c3496f19ea88bc85 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Mon, 23 Mar 2020 18:21:23 +0100 Subject: [PATCH] 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. --- eth/api_backend.go | 2 -- internal/ethapi/api.go | 6 +----- les/api_backend.go | 2 -- 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/eth/api_backend.go b/eth/api_backend.go index 0ad2d57fd..a82aee4eb 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -23,7 +23,6 @@ import ( "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/bloombits" "github.com/ethereum/go-ethereum/core/rawdb" @@ -191,7 +190,6 @@ func (b *EthAPIBackend) GetTd(blockHash common.Hash) *big.Int { } func (b *EthAPIBackend) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header) (*vm.EVM, func() error, error) { - state.SetBalance(msg.From(), math.MaxBig256) vmError := func() error { return nil } context := core.NewEVMContext(msg, header, b.eth.BlockChain(), nil) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index cb4d255da..68afa83c7 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -47,10 +47,6 @@ import ( "github.com/tyler-smith/go-bip39" ) -const ( - defaultGasPrice = params.GWei -) - // PublicEthereumAPI provides an API to access Ethereum related information. // It offers only methods that operate on public data that is freely available to anyone. type PublicEthereumAPI struct { @@ -808,7 +804,7 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo log.Warn("Caller gas above allowance, capping", "requested", gas, "cap", globalGasCap) gas = globalGasCap.Uint64() } - gasPrice := new(big.Int).SetUint64(defaultGasPrice) + gasPrice := new(big.Int) if args.GasPrice != nil { gasPrice = args.GasPrice.ToInt() } diff --git a/les/api_backend.go b/les/api_backend.go index 5627c34d6..756beaf6a 100644 --- a/les/api_backend.go +++ b/les/api_backend.go @@ -23,7 +23,6 @@ import ( "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/bloombits" "github.com/ethereum/go-ethereum/core/rawdb" @@ -168,7 +167,6 @@ func (b *LesApiBackend) GetTd(hash common.Hash) *big.Int { } func (b *LesApiBackend) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header) (*vm.EVM, func() error, error) { - state.SetBalance(msg.From(), math.MaxBig256) context := core.NewEVMContext(msg, header, b.eth.blockchain, nil) return vm.NewEVM(context, state, b.eth.chainConfig, vm.Config{}), state.Error, nil }