Execution model

source: https://www.evm.codes/about

  • stack based computer
  • all instructions take args from stack except PUSHx
  • sequential execution
    • JUMP / JUMPI
    • REVERT
  • execution context:
    • data regions
    • variables (program counter)
    • current caller (sender)
    • callee
  • code region:
    • sort of immutable
      • SELFDESTRUCT / redeploy via CREATE2 can cause it to change between 2 transactions
    • EOAs have empty
    • CODESIZE / CODECOPY
    • EXTCODESIZE / EXTCODECOPY for cross-contract
      • return zero for contracts under construction
      • indistinguishable from EOA, cannot trust detecting an EOA as an address on chain
  • stack:
    • 32byte word size
    • stores instruction inputs/outputs
    • one created per call context
    • destroyed at end of call context
    • 1024 values max
    • PUSH1, POP, DUP1, SWAP1
  • memory:
    • not persistent / destroyed at end of call context
    • initialized to 0
    • MLOAD / MSTORE
    • CREATE / EXTCODECOPY
  • storage:
    • retained past completion of a call
    • 32byte keys, 32byte values
    • SLOAD / SSTORE
  • calldata:
    • region
    • sent to transaction as part of smart contract transaction
    • immutable
    • CALLDATALOAD / CALLDATASIZE / CALLDATACOPY
    • xCALL
  • return data:
    • RETURN / REVERT to set
    • RETURNDATASIZE / RETURNDATACOPY
  • gas
    • validators “vet” transactions before they’re added
    • they get paid for this
    • memory expansion - offset accesses can cause more cost, grows quadratic
  • access sets - list of storage slots
  • touch slot lists - storage slot keys accessed by contract addresses
  • gas refunds
    • contracts w insufficient gas fail

Node types

source: eth docs – nodes and clients

  • Every L2 has its own EVM or VM
    • Have sequencer but not consensus
      • sequencer orders transactions
  • Ethereum has:
    • execution (EVM) (EL) (eth1)
      • listens to transactions
      • executes them in EVM
      • holds latest state/db of all eth data
    • consensus (PoS) (CL) (eth2)
      • implements PoS
    • validator - can add to consensus client
      • “secures” network
  • Running a node:
    • Validating full node: 32eth staked
      • winning a block gives you reward
      • and you get to order transactions from the mempool into the block
    • Consensus-only/nonvalidating full node
    • Light node: block headers only
      • downloads block headers only
  • “Gnosis safe” == “safewallet” == a smart contract wallet you can deploy to any EVM

thanks @dcbuilder and kuilin