Cyber Security

Luke Hally

Bitcoin and blockchain

September 17, 2021
Categories:

Thanks to my involvement in fintech, I’ve been around the edges of bitcoin and blockchain for a while

Traditional money relies on a trusted third party, either a government backing the currency or a bank keeping a ledger of transactions so we know the money is there. But before this, we had money with intrinsic value, i.e. gold, silver etc.

Digital currency is different in that it is digital, it can be easily modified, so how do we ensure the integrity of the currency – you got it, hashes.

Integrity

The blockchain is a distributed (not centralised) ledger which tracks transactions and uses hashes to ensure integrity. A block is a chunk of transactions. When miners create a new block, they take the hash of the previous block and add it to the new block (sounds like a Merkle-Damgard), this adds information from the previous block to the current blocks and forms a chain of integrity – if you change a block, you would need to change all subsequent blocks to cover up the change. Meanwhile miners are adding new blocks as fast as they can so you could never catch up to them.

If there is a dispute, the person with the longest chain wins.

Proof of work

Creating a bitcoin takes a lot of work. They also have a magic number – the hash must meet a certain condition, eg it has to start with certain string of characters. So the miner has to keep rehashing until this condition is met. This ensures that bitcoins can’t be created too quickly (it typically takes 10 15 minutes). The algos are also periodically modified to make mining harder.

Let’s practice

We completed an activity making our own blockchain. Each block had a form like this:

<block number>+<a bold prediction>+<has of previous block>+<serial number>

First step was to make a bold prediction of an organisation who is going to be hacked in the future. That’s easy, Services NSW, they have form. But alas, Richard our course manager had taken them in the first block! So I went with AUKUS, the new Australian, UK and US alliance. 

Next step was to find the last block. So I found the latest block was number 9, a cursory glance didn’t turn up any other block 9 or an existing block 10. Block 9 had a hash of: 0905e9c5415e21449f90b9aa3dfbaa809148c8e7b90765ff83612c2f3eb978dc

So my block is:

10+aukus+0905e9c5415e21449f90b9aa3dfbaa809148c8e7b90765ff83612c2f3eb978dc+serial number

For our block to be valid, it’s first character needs to be a 0 and second character needs to be a digit. How do we do this? Iterate the serial number until our hash is valid. So I started with 1 and incremented, hitting a valid hash at serial number 39. Giving me the block:

10+aukus+0905e9c5415e21449f90b9aa3dfbaa809148c8e7b90765ff83612c2f3eb978dc+39

With a hash of: 

035645f9efe10e11bfc0f7c84a1b1929aaa1e3b18025c346292a4431cfd7944e

I tested this on https://hackerstoolkit.net/sha256/ and also in terminal using open ssl (using this command: echo “10+aukus+0905e9c5415e21449f90b9aa3dfbaa809148c8e7b90765ff83612c2f3eb978dc+39” | openssl sha256).

Reflection

It was good to get a handle on using openssl in terminal and verifying my hash to two places gave me confidence. The next time I’m at a meetup and my blockchain/bitcoin connections are there, I’ll be able to actually talk about it and its applications with them. I now feel that I have a solid understanding of how the blockchain works and most importantly how it has inherent integrity.

And I finally understand the digital part of bitcoin. Digital transactions of real money still have real money behind them, it is just the information about the transaction that is digital. Digital currency is itself digital. I still don’t see the value of it, other than speculative trading, but I understand it.

Recent posts