Skip to content
Gav Wood edited this page Nov 14, 2017 · 10 revisions

Welcome to the polkadot-spec wiki!

Polkadot is primarily described by the Relay chain protocol; key logic between parachain protocols will likely be shared between parachain implementations but are not inherently a part of the Polkadot protocol.

Relay chain

The relay chain is a proof-of-stake blockchain in a similar balance/nonce mould to Ethereum, backed by a Web Assembly (Wasm) engine.

State & Transition Function

Its state is roughly similar to Ethereum: accounts are a mapping from a U64 account index to balance (U256) and either a nonce (U64) or code (H256, a SHA3 of Wasm code) and storage (H256, a Merkle-trie root for a set of H256 to U8[] mappings).

In reality almost all accounts would be basic and contain only two entries (balance and nonce). Code-bearing accounts ("high accounts") would fulfil specific functions (though over time these may expanded or contracted as changes in the protocol determine). The accounts can be listed:

  • Account 0: Left intentionally null.
  • Accounts 1...: The basic accounts.
  • Account ~4: Basic account lookup account. Stores a mapping U64 -> H160 providing a partial public-key derivative ("address", similar to an Ethereum address) for each account index. Can be used to register new accounts (in return for some price). All U64s begin at 0x1.
  • Account ~3: Parachain management account. Stores all things to do with parachains including parachain balances and current state.
  • Account ~2: Consensus account. Stores all things consensus (including the proof-of-stake algorithm) and code is the relay-chain consensus logic.
  • Account ~1: Administration account. Stores and administers low-level chain parameters. Can unilaterally read and replace code/storage in all accounts, create DOTs, &c. Hosts and acts on stake-voting activities.

For PoC-1, high accounts are likely to be built-in, though eventually they should be implemented as Wasm contracts.

The transition function may be compared to Ethereum, where:

is mostly similar to an unmetered variant of Ethereum runnong that all but removes smart contracts. Exceptions:

  • Utilisation of Wasm engine for code execution rather than EVM.
  • Code-bearing accounts do not harbour or increment a nonce when deploying.
  • Wasm intrinsics replace each of the EVM externality functions/opcodes:
    • ADDRESS -> account_index
    • BALANCE -> balances[]
    • CALLVALUE -> incoming_value
    • CALLDATA* -> incoming_data
    • CODE* -> this_code
    • BLOCKHASH -> blocks[]
    • TIMESTAMP -> current_time
    • NUMBER -> current_number
    • ORIGIN -> n/a
    • GASPRICE -> n/a
    • EXTCODE -> n/a
    • COINBASE -> n/a
    • DIFFICULTY -> n/a
    • GASLIMIT -> n/a
    • GAS -> n/a
    • LOG* -> n/a
    • CREATE -> deploy (which takes a new account index and clobbers any existing code there; no init function is run).
    • CALL -> call
    • RETURN -> (return in Wasm)
    • CALLCODE/DELEGATECALL/SUICIDE -> n/a
Clone this wiki locally