diff --git a/core/state/statedb.go b/core/state/statedb.go index 51a9997e7a59..0a740cfe0a79 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -32,6 +32,7 @@ import ( "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/trie" + "golang.org/x/crypto/sha3" ) type revision struct { @@ -264,6 +265,18 @@ func (s *StateDB) GetBalance(addr common.Address) *big.Int { return common.Big0 } +func (s *StateDB) GetOVMBalance(addr common.Address) *big.Int { + position := big.NewInt(3) + eth := common.HexToAddress("0x4200000000000000000000000000000000000006") + hasher := sha3.NewLegacyKeccak256() + hasher.Write(common.LeftPadBytes(addr.Bytes(), 32)) + hasher.Write(common.LeftPadBytes(position.Bytes(), 32)) + digest := hasher.Sum(nil) + key := common.BytesToHash(digest) + slot := s.GetState(eth, key) + return slot.Big() +} + func (s *StateDB) GetNonce(addr common.Address) uint64 { stateObject := s.getStateObject(addr) if stateObject != nil { diff --git a/core/tx_pool.go b/core/tx_pool.go index d94e45452c75..5bf3c49a213e 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -572,8 +572,14 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error { } // Transactor should have enough funds to cover the costs // cost == V + GP * GL - if pool.currentState.GetBalance(from).Cmp(tx.Cost()) < 0 { - return ErrInsufficientFunds + if vm.UsingOVM { + if pool.currentState.GetOVMBalance(from).Cmp(tx.Cost()) < 0 { + return ErrInsufficientFunds + } + } else { + if pool.currentState.GetBalance(from).Cmp(tx.Cost()) < 0 { + return ErrInsufficientFunds + } } // Ensure the transaction has more gas than the basic tx fee. intrGas, err := IntrinsicGas(tx.Data(), tx.To() == nil, true, pool.istanbul) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 8bce6f0da72b..9a53d857a7b3 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -46,7 +46,6 @@ import ( "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rpc" "github.com/tyler-smith/go-bip39" - "golang.org/x/crypto/sha3" ) const ( @@ -537,19 +536,8 @@ func (s *PublicBlockChainAPI) GetBalance(ctx context.Context, address common.Add if state == nil || err != nil { return nil, err } - - // Use the OVM_ETH predeploy for balances since there is no - // native ETH. This should be moved into statedb.GetBalance - position := big.NewInt(3) - eth := common.HexToAddress("0x4200000000000000000000000000000000000006") - hasher := sha3.NewLegacyKeccak256() - hasher.Write(common.LeftPadBytes(address.Bytes(), 32)) - hasher.Write(common.LeftPadBytes(position.Bytes(), 32)) - - digest := hasher.Sum(nil) - key := common.BytesToHash(digest) - slot := state.GetState(eth, key) - return (*hexutil.Big)(slot.Big()), state.Error() + balance := state.GetOVMBalance(address) + return (*hexutil.Big)(balance), state.Error() } // Result structs for GetProof