Skip to main content
6 of 9
added 145 characters in body
user avatar
user avatar

What is mining in simple words...

Bitcoin blockchain uses the Secure Hash Algorithm SHA-256 to generate a 32-byte numbers of the same length in a way that requires a predictable amount of CPU efforts. In order to receive a cryptocurrency reward (and record "legitimate" transactions in the ledger) miners are solving blocks' hash that meet a certain criteria.

SHA-256(Block Number, Timestamp, Nonce, Data, Previous Block's Hash) 

A brute-force search is repeated until miners discover a hash that is less than the target value.




macOS app

I've written a tiny Swift app to calculate a number of tries to discover a hash starting with 2, 4 and 8 zeros. As you can see below, we need 426 million tries to find a first hash number with eight leading zeros – "00000000".

enter image description here

Executing the following code just gives you an idea of ​​how many tries it takes to find the hash with the required value (consider, this script does not reflect the criteria for bitcoin mining).

import SwiftUI import CryptoKit struct ContentView: View { @State var counter: UInt32 = 0 @State var digest: SHA256.Digest? = nil var body: some View { HStack { VStack { Button("Start") { startMining() } } } } fileprivate func startMining() { repeat { counter += 1 let data = Data(String(counter).utf8) digest = SHA256.hash(data: data) print((digest?.description)!) print("\(counter) tries.") } while !(digest!.description.starts(with: "SHA256 digest: 0000")) } } 


Results

Let's launch this app and see what we got in the Xcode console if we search for 00:

SHA256 digest: 00328ce57bbc14b33bd6695bc8eb32cdf2fb5f3a7d89ec14a42825e15d39df60 286 tries. 

Then search for 0000:

SHA256 digest: 0000a456e7b5a5eb059e721fb431436883143101275c4077f83fe70298f5623d 88484 tries. 

And at last, search for 00000000:

SHA256 digest: 00000000690ed426ccf17803ebe2bd0884bcd58a1bb5e7477ead3645f356e7a9 426479724 tries. 

Now you know how much efforts a mining task requires and to what extent it loads the CPU.

P.S.

Today (August 25th, 2021) miners look for a hash number with nineteen leading zeros – "0000000000000000000", like in Block 697561.

user125245