First things first, there are numerous cryptocurrencies, and they each have a rule book on how they work. This rule book is known as the protocol. You are probably wondering what exactly this has to do with SegWit. Well, just like any computer program, cryptocurrencies need to be improved, and they need to be updated. During this process, bugs and glitches are caught and then fixed. Last year, the Bitcoin protocol was updated with none other than SegWit. You’re still wondering what SegWit is? We are about to get there!
So, how did SegWit come to be? Pieter Wuille was the first to introduce this concept during a Bitcoin conference back in 2015. Who is Wuille? He is a Bitcoin developer and the co-founder of Blockstream. When he first brought this idea up, he mentioned that SegWit could be the answer to a flaw within the Bitcoin protocol. Such an answer or solution is known as a patch in software development. He was concerned with transaction malleability or the possibility of Bitcoin being stolen from users by changing itty bitty pieces of transaction information. This stirred up a whole lot of commotion, and it took two years before it went live. It first went live in August 2017, and a few months later, that same patch was applied to the Litecoin protocol. Litcoin was based on Bitcoin’s protocol and shared the same troublesome flaw. Segwit was able to go in and fix the transaction malleability problem as well as make a few other improvements. There are still those who question the validity of Segwit in the Bitcoin network, so much so they have gone off and made their own cryptocurrencies, but that’s another story for another time. To understand what SegWit does to handle transaction malleability, we are going to need to discuss the terminology and the basics of how Bitcoin transactions work.
Bitcoin is a massive network made of thousands of computers that are known as nodes. Each of these nodes holds a record of each transaction made by Bitcoin. This is known as a blockchain. Processing transactions are mostly done by a group of nodes known as miners. Once miners put new transactions into a group called blocks, they can be added to the blockchain. Each of these blocks has 1MB of transaction information. These blocks are typically processed within 10 minutes, though it could take longer. Bitcoin, on the other hand, can process 3-7 transactions per second. How exactly do transactions work? Let’s try out this scenario.
Samantha would like to send 10 Bitcoins to her buddy Jack. For this to occur, she would need to pieces of information. She would need to know a public address that is similar to an email address, and she would need to know a private key that acts as a password. While anyone can see the public address, only Samantha and Jack can see the private key, and they prove that these public addresses do belong to two of our two friends, Samantha and Jack.
Once she has this information, Samantha would broadcast a request to the network. Miners would then process this transaction and encrypt it with a computer code known as a transaction ID. The transaction queues and waits its turn to be processed. This could take some time, depending on how much of a transaction fee was paid. The higher you pay, the faster the service. The transaction ID is then added with all the other transaction ID’s belonging to other users and encrypted once more. This keeps going until 1MB is processed, and a block is made.
So in the first example, everything went smoothly for our friends. Let’s take a look at what could happen in the same scenario if a transaction malleability was to occur. So, let’s say our friend Jack, isn’t that great of a friend. He could easily trick Samantha into sending 20BTC instead of 10BTC by utilizing the transaction malleability flaw in Bitcoin’s protocol to his advantage and change his friend, Samantha’s witness data before the transaction is confirmed. The transaction ID would change, but the transaction itself would not, and Samantha would be left only seeing the original 10BTC. When the network confirms this tampered transaction, it gets cancelled by the original transaction. Now, Jack and call up Samantha and whine about how he hasn’t gotten that 10BTC yet, even though he has. So, Samantha being the good friend that she is, looks and sees that her original request has not gone through. She will then pay a higher transaction fee to ensure that it does. Then it gets processed, and old Jacky Boy gets another 10BTC. Samantha and the miners are left in the dark as they have no idea this is occurring because once a transaction is added to the blockchain, it cannot be altered or removed.
This is where SegWit comes into play. To stop the use of witness data in changing transaction information, Pieter Wuille suggested removing it altogether from the transaction. That’s how SegWit was born and got its name. It means segregated witness. Since segregate means to remove, SegWit does just that with witness data. A segregated witness creates a sidechain. In these sidechains, the witness data is kept away from the main blockchain. This ensures that folks like Jack can’t change transaction IDs. Another cool feature about the Bitcoin segwit is that it is backward compatible. This means that nodes that have not been updated can still work with nodes that have been. This is considered crucial. Never should there be an update breaking backward compatibility. Such an “update” is a hard-fork and would require killing the main-chain.