Author

Topic: Exactly how does a miner... mine? (Read 643 times)

newbie
Activity: 6
Merit: 0
April 10, 2012, 12:00:52 AM
#3
And the target is changed every 2016 blocks so that the difficulty of mining can be changed... ok I get it now, thank you!
legendary
Activity: 4542
Merit: 3393
Vile Vixen and Miss Bitcointalk 2021-2023
April 09, 2012, 11:36:30 PM
#2
I know how to use a miner, how to use a pool and stuff like that, and I have done it before (and am right now), but I've always wondered what the actual process was to calculating hashes? What is my miner doing right now?
The idea of mining is to calculate a cryptographic hash of a block (a block is basically just a list of recent transactions, a hash of the previous block (so you can't prepare fraudulent blocks in advance), and some other stuff) such that the value of the hash is lower than a predetermined target. If it is, you win: your block gets included in the block chain and you receive the block reward (currently 50 BTC) as well all the transaction fees associated with that block. If the hash doesn't come under the target, you lose, and you have to try again by changing a small piece of data in the block (called the nonce) which causes the whole hash to change in a random way. The key point about a cryptographic hash is that it's impossible to predict what effect changing the nonce (or any other part of the data) will have on the hash: the only way to get a hash that meets the target is to try every possible nonce (a typical mining system is capable of trying millions per second) until you find one that works. This is key to the security of Bitcoin: it's impossible for anyone to introduce a fraudulent block without first using a ton of computing power to find one that meets the hash target. Not only that, they'd need (on average) more computing power than the rest of the network combined, because if anyone else finds a real block first, all the effort trying to produce a fraudulent block is wasted.

I've seen this:
Quote from: Pieter Wuille
Code:
doHash(block_header) {
  hasher = new SHA256();
  hasher.update(block_header[0..63]);      // update A1
  hasher.update(block_header[64..127]);  // update A2
  hash1 = hasher.getHash();
  hasher.reset();
  hasher.update(hash1);                         // update B
  hash2 = hasher.getHash();
  return hash2
}

but I have pretty much no clue what it means.
This code just calls the hashing function on the blocks, there's nothing special about it.
newbie
Activity: 6
Merit: 0
April 09, 2012, 11:10:31 PM
#1
I know how to use a miner, how to use a pool and stuff like that, and I have done it before (and am right now), but I've always wondered what the actual process was to calculating hashes? What is my miner doing right now?

I've seen this:
Quote from: Pieter Wuille
Code:
doHash(block_header) {
  hasher = new SHA256();
  hasher.update(block_header[0..63]);      // update A1
  hasher.update(block_header[64..127]);  // update A2
  hash1 = hasher.getHash();
  hasher.reset();
  hasher.update(hash1);                         // update B
  hash2 = hasher.getHash();
  return hash2
}

but I have pretty much no clue what it means.
Jump to: