Safety
Last updated
Last updated
The safety property is a statement about how long the transaction has to be on the selected chain before we have our confidence that a transaction won't revert is at least . That is, with the .
We already agreed there is no hope to defend against a -attacker, so we assume .
For such , we want the confidence to grow exponentially fast. In other words, if we make twice as small, we don't want to be twice as large. In fact, we want something much stronger: that no matter how many time we halve , each time would add a constant amount of time. If you have some background (say, from in the appendix), you know that such a relationship between and can be expressed by the following equation:
This motivates the following:
Definition? The protocol is safe if for any it holds that
The problem with this definition is that, as it turns out, it is impossible to satisfy.
Before we understand how to correct the definition, we discuss a magical world where it can be satisfied, and is actually satisfied by Bitcoin.
Consider how Bitcoin works under the following unrealistic assumption: the honest network never creates orphan blocks. That is, all honest blocks to ever have and will be created are arranged in a chain.
Hence, even when attacked, the network looks something like this:
where is the transaction the adversary tries to double-spend and is a conflicting transaction.
We expect the honest network to create blocks for any blocks created by the attacker. In other words, the honest network createes blocks faster. No matter what is, as long as it is smaller than , the gap between the honest and adversarial chain will increase. And, as we reason later, the probability that the adversary reverts the chain decreases exponentially with this gap.
In reality, orphans do exist in the honest network. However, recall that we assumed that the adversary can arrange their blocks in a perfect chain. This means that the attacker can revert the chain with less than half the hashing power. Say that the honest network orphans one in three honest blocks, and that . We find that the honest network creates of the blocks, but a third of them goes to waste, so only two thirds of that, namely of all the blocks, are honest network blocks. This means that although , the adversary and honest network are neck to neck. If we slightly increase the adversary fraction to , the attack will almost certainly succeed.
More generally, say that a fraction of of the honest blocks is orphaned. For any blocks created by the adversary, the honest network creates blocks, but only will be honest chain blocks:
Hence, the network has no hope against an -adversary unless . Note that the no-orphans case described above is exactly when , and we get the usual equation , or .
If we solve the more general equation for we get the following condition:
You can check that the right-hand side is for , and goes to as approaches , let us plot it:
Strictly speaking, we conclude that Bitcoin could never satisfy the safety definition we proposed above. The orphan rate is always positive. The Bitcoin orphan rate is estimated to be at most one in , so if we plug into our formula, we get that Bitcoin is "only" safe against adversaries with at most of the hashrate.
This almost makes it seem as though there are no repercussions to this entire orphan thing, and we can just ignore it. But that's wrong. Bitcoin's very low throughput is the price Satoshi had to pay to obtain such a small orphan rate.
More generally, is mostly determined by two quantities: the block delay , chosen by the protocol designer, and the network latency , which is also somewhat determined by the protocol designer. "Huh?" you ask, how can the protocol designer affect the network latency? By choosing the block size! Larger blocks take longer to traverse the network. This is not because they contain more data, that actually has negligible effect. It is actually because the data needs to be verified by each node, and the verification process typically grows linearly with the size of the block (verifying transaction inputs will take about four times longer than verifying transaction inputs).
To ensure a low orphan rate, Satoshi suggested to parameterize Bitcoin such that . It is this requirement that protects us from high orphan rates degrading the security. It is this requirement that is more commonly known as "the Bitcoin scaling problem".
It is common to wonder wether a ten-minute block delay is an exaggeration. Won't we be fine if we decrease it to, say seconds?
To better understand the consequences, we will quickly analyze the relationship between , , and .
we can compute that
So we expect at least orphans per network delay. And since there are block delays in a network delay, we expect at least orphans in a block delay.
The approximation is only accurate for very small values of . That is, under the assumption that . But we can clearly see that in this regime the orphan rate is inversely proportional to the block delay. That is, by making the block delay twice shorter, we double the rate of orphans, and so on. In particular, decreasing the Bitcoin block delay to, say seconds, will cause at least as many orphans. Now instead of we have , and putting it into the equation we get that the threshold for double-spend attacks reduced to .
That might not seem that much, but when we analyze confirmation times we will see this has very tangible bearings on how long it takes to confirm a transaction.
Also, keep in mind that we only computed a lower bound on the number of orphans, and a very rough one at that. We only considered cases where a single block is orphaned, and did not take into account the scenario that longer chains of two, three, or more blocks, are also orphaned. These events become increasingly likely as orphan rates increase, making non-negligible higher-order contributions to the orphan rates.
It is a common misconception that “orphan rates decrease gains for miners”. This misunderstanding follows from the reasonable thought that if we have to throw blocks in the garbage then whoever mined this block is in the loss.
However, that is not quite the case. The difficulty adjustment algorithm only controls the issuance rate of non-orphan blocks. There is no other way: since difficulty has to be in consensus, it can only depend on blocks that are on the chain.
In particular, if we have, say, an orphan rate of 20%, then mining blocks will be 20% easier, increasing the block rates to compensate. Yes, one fifth of the blocks you make will go to the trash, but you will make 1.25 times more blocks, giving you the same rate of non-orphan blocks.
You might be tempted to think that a 20% orphan rate implies only 80% of the hash rate you see on the blockchain goes towards non-orphan blocks. So if the difficulty requires one tera hash per second to see a block every ten minutes, then an adversary will only need 800 giga hash to 51% attack the network. Again, this is not the case, the hash rate read off the difficulty only takes non-orphan blocks into account. This (combined with the fact that nodes do not broadcast blocks they see as orphans) makes measuring orphan rates in practice extremely difficult (especially if we consider that old orphans can be forged for cheap).
That being said, there are adverse consequences to high orphan rates (besides the wasted work): they introduce noise that increases confirmation times, and increase the advantage for miners with a better internet connection.
So if we want any hope for a security definition that is actually feasible, we need to accept the fact that our assumption on a fixed network delay comes with the price of having to choose some , and then set the parameters such that the network is secure assuming of the miners are honest.
One might be tempted to use the expression we derived for in the definition, but that would be a mistake. This computation was specific to Bitcoin. Our definition needs to be general. In fact, it shouldn't use the word orphans at all, as this would be too presumptuous. Orphans are just one way that things can go wrong, but we need to be ready for anything.
The property of orphans that interests us is this: as goes to zero, the orphan rate also goes to zero, and with it (though we have yet to prove it!), the required . This is the magic property that we want.
This leads us to the following:
Definition: A blockchain protocol is -safe if for any it holds that . A protocol is safe if it is -safe.
A necessary (and almost sufficient) condition for an orphan to be created is that more than one block is created within a period of . As , the number of blocks created in this period ditributes as . Using the approximation
For those not used to , it might seem "complicated" to write something like "-safe", but it is actually a great example of how asymptotic notation can help us conveniently focus on what matters to us: that as goes to , the value of required so that we could be -safe also goes to . The relationship between and could be arbitrarily complicated, but we don't mind. We only care that they vanish together.