Monthly Archives: November 2022

Blockchain example slide

Proof of Work why use it and why does it use energy

Proof of Work

Proof of work relates to mining of cryptocurrency. It uses computing resources to solve a mathematical puzzle of sorts that takes a lot of compute power to solve but a minimum amount of power to verify that it has been completed. It is an example of a one way function. Easy to go one way but hard to go in the other. Imagine throwing a glass of water in the ocean, now imagine getting all of that water and only that water back out, like running a film backwards, might be impossible. The closer the one way function is to the glass in the ocean example the more secure a blockchain can be made. Why is that? Because it would take so much effort to mutate or corrupt the blockchain that it is not even worth trying.

Brilliant Idea, from Anti-SPAM to Blockchain

In the case of Bitcoin, mining occurs across thousands of nodes that can easily verify that the “work’ has been done and as long as there is a > 50% consensus among mining nodes , then the block is deemed valid and the nodes accept it and move on to the next block of transactions. So it would take an enormous amount of computing power to ‘fake’ a block and create a duplicate spend or a spend that pays an entity some unearned (Bitcoin) BTC, stealing it effectively. That in essence is the brilliance of Bitcoin and it’s pseudonymous creator Satoshi Nakamoto. All the ideas are not original, there was once an idea to use proof of work to prevent spam in email in the mid 1990s when SPAM became a nuisance. For regular uses it would delay the email by a few seconds, for a spammer sending out 1000’s of emails their computer would slow down to much to make it worth it. Satoshi Nakamoto took this idea and applied it to Bitcoin.

The chain part of block chain

On top of this, proof of work  that secures a single block, every block contains the hash of the previous block making it extremely hard to ‘fake’ out and create old blocks over as many hashes would have to be faked. So the longer the chain the more secure older transactions become as they become harder and harder to undo , or fake out.

Hashing in Cryptocurrency

Hashing is the key. Hashing is used in several ways in cryptocurrency.(toward the end of this post a second use is covered) . When mining a block a hash is generated for that block, a SHA256 hash. But not just any hash works. It has to be lower than a specific number determined by the difficulty adjustment, the so called target hash. This changes periodically to keep the outputs of blocks on the block chain, a giant electronic ledger of transactions, blocks are produced very 10 minutes on average. This also limits how many transactions can occur in a given time period. Blocks contain a finite number of transactions and they come out at period intervals, so there are only so many made per day. For Bitcoin this limits the daily transaction to something like around 300000. Other cryptocurrencies do better in this regard (but, buyer beware, they are beholden to companies or individuals that created them,so not independent from control like Bitcoin), so do layer 2 solutions like the Lightning network for Bitcoin. in the future most likely only large infrequent transactions will occur on Bitcoin main chain. With other solutions like the Lightning network or other cryptocurrencies serving to move money like PayPal or a Point Of Sale network, or Swift for that matter.

To create the special hash know as the target hash that meets the difficulty requirement means creating a hash that is lower than a specific 256 bit number. It contains a bunch of zeros at the beginning. This is done by add what is called a nonce ( just a random string will work, used just once  to make the hash come out lower than the target) to the block of transactions and computing the hash. The nonce can be a completely random string or a sequence of numbers tried in order, it really doesn’t matter. The only requirement is that whatever it is it creates a hash output that is lower than the number, target hash, specified by the difficulty requirement. In mining the first node that obtains this number will broadcast the result on the BTC network, all mining nodes will check it (hash the block and see if they agree, quick and easy to do), if it’s OK, the block becomes accepted added to the chain and that miner, the one who solved the hash, gets the block reward along with the fees for all the transactions that have been validated in the block. And, all nodes move on to the next block.

The hash itself

A typical block hash would look something like this…

00000000000000000007cd983a54a4eaf969d79961681fa2fa41eff0aba4a168

Notice all the zeros. With 256 byte number, using SHA256, it is hexadecimal where every number is 0-15 it takes a while to arrive at a number like this. Basically all the nodes that handle the blockchain that are mining are trying to get a ‘low’ number by changing the nonce.

Energy

This takes a lot of computing power and therefore energy. And, this is the complaint when it comes to cryptocurrency that are mined such as Bitcoin. The energy used to mine Bitcoin is equal to that of a small country. But, it has to be remembered that the whole financial technology sector of the economy still dwarfs the energy use of Bitcoin. Just imagine all of the ATMs alone that are plugged in all over the world, the computers running in the banks, heating, other electric and etc. Also, Bitcoin can be mined using energy that is otherwise orphaned. Meaning energy that can not be used for anything else. An example is natural gas and a petroleum well that might normally be flared off. Instead of flaring it off, it could be burned in a gas turbine turning a generator and run mining equipment. The mining equipment could be connected via Cell network or Satellite if no wire are available in a remote location. It is a way of burning a fuel at the source and generating value from it that otherwise would go to waste.

Proof of Work Example

Just a simple example of using a nonce along with a string ‘hello’ in this case and then printing out the resulting hashes of the new compound string of hello+nonce.

As more zeroes are required it gets harder and harder to find a nonce that will satisfy the requirement. To find the first hash with one zero at the start it takes 28 tries, ‘hello28’.

To get 8 leading zeroes it takes hello1202655595  = 1202655595 tries, on fairly regular computer it took from 2022-11-19 15:42 to 2022-11-19 16:48. Just over 1 hour.

Proof of Work Here it comes, ready…

I can give you the hash…

00000000e0d103722c6e172e145d15b9e909e109b47b30d741911bdb3cf3da84

and the string….

hello1202655595

….and this is proof that work was done. You can prove it. It took work to get this result, the computer ‘did’ something hard. It takes almost no energy and time to verify that the hash above is generated by hello1202655595, so it is cheap to verify but expensive to produce.

By ‘stamping’ this result into the blocks on the blockchain, hash of previous block into every block, it is very hard (glass of water back out the ocean hard) to create a forgery or do some other type of nastiness to the blockchain. Proof of Work secures the blockchain.

(Python code at the bottom of this post)

erick@OptiPlex-7010:~/python/hashing$ python3 multi-pow-hash-of-string.py 
Enter String to hash: hello
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
2022-11-19 15:42:15.173991 1 hello28 02a13c40ba00dc0fb199d3cbe5b01be59d937775890243fd411bdf001935ffc8
2022-11-19 15:42:15.175116 2 hello227 001b92541ed0a22b0cb89018b561d895503206c0082c0ecf2d0b7e5182191eed
2022-11-19 15:42:15.206154 3 hello10284 0006bc9ad4253c42e32b546dc17e5ea3fedaecdabef371b09906cea9387e8695
2022-11-19 15:42:15.350531 4 hello60067 0000e49eab06aa7a6b3aef7708991b91a7e01451fd67f520b832b89b18f4e7de
2022-11-19 15:42:15.771205 5 hello156056 0000037660ee0e22df67a053537e000325bbfad2cce9b8b7c795f6aa961d5cb7
2022-11-19 15:43:47.285252 6 hello33290382 000000865194de5c0744d72183dcce2eca2b69264b749a1798f1b6996baef7de
2022-11-19 15:49:22.363936 7 hello121001637 0000000bcd89bc714263460f7b1fc82562410b96eaeec5cc2175e83f2d215046
2022-11-19 16:48:46.136385 8 hello1202655595 00000000e0d103722c6e172e145d15b9e909e109b47b30d741911bdb3cf3da84

Keys and Addresses

To round it out, the other main use of cryptography in cryptocurrencies, the private key, secures your ‘coins’. If you aren’t careful to hide and not reveal your private key, you lose your coins. Your public key which is basically translated into an address for BTC (and others) it is a 160 byte number can be freely given out, posted online, in email, put it anywhere you wish. Why? Because all someone an ever do with the public key/address is send you some ‘coin’. So if they did, great. And, if it is a publicly transparent blockchain like Bitcoin and most others, privacy coins such as Zcash and Monero for example being the exception, you can trace the transactions. Just put a public address into the browser search bar and various tools will appear that allow you to trace transactions to an address. So the criminals that think cryptocurrency gives them some kind of magic cloaking mechanism for their transactions are getting it wrong. The cryptography in cryptocurrency has nothing to do with keeping a record of transactions securing hidden away, in fact the transactions are as transparent as they could possibly be.

 



Infographic showing #3 a blockchain and a block consisting of it’s sequence number, the hash of the previous block and the nonce, plus a record of transactions.

