knowledge-kitchen

Blockchain - The Nuts & Bolts of Hashes, Merkle Trees, Private & Public Keys, and Smart Contracts

Database Design

  1. Overview
  2. Bitcoin basics
  3. Smart Contracts
  4. Conclusions

Overview

Concept

A blockchain is mechanism for storing data with a few properties that make it unusual.

Creation myth

The true indentity of the inventor of blockchain is either unknown or disputed.

Kleinman’s family are currently embroiled in a farcical legal dispute with Wright.

Bitcoin basics

Example code

Some of the basic cryptography concepts mentioned in this section, including hashes and digital signatures, are exhibited in Python code in a companion set of Jupyter Notebooks

Hash

A cryptographic hashing function is a algorithm that can take data of an arbitrary length and produce a unique fixed-length ‘digest’ form of the data - the hash of the data.

Hash (continued)

Hash SHA256

Hash (continued)

Hashes have two important use cases:

The recipient can then run the message through the hashing function, and compare the hash to the hash received from the sender. If the two match, then the message has not been tampered with by a 3rd party.

Thus, if trying to find data that produces a hash with specific attributes, a brute force approach must be taken, where a message is modified and hashed repeatedly until a hash with the desired attributes is encountered.

Proof of work systems require that a message sender have performed a particular amount of computational work by rejecting messages that do not contain a hash meeting specific requirements.

The first such system, created in 1997, was called Hashcash, and was intended to make spam unprofitable by requiring emails to show proof of work.

Nonce

A nonce is arbitrary data added to a message in order to change the hash of that message so as to hopefully meet the hash requirements of a proof of work system.

PS:

Nonce (continued)

Nonce

Mining

Mining is the process of trying out different nonces over and over again until one is found which, when added to the data in the message such that the requirements of the proof of work system are met.

Mining (continued)

Mining

Public key cryptography

Public key cryptography is a set of technologies for proving ownership of digital data. Two mathematically interrelated keys (text strings) are involved:

It is derived from the private key by a one-way mathematical function.

Public key cryptography (continued)

There are two main uses of public key cryptography:

Only the recipient, who holds the corresponding private key, will be able to decrypt the message.

The recipient can use the sender’s public key to verify the authenticity of that signature, and thus the message.

Privacy

Public key encryption for privacy

Authentication

Public key encryption for authentication

Addresses

In blockchains, each user has an address from which they can send or receive cryptocurrency transactions.

Merkle tree

A Merkle Tree, or hash tree, is a hash of hashes, where the top-most hash can be considered a fixed-length digest of the data beneath it.

Merkle tree (continued)

Merkle Tree

Block

At last, we come to the foundational concept of the blockchain - the block! Each block includes:

Block (continued)

A block

Block (continued again)

A block

Block (continued once more)

Since each new block includes the hash of the previous block, any tampering with data in previous blocks (which would change their hashes) would invalidate subsequent blocks.

Invalid blockchain

Block (continued yet again)

Since the proof of work scheme requires that a block’s hash meet certain specific requirements which are time-consuming to achieve, there is an intentional latency to the system.

Transactions

Each transaction stored in a block includes details about the sender, the recipient, and the amount of funds to transfer.

The authenticity of this signature can be validated by anyone, by simply using the sender’s public key.

Mining (continued)

Computers running the full version of the blockchain software (a.k.a. ‘full nodes’) compete with one-another to solve the hashing challenge of the proof of work system.

They tend to pick those transactions that offer them the highest tip, if any are available.

Smart Contracts

Concept

While Bitcoin included a limited scripting language that allowed some programmable logic to be placed inside of any transaction, Ethereum is the blockchain that took this concept to the next level.

The entire network is considered a single virtual machine execution environment.

Dapps

Decentralized applications, similar to the apps that most people are familiar with on the web, can be hosted on a blockchain, in combination with related decentralized platforms.

Tokens

Tokens are arbitrary representations of value.

This standardization allows for interoperability among smart contracts and even between different blockchains.

Other tokens act as symbolic representations of ownership or possession of physical goods.

Still other tokens are useless except for the fact that you can trade them for other tokens or fiat currency.

DeFi

The world of decentralized finance (DeFi) - finance on the blockchain - has become extremely popular within the last year.

Concerns

Concept

Given the relative newness of blockchain, the incessant touting of its disruptive capabilities, and its explosive growth as a means of financial speculation and perhaps exploitation, many concerns about it have cropped up, including:

Listen to crypto explainer Andreas Antonopoulos consider “Blockchain vs. Bullshit””.

View the Cambridge Center for Alternative Finance’s comparisons of Bitcoin’s energy consumption to other common energy draws.

Watch self-proclaimed Satoshi, Craig Wright, denounce decentralization as “a lie” and the Brookings Institute tout its crime-fighting properties.

Nobody is really sure if this is possible.

Some nations, like China, are trying to subvert it.

Conclusions

Thank you. Bye.