Blockchain
Let’s take a little deeper insight into the blockchain and analyze it from bottom up starting from a Hash.
Hash
Data | Hash |
---|---|
Hi | 3639EFCD08ABB273B1619E82E78C29A7DF02C1051B1820E99FC395DCAA3326B8 |
Blockchain | 625DA44E4EAF58D61CF048D168AA6F5E492DEA166D8BB54EC06C30DE07DB57E1 |
How are you? | DF287DFC1406ED2B692E1C2C783BB5CEC97EAC53151EE1D9810397AA0AFA0D89 |
Crypto currency | 6EC60FE39028887E7FE9C4B025545748953C27515073BF9AD17CEB5417A407D7 |
In the above examples, the input string is of variable lengths, but the output always has a fixed 256-bit length. This turns out to be even more complex when you are dealing with a huge amount of data and transactions. So basically, a hash is unique for every input, which makes it more convenient to store the hash instead of the original string wherever appropriate. The best example is password storage where the actual password string does not get stored in the database; instead, you keep just the hash of the password which makes your system more secure. Let’s now analyze the internals of the hashing procedure and see how we can use it in a blockchain.
- 1.
Deterministic—Processing the same input multiple times always produces the same result. This is very important because if you get different hashes for multiple iterations of the same input then it will be impossible to keep track of the input.
- 2.
Quick Computation—The hash function should be capable of returning the hash of an input quickly. If the process isn’t fast enough then the system simply won’t be efficient.
- 3.
Pre-Image Resistance—For any given hash value H(A) it is infeasible to determine A, where A is the input and H(A) is the output hash.
- 4.
Pseudorandomness—For any small change in the input, the changes that will be reflected in the hash will be huge. Let’s check it out using SHA-256. The words Single and Mingle have just a one alphabet different but their hashes are completely different.
Single | 8888A029AAF60B70574640EFD1655343D1C46C692918C113C16F44F606477253 |
Mingle | 5FB188B33D53EAD28780E22822A34CE1C624740A6F5C85C7AF0D12607EAF5D51 |
- 5.
Collision Resistant—Given two different inputs X and Y where H(X) and H (Y) are their respective hashes, it is infeasible for H (X) to be equal to H(Y). So, for the most part, each input will have its own unique hash.
- 6.
Puzzle-Friendly—For every single output “Y,” if k is selected from a distribution with high min-entropy it is infeasible to determine an input x such that H(k|x) = Y. Assume you have an output value “Y.” If you select a random value “k” from a wide distribution, it is infeasible to determine a value X to the extent that the hash of the concatenation of k and x will produce the output Y. Please note the word “infeasible,” it is not impossible. In fact, the mining process works upon this.
MD 5: Produces a 128-bit hash. Collision resistance was broken after ~2^21 hashes.
SHA 1: Produces a 160-bit hash. Collision resistance broke after ~2^61 hashes.
SHA 256: Produces a 256-bit hash. This is currently being used by Bitcoin.
Keccak-256: Produces a 256-bit hash and is currently used by Ethereum.
Block
Block Identifier, which is a sequential number.
Nonce, which is a random number.
Tx, which is the actual transaction information.
Prev, which is the hash of the previous block.
Hash, which is the computed hash value of the data and Nonce.
Mining
Miners enter the Bitcoin network by configuring the Bitcoin core software and building a node environment on a computer that meets minimum resource requirements. After completing the environment build, a potential miner performs the initial block download that synchronizes nodes within the network downloads block and points the node to the tip of the best blockchain.
Mining generates new Bitcoins in each block, practically like a central bank printing new money. The amount of Bitcoin generated per block is fixed and diminishes with time.
Mining generates trust by ensuring that transactions are only confirmed if enough computational power was devoted to the block that contains them. More blocks require more computation, which eventually means more trust.
The Bitcoin system of trust is fundamentally based on computation. Transactions are bundled into blocks, which requires a huge amount of computation to prove, but only a little amount of computation to verify as proven, in a process called mining. Bitcoin mining is purposely designed to be extremely resource-intensive and difficult so that the number of blocks found each day by miners remains fixed. So, a good way to describe mining is like a puzzle that resets every time somebody finds a solution and its difficulty automatically adjusts so that it takes about ten minutes to find a solution. The puzzle used in Bitcoin is developed based on a cryptographic hash, which is asymmetrically difficult to solve, but at the same time easy to verify and its difficulty can be adjusted. Finding such a solution, in blockchain terms “Proof of Work,” requires millions of hashing operations per second, across the entire Bitcoin network. The algorithm for Proof of Work involves hashing the header of the block and a random number with the SHA256 cryptographic algorithm, until a solution matching a predetermined pattern emerges. The first miner who finds such a solution wins the round of competition and publishes that block into the blockchain. Every ten minutes, miners produce a new block, which comprises all the transactions since the last block. New transactions are continuously flowing into the blockchain network from user wallets and various other sources. As these transactions enter into the Bitcoin network nodes, they get collected into a temporary unverified transaction pool of each Bitcoin node. When miners build a new block of transactions, they pick the unverified transactions from this pool and then try to solve a very difficult problem (Proof of Work) to prove the validity of that new block.
The Bitcoin mining network difficulty is the measure of how difficult it is to find a new block. It is recalculated every 2016 blocks to a value such that the previous 2016 blocks would have been generated in exactly two weeks had everyone been mining at this difficulty. This will yield, on average, one block every ten minutes.
As every new block added to the blockchain is based on the previous block added, it adds even more computation on top of that block, thereby increasing the trust in those transactions. The blocks that are mined after the one that contains your transaction act as additional assurance; as more blocks get piled up more computation is required in a longer and longer chain. Each block that is mined on top of the one containing your transaction is called one confirmation for that transaction. As more blocks get added on top of each other, it becomes exponentially difficult to reverse the transaction, thereby making it increasingly trusted by the network. By convention, any block with more than six confirmations is considered irrevocable, as it would require an enormous amount of computation to invalidate and recalculate six blocks.
Bitcoin
Facebook: Like, Share, and Comment are a few of the social transactions between the user and the system.
Twitter: Tweet and Retweet are the basic transactions that a user makes on the system.
Github: The developer user interacts with the system via Push, Pull, Merge, and so on.
Crypto currency/Bitcoin: Send money is a transaction.
Transaction 1: Dave sends $25 to Emily at 1/1/2018 5:00 PM UTC
Transaction 2: Dave sends $15 to Joan at 1/1/2018 5:20 PM UTC
Transaction 3: Joan sends $56 to Mike at 1/1/2018 5:45 PM UTC
Transaction 4: Mike sends $35 to Emily at 1/1/2018 6:00 PM UTC
Crypto Currency Wallet
Once Mark signs up for a Bitcoin account, his wallet application will randomly generate a private key together with its corresponding Bitcoin address.
His Bitcoin address is merely a number that corresponds to a key that he can use to control access to the funds. There is no association between that address and an account.
Until the moment when this address is participating in a Bitcoin transaction as a sender or a receiver (recipient) of value posted on the Bitcoin ledger (the blockchain), it is simply part of the massive number of possible addresses that are valid in a Bitcoin.
Once the address has been associated with a transaction, it becomes part of the identified addresses in the network and Mark can check his balance on the public ledger (explained later).
- 1.
Receiver: The destination Bitcoin address for the transaction
- 2.
Value: The amount of Bitcoin to send
Most of the crypto currency wallets provide a feature called send by QR code. Around the input field for the Bitcoin address, there is a small icon that looks like a QR code. This allows Harry to scan the barcode with his smartphone camera so that he doesn’t have to type in Mark’s Bitcoin address (e.g., 1Cdid9KFAaatwczBwBttQcwXYCpvK8h7FK), which is quite long and difficult to type. The mobile wallet application fills in the Bitcoin address scanning the QR code and Harry can check that it scanned correctly by comparing a few digits from the address with the address displayed by Mark. Harry then enters the Bitcoin value for the transaction, 0.10 Bitcoin. He then presses Send to transmit the transaction. Harry’s mobile Bitcoin wallet constructs a transaction that assigns 0.10 Bitcoin to the address provided by Mark, sourcing the funds from Harry’s wallet and signing the transaction with Harry’s private keys. This tells the Bitcoin network that Harry has authorized a transfer of value from one of his addresses to Mark’s new address. As the transaction is transferred via the peer-to-peer protocol, it quickly broadcasts across the Bitcoin network. In a split second, most of the nodes in the network receive the transaction and see Mark’s address for the first time.
At first, Mark’s address will show the transaction from Harry as “Unconfirmed” since the transaction has been propagated to the network but has not yet been added in the Bitcoin transaction ledger (blockchain). To be included in the blockchain, the transaction must be picked up by a miner and included in a block of transactions. Once a new block is created—in the current situation it takes about ten minutes (Proof of Work and validation process)—the transactions within the block will be accepted as “confirmed” by the network and available to be spent. Now the transaction is seen by everyone immediately after it is included in a newly mined block. Mark is now the proud owner of 0.10 Bitcoin that he can spend. Mark can buy something using the Bitcoins he has now.
Types of Wallets
- 1.
Desktop wallets are designed for PCs and Mac, which has to be downloaded and installed on the computer. Once installed, they are only accessible from the same computer in which they are installed. Desktop wallets are more secure; however, if your computer is hacked or infected by a virus then there is the possibility of you losing all your funds.
- 2.
Online wallets are cloud-based software accessible from any computer from any location. They are very easy to access, but online wallets store your private keys in a centralized online storage and are managed by a third party, which makes them vulnerable to hacking attacks and theft.
- 3.
Mobile wallets are software applications available on your favorite mobile app store for download and installation on your smartphones. These are the most convenient of all the wallets that can be used from anywhere including retail stores. Mobile wallets are simpler than desktop wallets due to resource limitations on the mobile, but they provide most of the essential features required for most of the transactions.
- 4.
Hardware wallets store a user’s private key in a hardware device such as USB. Hardware wallets provide options to make online transactions in a highly secured fashion by storing the user’s private keys in an offline storage. Hardware wallets are compatible to be used over different protocols and support multiple crypto currencies. Users connect the wallet to their internet-enabled computer via the USB, enter their PIN or password to login to the wallet, and start making transactions. Hardware wallets come with a higher price point, but they are the best wallet for serious crypto currency holdings where spending a small sum toward securing the private keys is extremely critical to safeguard the value of the assets you own on the blockchain.
- 5.
Paper wallets are a completely disconnected non-electronic way of storing the private keys. They are basically a physical copy of your public and private keys on paper. It is an old school traditional approach of maintaining your secret yourself. Transferring Bitcoin or any other type of crypto currency to your paper wallet is relatively straightforward and involves transfer of coins from an electronic wallet to the public address displayed on the printout of your paper wallet. To withdraw or send coins to another wallet, you will need to transfer funds from the paper wallet to a software wallet. This process is referred to as sweeping which can be done either manually entering your private keys or scanning a QR code that normally prints on the paper wallet.
Wallet Security
If your wallet gets hacked or you send money to an incorrect address or to a scammer, there is absolutely no way to recover lost currency or reverse the transaction. Let’s now look at some precautions that will prevent you from great loss.Always remember, losing your private keys is equivalent to losing your money. Whichever wallet you use, you must take extreme precautions and be very careful!
- 1.
Backup the Keys—Backing up your wallet keys can save you a lot of turmoil and trouble. Anything can happen at any time; your phone might get lost or your computer might crash. Backing up your crypto currency wallets can come to your rescue and make a critical crypto-catastrophe into a minor problem that can be fixed without any loss of your crypto currency.
- 2.
Cold Storage—Cold storage is achieved when crypto currency private keys are created and stored in a secure offline environment. Cold storage is important for anyone with high-value crypto holdings. Online computers are vulnerable to hackers and should not be used to store a significant amount of Bitcoins.
- 3.
Hardware Wallet—These are the physical devices created to keep your crypto currency safe. When you request a payment, the hardware wallet’s API creates and signs the transaction and provides a public key which is directed to the network by the API. This ensures that the signing keys never leave the hardware wallet. Hardware wallets come with support for advanced features such as multi-signature transactions.
- 4.
Multi-Signature—Wallets are advanced security configuration available with most of the crypto currency platforms and supported by most of the popular wallets. It involves multiple stakeholders to be involved in a transaction. When you configure your Bitcoin address to be multi-signature then it requires another user(s) to sign the transaction along with you before the transaction can be broadcast to the blockchain network. The first multi-signature wallet was launched in the market by BitGo in 2013.