Exercise: Try a Mining Simulator

Have you ever tried to guess the outcome of a hashing algorithm? Trying out a mining simulator will give you an appreciation for how incredibly unlikely it is to select an input that will give you a specific hash digest. In this exercise, we'll make an attempt at guessing which nonce values will provide us with a desired hash, and have a look at how blocks are linked together.

Finding a hash

This site will allow you to try out some mining first by trying to find a compatible hash, in this case one that starts with 4 zeros, and then by trying to find a chain of "blocks" or hashed data. 

Let's start with trying to "mine a block", or find a hash starting with 4 zeros for some arbitrary data. Visit https://andersbrownworth.com/blockchain/block and input some data in the data field, your name, your favorite song, lorem ipsum, whatever you like! Then try to guess what nonce (random number) added to that data and run through a hashing algorithm that will result in a hash starting with 4 zeros. Try typing different numbers in the nonce field to see what hash it produces. Try it for a few min until you either get very lucky or very bored. When done, push the "mine" button and the site will run through nonces, starting with 0, for you until it finds a nonce that results in a hash starting with 4 zeros.

Note the time it took the site to find an appropriate nonce. The resulting nonce also represents the number of guesses the site had to make before finding a suitable nonce.

 

Mining a blockchain 

Bitcoin's blockchain consists of hundreds of thousands of blocks linked together with this hashing. Each block contains the hash of the previous block. Let's visit https://andersbrownworth.com/blockchain/blockchain to visualize this and try it for ourselves. 

Here we can see that there is now an additional data field that will be included in each hash we find. We have a data field, a nonce field and now a field for the previous block hash. These three data fields are used to find the hash for each of our "blocks" here. 

Start with block one, add your arbitrary data, (note that here the previous block hash field is set to all zeros) and start trying to guess a suitable nonce. Again, once you've gotten bored of guessing you can push the "mine" button and see how many guesses we're required to find a suitable hash. 

Move one to block two. Add more arbitrary data, the site will automatically pull in the hash of the previous block, and start guessing a nonce. You can repeat this process on the site all the way up to the 5th block.


Source: Saylor Academy
Creative Commons License This work is licensed under a Creative Commons Attribution 4.0 License.

Last modified: Tuesday, October 5, 2021, 2:42 PM