Ethereum

Clients

Full nodes(size is ~340GB:

  • Parity (Rust)
  • Geth (Go) ← most popular

Ownership

Private key k is 256 bits or 32 bytes, a huge number, generated randomly1, for example:

k = c058c9248b784d9f9664a28eec87c30bb19e00beb33701ae4c414d099f34b533

Public key K can be derived from the private key k, using elliptic curve multiplication:

K = k*G

where G is a publicly known Generator point on an elliptic curve. It is not feasible to do a reverse operaion2.

An ethereum address A can be derived from the public key K, using Keccak-256 one-way hashing function:

A = Keccak256(K), get last 20 bytes

Wallets

Wallet holds and manages the keys.

  • Non-deterministic - a bunch of unrelated keys, each key requires a separate backup
  • Deterministic(HD) - seed → deterministic keys, only a seed requires a backup

1 ETH = 1018 Wei

Accounts

Ethereum is an Account-based blockchain. Each Account has a balance, unlike UTXO-based blockchains(like Bitcoin) where the balance is a sum of UTXOs:

  • In UTXO-blockchains a private key k controls multiple UTXOs
  • In Account-blockchains a private key k controls a single Account

There are 2 types of accounts:

  1. Externally Owned Accounts, with properties:

    • Ownership through a private key k
    • Has an address A
    • Can initiate transactions
  2. Contract Accounts, with properties:

    • Owned by a smart contract code
    • Has an address A
    • Can't initiate transactions(no k)
    • Can call other smart contracts

The only way a Contract Account can fire a transaction is in response to another EOA transaction.

Blocks

  • Blocks contain transactions
  • Block is generated about every 12 seconds
  • Block size is about 90KB

Transaction Structure

  • Nonce — transaction number, issued by EOA, prevents replays
  • Gas price — amount of ether(in wei) originator is willing to pay per 1 gas
  • Gas limit — max amount of gas an originator is willing to buy
  • Recipient — destination ETH address
  • Value — amount of ETH(in wei) to send
  • Data — binary payload(for smart contracts)
  • v, r, s — components of ECDSA

Gas is a constant price per operation(opcode) on the EVM, for example ADD costs 3 gas and BALANCE costs 100 gas, see: evm.codes. Gas is decoupled from ether because ether is volatile, and if, for example, ether price sharply rises, the validators can nevertheless lower the gas prices. Ethereum requires a Gas limit, because EVM is Turing-complete, thus loops are possible and there is no way to predict if the program is finite, so Gas limit protects the network against the denial of service attack. When the Gas limit is reached the program stops.

Unlike Bitcoin, where an entire UTXO must be spent, Ethereum utilizes a Nonce to monitor an Account's spending. Suppose an Account with 10 ETH conducts two transactions for 5 and 6 ETH, respectively. The network will consult the Nonce field to determine the order(and thus which transaction to execute and which one to reject).

Transactions can be classified as:

  • Payment — a transaction with a Value
  • Invocation — a transaction with Data
  • Payment and invocation — a transaction with both a Value and Data

The Gas limit for a simple a Payment is 21000.

It is possible to override or cancel a transaction until it's included in a block. To cancel, set a value to 0, recipient to your own address and a gas price should be higher than that of the original transaction.

Ethereum Smart Contracts


  1. Generating a private key k must be done in a secure way, using true random generator. Tossing a coin 256 times and writing down the sequence of 0s and 1s is a way to get truly random and secure k

  2. Unless you have a working quantum computer