|
|
@ -23,26 +23,18 @@ uint256 CBlockHeader::GetHash() const |
|
|
|
uint256 CBlockHeader::GetPoWHash() const |
|
|
|
uint256 CBlockHeader::GetPoWHash() const |
|
|
|
{ |
|
|
|
{ |
|
|
|
uint256 thash; |
|
|
|
uint256 thash; |
|
|
|
// Convert it to Cryptonight header format.
|
|
|
|
// Convert it to Cryptonight header format, i.e. nonce at 39th byte.
|
|
|
|
uint8_t cnHeader[76] = {}; |
|
|
|
uint8_t cnHeader[80] = {}; |
|
|
|
// Bitcoin header size is 80 bytes, while CN is 76 bytes.
|
|
|
|
// Copy nVersion, prevblockhas, and 3 bytes of merkleroot.
|
|
|
|
// To reduce it to 76, combine nVersion(4 bytes) and hashPrevBlock(32 byte)
|
|
|
|
memcpy(cnHeader, BEGIN(nVersion), 39); |
|
|
|
// into 32 byte SHA2 hash.
|
|
|
|
uint32_t offset = 39; |
|
|
|
uint8_t combineHash[32] = {}; |
|
|
|
|
|
|
|
CSHA256().Write((uint8_t*)BEGIN(nVersion), 36).Finalize(combineHash); |
|
|
|
|
|
|
|
memcpy(cnHeader, combineHash, sizeof(combineHash)); |
|
|
|
|
|
|
|
uint32_t offset = sizeof(combineHash); |
|
|
|
|
|
|
|
// Copy 7 bytes of hashMerkleRoot
|
|
|
|
|
|
|
|
memcpy(cnHeader + offset, BEGIN(nVersion) + 36, 7); |
|
|
|
|
|
|
|
offset += 7; |
|
|
|
|
|
|
|
// Copy nonce.
|
|
|
|
// Copy nonce.
|
|
|
|
assert(offset == 39); |
|
|
|
|
|
|
|
memcpy(cnHeader + offset, BEGIN(nVersion) + 76, 4); |
|
|
|
memcpy(cnHeader + offset, BEGIN(nVersion) + 76, 4); |
|
|
|
offset += 4; |
|
|
|
offset += 4; |
|
|
|
// Copy the rest of hashMerkleRoot (25 bytes)
|
|
|
|
// Copy remaining 29 bytes of hashMerkleRoot
|
|
|
|
memcpy(cnHeader + offset, BEGIN(nVersion) + 36 + 7, 25); |
|
|
|
memcpy(cnHeader + offset, BEGIN(nVersion) + 39, 29); |
|
|
|
offset += 25; |
|
|
|
offset += 29; |
|
|
|
assert(offset == 68); |
|
|
|
assert(offset == 72); |
|
|
|
// Copy the rest of the header (timestamp and bits).
|
|
|
|
// Copy the rest of the header (timestamp and bits).
|
|
|
|
memcpy(cnHeader + offset, BEGIN(nVersion) + 68, 8); |
|
|
|
memcpy(cnHeader + offset, BEGIN(nVersion) + 68, 8); |
|
|
|
// Compute the CN hash.
|
|
|
|
// Compute the CN hash.
|
|
|
|