So you’ve read some stuff about blockchain (maybe even my last article), you’ve had a few conversations about it… But still don’t really get it?
What you really want to know is…
How does blockchain work?
Blockchain technology consists of many different pieces. Just like with Lego, you choose the pieces you use to make the finished product. This post and my next post will explore the key building blocks and how blockchains are made:In this post we will look at 2 of the building blocks that show how blockchain works:
1) Transactions (Bitcoin as an example: sending money between participants, proving ownership and identity)
2) The blockchain structure (the chain of blocks and how to put one together)
To do this, we need to know more about the concept of hashing…
Making a hash of it
A hash (or hash reference) is a random string of numbers. Hash functions are a method of creating an identifier for a set of data. You put something in, the function does its thing with the code, and it spits something out. That something is called a hash (or hash reference).
The hash spat out by the function is determined by whatever you put into it in the first place.
For example, when you input the sentence ‘Amanda loves blockchain’, the output might be ‘288ejald20038afljadl463283lqpppskw42839’. This is called the ‘hash’.
The hash of ‘Amanda loves blockchain’ will always be ‘288ejald20038afljadl463283lqpppskw42839 when that sentence is run through a hash function, because it is determined by the sentence I entered.
Hash references are usually irreversible, which means that given ‘288ejald20038afljadl463283lqpppskw42839’, I cannot work out that the input was ‘Amanda loves blockchain’. I’ve just used random combinations of characters here, but usually hash references are set lengths depending on the function that produces them.
Hashing can therefore be used to prove the ‘identity’ or content of a particular set of data, without revealing the content itself.
Building Block 1) Transactions – public and private keys
One use of hash references in blockchains is creating transactions; sending money or an equivalent ‘cryptocurrency’ (digital money) from one participant to another. The Bitcoin blockchain is the most well known example of this.
Public and Private Keys
The public and private key system enables one person to send cryptocurrency to another. Each person needs a pair of keys, one public and one private, to enter into transactions. We can use the public key to generate the private key through a mathematical formula, so that they’re digitally linked.
The public key also produces your ‘address’, which you need for someone to send you something (eg. A Bitcoin) on a blockchain.
There is a private key linked to each public key. The private key is secret and only its owner should know what it is, like a password.
If someone else gets access to your private key, they can use it to impersonate you and steal your stuff.
Private keys are simultaneously a proof of ownership and of identity. By proving you have the private key linked to a particular public key, you can prove you are the owner of a token or asset on a blockchain.
Private keys are used to provide a digital ‘signature’ on every transaction that is sent on the blockchain – to prove authorisation by the true owner of the value being moved.
It is possible to require multiple private key holders to sign a particular transaction to provide extra security – this is called ‘multisig’ and can be useful if more than one person’s authorisation is required to release funds.
If you have a business and want multiple staff to sign off on certain purchases for example, this could be one way of doing it.
Building block 2) The blockchain structure
This is about how we put the information about transactions into the blockchain.
Each transaction is hashed into a structure known as a ‘Merkle tree’. This looks like an upside-down tree with multiple branches, where the hash of each transaction is used to combine multiple transactions into blocks.
By using the hash references of the data, the information is condensed down into a more manageable format and packaged together in the blockchain structure. Yet you can still trace all the way back to the underlying information, because the system of hashing links everything together.
The hash of transaction 1 and transaction 2 is combined, this is then hashed and combined with the hash of transactions 3 and 4, etc. In this way , the hash of all transactions are combined in one block, whose hash contains a reference to all the transactions within it:
You can see above that transactions 1 and 2 are hashed into reference R12. This is then hashed into R1234 with the reference R34. R1234 therefore references back to all 4 underlying transactions.
Transactions 1,2,3 and 4 are added into a block whose ‘block header’ (like the title of each block) will contain the R1234 hash reference to them.
The block header of each block contains a few things:
– A hash pointer – which links to the previous block.
– A timestamp
– The hashed data
Using this system, all transactions in the blockchain are ordered and marked.
How to alter a blockchain
Once recorded on the blockchain, the transactions cannot be modified, because changing the data within each block will change the hash references (remember hashes are dependent on the data within them, like in the ‘Amanda loves blockchain’ example above).
So if the sentence was changed to ‘Amanda hates blockchain’, the hash might become ‘934tnglaao3ri82000ofoajda002eu12473’, and would be instantly unrecognisable if compared to the original hash output.
Which is good, because no one would ever write that, let alone make a permanent record of it on a blockchain.
This system makes fraud impracticable, although not impossible, in a blockchain. Because changing a hash reference must involve changing all the previous hash references that have contributed to that hash.
So a fraudster trying to change some information (maybe registration details, transaction amount etc) would need to alter the hash of the relevant transaction, all the hashes that refer to it within the same block, and then all the previous block hash references and data hashes within them back to the beginning of the blockchain… You see how it is possible, but highly improbable.
The sequence of data made up by the chain of blocks constitutes the digital distributed ledger of transactions, or the blockchain. As blocks are added to the chain, the previous blocks are further cemented into the blockchain.
You now know about some of the main principles on which blockchain technologies are built – celebrate!
Watch out for part II of How blockchain works coming soon where we’ll explore mining and how cryptocurrencies like Bitcoin are created!