Skip to content

Instantly share code, notes, and snippets.

@nichochar
Last active May 13, 2022 21:58
Show Gist options
  • Save nichochar/5302e4b050c762cd7ba18d7c356704ae to your computer and use it in GitHub Desktop.
Save nichochar/5302e4b050c762cd7ba18d7c356704ae to your computer and use it in GitHub Desktop.

Definition

A blockchain is a distributed, append-only database that is shared among the nodes of a computer network. It has no central authority, but rather relies on consensus between nodes to validate the chain of data as it gets built. The innovation with a blockchain is that it guarantees the fidelity and security of a record of data and generates trust without the need for a trusted third party (like a bank, a government, or a private company).

Blockchains are best known for their crucial role in cryptocurrency systems, such as bitcoin (2009) or ethereum (2013), even though they were invented in 1991 for timestamping documents in a way that could not be tampered with.

Blocks

The internal data structure of a blockchain is an ordered linked list of blocks, which are immutable data containers.

Blocks contain a nonce (explained below), new transaction data, the previous block’s hash, and the hash of the previous parts, concatenated.

Once the block data is approved, through consensus algorithms, the block write is committed and will forever be a part of the blockchain.

The hash function is public knowledge (usually, sha256), meaning anyone can validate the chain.

Modifying the transactions data of a block will invalidate not only its own hash, but all subsequent ones.

Consensus

Because blockchains are decentralized, there is not central authority that can be trusted to know that the next block (containing all new transactions) is valid. Therefore, they require a consensus algorithm to build confidence about this validity.

This is actually a hard problem that peer-to-peer networks have struggled with, and bitcoin solved cleverly by using an algorithm called proof-of-work, originally invented in 1993 to combat spam emails or other denial of service type attacks.

The intuition of this algorithm is that all nodes compete to be the creator of the next block. They all have the transaction data to put in it, and a hard puzzle condition (create an output_hash hash with multiple leading zeroes). They randomly try different nonces and compute:

output_hash = hash(nonce, data, previous_block_hash)

Finding the right nonce is hard, but verifying it is easy. Miners get rewarded for winning this game, incentivizing more miners, and therefore incentivizing security to the network.

There are other consensus algorithms, the most promising of which is called proof-of-stake.

\

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment