Blockchain Nuts and Bolts: Part 1

Michael Coon
Coinmonks
7 min readMar 29, 2018

--

There are probably hundreds, if not thousands, of explanations of blockchain out there. Some are really good, and some, well, you know. Since I tend to get positive responses to my own definition of blockchain, I figure why not offer them to a broader audience. If you are new to blockchain or just want another perspective, this article might come in handy.

Let’s start with what you are using right now: the Internet. You have a web browser that is connecting to a server operated by Medium Inc. The browser asks that server for data and the server returns bytes that the browser renders and displays back to you as images and text. Simple enough.

There is something going on behind the scenes that is beautifully transparent to you: HTTP. When the browser asks the server for data, it has to speak a language that both the server and browser understand. This is what HTTP is: a standardized communication protocol between the browser and server. It allows us to generically build web applications without having to worry about low-level details like network protocols.

I truly appreciate the contributions of the giants that came before us, because if I had to deal with low level network protocols to build an application, well, I would spend a lot of time and energy figuring out which network to talk to, what machines to communicate with in that network, and what protocols to use. Aha! Now I’m describing precisely where we are in blockchain’s young history.

HTTP Analogies

Before the days of HTTP, and browsers in general, the “internet” wasn’t really inter-connected. There were several networks and protocols at play until the community finally settled on a set of standard protocols like TCP/IP and HTTP (https://en.wikipedia.org/wiki/History_of_the_Internet).

If you squint enough, you could say that this blockchain evolution is really just another kind of Internet. Except, it’s not exchanging HTML and image data (yet); it’s exchanging transaction data. More specifically, transaction data organized into groups called “blocks”. There are many networks sending these blocks around using different formats and protocols. And this is analogous to the early days of the Internet — like really early; like 1960’s early. Keep this in mind anytime you hear about blockchain — it’s complicated because it’s still a mess. But so was the early Internet.

Blockchain is kind of like the Internet; except instead of exchanging HTML and image data, it’s exchanging transaction data

Since we are really over-simplifying the concepts, why not keep going and explain it with terms we already understand? Consider that we use an Internet browser to view content served from an Internet server. The blockchain equivalent is that we use a blockchain wallet to view content produced by a blockchain miner. The wallet, like the browser, is the user-facing element of blockchain. The miner, like a server, generates data in the form of blocks. But on the Internet, the browser has a way of finding the server to ask for data. How does a wallet find the miner on the blockchain network?

A blockchain wallet relies on a client to perform the routing and networking necessary to interact with a blockchain miner. The same way a router sits between your browser and a server, a blockchain client sits between a wallet and one or more miners to handle the discovery and networking protocols.

Blockchain wallets interact with clients that communicate with miners to exchange transaction data

As already mentioned, a wallet is the user-facing component for blockchain. Its primary purpose is to allow a user to authorize and submit transactions to the network using a private key that only the user can access. We will cover wallets in more detail later; for now, let’s tackle this key thing…

Public and Private Keys

When we think of keys we think of little metal things we carry around to unlock doors and such. Each key has small grooves that fit into the slots of a lock. The slots and grooves must line up for the key to work. Public and private keys are similar in that the grooves of one must fit into the slots of the other. But instead of a mechanical fit, there is a mathematical fit.

Really the only thing you have to know about these keys is that the public and private key operate as a pair. If you encode something using the public key, it is only readable by its private key. If you encode something with the public key, it is only readable using the private key.

Undoubtedly you will hear references to “signing transactions” in blockchain. This basically means running some transaction bits through a math function along with the bits from the private key to generate a new set of bits called a “signature”. That signature can then be mathematically analyzed along with a public key to determine if, in fact, the public key’s private counterpart was used to generate that signature. In this way, every transaction signature submitted to the network is authenticated to have been signed by the private key owner, and thus the transaction’s author. This is the essence of what makes blockchain secure: transactions that do not pass this signature test are rejected from the network. And the likelihood of someone reconstructing someone else’s private key is so insanely improbable that you might as well say it’s impossible¹.

Miners

So who verifies these signatures? This is the job of a miner. They use the public key/address of the transaction’s sender to verify the embedded signature before including that transaction in a block. The miner is the most critical part of a blockchain network since its job is to verify all these transactions and put them into blocks. And because it’s so critical, it’s susceptible to cheating. How do we know if these miners are not allowing double spending from accounts or ignoring some set of transactions?

Every miner must prove to the network that they have something to lose if they cheat. This is accomplished in a growing number of ways but most commonly a proof-of-work (PoW) algorithm is used. With PoW, the miner has to solve a very complex math problem. This isn’t the kind of math that you can solve on a desktop or laptop, this takes a massive amount of CPU power, which translates to electrical power, which translates to money being spent. When they solve this math problem, they present the solution along with the block of transactions as evidence that they expended resources to create this new block. If they cheat, they just spent a whole bunch of money doing this math problem for nothing! So how is cheating detected?

Hashing

When a miner builds a block of transactions, it has to generate a “header” for each block. This header is composed of several things but one critical element is its “hash”. As John Oliver highlighted on his blockchain episode, hashing is kind of like taking chicken and turning it into a chicken nugget. The miner mashes bits together with the help of a math function to produce a smaller set of bits. This is a one-way function…you cannot reverse the process much like you cannot re-generate the chicken from a chicken nugget. So what goes into a block’s hash?

Every transaction to be included in the new block is run through this math function to generate a hash for each transaction. The bits from those hashes, along with the hash of the previous block, are run through the math function to generate a new hash that gets used in the new block header. Changing any of these bits going into the math function will dramatically change the output bits. So I can use that to verify if anything was changed by running the same transaction and previous block data through the same math function and compare the hash values. If the hashes are different, I immediately know something has changed. And because every block’s header is composed of the data within that block as well as the header of the previous block, the blocks are “chained” together by these hashed values — thus the name block-chain.

Racing

There isn’t just one miner doing all this work; there are thousands of them. Each of them are competing in a race to solve the math puzzle and claim the right to create one of these new blocks. Why are they doing this? Money, of course!

Every transaction includes a small fee that incentivizes the miner to actually verify and include the transaction in a block. In addition, the network usually rewards the miner with a certain amount of currency for each block it generates. In BitCoin, for example, each block is worth 12.5 BTC (valued today at about $98K USD). In Ethereum, each is worth 5 ETH (valued at about $2400 USD). Depending on market prices, this can be very lucrative; but is also very expensive to compute.

I’m going to stop here to let some of this sink in before moving on to Clients in part 2.

¹Some argue that the current algorithms used in blockchain can be broken. And time travel is also theoretically possible but no one has done it. Millions of hackers try to break blockchain every day. It’s not to say that it will never happen, but the odds are way against them because of the complexity of key generation.

Get Best Software Deals Directly In Your Inbox

--

--

Michael Coon
Coinmonks

Blockchain enthusiast, smart contract wizard, seasoned software engineer, personal development junkie