Introduction to SegWit – Part 1. The Issue of Malleability on the Bitcoin Network

Every bitcoin transaction includes a 64-digit hash, also known as a transaction identifier. A hash, also known as a cryptographic hash, is a string of data created by a cryptographic algorithm. The algorithm creates only one hash for one set of data and this hash is always the same for the same set of data, yet hashes for the sets of data that may be just a little bit different look very differently. For example, a hash for the set of numbers (0,0,2,2) can be 11231323 and a hash for the set (0,1,2,2) can be 5556777.

Sets of numbers of the computer networks are much larger than in the example above and can consist of thousands of transactions or other pieces of information, yet even large sets of data would have hashes that are relatively short. For example, block #503535 on the Bitcoin network has information about 2212 transactions. You can see all the information about the block here: The hash for the block is 0000000000000000004ec519f0bc9e267216bdbe0be8dda8347cc82301a601dd

The algorithm that the Bitcoin network uses to create hashes is called SHA-256. It was created by the National Security Agency and it is one of the most secure cryptographic hashing algorithms in the world. This algorithm is one of the reasons why Bitcoin network is so secure.

The reason why the Bitcoin network and other computing systems use hashes is that a hash is a quick and convenient way to check the validity of large sets of data without having to process all the data or even have access to the data. Here’s how it works: you have a set of data that consists of 1,1,1,3,4,5. You create a hash for this data using a secure cryptographic algorithm and let’s say that the hash is aX5. Then, you give this hash to someone else and this someone else needs to check if the data that they have received from a third party is the same as the data that you have. Using a hash, they don’t even need to spend time looking at your data. They don’t need the original data at all. All they need is to ask the third party for the hash for the data and then compare the hash to aX5. If the hash they get is the same, it means that the data is the same. If the data is even a little bit different, then the hashes are going to be different, too.


How transactions work on the Bitcoin blockchain

During a transaction on the Bitcoin network, a party transfers digital ownership of a certain amount of bitcoins to another party. For example, if you have 3 bitcoins in your wallet and you want to send 1 bitcoin to your friend, what you are doing is transferring the right to 1 coin to your friend. The remaining 2 coins will stay in your wallet and you will still be the owner of that amount of the digital currency.

For the bitcoin network to accept a transaction is valid, the transaction needs to have at least one input, which means that a transaction can have more than one input. An input is a reference to a transaction that has occurred on the bitcoin network in the past. Every input on the network is an unspent output of one or several of the previous transactions. For example, let’s say you want to send 1 bitcoin. 0.6 will come from wallet address #2, 0.15 will come from address #4 and 0.25 will come from address #7. If you have no money in wallets with addresses 1, 3, 5, 6, then you can’t use these addresses as inputs.

Every input needs to have a digital signature, which is the same as the transaction identifier mentioned in the very beginning of this article. The signature of the identifier is associated with a private key of a bitcoin wallet of the sender. While all of this may sound complicated, the network can verify this data very quickly because it can use hashes instead of huge sets of data.


The issue of malleability

The way the bitcoin network creates the transaction identifier (also known as the signature or txid) makes it possible for a third party to slightly modify it. When such a modification happens, the transaction doesn’t change. The same amount of digital currency will leave the addresses specified in the transaction and will arrive to the destination. However, when the malleability occurs, the transaction gets confirmed by the network under a completely different txid. This can happen when a node on the network that is relaying the transaction or the miner that includes the transaction in the block introduces a tiny change to the txid of the transaction. Malleability on the bitcoin network is only a problem when a party needs to spend funds before the funds get confirmations from the network.

This is the reason why the issue exists in the first place. When Satoshi Nakamoto created the network in 2009, the network was not popular enough for people to want to spend the funds right away. However, malleability can be an issue for the merchants that want to spend funds right away after receiving them. The more popular bitcoin gets, the more merchants get on board with the currency, the more important the issue is going to become.

SegWit protects the network from malleability. SegWit is short for Segregated Witness. It is a protocol to which users of the bitcoin network can move the parts of the transactions that have the malleability risks.