#StackBounty: #solidity #evm #pyethereum What Sequence Occurs 'Under the Hood' When an Ethereum Contract Function is Called?

Bounty: 50

It seems when a single function is called, the Ethereum Virtual Machine:

  1. Does ‘pre-call checks’ for exceptions/errors.

  2. Computes the amount of gas needed, checks that the accounts involved exist.

  3. Gets the function parameters.

  4. Creates a calldata buffer & returndata buffer in memory, as subtly depicted in py-evm code:

source https://github.com/ethereum/py-evm/blob/0ff7bc0f820250d7f15e804bc09870776ea34eb5/eth/vm/logic/call.py

  1. Consumes Gas and performs the compute via stack operations & opcodes. (SideQuestion: Are both stack operations & opcodes stored in the Virtual ROM EVM code?)
  2. It seems the evm does a ‘1st pass’ where the values & pointers are added to the stack [and to the stack’s memory scratchpad as needed].
    (Uncertain as to this ^ process?)

  3. Then once the function completes/returns, the EVM discards memory (including the the 2 buffers) & stack frame data.

Main source: Ethereum’s py-evm i.e. https://github.com/ethereum/py-evm/blob/0ff7bc0f820250d7f15e804bc09870776ea34eb5/eth/vm/logic/call.py

What am I missing here?

When I step through on Remix to view the stack, it seems the EVM does a ‘1st pass’ where it loads what the function needs into the function’s stack + memory, is this correct? Is this referred to as the function’s call stack/call frame?

It seems many devs including myself are unclear on this ‘under the hood’ sequence. Thank you.

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.