I’ve worked in cryptography, information security, and digital money for half of my life (20 years, but who’s counting?), and I’ve never worked on a cryptosystem as ambitious as Zcash. Fortunately, I’ve also never worked with ateam so uniquely skilled at the exacting task of constructing secure and practical cryptosystems.
An essential part of the practice of computer security is an “adversarial” process in which you try to attack a system — to find weaknesses in it — at the same time as you are trying to strengthen it. This process can be disconcerting to outsiders, but to computer security experts, if we see someone finding, fixing, and publishing security issues, this gives us confidence that the system is getting stronger.
In this blog post, we report on the security issues we’ve found in the Zcash protocol while preparing to deploy it as an open, permissionless financial system.
Some of our team published the original Zerocash science paper , with scientific peer review, in 2014. Recently, we have extended and improved the protocol, written a detailed new protocol specification , and scoured it for security vulnerabilities.
To date, we’ve found and fixed three security vulnerabilities:
- Zooko Wilcox found the Faerie Gold vulnerability , which would have made it possible to fool a Zcash user into thinking they received a bunch of spendable notes. In fact, when they try to spend the notes they will find that only one of them can be spent.
- Taylor Hornby found the InternalH Collision vulnerability , which would let someone double-spend a specially-crafted note, if they have a computer powerful enough to find 128-bit hash collisions.
- Daira Hopwood found a non-exploitable mistake in the security proof , where if one of the pseudorandom functions the protocol uses is not also collision-resistant, then notes sent to a specially-crafted private address could be double spent. (This was not exploitable because the function that is actually used does happen to be collision-resistant.)
Here is Taylor’s write-up of the most impactful of these three — the InternalH Collision Vulnerability, which he found.
— Zooko Wilcox, 2016-04-25
The InternalH Collision Vulnerability
Had we launched Zcash without finding and fixing the InternalH Collision vulnerability, it could have been exploited to counterfeit currency. Someone with enough computing power to find 128-bit hash collisions would have been able to double-spend money to themselves, creating Zcash out of thin air.
Finding 128-bit hash collisions requires 2 64 parallelizable operations, which is within reach of attackers today, so the vulnerability would have been exploitable in practice. Let’s see how the attack works, and what we did to fix it.
The weakness was in the commitment scheme for notes. Commitment schemes are useful cryptographic tools because they let you publish a commitment to some information without revealing it. Then, at some later time, you can open the commitment to reveal the information and prove to everyone that it’s the same information you committed to in the first place.
In order for this to work, commitment schemes need to satisfy two properties:
- Hiding : You don’t learn anything about the information from seeing the commitment. Even if you’re pretty sure of what the information was, you shouldn’t be able to confirm your guess.
- Binding : If you commit to some value, you shouldn’t be able to change your mind later and say you actually committed to a different value. A commitment should open to one unique value, and it shouldn’t be possible to open the commitment to any other value.
In Zcash, the fundamental object of value is called a “note”, which consists of the values ( a pk , v , ρ , r ) which have special meanings in the protocol. As part of the protocol, commitments to notes are published onto the blockchain. Here’s how that commitment was computed in the original design:
InternalH = SHA256Compress ( a pk ∥ ρ ) truncated to 128 bits
k = SHA256Compress ( r ∥ InternalH )
cm = SHA256Compress ( k ∥  192 ∥ v )
Here, SHA256Compress is the compression function used internally by the SHA256 hash function.
The InternalH Collision vulnerability exists because this scheme is missing the binding property. It’s possible to commit to one note and then open the commitment later to a different note.
It’s easy to see how this can be done if you can collide 128-bit hashes. The commitment starts out by computing InternalH , an 128-bit hash of a pk and ρ , and then committing to that hash. If you find an InternalH collision, then you have two different a pk and ρ pairs ( a pk , ρ ) and ( a pk ′, ρ ′) that give the same InternalH , and you’ll be able to open the commitment to either of ( a pk , v , ρ , r ) or ( a pk ′, v , ρ ′, r ) . So the commitment scheme isn’t binding. How does this weakness translate into an attack?
Commitments to all notes in existence are stored on the blockchain. In order to spend a note, you must prove in zero-knowledge that you know the spending key for a note that was committed to on the blockchain and you must reveal that note’s nullifier. The nullifier is a value that’s supposed to be unique for each note. To make sure no note can be spent twice, all nodes on the network check that they haven’t seen the newly-revealed nullifier before.
The nullifier of a note ( a pk , v , ρ , r ) owned by a spending key a sk is computed by applying a psuedorandom function to ρ , i.e. the nullifier is PRF nf a sk ( ρ ) . The spender must prove in zero-knowledge (without revealing ρ or a sk ) that they computed the nullifier correctly.
The InternalH weakness lets an attacker craft a note commitment for which two different valid ρ values exist. They can find ρ 1 and a different ρ 2 such that the commitment opens to either ( a pk , v , ρ 1 , r ) or ( a pk , v , ρ 2 , r ) . The attacker can spend the note commitment a first time using ρ 1 revealing the nullifier PRF nf a sk ( ρ 1 ) , and then spend it a second time using ρ 2 revealing the nullifier PRF nf a sk ( ρ 2 ) . In effect, this note has two different nullifiers instead of just one, so it can be spent twice. Since all of this is done in zero knowledge, none of the nodes on the network can tell that both spends are referencing the same note commitment. Another variant of the attack works by finding two different a pk , rather than two different ρ.
For every 128-bit hash collision the attacker finds, they can effectively double their wealth by combining all of their Zcash into one double-spendable note and then double-spending it to themselves. So even though the 2 64 operations to find a collision aren’t cheap, the attack quickly pays off.
If you read Section 5.1 of the original Zerocash science paper , you’ll find that InternalH was chosen to be 128 bits in order to give the commitment scheme a very strong property called statistical hiding . The ordinary hiding property is computational: it says that you can’t learn anything about the input unless you have an absurdly fast computer (i.e. capable of breaking SHA256). Statistical hiding says that even if you have an infinitely fast computer , you still can’t learn anything about the input. This would have allowed Zcash to retain its privacy guarantees even if one day the SHA256 hash function were broken.
To fix the vulnerability, we switched to a different commitment scheme that has secure binding. In order to keep the Zcash zero-knowledge proofs efficient to compute, we dropped the powerful statistical hiding property and settled for the regular one. This shouldn’t matter in practice, since in order to break the hiding property of our new commitment scheme, you’d have to break a well-studied security property of SHA256, which seems unlikely to happen anytime soon. Here’s our current design for the note commitment scheme:
cm = SHA256 ( 0xB0 ∥ a pk ∥ v ∥ ρ ∥ r )
You can find the full details in our protocol specification .
Building secure crypto protocols is hard, and even our team of world-class cryptographers and security engineers will make mistakes along the way. Despite the challenge, we’re optimistic that our practices of careful security review and transparency will lead to a secure product.
At this point the Zcash protocol has been subjected to intense security review, first through scientific peer review, and then by our in-house team of experts. But we need even more scrutiny to gain assurance that the protocol is safe.
If you like the challenge of hunting for bugs in crypto protocols, we would love it if you had a look over our protocol specification . If you can break our protocol and tell us how you did it, you will be helping all of humanity to gain an open, permissionless, privacy-preserving financial system!
— Taylor Hornby with Zooko Wilcox, 2016-04-25