EVM State#
The EVM is a state machine. A valid Ethereum program or valid bytecode can manipulate that state.
A specific opcode is an operation that manipulates that state.
Program Counter (pc)#
The program counter points to the next opcode that the EVM is going to execute.
Stack / Memory / Storage#
All of them are part of the EVM state. And are the areas where the EVM manipulates and stores data.
Program#
This is where we store the bytecode of the current program. It can not change during execution, which makes it immutable.
Sender#
Address of the account currently executing this program. Equivalent to msg.sender in Solidity.
Gas#
We need to keep track how much gas we currently have and how much we already consumed. Most opcodes make the gas counter go down.
Value#
How much Ether (wei) this current execution can consume.
Calldata#
Is the input to our program.
Flags#
We are going to keep track of two flags. The stop_flag and revert_flag. If one of them is True the current execution is going to stop.
Returndata#
The EVM can return data after execution. We store this data in return.
Logs#
There are several opcodes that emit logs when executed. The result of these logs is saved here.
class State:
    def __init__(self,
                 sender,
                 program,
                 gas,
                 value,
                 calldata=[]):
        self.pc      = 0
        
        self.stack   = Stack()
        self.memory  = Memory()
        self.storage = Storage()
        
        self.sender   = sender
        self.program  = program
        self.gas      = gas
        self.value    = value
        self.calldata = calldata
        
        self.stop_flag   = False
        self.revert_flag = False
        
        self.returndata = []
        self.logs       = []