The miner of the block gets the reward plus all the fees for the transactions. In 2021 when this was made the block reward was 6.25BTC per block mined. This is cut in half approximately every 4 years, until it drops off  altogether around the year 2140. By then the fees will be the only thing sustaining the miners financially. The fact that there is only a finite amount of Bitcoin that can be mined, ever, 21 Million of them, keeps inflation of Bitcoin at bay. This is not the case for all coins, some cryptocurrencies can create more and more coins at will, so they are inflationary. Bitcoin is a fixed supply of which most of it has been mined already. So most of the stock is already created and the flow of more coins gets lower and lower with each block reward halving, every 4 years. This concept of stock to flow is important because it is a measure of scarcity. If something can be made easily like fiat currency the flow can be a large input to the stock in existence. This is what is going on in 2022 with economies all over the world that have printed massive amounts of fiat money during the Covid crisis, when the stock to flow is not a good ratio, inflation results. The opposite occurs with gold for example, it is hard to increase the amount of gold pulled from the earth, so the flow of new gold into the current world stock of gold is less than 2% per year, (I think that I remember the max was just 2.2% somewhere in the WW2 time frame) so in essence the market is never flooded with new gold, which would debase gold against other stores of value.

Blockchain example slide

 

 

Blockchain example slide

'''
https://www.pythoncentral.io/hashing-strings-with-python/
'''
import hashlib
from datetime import datetime

mystring = input('Enter String to hash: ')
# Assumes the default UTF-8
hash_object = hashlib.sha256(mystring.encode())
print(hash_object.hexdigest())

for DIF in range(1,32):
    for n in range(1,1000000000000):

            x = mystring + str(n)
            hash_object = hashlib.sha256(x.encode())
            d = hash_object.hexdigest()

            #print(x,d)
            tally = 0

            for z in range(0,DIF):
                    if d[z] == '0':
                            tally += 1

            if tally == DIF:
                break

    timestamp = str(datetime.now())

    print(timestamp,DIF,x,d)

Resources

https://seekingalpha.com/article/4452010-bitcoin-energy-usage-isnt-a-problem-heres-why

https://ingoldwetrust.report/the-stock-to-flow-ratio-as-the-most-significant-reason-for-golds-monetary-importance/?lang=en

JPEG image Metcalfe's Law BTC

Bitcoin Charting Resources for Long Term Investing

“Good investing is not necessarily about making good decisions. It’s about consistently not screwing up.” – Morgan Housel author of The Psychology of Money

Accumulation/Distribution Aids

2 year moving average investor tool

https://www.lookintobitcoin.com/charts/bitcoin-investor-tool/

Puell Multiple, an oscillator, accumulate at bottoms, distribute at tops

https://www.lookintobitcoin.com/charts/puell-multiple/

MVRV Z-Score, an oscillator, accumulate at bottoms, distribute at tops

https://www.lookintobitcoin.com/charts/mvrv-zscore/

Pi cycle top indicator, finds tops…it actually worked again in 2021

https://www.lookintobitcoin.com/charts/pi-cycle-top-indicator/

Market Sentiment, fear and greed index…

Fear mode = Might be a buying opportunity, people are scared and dumping BTC probably at a loss to them in full panic mode, macro indicators are crashing, full panic, bank run on exchanges, major crisis crypto or otherwise…

Greed Mode = Look out, euphoria is happening, price may drop soon as BTC is in the news and suckers buying in late in the game pushing the price parabolic, like the old saying, ” Bulls run up the stairs only to jump out the window.”…

https://www.lookintobitcoin.com/charts/bitcoin-fear-and-greed-index/

HODL wave 1 year. BTC sitting on chain for more than a year, shows if people are accumulating or distributing

https://www.lookintobitcoin.com/charts/1-year-hodl-wave/

Realized Price, might be a good indicator of fair value for BTC.  A gauge of relative under/overvalue….

https://www.lookintobitcoin.com/charts/realized-price/

Wallet Sizes, who is holding large amounts of BTC, good to track the ‘smart money’, are they accumulating or distributing?

Wallet > 1 BTC

https://www.lookintobitcoin.com/charts/wallets-greater-than-1-btc/

Wallet > 10 BTC

https://www.lookintobitcoin.com/charts/wallets-greater-than-10-btc/

Wallet > 100 BTC

https://www.lookintobitcoin.com/charts/wallets-greater-than-100-btc/

Wallet > 1000 BTC

https://www.lookintobitcoin.com/charts/wallets-greater-than-1000-btc/

Look into Bitcoin, has many more charts…

https://www.lookintobitcoin.com/charts/


Mayer Multiple

Basically accumulate until it hits 2.4, then hold, sell at the top optionally, then when it drops below 1.5 start accumulating again.

https://bitcoinition.com/charts/mayer-multiple/

Metcalfe’s Law Model

This is a static chart, (don’t remember where it is from) would love to see this as a dynamic one. Seems to show a fair value for BTC. Paper on Metcalfe’s law and Bitcoin