Homework
Office hours
Our starting point into cryptocurrencies is to build a digital version of a banking system, where people can transfer money to each other electronically over the Internet without the need for a single trusted banking authority.
It should be "secure" against "powerful adversaries."
(We will make more precise today both the security requirements and the kinds of adversaries that we can withstand.)
Alice | Mallory | Bob | ||
---|---|---|---|---|
$\longrightarrow$ | $\longrightarrow$ |
In the physical world, when Bob receives a check from Alice, he may be suspicious that Alice is trying to deceive him. He needs to be able to verify the following three properties.
Alice properly signed the check
Alice possesses $1 in her bank account
Alice does not double spend the money by writing a check to someone else at the same time
For a digital monetary system:
Source: Wikipedia
Imagine for the moment that there was a book where:
If you had such a ledger, you could use it to:
In fact, you don't even need to do both! One can be inferred from the other.
The account model is what we are used to from the traditional banking system. In this approach, the bank maintains a list of every account and its current balance. When a transaction is submitted, the bank updates its record of accounts by debiting the sender and crediting the receiver.
Most cryptocurrencies work in the other direction: they store a public ledger containing every financial transaction ever made. This is called the unspent transaction output model, or UTXO.
[Image source: Nakamoto whitepaper]
(Note: transactions are slightly more complicated than just a digital signature; they can involve more sophisticated computer scripts. We will return to this point in a future lecture.)
The data structure for such a ledger is a blockchain. It is a sequence of blocks, which themselves contain several transactions.
If everyone acts honestly, the intention is that new blocks are only added to the end of the chain.
[Image source: Nakamoto whitepaper]
At a high level, there are three types of participants within Bitcoin.
A light client only needs to hold one or more secret keys for a digital signature scheme. (And optionally also a small amount of additional data, which we will discuss next time.)
We consider the corresponding public key also to be the name of their bank account. These accounts might have money, if (1) someone else has sent money to this account within some transaction in the past and (2) no subsequent transaction has spent the money.
A miner additionally tries to write new blocks on the blockchain.
We will explore the role of miners in more detail today.
Bitcoin needs miners: without them, no money transactions can ever be recorded.
So the system incentivizes people to become miners in two ways. If you create or mine a new block, then:
You get to create new coins out of thin air. Specifically, you get 6.25 Bitcoins, which is worth about $140,000 at current exchange rates. (This is the only way that new currency gets introduced into circulation.)
You receive the fees that people set aside for you within their transactions.
If all miners act honestly, then the ecosystem works well: people can conduct money transfers over the Internet, and the miners receive a reward for their efforts.
But what if miners are dishonest? What could go wrong?
Just to state upfront: a bad miner cannot directly create a new transaction to spend your money. Only you can do that, because it requires your secret key.
In more detail, thanks to existential unforgeability under a chosen message attack:
Recall that we will consider three categories of security concerns in this course.
Bitcoin doesn't provide any confidentiality guarantees: the whole world knows how much money is in each account, and perhaps might be able to link an account to a real-world identity. (More on this later.)
The other two security issues can be impacted by a malicious miner.
Here are 3 types of attacks that a malicious miner could perform. (Note: there are other possible attacks too.)
[Image source: Bitcoin wiki]
As an example, suppose that Mallory pays Alice and subsequently Alice pays Carol. If a miner deletes the Mallory-to-Alice transaction, then the later transaction becomes invalid as well because Alice no longer has any money to spend.
Even worse, if Mallory is the miner, then Mallory could post a new transaction that pays the money to another account under her own control... perhaps her friend Bob, or perhaps another account held by herself). In this way, Mallory has reclaimed her previously-spent money to spend again in the future.
Cryptocurrencies like Bitcoin have been carefully designed to ensure that censorship, inconsistency, and double spending attacks are practically infeasible to perform. (Note: these 3 attacks are actually related, but for the purposes of today's lecture we will treat them separately.)
Before we describe Bitcoin's strategies, let's discuss:
One possible option is to find a single person who the whole world trusts, and ask that person to be the sole miner in the scheme.
Sadly, we do not have such fully-trusted people. And even if we somehow found such a person, we might ask them to run everything for us, not just the banks. In political terms, this corresponds to a (benevolent?) dictatorship.
To extend the political analogy further, over the centuries humankind has designed democratic social structures in which we:
These political systems are often less efficient and nimble than a dictatorship might be, but they are more stable as a result.
Cryptocurrencies abide by these principles too! Let's see how.
Let's see how Bitcoin thwarts these attacks, one at a time. For now, let's just assume that the miners all promise never to conduct a double-spend attack. (We'll fix this trust issue later.)
Bitcoin includes two components to thwart censorship:
There is a connected network of Bitcoin nodes that gossip or broadcast any transaction they hear. This way, any sender can get their transactions heard by any node and miner who happen to be connected to the network right now.
We will say more about broadcast protocols in future lectures. For now let's assume that this part works perfectly.
There is a randomized election system (or in other words, a lottery) to choose the next miner. It doesn't matter (much) who wins the election; the important part is that the nodes have agreement on who has won.
The upshot here is: each individual miner can still censor your transaction if they want. Nevertheless, as long as at least one miner is honest, then your transaction will eventually get put into a block.
This is an example of an anytrust assumption; we will see more examples later in the semester.
The miner inserts their winning lottery ticket -- or more formally, the nonce
-- into the block as well. Other miners and nodes will only consider a block to be valid if it includes a winning nonce
.
Just like with the earlier political analogy: we have designed a cryptocurrency that is more stable, but at the expense of speed. Whereas you might assume that an Internet-based money scheme would be fast, instead this system is purposely slow. Within Bitcoin,
In computer science terms: the throughput of this monetary system is low.
This strategy also solves the problem of inconsistency, which was the fear that nodes might see different blockchains.
(Recall that we are assuming for the moment that miners will never go back and try to rewrite history.)
Even with this simplifying assumption in place, one concern is that two miners might win the lottery at (almost) the same time.
If this happens, they will produce blocks that are different -- they have different nonce
s, and they each pay the mining rewards and fees to themselves.
[Image source: Mango Research]
We can overcome this issue by using the peer-to-peer network to broadcast these blocks as well. Then we can impose a rule that all honest nodes should follow:
Always choose the largest* blockchain. As a tiebreaker, choose the chain that you heard first.
In Bitcoin terminology, each block contains a counter called its block height.
(*Note: we will make one small tweak to this rule in a few minutes.)
[Image source: Mango Research]
Once again, we have resolved an attack at the expense of speed. Let's look at the above picture in the following scenario: block A
already exists, and now in th present it happens to be the case that two miners win the lottery at nearly the same time and post blocks B
and B2
.
Suppose also your transaction occurred in block B
but not in block B2
.
In computer science terms: the latency of any individual transaction is high.
The final -- and most insidious -- attack that we have to prevent is the double spend.
[Image source: Bitcoin wiki]
We will also solve this problem by intentionally imposing friction into the cryptocurrency. Specifically, we haven't discussed yet how miners win the election and get the right to create a new block.
Assume that there are more honest miners than dishonest miners. Our goal is to choose an election method that is fairly likely to elect an honest miner.
[Image source: Nakamoto whitepaper]
Here's how it works. Every miner collects all of the transactions from the peer-to-peer network, and forms a block. Then:
nonce
value however it wants. (It can choose this at random, or make a counter, or anything it wants.)0
bits, then the miner has won the election and quickly posts the result to the peer-to-peer network. Otherwise, it goes back to step #1 to try again.Currently, the Bitcoin miners collectively perform about $295 \cdot 10^{18}$ hashes per second.
This corresponds to $177 \cdot 10^{21}$ hashes every 10 minutes. The difficulty level of Bitcoin is currently set to require this many hash computations in expectation, in order to produce a winning nonce
.
[Image source: blockchain.info]
That's a lot of work! By means of comparison, your laptop's CPU can probably perform about a billion hashes per second. If you have a nice graphics card, that might be able to perform a few trillion hashes per second.
This effort by the miners is called a proof of work. Only after performing this work can a miner post a block.
The proof of work puzzle relies on the property that a hash function "looks random" even though it is public and deterministic.
If an adversary [Mallory] has not explicitly queried ... on some point $x$, then the value of $H(x)$ is completely random... at least as far as [Mallory] is concerned.
– Jon Katz and Yehuda Lindell, Introduction to Modern Cryptography
So if we ask the miners to find an input whose SHA-256 hash digest begins with several 0
bits, we believe that the miners cannot do anything more intelligent than just a guess-and-check approach.
This property of a hash function is called puzzle friendliness.
(Technically speaking: this property is a stronger requirement than collision resistance, but a weaker requirement than the random oracle assumption.)
Because the computational power in the world goes up over time, the difficulty of the puzzle must adjust over time. If miners start finding blocks faster than the desired 10 minute interval, then difficulty of finding a block increases.
As a result, we need to make a small change to the rule that honest nodes follow:
Always choose the blockchain with the most cumulative difficulty.
In general, this typically corresponds to the blockchain with the tallest height.
Bitcoin relies on the following assumption:
The majority of the computational power used for mining (at any given time) is controlled by honest miners.
If this assumption holds, then a leader election based on proof of work (eventually) stops double-spending attacks. That's because a dishonest miner cannot keep up with the raw computing power of the honest majority.
(Note that this assumption is weaker than the "anytrust" assumption that we discussed earlier.)
To see why this is the case, let's use the same picture as before, but now assume that:
D
has been posted.B
.[Image source: Mango Research]
To do this, the miner will need to post many proofs of work in a row, very quickly. It needs to create $3 + N$ blocks faster than the real world produces $N$ blocks.
This is a Markov chain problem. [Image source: Nakamoto's whitepaper] calculates that even if a dishonest miner controls 10% of all the hash computing power on the blockchain, it will only have about a 1.3% chance of succeeding at this attack.
The attacker can increase its chance of success by buying or renting more computational power. In response, defenders can resist this attack by waiting for more blocks to be confirmed in the public, honest chain.
Suppose there is a transaction that pays you money, but you don't trust the sender and you want to be confident that the money is "safe" and cannot be taken away from you through a double spend attack. You want to be 99.9% confident that your money is safe (i.e., that a double-spend succeeds with only 0.1% probability).
The Nakamoto whitepaper includes the following table that shows how many blocks you need to see mined after your block, as a function of the dishonest miner's computational power.
Adversary's computational power | # blocks required |
---|---|
10% | 5 |
15% | 8 |
20% | 11 |
25% | 15 |
30% | 24 |
35% | 41 |
40% | 89 |
45% | 340 |
There are two important takeaways from this table:
The hash power required to execute a double-spend attack quickly becomes onerous enough to be not worth it, for all but the most expensive transactions. Even if the attacker controls even 10% of the Bitcoin network's computing power, executing a double spend attack will likely take more than one hour. By contrast, if the miner uses this hash power honestly to create new blocks, it could have earned (in expectation) tens of thousands of dollars in mining fees.
On the other hand, if the attacker controls the majority of the hash power, then your money is never safe; even transactions made years ago could eventually be double-spent. This is called a 51% attack.
Let's state that a node considers a block to be finalized if it is at least $k$ blocks deep inside of the longest chain. We'll declare a transaction to be finalized if it is part of a finalized block. (The choice of $k$ here affects the probability of an erroneous decision.)
Overall, this proof of work construction achieves the following objectives.
(Note that we have not yet provided any security guarantees to the light clients.)
In order to achieve these goals, Bitcoin is purposely designed to be:
Over the next few weeks of this course, we will explore alternative ways to satisfy the liveness and safety goals with different tradeoffs.