ethereum training

Ethereum Virtual Machine

Ethereum POC5 (well, almost...)

ethercasts

Ethereum Yellowpaper

Yellowpaper
  • Stack based architecture (256bit word size)
  • Transaction-based state machine
  • Low level bytecode language “EVM code”
  • Pay fee per step (no infinite loops)
  • Code is immutable

Transaction-based state machine

Transaction-based state machine

Ethereum Accounts

  • accounts are identified by 20 byte-address i.e. 0xd32fd7ecf43d1c2c0c553f1f515a8b5973456ec2
  • have ether balance
  • either externally owned (user accounts)
    • private key known to owner
  • or contract with:
    • contract code
    • storage (empty by default)
    • no private key

Denominations

1Wei
10^12Szabo
10^15Finney
10^18Ether

Messages / Transactions

  • transactions have value: amount in ether
  • recipient: address (externally owner or contract), or none to create contract
  • data arguments
  • cost of execution gas/gasprice
  • contracts can return a value (functions)

Fees

  • gas used to pay for execution of contracts
    • gaslimit - maximum amount of gas to pay
    • gasprice - fee to pay to miner per step
  • when contract runs out-of-gas (OOG): state changes reverted (except for balance & fees)

Fee schedule

1Default amount of gas to pay for execution cycle.
0STOP or SUICIDE
20SHA3, SLOAD, BALANCE, CALL
100SSTORE (sometimes double or waived)
1Every additional word when expanding memory
5Every byte of data or code for a transaction
500Every transaction

Code execution

  • init/code block: init executed upon creation, returns body with code to be persisted
  • Stack - each item 256 bit, LIFO, push/pop
  • Memory - word based indexing, unlimited byte array (limited by fees), reset at end of computation
  • Storage - persisted key/value store

Operations

Arithmetic Operations

ADDAddition operation
MULMultiplication operation
SUBSubtraction operation
DIVInteger division operation
SDIVSigned integer division operation
MODModulo remainder operation
SMODSigned modulo remainder operation
EXPExpontential operation
NEGNegation operation

Relation Operations

LTLess-than comparison
GTGreater-than comparison
EQEquality comparison
NOTSimple not operator

Bitwise Logic Operations

ANDBitwise AND operation
ORBitwise OR operation
XORBitwise XOR operation
BYTERetrieve single byte from word

Crypto Operations

SHA3Compute SHA3-256 hash

Environmental Information

ADDRESSGet address of currently executing account
BALANCEGet balance of currently executing account
ORIGINGet execution origination address
CALLERGet caller address
CALLVALUEGet deposited value by the instruction/transaction responsible for this execution
CALLDATALOADGet input data of current environment
CALLDATASIZEGet size of input data in current environment
GASPRICEGet price of gas in current environment

Block Information

PREVHASHGet hash of most recent complete block
COINBASEGet the block’s coinbase address
TIMESTAMPGet the block’s timestamp
NUMBERGet the block’s number
DIFFICULTYGet the block’s difficulty
GASLIMITGet the block’s gas limit

Stack, Memory and Storage Operations

PUSH1..32Place n-byte item on stack
POPRemote item from stack
DUPDuplicate stack item
SWAPExchange stack items
MLOADLoad word from memory
MSTORESave word to memory
MSTORE8Save byte to memory
SLOADLoad word from storage
SSTORESave word to storage

Flow Operations

STOPHalts execution
JUMPAlter the program counter
JUMPIConditionally alter the program counter
PCGet the program counter
MSIZEGet the size of the active memory
GASGet the amount of available gas

System Operations

CREATECreate a new contract
CALLMessage-call into contract
RETURNHalt execution returning output data
SUICIDEHalt execution and obliterate account

What's next?

⇒ Learn Serpent

Questions / Feedback?