Reading “How Bitcoin Works,” Chapter 2 of Mastering Bitcoin

Chad Ostrowski
BitClass
Published in
8 min readOct 6, 2017

My summary & reactions to Chapter 2 of the book Mastering Bitcoin. You may want to start with my synopsis of Chapter 1.

A supposed overview of how the Bitcoin network works, from the old version of Chapter 2 of Mastering Bitcoin. I don’t find this image particularly illuminating, but it is pretty.

First things first: an apology

I misled you in my last post. I advertised that I was reading the 2nd edition of this book, but I had in fact read Edition 1.

Why did this happen? Because I started reading the online version before the paperback came in the mail, thinking that it was the most recent version.

How did I discover it? Because Lisa and I compared notes on Monday (as per our schedule), and I realized that the list I gave in my last post of different types of wallets is a bit outdated.

If you want to read the most recent version for free, that one is available at a different spot online, as explained on their download page.

Chapter 2, “How Bitcoin Works”, synopsis & reactions

The bitcoin system, unlike traditional banking and payment systems, is based on decentralized trust. Instead of a central trusted authority, in bitcoin, trust is achieved as an emergent property…

This chapter walks through a couple example transactions on the Bitcoin network. The author, Andreas M. Antonopoulis, actually created transactions on the blockchain for us to examine. Here are some websites he gives for doing this transaction examining, along with some of my own thoughts as I looked through these:

  • Bitcoin Block Explorer: I like the “latest transactions” part that shows bitcoin transactions pouring in, and wonder what such a thing would look like for all Visa transactions happening right now. Probably too noisy!
  • BlockCypher Explorer: this is run by a company called BlockCypher, which calls its product “the infrastructure fabric for blockchain applications.” I don’t know what that means. They have a big call-to-action button that says For Business. I am not a business, so, so far this seems like a website not geared toward me. Then another big call-to-action button that says For Developers. Wait! I am one of those. But what even is this? “Considering a blockchain application? Contact us,” they say. Am I considering a blockchain application? I don’t know!
  • blockchain.info: I used to work with the president & co-founder of this site! Nicolas Cary. Hello, Nic! Remember when we hung out in Costa Rica together? Good times.
  • BitPay Insight: This is run by the same people who make the wallet I mentioned in my last post! The one I may have downloaded somewhat by mistake, but which I like anyhow.

Buying a Cup of Coffee

Bob says, “That’s one-dollar-fifty, or fifteen millibits.”

“millibits,” lol — do people say this? I’m going to start saying this.

The first example the book walks us through is Alice, introduced in my last post, buying herself a cup of coffee using bitcoin (here’s her transaction in the four different sites listed above; my favorite is the BlockCypher one). Bob who runs the coffeeshop says the “millibits” line, and then gives Alice this payment request QR code:

Bob’s Cafe payment request—you can scan this with a Bitcoin wallet app, but DON’T SEND MONEY. You will lose that money and any savvy book reader can steal it, i guess

This QR code encodes four different data points:

  1. A bitcoin address: "1GdK9UzpHBzqzX2A9JFP3Di4weBwqgmoQA"
  2. The payment amount: "0.015"
  3. A label for the recipient address: "Bob's Cafe"
  4. A description for the payment: "Purchase at Bob's Cafe"

These last two seem potentially exploitable to me! I’m not yet sure how I can go about creating my own QR codes, but a similar mechanism was recently exploited with a certain Ethereum wallet app to steal loads of money. If I create a label with some JavaScript embedded in it, then some wallet apps might actually execute that JavaScript when they display my label to their users, and I could potentially use that to do Bad Things.

A quick tip for looking at giant hashes

When I come across a giant hash, like “1GdK9UzpHBzqzX2A9JFP3Di4weBwqgmoQA”, my first inclination used to be to gloss over the whole thing and remember none of it. Don’t do this. Instead, just pay attention to the first three characters. “1Gd” — in most cases, when you’re just being a human reading about something, you’re probably not going to come across any other hashes that start with those three characters. So that’s all you have to memorize in order to keep things straight while you read!

Is Chapter 2 for non-techies?

I asserted in my last post that Chapters 1 & 2 of this book make a good, in-depth introduction to Bitcoin even for noncoders. I said this because the book says so itself.

Having read Chapter 2, do I agree?

I agree with caveats. This chapter was harder for me to read than the first. It’s fairly dense with new vocabulary, and I think I had an advantage because of some previous learning I’ve done. So, before you go read Chapter 2, I recommend you do the same learning! And then you can approach Chapter 2 as I did: an exercise in learning some of the lingo used by bitcoin/blockchain developers.

