It seems when a single function is called, the Ethereum Virtual Machine:
- Does ‘pre-call checks’ for exceptions/errors.
- Computes the amount of gas needed, checks that the accounts involved exist.
Gets the function parameters.
Creates a calldata buffer & returndata buffer in memory, as subtly depicted in py-evm code:
- Consumes Gas and performs the compute via stack operations & opcodes. (SideQuestion: Are both stack operations & opcodes stored in the Virtual ROM EVM code?)
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?)
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.