Hash Functions
Learn the different attacks on hash functions in this lesson.
Overview
Bitcoin relies on two different hash functions, namely SHA256 and RIPEMD160. These functions have four different applications in Bitcoin:
-
Addresses are mainly derived from a public key by
-
Solving the PoW requires finding a nonce , such that
where is the pre-defined target.
-
Each block header is uniquely defined by its hash .
-
Transactions are stored in a Merkle tree by applying double SHA256 in each step.
We outline the consequences of a successful attack against a hash function of these applications. For simplification, we consider as being one single primitive, which we call the address hash.
Attacks against the address hash in P2PKH transactions
Attacks against the address hash in P2PKH transactions include the following three possibilities:
-
Preimage attack: The preimage attack aims at revealing the public key from an address hash . As the public key gets revealed during a transaction, there’s no preimage attack against already spent transactions as the public key is already known. A preimage attack against the address hash can thus only be applied to reveal the public key for a UTXO. However, this attack isn’t enough to unlock the UTXO since the unlocking script requires both a public key and a valid signature, as shown in this section. Since the public key gives no information about the private key that’s needed for the signature, a preimage attack against the hash function carries no risk for any UTXO.
-
Second preimage attack: The second preimage attack aims at finding a different public key that hashes to the same address as a given does, i.e.,
Even if an attacker finds a valid second preimage for , they can’t steal the coins because they don’t know the corresponding private key . So, they can’t sign a transaction that would spend the corresponding UTXO.
-
Collision attack: The collision attack aims at finding two different public keys that hash to the same address, i.e.,
However, a successful collision attack gives no advantage to the adversary because they control both and , but have no knowledge about the corresponding private keys.
In summary, we can say that an attack against the address hash gives no advantage for an attacker, as long as the signature scheme isn’t affected by another attack.
Attacks against the PoW
Attacks against the PoW include in particular the preimage attack. The preimage attack against PoW aims at finding a valid block header that fulfills
for a freely chosen . Such an attack would break Bitcoin’s mining mechanism. However, it’s important to understand that not every preimage that satisfies the previous equation is a valid solution to the PoW. The reason is that the Bitcoin network not only checks if the hash of the header is below the target but also checks if the metadata of the header is valid as well. So, an attacker can’t simply compute a preimage of any chosen but must find a whose preimage is recognized by the network as a valid block header of 80 -bit size. Looking at the block header’s entries, one sees that the version number, the hash of the previous block, and the difficulty target as well are considered to be fixed. Thus,
-
Preimage attack against a fixed Merkle root: This attack assumes a fixed Merkle root.
give the following estimation of the probability of a successful attack:Giechaskiel et al. (2016,2018) (Ilias Giechaskiel, Cas Cremers, and Kasper B. Rasmussen. On bitcoin security in the presence of broken cryptographic primitives. In Ioannis Askoxylakis, Sotiris Ioannidis, Sokratis Katsikas, and Catherine Meadows, editors, Computer Security ESORICS 2016, pages 201-22, Cham, 2016. Springer International Publishing.) - (Ilias Giechaskiel, Cas Cremers, and Kasper B. Rasmussen. When the crypto in cryptocurrencies breaks: Bitcoin security under broken primitives. IEEE Security Privacy, 16(4): 46-56, July/August 2018.) We are looking for a block header whose -bit hash is below a given , whose value starts with zeros. If an attacker controls bits of the input, there are possible input values to the hash function, which need to map to a hash value below the target, which means that they need to hash to one of the values in the target interval. Since these values are uniformly distributed across values, we get an expected number of existing -bit preimages.
As there are preimages of size -bit, which are distributed across values, we get the probability of that a given hash below the target has a preimage of size -bit. If we assume that an attacker is able to evaluate hash values, we get a probability of of breaking the mining process. By observing the unfixed bits of the block header’s entries (the nonce and a part of the timestamp) and the current difficulty,
estimate that the probability of success is about , which can be considered as negligible.Giechaskiel et al. (2018) Ilias Giechaskiel, Cas Cremers, and Kasper B. Rasmussen. When the crypto in cryptocurrencies breaks: Bitcoin security under broken primitives. IEEE Security Privacy, 16(4): 46-56, July/August 2018. -
Preimage attack against a variable Merkle root: If the attacker can vary the Merkle root, they get an additional 32 bytes of freedom, and can thus break the mining process because of these considerations. In order to control the variable Merkle root, the attacker mines the block with only a coinbase transaction.
Get hands-on with 1200+ tech skills courses.