The last time Hackerfall tried to access this page, it returned a not found error. A cached version of the page is below, or clickhereto continue anyway

Scorex-Lagonaki/components.md at master ScorexProject/Scorex-Lagonaki GitHub

The Architecture Of A Cryptocurrency

Though we have thousands cryptocurrencies buzzing around at the moment, all of them share the same implementation design. Basically every cryptocurrency implementation has following parts:

Network Protocol

P2P network is the core of a cryptocurrency, and the core is following some network protocol. It is pretty simple usually. For example, p2p network of a cryptocurency could be implemented with asynchronous exchange of the following messages:

The minimalistic set is pretty similar to Scorex message types. Bitcoin has more complicated protocol for sure(https://en.bitcoin.it/wiki/Protocol_documentation#Message_types) as well as NXT.

Let's consider an example of a blockchain downloading with messages types given above if peer A knows only peer B and has genesis block only. So possible trace of interaction of A and outer world could be as follows (where A -> (B, M2) means (peer A sends an instance of message kind M2 to peer B)):

  1. A asks B for peers: A -> (B, M5)
  2. A asks B for a B's blockchain height: A -> (B, M3)
  3. B replies for the first message with known peers C & D: B -> (A, M6)
  4. B replies for the second message with it's height H(B): B -> (A, M4)
  5. A asks C for its blockchain height: A -> (C, M3)
  6. A asks D for its blockchain height: A -> (D, M3)
  7. C replies with its blockchain height H(C): C -> (A, M4)
  8. D replies with its blockchain height H(D): D -> (A, M4)

    So A have 3 known heights H(B), H(C), H(D) and a bigger height means better chain(for a Proof-of-Work cryptocurrency), so A chooses peer with a best chain, e.g. D. Then it's going to download a chain from D with a following cycle:

  9. A asks D for a block with height (2,3,...,H(D)): A -> (D, M7)

  10. D replies with a block requested serialized into a binary form: D -> (A, M2)

Any real trace is much more complicated than this example :)

Consensus Protocol

By using network protocol a node can download one chain or another or even multiple chains (as different peers can have different chains). Then the question is what is the canonical chain shared by majority, the right kind of history an user can rely on. Consensus protocol aims to solve the problem.

A node follow rules to determine canonical chain like these:

  1. Every block in a chain must be valid as well as its signature

  2. Every block must have a valid reference to its parent with first block having reference to a genesis block which is constant for an each node

  3. Every block must be generated by a party having a right to produce it

  4. From multiple chains, one having maximum score is the canonical. If few chains have the same score first seen or a random one could be chosen

Some notes about the rules:

Transaction Protocol

A block contains transactions. A transaction is the global state modifier. In simplest case it modifies balance sheet. As there's no central party, each node need to have the same state as others(for the same block height). So each node executes all the transactions coming within blocks, and validity rules must be same for each network participant.

A transaction could be implemented in different ways depends on goals:

Internal State

In Bitcoin node store no any state at all or use different formats for it, e.g. UTXO list or some indexes in addition to that. In contrast, Ethereum has state hash stored into each block, so each node must comply with some standard state representation interface given in the Yellow Paper to check block validity. There's also interesting proposal from Bill White(coming along with Coq theory) about using special kind of Merkle tree and storing its root into block for scalability's sake: http://qeditas.org/gitweb/?p=ledgertheory.git;a=blob_plain;f=lightcrypto.pdf;hb=HEAD.

The Protocols Mess Problem

The real problem of cryptocurrency development process is the mess of all the parts described above. The most known example, even simple change in software validation(so in Transaction Protocol) could causes hardforking.

Acknowledgments

The idea of Network/Transaction/Consensus protocols was initially explicitly stated by L.M Goodman in the "Tezos: A Self-Amending Crypto-Ledger Position Paper" (http://tezos.com/position_paper.pdf). I would like to thank lead Nxt developer Jean-Luc Picard for conversations via dev maillist, and Bill White for very thoughtful conversations.

Following Articles

Continue reading on github.com