Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: TierNolan on May 11, 2013, 12:01:42 AM



Title: Exact definition of POW
Post by: TierNolan on May 11, 2013, 12:01:42 AM
The POW for a block is equal to 1/target.  Is there an exact way to calculate it?  Presumably, it is an integer division and so approximate.


Title: Re: Exact definition of POW
Post by: MatthewLM on May 11, 2013, 12:21:58 AM
The proof-of-work  is a method/system for demonstrating that work has been done. I guess you mean the block work, ie. the number used as the extent to which work has been done. You can see how it is calculated in the satoshi client here: https://github.com/bitcoin/bitcoin/blob/33edd0a477f4448be9c6c4949fbff4e53f16cac6/src/main.h#L1725

No idea why it is in the header file.

In cbitcoin the calculation is a bit more complicated: https://github.com/MatthewLM/cbitcoin/blob/master/src/CBValidationFunctions.c#L28


Title: Re: Exact definition of POW
Post by: leijurv on May 11, 2013, 12:25:55 AM
No... The POW of a block is the nonce which makes the hash below the target. It's not 1/target. Maybe you mean that one in every 2^256/target nonces will be below the target?


Title: Re: Exact definition of POW
Post by: grue on May 11, 2013, 12:32:32 AM
The POW for a block is equal to 1/target.  Is there an exact way to calculate it?  Presumably, it is an integer division and so approximate.
floating point is approximate (rounding rules dependent on implementation and precision), integer division isn't.


Title: Re: Exact definition of POW
Post by: TierNolan on May 11, 2013, 01:32:51 AM
The proof-of-work  is a method/system for demonstrating that work has been done. I guess you mean the block work, ie. the number used as the extent to which work has been done. You can see how it is calculated in the satoshi client here: https://github.com/bitcoin/bitcoin/blob/33edd0a477f4448be9c6c4949fbff4e53f16cac6/src/main.h#L1725

No idea why it is in the header file.

In cbitcoin the calculation is a bit more complicated: https://github.com/MatthewLM/cbitcoin/blob/master/src/CBValidationFunctions.c#L28


Shouldn't it be the same?  I guess it doesn't matter much, since a tie isn't likely to last long.


Title: Re: Exact definition of POW
Post by: kjj on May 11, 2013, 02:59:14 AM
The proof-of-work  is a method/system for demonstrating that work has been done. I guess you mean the block work, ie. the number used as the extent to which work has been done. You can see how it is calculated in the satoshi client here: https://github.com/bitcoin/bitcoin/blob/33edd0a477f4448be9c6c4949fbff4e53f16cac6/src/main.h#L1725

No idea why it is in the header file.

In cbitcoin the calculation is a bit more complicated: https://github.com/MatthewLM/cbitcoin/blob/master/src/CBValidationFunctions.c#L28


Shouldn't it be the same?  I guess it doesn't matter much, since a tie isn't likely to last long.

Same?  Tie?

Work is based on the difficulty, not the hash.


Title: Re: Exact definition of POW
Post by: TierNolan on May 11, 2013, 07:16:35 AM
Same?  Tie?

Work is based on the difficulty, not the hash.

The point is that if you have a different formula for working out the POW per block, you could have 2 chains, where there is disagreement on which one has more POW.  However, as long as they are nearly the same, 1 - 2 blocks should move one ahead of the other.


Title: Re: Exact definition of POW
Post by: kjj on May 11, 2013, 11:51:46 AM
Ahh, ok.  In that case, you need to look at the header.  The exact integer amount of work that a block is "worth" is encoded in the bits field.  The wiki page (https://en.bitcoin.it/wiki/Difficulty) describes the format, and someone already posted a link into the actual source where the calculation is done.

If you are looking for the math that updates the expected next target once a 2016 block window has been completed, let me know.  I think it is in main.cpp, and I can find it, it is just annoying to do from this computer.  It basically calculates what the difficulty in the previous window should have been to get an average of 10 minutes per block.

Edit:  Oh, blocks that have the wrong difficulty in the header are rejected as invalid, so there won't be any subtle disagreements,


Title: Re: Exact definition of POW
Post by: TierNolan on May 11, 2013, 01:12:43 PM
If you are looking for the math that updates the expected next target once a 2016 block window has been completed, let me know.

I have read it before.  My memory is that it calculates the target, not the difficulty.  As you say the link gives the official definition.

(1 << 256) / (target + 1)


Title: Re: Exact definition of POW
Post by: MatthewLM on May 11, 2013, 01:54:34 PM
Shouldn't it be the same?  I guess it doesn't matter much, since a tie isn't likely to last long.

The result is the same but the code is different.

The next target in the satoshi client is calculated here: https://github.com/bitcoin/bitcoin/blob/master/src/main.cpp#L1110

The "bits" field contains the claimed target for the block. The target is different than the block work, but the block work is derived from the target.