3

In order to modify GetBalance function to fork go-ethereum, I find difficulties to get a reference of the running evm. The function has a reference for self *StateDB:

func (self *StateDB) GetBalance(addr common.Address) *big.Int

but I cannot get an evm of type *vm.EVM from StateDB. I need the evm to make a contract call inside the GetBalance function for this fork. Is it possible in some way to get the evm from StateDB, or should I use any other strategy?

  • 1
    What do you want to achieve? Do you want to execute a smart contract from GetBalance? I think you can call GetBalance outside the EVM so you wont be able to get the running instance of the EVM in that case. – Ismael Jun 5 at 18:23
  • Yes, I want GetBalance to call a SC whenever it is run. So I don't want to call GetBalance, but to force a SC call when go-ethereum calls GetBalance. This is why I need an EVM reference inside GetBalance scope. – Juan Ignacio Pérez Sacristán Jun 6 at 7:24
0

getBalance doesn't require EVM because it only reads data in StateDB.

Therefore, it is in core/state/statedb.

I recommend creating a new instruction.

and reference other instructions changing stateDB.

for example, opStaticCall in core/vm/instruction

func opStaticCall(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *Memory, stack *Stack) ([]byte, error)

this function calls staticCall in core/vm/evm

func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte, gas uint64) (ret []byte, leftOverGas uint64, err error)

this function include this line

evm.StateDB.AddBalance(addr, bigZero)
  • Sorry but, this solution wouldn't allow to invoke contract call from inside getBalance, and there is where I need it to be. opStaticCall requires an interpreter *EVMInterpreter parameter I still don't have inside getBalance function. – Juan Ignacio Pérez Sacristán Jun 3 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.