EVM

State Machine

  • Ethereum is a distributed state machine. Ethereum's state is a machine state, which can change from block to block according to a pre-defined set of rules, and which can execute arbitrary machine code.

  • The specific rules of changing state from block to block are defined by the EVM.

  • The state is an enormous data structure called a modified Merkle Patricia Trie, which keeps all accounts linked by hashes and reducible to a single root hash stored on the blockchain.

  • Deterministic state transition function: Y(S, T)= S’ → Given an old valid state (S) and a new set of valid transactions (T), the Ethereum state transition function Y(S, T) produces a new valid output state S'

Bytecode

  • Bytecode is a hexadecimal representation of the functions in a Solidity contract. The data payload of a transaction creating a smart contract is itself bytecode that runs the contract constructor, sets up the initial contract state and returns the final contract bytecode.

  • Constructors are not present in the contract once deployed.

ABI

ABIs are the definitions that help us know the method names, parameters and arguments, and data types that we can use to interact with a smart contract, and also the structure of events emitted by the smart contract. For functions, here are the properties found in ABIs (source):

  • type: specifies the nature of the function and will be one fof function, constructor, receive or fallback

  • name: what that function’s name is.

  • inputs: an array of objects with the following schema:

    • name: the name of the parameter.

    • type: the type of that parameter.

    • components: used when the type is a tuple.

  • outputs: an array of objects similar to inputs.

  • stateMutability: a string that specifies the state mutability of this function. Values are view, pure, view, nonpayable, and payable.

Opcodes

Opcodes are 1 byte in length leading to 256 different possible opcodes. The EVM only uses 140 unique opcodes.

Function Selectors

Function selectors are defined as the first four bytes of the Keccak hash of the canonical representation of the function signature.

// Examples of function selectors 
keccak256(“store(uint256)”) →  first 4 bytes = 6057361d
keccak256(“retrieve()”) → first 4 bytes = 2e64cec1

References: https://github.com/ethereumbook/ethereumbook/blob/develop/13evm.asciidoc

Last updated