Recommended Learning before you read Chapter 2

Start with this fantastic video from 3Blue1Brown:

A superb introduction to the concept of distributed consensus & replacing units of money with a ledger of transactions

The other concept that I already had in my head:

The first thing to understand about bitcoins is that they do not exist, neither in digital or real form. The only thing that exists is the list of transactions.

This from previous coworker of both me and Nic Cary, Grant Ammons! Hi, Grant!

This idea is also introduced toward the end of the video above—if you have a ledger of all transactions that have ever occurred, then you don’t need currency. Or rather, the ledger is the currency. I can tell how much money you can spend because I can trace where all the money in your wallet came from, right back to when it was minted.

So as Chapter 2 would talk about inputs and outputs, I was able—with some effort & plodding reading pace—to map it to these ideas.

The Vocabulary of Bitcoin wallets

When you have a Bitcoin wallet, it will tell you that you have a certain amount of money in it. “10 millibits,” it will say. (Which is what? 40 bucks right now? Not bad!)

But remember, bitcoins do not exist. All that exists is the list of transactions.

Your wallet app is lying to you. It’s simplifying. It’s doing something akin to figuring out how much money you have in your bank account by looking back through your whole transaction history—it adds up all the credits to your account, and subtracts all the debits from your account. And it tells you the total.

The part that was hard to keep in my head was the weird words that blockchain people use for these credits and debits. (It would personally have not helped me if they had used the words “credits” and “debits” instead, because I also find banking confusing in general.) A credit to my account is an output to my account. What?

That is, if you look back through the entire history of all transactions in the network, all of them will output money to one or more different addresses. It’s like looking through the history of all payments on Venmo. And if you add up all the outputs that have come into your address, that’s the total amount of money you’ve ever received.

But each transaction in the whole history of all transactions also have inputs. And these inputs are the outputs of previous transactions. This is where my brain had to move slowly and build up a new mental model. I’m used to thinking about transactions in an account-centric way. Money into and out of one account. But thinking about the Bitcoin ledger, I have to work to switch to a transaction-centric model.

So when I give someone money from my Bitcoin wallet, that money doesn’t come from my wallet, per se. Instead, it comes from the previous outputs that I have received, which I haven’t spent yet. Or, I could say, it comes from the previous outputs to an address I control. (And how do I control an address? With my private key! For this , I already have a decent mental model built up.)

So the amount of money in my wallet is the sum of all transaction outputs that list me as the recipient minus the sum of all transaction inputs that list me as the patron.

But wait, there’s more

Since I don’t have a simple pot of bitcoins sitting in my wallet, but instead have a list of transactions with my address listed as the output, I don’t simply send someone money.

Say I’m gonna send you $3. In bitcoin-land, I don’t say “cool, here’s three dollars.” Instead, I say “here’s the one dollar I got from Gopesh, and here’s the one dollar I got from Joe, and here’s the 50 cents I got from Alice, and here’s 50 cents of the 75 cents I got from Jing.” So this one new output is made up of four different inputs: ($1 from Gopesh) + ($1 from Joe) + ($0.50 from Alice) + ($0.75 from Jing).

Now, I don’t have to do this, while I’m actually sending someone money. That would be a ridiculous hassle. Instead, my wallet application does all of it.

And actually, note that in my previous example the inputs available to me (the $1 + $1 + $0.50 + $0.75) add up to more than the $3 that I wanted to send you. They add up to $3.25. Well, I have to specify that $0.25 of it goes back to me. So the full transaction would look like this:

Using
($1 from Gopesh) + ($1 from Joe) + ($0.50 from Alice) + ($0.75 from Jing)
I will give
($3 to you) + ($0.25 to myself)

This feels goofy, for sure. But that’s because, as I said before, I’m used to thinking in an account-centric model, but when thinking about a public ledger of all transactions between anyone ever, I need to switch to thinking in a transaction-centric model.

Switching my thinking in this way was, for me, the hardest work of Chapter 2.

That was not quite a summary!

I didn’t summarize all of the details of Chapter 2.

The parts I didn’t mention were easier for me. I only dove into the details on the parts that tripped me up the most. Maybe other parts will trip you up. But hopefully, if you’re going to read it, my clarifications will help you get more out of it.

Let me know if this helped you! And let me know which parts you found the most interesting/perplexing.

--

--

Chad Ostrowski
BitClass

The cool summer starlight; the warm winter snow. I am interested in illegal fictions.