MINING, PRIVACY AND WALLETS
Last issue, we were introduced to the concept of traditional monetary system, cryptography and blockchain. It set the base for the concepts we will discuss here. Before digging deeper, we shall talk a bit more into mining of a crypto. I would recommend reading the earlier part once again to get re-acquainted with the concepts before diving deeper into crypto-currency.
Nonce (Number Only Used Once)
I’m sure the readers of the previous article must have got many queries – what is the “guessing game”; what basis do you “guess” the number; what is that “magical” number which helps you input the new block and extend the chain; why do we need to guess it; what will we get and why? Five questions, one answer – “Nonce” or Number Only Used Once. I hope you remember that in cryptography, the one sender cannot decrypt the encrypted ciphertext sent by another sender, even though both senders have the same public key of the receiver. We will build on this.
A nonce is just a sequential number tied to every transaction that represents the number of transactions the sender account has made on the network.
Say, I created a brand-new Ethereum account. My friend Aakash sends me 5 ETH. This doesn’t affect my account’s nonce because I wasn’t the sender. I then sent 1 ETH to my friend Akshita. The transaction that sends that 1 ETH needs to have the nonce of 0, because it’s the first transaction my account is sending. Later that day, I sent 2 ETH to my friend Sakshi. That transaction will need to have a nonce of 1.
What happens if I submit a transaction with a nonce that has already been transacted? The said transaction will be rejected by the network. What happens if I submit a nonce that’s higher than the correct next nonce to use? The transaction will get stored in the mempool of the nodes in a pending state. It will remain in the mempool of the node until transactions with all nonces between the last valid incremental nonce for the account and the transaction stored in the mempool have been transacted to the network, and then the transaction will be executed as normal. It’s possible that the nodes eventually drop your transaction out of the mempool if it’s been waiting there for too long.
A mempool is short for memory-pool. It is a holding room, kind of like a waiting room for all unconfirmed transactions a node can see on the crypto-currency network. Remember that the node is just a user like us.
The ultimate use of nonce is to prevent double spending. Every time you spend, the nonce increases by 1. This prevents the same transaction from being submitted over and over again.
In order to keep the blockchain secure, data from previous blocks are encrypted or “hashed” into a series of numbers and letters. This is done by processing the block input through a function, which produces an output of a fixed length. Which is, as you read in the previous article, is the SHA 256 hashing.
The function used to generate the hash is deterministic, meaning that it will produce the same result each time the same input is used. It also means that the function can generate a hashed input efficiently, makes determining the input difficult (leading to the blockchain’s security), and makes small changes to the input result in a very different hash. This complex system creates the privacy net of blockchain.
Finding the Nonce
The process of guessing the hash starts in the block header. It contains the block version number, a timestamp, the hash used in the previous block, the hash of the Merkle Root, the nonce, and the target hash.
If the hash meets the requirements set forth in the target, then the block is added to the blockchain. Cycling through solutions in order to guess the nonce is referred to as “proof of work”, and the miner who is able to find the value is awarded the block and paid in cryptocurrency.
Determining which string (an alphanumerical value) to use as the nonce requires a significant amount of trial-and-error, as it is a random string. A miner must guess a nonce, append it to the hash of the current header, rehash the value, and compare this to the target hash. If the resulting hash value meets the requirements, the miner has created a solution and is awarded the block.
It is highly unlikely that a miner will successfully guess the nonce on the first try, meaning that the miner may potentially test a large number of nonce options before getting it right. The greater the difficulty—a measure of how hard it is to create a hash that is less than the target—the longer it is likely to take to generate a solution; and ergo, the higher electricity costs to run the computer. This is the reason super-computers are used to generate random numbers as they have superior computational speed than personal computers.
Block difficulty is kept the same across the entire network, meaning that all miners have the same chance of figuring out the correct hash. Cryptocurrency networks typically establish a target number of blocks they want to be processed during a specific time period, and periodically adjust the difficulty in order to ensure that this target is met. If the number of blocks processed does not meet this target then the difficulty will be reduced, with the reduction in difficulty set to the amount of time over the limit the processing time was.
Proof of Work
This explanation will focus on proof of work as it works in the crypto network. Cryptos are digital currencies having an underlying distributed ledger known as a “blockchain”. This ledger contains a record of all crypto transactions, arranged in sequential “blocks”, so that no user is allowed to spend any of their holdings twice – which is the function on nonce. In order to prevent tampering, the ledger is “distributed” to each and every user in the system; an altered version would quickly be rejected by other users.
The way that users detect tampering in practice is through hashes, long strings of numbers that serve as proof of work. Put a given set of data through a hash function (just like SHA-256), and it will only ever generate one hash. Due to the “avalanche effect”, however, even a tiny change to any portion of the original data will result in a totally unrecognizable hash. That is the quality of a good hash. Whatever the size of the original data set, the hash generated by a given function will be the same length. The hash is a one-way function: it cannot be used to obtain the original data, only to check that the data that generated the hash matches the original data.
Generating just any hash for a set of bitcoin transactions would be trivial for a modern computer, so in order to turn the process into “work”, the bitcoin network sets a certain level of “difficulty”. This setting is adjusted so that a new block is “mined” – added to the blockchain by generating a valid hash – approximately every 10 minutes. Setting difficulty is accomplished by establishing a “target” for the hash: the lower the target, the smaller the set of valid hashes, and the harder it is to generate one. In practice, this means a hash that starts with a very long string of zeros.
Before explaining wallets, it is important to know what our names, i.e. us, as a node are present in a list. Every node has an address. It is like saying every person has a home. But, a person can own multiple homes right? Similarly, every node can have multiple addresses. Now, in a network, everyone uses a “codename”. Codename is nothing but a string of alphanumeric characters. In our example, we will use simple codenames. Again, node is a human on a computer in a network running the show, addresses are in codenames. Like a node belonging to RAJAT can have 2 codenames, or 2 addresses like tiger123 and lion987. It is to mask identity so that others will not be able to know the actual person behind the address. It’s like anonymously gifting something to some address. If someone sent 5 ETH to 37zhMqtceYYsdkTjyY1vB9XLn8z78FXACs, it is quite possible, the person behind that address is our own Prime Minister. Although I doubt he uses cryptos. Why are the strings so complicated? The answer is in my previous article under “Cryptography” heading.
Say RAJAT texts AKSHITA on WhatsApp to pay for the dinner. This is the first time AKSHITA is paying RAJAT, but she doesn’t know what RAJAT’s codename / address is. In order to edit the list correctly, she needs to know the address which belongs to me. It’s like knowing the physical address to my name to send something. AKSHITA knows her own codename i.e. address so she will deduct, say INR 100 from “hawk123” and add INR 100 to “lion987”. And thus it is – AKSHITA paid RAJAT INR 100, but to the world, hawk123 paid INR 100 to lion 987. And that address can be as unique as firepengiundiscopanda42069. As weird as you want it to be. In reality, it is a complex set of alphanumeric numbers. The earlier address / codename was just to explain. But since, my address is known, I can add another address to the list which belongs to me. How does it belong to me? Because I have the private keys to it. Means hawk123 can pay lion987 and fox654 – the latter two belonging to me.
The first thing to understand is that your crypto is not stored in your wallet. Crypto isn’t inside your computer and it’s not sitting on a USB stick. Remember, your crypto only exists on the shared list (decentralized, distributed blockchain).
Remember back to the analogy in our private key lesson. The crypto list is like a public set of lockers, that is where your crypto exists. So, your wallet is actually just storing the keys to your crypto, not the crypto itself. This means that a wallet can be all kinds of different things. Since it’s really just something that stores your keys, it can even be a piece of paper!
This system makes crypto incredibly resilient. You can lose your wallet, but as long as you know your private key, your crypto is safe. There are people all around the world who are storing the list where your crypto is kept, and you can store a copy for yourself too. What happens if you lose your list? Just ask someone else to send you their copy. It’s that simple.
Although a crypto wallet can be a piece of paper, there is a reason you may want to avoid that. Every crypto locker (or address) has exactly one key to open it. That means for every address you want to use, you need a separate key. Imagine keeping track of dozens, or even hundreds of pieces of paper with all your private keys and addresses on them!
It is like having multiple addresses, having unique locks, and unique private keys. One needs to manage all of them right? This is where a modern crypto wallet comes into play, also known as hierarchical deterministic wallet, or HD wallet.
The HD wallet uses a set of words which is called a “seed” and from the seed, complicated formulas are used to create unique pairs of keys and lockers. There can bet between 12 to 24 set of words. It can be as random as – “fire dustbin pizza school cigarette minister mouse laugh disaster tears football chocolate”. Now only you should know these words. You can create millions of addresses from a same set of words, or a single seed. The formulas that are used to create these keys from your seed are actually the same for different wallet manufacturers. This means if your device is lost or broken, all you need is your words and a new wallet to recover your bitcoin. Even if your chosen wallet manufacturer goes out of business, you can pick up a device from a competitor and all your bitcoin keys will be restored. You just need to give it your set of words.
Since those 12-24 words can create all of your bitcoin keys, NEVER let anyone see them and NEVER type them on a computer. They are all someone needs to steal your bitcoin.
Obviously, it doesn’t make sense for us to run the formulas ourselves. So we will need a bitcoin wallet. This can either be software, or a hardware wallet. A hardware wallet is a USB-like device that stores your seed words and manages your keys and addresses for you. It is also responsible for helping you send bitcoin by signing your transactions and broadcasting them to the network. A software wallet serves the same function, but it can simply be an app on your phone or computer. So you can very well imagine what happens if you lose the keys or the wallet. You will simply lose yourself.
I hope this clears the issue on mining and storing crypto because the next part, we will be touching the issue of trading, transacting and issuing crypto.
Disclaimer: Please do not copy any material without permission. The author can be reached out at firstname.lastname@example.org. All the content is based on the author’s understanding and knowledge. Also, all names used are not fictitious and are not coincidental, as they all are my good friends and surely won’t object to their usage in an educational article. Thank you for reading.