2

I'm working on instrumenting VM of GETH in order to index interesting data from the blockchain. I did manage to intercept the call and see internal transactions, but I want to go a little deeper, and 1) understand what method is called on the smart contract 2) Call myself a method on the smart contract I'm investigating on that line in evm.go

return interpreter.Run(contract, input, readOnly)

first of all I'm noticing that many many time input is just empty, shouldn't always contain the function to call on the SC? Is there some facility inside GETH to understand what input is? Ie which method call it represents? how can I add ( if I can ) add another call to interpreter.Run to call another method on the contract? ( for instance balanceOf on an erc20 contract? )

2
  • You mean instrumenting as in benchmarking or looking into the VM for figuring out the stack trace and the contract calls?
    – DaveIdito
    Nov 6, 2018 at 14:38
  • @Davelvito figuring ouit the stack trace and contract calls... Nov 6, 2018 at 17:02

1 Answer 1

3
+50

I'm noticing that many many time input is just empty, shouldn't always contain the function to call on the SC?

Not necessarily. A public function selector in CALLDATA is optional. Calling into a contract with empty CALLDATA will execute the contract nonetheless. In practice, the fallback function will be executed, and it simply receives (and sometimes refuses) Ether.

Is there some facility inside GETH to understand what input is? Ie which method call it represents?

Do not know about GETH. From an execution standpoint, all you'd have would be the target contract address and the CALLDATA input bytes. If there are any, the first four bytes represent the public function selector (the "method call it represents"). Going from the 4-byte selector to an actual function name or prototype can be partially done: reverse lookup tables were built, using various means. A public one can be found here: https://www.4byte.directory/

how can I add ( if I can ) add another call to interpreter.Run to call another method on the contract? ( for instance balanceOf on an erc20 contract? )

That's specific to GETH, and I do not know that client specifically. Sorry I can't answer this one. I can only tell you it can be done, you'll need to find where to hook your code, and then it's a matter of dispatching properly (knowing the ABI of the target routine, you will be able to build valid CALLDATA, including the function selector I mentioned earlier.)

1
  • 1
    This is actually a good answer, covering the fallback function, that is good. Unfortunately can't deserve the bounty cause covering GETH is what I need. Nov 7, 2018 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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