Skip to content

Commit f382894

Browse files
committed
Fixed merged mining block hash calc
1 parent c359843 commit f382894

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/cryptonote_core/cryptonote_basic.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,20 @@
2525
#include "misc_language.h"
2626
#include "tx_extra.h"
2727
#include "ringct/rctTypes.h"
28+
#include "cryptonote_protocol/blobdatatype.h"
2829

2930

3031
namespace cryptonote
3132
{
3233
struct block;
3334
class transaction;
35+
class transaction_prefix;
3436
struct tx_extra_merge_mining_tag;
3537

3638
// Implemented in cryptonote_format_utils.cpp
3739
bool get_transaction_hash(const transaction& t, crypto::hash& res);
40+
void get_transaction_prefix_hash(const transaction_prefix& tx, crypto::hash& h);
41+
void get_blob_hash(const blobdata& blob, crypto::hash& res);
3842
bool get_mm_tag_from_extra(const std::vector<uint8_t>& tx, tx_extra_merge_mining_tag& mm_tag);
3943

4044
const static crypto::hash null_hash = AUTO_VAL_INIT(null_hash);
@@ -353,8 +357,18 @@ namespace cryptonote
353357
if (hashing_serialization)
354358
{
355359
crypto::hash miner_tx_hash;
356-
if (!get_transaction_hash(b.miner_tx, miner_tx_hash))
357-
return false;
360+
361+
if (b.miner_tx.version < 2) {
362+
if (!get_transaction_hash(b.miner_tx, miner_tx_hash))
363+
return false;
364+
} else {
365+
get_transaction_prefix_hash(static_cast<const transaction_prefix&>(b.miner_tx), miner_tx_hash);
366+
const uint8_t data[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbc, 0x36, 0x78, 0x9e, 0x7a, 0x1e, 0x28, 0x14, 0x36, 0x46, 0x42, 0x29, 0x82, 0x8f, 0x81, 0x7d, 0x66, 0x12, 0xf7, 0xb4, 0x77, 0xd6, 0x65, 0x91, 0xff, 0x96, 0xa9, 0xe0, 0x64, 0xbc, 0xc9, 0x8a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
367+
blobdata blobdata((char*)data, sizeof(data));
368+
const unsigned char* p = (unsigned char*)&miner_tx_hash;
369+
for (int i = 0; i != HASH_SIZE; ++ i, ++ p) blobdata[i] = *p;
370+
get_blob_hash(blobdata, miner_tx_hash);
371+
}
358372

359373
crypto::hash merkle_root;
360374
crypto::tree_hash_from_branch(b.miner_tx_branch.data(), b.miner_tx_branch.size(), miner_tx_hash, 0, merkle_root);

src/main.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ NAN_METHOD(get_block_id) {
165165
if (!Buffer::HasInstance(target)) return THROW_ERROR_EXCEPTION("Argument should be a buffer object.");
166166

167167
blobdata input = std::string(Buffer::Data(target), Buffer::Length(target));
168-
blobdata output = "";
169168

170169
enum BLOB_TYPE blob_type = BLOB_TYPE_CRYPTONOTE;
171170
if (info.Length() >= 2) {

0 commit comments

Comments
 (0)