As with mining, what are the bitcoin miners really solving? I read they are solving hashes, but what does that really mean. Can we see what they are solving? Can someone give an example of what a bitcoin mining machine sees to solve?
They try to find a random nonce (a little random data) that goes into a block and makes the block have a (SHA256) hash that (in binary) starts with a certain amount of 0's. The more zeroes the more rare hash is. A good hash' outcome is not predictable, and so you have to try a lot of times to find a good nonce.
The amount of zeroes are based on how difficult it is supposed to be to find a block. In Bitcoin it adjusts to have a new block every 10 minutes (on average, given the rate at which previous blocks are found).
Interesting: because the hashes are unpredictable it doesn't matter how the nonce changes! Most of the time it's just a number counting upwards from 0!
Here is an extremely simplified sketch of the problem, but it should give a pretty good idea of what the problem is.
This is the hash of the lastest block (shortened to 30 characters):
These are the hashes of a few valid transactions waiting for inclusion (shortened).
And this the hash of one special transaction that you just crafted, which gives 25BTC (the current reward) to yourself:
Building the next block:
Now, let's use a gross approximation of what a new block might look like (the real one uses binary format). It contains the hash of the previous block and the hashes of those 3 transactions:
Now let's do mining by hand! Our goal is to complete this block with a nonce (a piece of garbage) such that the hash of the new block starts with 13 zeros (considering the previous hash, it seems that 13 zeroes is the current difficulty!).
Mining (trying to finalize this block):
Let's try with nonce=1, and compute the hash of the block (I'm using the md5 hash algorithm, but Bitcoin uses double sha256):
> echo "00000000000001adf44c7d69767585--5572eca4dd4-db7d0c0b845-916d849af76--1" | md5sum
No luck, the hash does not start with a 0… Let's try with nonce=2
> echo "00000000000001adf44c7d69767585--5572eca4dd4-db7d0c0b845-916d849af76--2" | md5sum
If we pursue until nonce=16, we get our first leading zero.
> echo "00000000000001adf44c7d69767585--5572eca4dd4-db7d0c0b845-916d849af76--16" | md5sum
For nonce=208, we get two leading zeroes!
> echo "00000000000001adf44c7d69767585--5572eca4dd4-db7d0c0b845-916d849af76--208" | md5sum
Continue like this… If you finally find a hash that has 13 leading zeroes… you're a winner! Other miners will now build upon your block, you've just got 25BTC.
But you'll have to be fast!
Back to step 1…
If someone manages to build a block before you do, you'll have to start again from the beginning with the new block's hash (the one of the winner).
The following is a description of the global, statistical gamble which is played every 10 or so minutes. The interval of the game is controlled by the difficulty which says how many "hashes" are needed per interval.
In other words, the
target define the "odds of the house" against your chance of getting a winning SHA hash. The
nonce is the "scratch off" area.
Each hash consumes electricity, and emits heat, which requires additional cooling.
This is what is done with each hash:
At a high level, the miner software takes a list of active transactions, and then groups them together in something called a "block".
Or more accurately stated: The miner software coverts all the transactions into a summary view called a "merkle root", and hashes it, which is representative of the transactions.
Then mining software converts this to into a binary format called a Block Header, which also references the previous blocks (also called a chain).
Field Purpose Updated when... Size (Bytes)
Version Block version number You upgrade the software and 4
it specifies a new version
hashPrevBlock 256-bit hash of the previous A new block comes in 32
hashMerkleRoot 256-bit hash based on all A transaction is accepted 32
the transactions in the block
Time Current timestamp as seconds Every few seconds 4
since 1970-01-01T00:00 UTC
Bits Current target in compact format The difficulty is adjusted 4
Nonce 32-bit number (starts at 0) A hash is tried (increments) 4
The miner hardware changes a small portion of this block called a "nonce".
The block header is hashed and compared to the Target as if it were simply a large number like 10,000,000 > 7,000,000 (the real numbers are much bigger, and in hex). The target is compressed and stored in each block in a field called bits.
An expanded target looks like this:
And the goal is to make sure the SHA256 hash of the block is less than this value. In the example below "
83ee" is smaller than "
To simplify this concept, you can ballpark the target by counting the leading zeros (as the other answer here explains). Here is an example:
Here is a sample block with transactions you can view on BlockChain.info. Look in the upper right hand corner of the webpage for this hash:
That previous hash was from today and has 14 leading zeroes. Let's compare that to what was needed 3 years ago with block 100 which has 8 leading zeros.
So at the end of the day, all a miner does is:
- Take a block header as input
- Change the Nonce
- Test if the Block Header hash is less than the Target. If it is, you win.
- Go to step 2 (or go to step 1 if someone else won the block)
Want to see what Bitcoin-QT does when it finds a block?... I posted it here.. The information in this post will help you understand what happened.
Mining provides a way to reach consensus on what the transaction ledger should look like and know that nobody is cheating.
That's the non-technical definition of mining.
The "authority" for double spending is the blockchain. The blockchain consists of the history of all blocks in the blockchain plus the next block of transactions. The reward subsidy currently is 25 BTC to the party that submits the next block. But hey ...you would like that 25 BTC (worth currently about $825) as would I as would everyone else. So how do you make it so that I can't cheat and claim the block myself?
Well, you put in a system that you and I have to compete. That's what the proof of work does -- it makes it so that when I claim the reward it is easy to prove that I really did the work involved. So for me to have a 2% chance of solving a block I need to put in 2% of of the mining work. There's no way for me to put in less than 2% of all the work and still solve blocks at least 2% of the time (on average).
Thus as a result, when a transaction block is submitted, all the peers verify that there were no double spends, that the right amount of subsidy was claimed, and that the submitter truly expended the work necessary for that solution. With those three rules, then there doesn't not need to be a central authority managing the process or able to control the outcome.
Miners guess a random target number that solves an equation generated by the Bitcoin Protocol. Of course, computers make this guess, not people.
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 processor 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 (established by system).
A "guess number" is formed from a final hash of current block hash, nonce, data and previous block hash. A brute-force search is repeated until miners discover a hash that is less than the target number.
Bitcoin miners are solving complex mathematical puzzles in a process called proof-of-work, which helps secure the Bitcoin network and create new bitcoins. These puzzles are based on cryptographic hash functions, and the main goal is to find a specific input called a nonce that, when combined with the transaction data and previous block's hash, produces an output (a hash) that meets certain requirements, such as having a specific number of leading zeros.
The puzzles are designed to be hard to solve, requiring a lot of computational power, but easy to verify once the solution is found. Miners are essentially searching for a needle in a haystack by trying different nonces until they find the one that meets the required conditions.
The process of solving these puzzles serves two main purposes:
Securing the network: The proof-of-work process makes it difficult for anyone to attack the network or manipulate transaction data. To do so, an attacker would need to control more than 50% of the total mining power, which is highly unlikely given the distributed nature of the network and the vast amount of computational resources required.
Creating new bitcoins: Miners who successfully solve the puzzle and add a new block to the blockchain are rewarded with newly created bitcoins (the block reward) and transaction fees from the transactions included in the block. This serves as an incentive for miners to contribute their computational resources and helps maintain a controlled and predictable supply of new bitcoins.
As more miners join the network and the total computational power increases, the difficulty of the puzzles automatically adjusts to ensure that a new block is added to the blockchain approximately every 10 minutes. This self-adjusting mechanism helps maintain the security and stability of the Bitcoin network.
Bitcoin miners solve a complex mathematical puzzle, called proof-of-work, to generate new bitcoins and secure the network. This puzzle is based on a cryptographic hash function called SHA-256, and the goal is to find a specific input (called a nonce) that results in a hash value that meets certain requirements. Here's a detailed explanation of the process:
Preparing the block: Miners gather recent, unconfirmed Bitcoin transactions and organize them into a data structure called a block. Each transaction is checked to ensure it's valid and not a double-spend attempt. The block also contains a reference to the previous block in the blockchain (by including its hash) and a timestamp.
Calculating the target: The Bitcoin network adjusts the puzzle's difficulty based on the total mining power to maintain an average block generation time of 10 minutes. The difficulty determines the target value for the hash. The target is a 256-bit number, and miners must find a hash that is equal to or lower than this target.
Finding the nonce: Miners generate the hash by combining the block's data, the previous block's hash, and a nonce (a random number). They repeatedly change the nonce and recompute the hash until they find a hash that meets the target requirement. Since hash functions are unpredictable, miners must try many different nonces before finding a valid one. This process is computationally intensive and requires a lot of trial and error.
Proof-of-work: Once a miner finds a valid nonce, they have effectively solved the puzzle and completed the proof-of-work. The valid nonce proves that the miner has expended a significant amount of computational effort to find the solution, thus securing the network.
Broadcasting the block: The miner broadcasts the solved block, along with the valid nonce, to the entire network. Other nodes in the network verify the block and its proof-of-work. If it's valid, they add the block to their local copy of the blockchain.
Block reward: As a reward for solving the puzzle and adding a new block to the blockchain, the miner receives newly created bitcoins (the block reward) and the transaction fees from the transactions in the block. The block reward serves as an incentive for miners to contribute computational resources and secures the network.
This entire process ensures that the Bitcoin network remains secure, transactions are confirmed, and new bitcoins are generated in a controlled and predictable manner. As more miners join the network and the total computational power increases, the difficulty of the puzzle automatically adjusts to maintain the 10-minute block interval, keeping the system stable and secure.