# Difference between revisions of "Proof of work"

(Created page with "This page describes Bitmessage's Proof of work ("POW") mechanism as it currently exists. In this document, hash() means SHA512(). SHA512 was chosen as it is widely supported a...") |
|||

Line 1: | Line 1: | ||

This page describes Bitmessage's Proof of work ("POW") mechanism as it currently exists. In this document, hash() means SHA512(). SHA512 was chosen as it is widely supported and so that Bitcoin POW hardware cannot trivially be used for Bitmessage POWs. The author acknowledges that they are essentially the same algorithm with a different key size. | This page describes Bitmessage's Proof of work ("POW") mechanism as it currently exists. In this document, hash() means SHA512(). SHA512 was chosen as it is widely supported and so that Bitcoin POW hardware cannot trivially be used for Bitmessage POWs. The author acknowledges that they are essentially the same algorithm with a different key size. | ||

− | + | averageProofOfWorkNonceTrialsPerByte is a constant which equals 320 | |

− | + | payloadLengthExtraBytes is a constant which equals 14000. The purpose of this value is to add some extra weight to small messages. | |

=== Do a POW === | === Do a POW === |

## Revision as of 20:27, 4 April 2013

This page describes Bitmessage's Proof of work ("POW") mechanism as it currently exists. In this document, hash() means SHA512(). SHA512 was chosen as it is widely supported and so that Bitcoin POW hardware cannot trivially be used for Bitmessage POWs. The author acknowledges that they are essentially the same algorithm with a different key size.

averageProofOfWorkNonceTrialsPerByte is a constant which equals 320

payloadLengthExtraBytes is a constant which equals 14000. The purpose of this value is to add some extra weight to small messages.

### Do a POW

Let us use a msg message as an example.

payload = embeddedTime + encodedStreamNumber + encrypted

target = 2^64 / ((length of the payload in bytes + payloadLengthExtraBytes + 8) * averageProofOfWorkNonceTrialsPerByte)

initialHash = hash(payload)

start with trialValue = 99999999999999999999

also start with nonce = 0 where nonce is 8 bytes in length and can be hashed as if it is a string.

while trialValue > target: nonce = nonce + 1 resultHash = hash(hash( nonce + initialHash )) trialValue = the last 8 bytes of resultHash, converted to an integer

When this loop finishes, you will have your 8 byte nonce value which you can prepend onto the front of the payload. The message is then ready to send.

### Check a POW

Let us assume that 'payload' contains the payload for a msg message (the nonce down through the encrypted message data).

nonce = the first 8 bytes of payload

dataToCheck = the ninth byte of payload on down (thus it is everything except the nonce)

initialHash = hash(dataToCheck)

resultHash = hash(hash( nonce + initialHash ))

POWValue = the first eight bytes of resultHash converted to an integer

target = 2^64 / ((length of payload + payloadLengthExtraBytes) * averageProofOfWorkNonceTrialsPerByte)

If POWValue is less than or equal to target, then the POW check passes.