1

I'm trying to re-construct the "hashing blob" for an old block and calculate the correct hash to validate some code, but I can't seem to get the correct results. I've confirmed (via unit tests against the monero source code) that my hash functions are correct mathematically, so it seems im getting the hashing blob contents wrong. If we take an old block as an example:

     {
  "id": "0",
  "jsonrpc": "2.0",
  "result": {
    "blob": "0606f8e7a8ce05a5449f2dc32fff0730d58751fac5a2b9d58c59622f8a8d58d18e9886eddcdb01bb8c000002b4f45501fff8f35501defcecf286c701026b19155b8fe479865890c2afe0aa91c8720c8f42b92f65b4c4d6f46a6c2871142b01b1d42f59be8beaefa1cc2d05a2c13ddae9029eb5d453032e248e4815c823caff020800000006a2d1e02100164af21d26273d2ca49cd41a3ae063c4bcdae6bd183788688e09872d2c275e352aee7eef90967e15f63e32d3779db73cd7aed093e5046ecfe5ef796017a00fbe4298fe4ff7bb2420a38be5dcce32e032f8831f4de268f9d9ac1b12de5cd13938591882ac9bda633c0104cce9071167cdc0623b6d24eeb88b4830dd1f018063466ef4ba2f3b75c65f595f2ab17f04c8be4030d825ee724da1adaceafc7f10709fac0011fb460a58dc7a340ccf8a918a33f7af32713bd640a23a4e9bea344efa853b739122b3c9f6d8eb24b25a9ba30b3c17cc599cf91a02057a1175ec646b4f4b5aa5429da047df50379115bdb0ef097cce0c74954554ed2519ce8dd78815d32ade2395adce8ce89d5e0e99fdf5b1386be0673b7b00af56b3b251acd1602999ac2657603db4a8c18c42db2d74a28405739a77d914b3962172fdf1018c38ca4d125b7a9729f3b60052d328bc495a47065aec970831110b5a6abe7dd6699b2dcd73cf512b46d4c1bb154149583cc1c8f6b6b32ee52a895a0e78a5ead9d27cc679d6f08adc375292668b41f1119b314cb1bcac84730814d7949c636ad32ecf04bf39e0b7a320362353b2b11fc0570ab8f38363003520874547586931db71265addd9030a0fb25728e15baf96568797417f7faef04190d3a2c12cee2c260a330d8963e76a93c6b992938d431e11d9f9e6a96bf12c468af37c0aba16312bf5962527df90f85d37658112c80a8a31a76cf39b9e9f9300edfe47f5a7c3adf509dd198b2a3f8396c7545a6c14a8edd1741cdf829b5ce62e3e926e816297ba9c2002ed1423793c944410c9ba0bb6b51c39ba4e9d390fc7d7715b31185f95c78905e8ecf30a30f217d44a1cd851df4ffe00da12516ce64dbd7eae5de02ec0e6584384d30cd8cb83d19d32cd5e5ddea4688aa4460727d30f7ad725c8d34cec5de9886cf3ca982aa4dfff09759ae751db2e5e117af41d0a5ce307d8c3531c32ea802ab742a38068",
    "block_header": {
      "block_size": 310200,
      "block_weight": 310200,
      "cumulative_difficulty": 3689770636864650,
      "depth": 328990,
      "difficulty": 29957012891,
      "hash": "71833b89e1ebc8fea4de794ac317873f6a441666be79f7b60e5e3754c85535cd",
      "height": 1407480,
      "major_version": 6,
      "minor_version": 6,
      "nonce": 36027,
      "num_txes": 22,
      "orphan_status": false,
      "pow_hash": "",
      "prev_hash": "a5449f2dc32fff0730d58751fac5a2b9d58c59622f8a8d58d18e9886eddcdb01",
      "reward": 6839439408734,
      "timestamp": 1506423800
    },
    "json": "{\n  \"major_version\": 6, \n  \"minor_version\": 6, \n  \"timestamp\": 1506423800, \n  \"prev_id\": \"a5449f2dc32fff0730d58751fac5a2b9d58c59622f8a8d58d18e9886eddcdb01\", \n  \"nonce\": 36027, \n  \"miner_tx\": {\n    \"version\": 2, \n    \"unlock_time\": 1407540, \n    \"vin\": [ {\n        \"gen\": {\n          \"height\": 1407480\n        }\n      }\n    ], \n    \"vout\": [ {\n        \"amount\": 6839439408734, \n        \"target\": {\n          \"key\": \"6b19155b8fe479865890c2afe0aa91c8720c8f42b92f65b4c4d6f46a6c287114\"\n        }\n      }\n    ], \n    \"extra\": [ 1, 177, 212, 47, 89, 190, 139, 234, 239, 161, 204, 45, 5, 162, 193, 61, 218, 233, 2, 158, 181, 212, 83, 3, 46, 36, 142, 72, 21, 200, 35, 202, 255, 2, 8, 0, 0, 0, 6, 162, 209, 224, 33\n    ], \n    \"rct_signatures\": {\n      \"type\": 0\n    }\n  }, \n  \"tx_hashes\": [ \"4af21d26273d2ca49cd41a3ae063c4bcdae6bd183788688e09872d2c275e352a\", \"ee7eef90967e15f63e32d3779db73cd7aed093e5046ecfe5ef796017a00fbe42\", \"98fe4ff7bb2420a38be5dcce32e032f8831f4de268f9d9ac1b12de5cd1393859\", \"1882ac9bda633c0104cce9071167cdc0623b6d24eeb88b4830dd1f018063466e\", \"f4ba2f3b75c65f595f2ab17f04c8be4030d825ee724da1adaceafc7f10709fac\", \"0011fb460a58dc7a340ccf8a918a33f7af32713bd640a23a4e9bea344efa853b\", \"739122b3c9f6d8eb24b25a9ba30b3c17cc599cf91a02057a1175ec646b4f4b5a\", \"a5429da047df50379115bdb0ef097cce0c74954554ed2519ce8dd78815d32ade\", \"2395adce8ce89d5e0e99fdf5b1386be0673b7b00af56b3b251acd1602999ac26\", \"57603db4a8c18c42db2d74a28405739a77d914b3962172fdf1018c38ca4d125b\", \"7a9729f3b60052d328bc495a47065aec970831110b5a6abe7dd6699b2dcd73cf\", \"512b46d4c1bb154149583cc1c8f6b6b32ee52a895a0e78a5ead9d27cc679d6f0\", \"8adc375292668b41f1119b314cb1bcac84730814d7949c636ad32ecf04bf39e0\", \"b7a320362353b2b11fc0570ab8f38363003520874547586931db71265addd903\", \"0a0fb25728e15baf96568797417f7faef04190d3a2c12cee2c260a330d8963e7\", \"6a93c6b992938d431e11d9f9e6a96bf12c468af37c0aba16312bf5962527df90\", \"f85d37658112c80a8a31a76cf39b9e9f9300edfe47f5a7c3adf509dd198b2a3f\", \"8396c7545a6c14a8edd1741cdf829b5ce62e3e926e816297ba9c2002ed142379\", \"3c944410c9ba0bb6b51c39ba4e9d390fc7d7715b31185f95c78905e8ecf30a30\", \"f217d44a1cd851df4ffe00da12516ce64dbd7eae5de02ec0e6584384d30cd8cb\", \"83d19d32cd5e5ddea4688aa4460727d30f7ad725c8d34cec5de9886cf3ca982a\", \"a4dfff09759ae751db2e5e117af41d0a5ce307d8c3531c32ea802ab742a38068\"\n  ]\n}",
    "miner_tx_hash": "f454f19648e8c85c95fb5aae9fedf93cafd0346e3aa58f10f96f47db47d9eb43",
    "status": "OK",
    "tx_hashes": ["4af21d26273d2ca49cd41a3ae063c4bcdae6bd183788688e09872d2c275e352a","ee7eef90967e15f63e32d3779db73cd7aed093e5046ecfe5ef796017a00fbe42","98fe4ff7bb2420a38be5dcce32e032f8831f4de268f9d9ac1b12de5cd1393859","1882ac9bda633c0104cce9071167cdc0623b6d24eeb88b4830dd1f018063466e","f4ba2f3b75c65f595f2ab17f04c8be4030d825ee724da1adaceafc7f10709fac","0011fb460a58dc7a340ccf8a918a33f7af32713bd640a23a4e9bea344efa853b","739122b3c9f6d8eb24b25a9ba30b3c17cc599cf91a02057a1175ec646b4f4b5a","a5429da047df50379115bdb0ef097cce0c74954554ed2519ce8dd78815d32ade","2395adce8ce89d5e0e99fdf5b1386be0673b7b00af56b3b251acd1602999ac26","57603db4a8c18c42db2d74a28405739a77d914b3962172fdf1018c38ca4d125b","7a9729f3b60052d328bc495a47065aec970831110b5a6abe7dd6699b2dcd73cf","512b46d4c1bb154149583cc1c8f6b6b32ee52a895a0e78a5ead9d27cc679d6f0","8adc375292668b41f1119b314cb1bcac84730814d7949c636ad32ecf04bf39e0","b7a320362353b2b11fc0570ab8f38363003520874547586931db71265addd903","0a0fb25728e15baf96568797417f7faef04190d3a2c12cee2c260a330d8963e7","6a93c6b992938d431e11d9f9e6a96bf12c468af37c0aba16312bf5962527df90","f85d37658112c80a8a31a76cf39b9e9f9300edfe47f5a7c3adf509dd198b2a3f","8396c7545a6c14a8edd1741cdf829b5ce62e3e926e816297ba9c2002ed142379","3c944410c9ba0bb6b51c39ba4e9d390fc7d7715b31185f95c78905e8ecf30a30","f217d44a1cd851df4ffe00da12516ce64dbd7eae5de02ec0e6584384d30cd8cb","83d19d32cd5e5ddea4688aa4460727d30f7ad725c8d34cec5de9886cf3ca982a","a4dfff09759ae751db2e5e117af41d0a5ce307d8c3531c32ea802ab742a38068"],
    "untrusted": false
  }
}

Then the hashing blob should be (in Hex):

  • Versions: 0606
  • Timestamp: f8e7a8ce05
  • Prev Id: a5449f2dc32fff0730d58751fac5a2b9d58c59622f8a8d58d18e9886eddcdb01
  • Nonce: bb8c0000
  • Transactions Tree Root: 6b4c34591fb7dd7d6664881f7c7e675aae7709d0acca033c6226727125c2127a
  • Transaction Count: 17

So the full blob should be:

0606f8e7a8ce05a5449f2dc32fff0730d58751fac5a2b9d58c59622f8a8d58d18e9886eddcdb01bb8c00006b4c34591fb7dd7d6664881f7c7e675aae7709d0acca033c6226727125c2127a17

The header says that the hash of this should be:

71833b89e1ebc8fea4de794ac317873f6a441666be79f7b60e5e3754c85535cd

But I can't seem to get that result when hashing.

Am I constructing the block correctly?

Or better yet, Is there some test data somewhere that shows exactly what the hashing blob should look like for a specific block?

Edit: So I figured out that the block id requires the hashing blob to be prefixed with the size of hashing blob. So I'm now able to hash the blob to get the correct hash Id. But im still currently stuck at validating the difficulty.

1
  • This is a few years old post but I am trying to recreate the block hash myself.. What was the prefix you added? It is a varint converted to hex to represent the length of the blob hash above (0606...)? Did you have to change any of the other fields above (such as timestamp from jtgrassie answer)?
    – kg_sYy
    Commented Jan 13, 2021 at 21:10

1 Answer 1

1

The hashing blob is constructed (in the source code):

blobdata get_block_hashing_blob(const block& b)
{
  blobdata blob = t_serializable_object_to_blob(static_cast<block_header>(b));
  crypto::hash tree_root_hash = get_tx_tree_hash(b);
  blob.append(reinterpret_cast<const char*>(&tree_root_hash), sizeof(tree_root_hash));
  blob.append(tools::get_varint_data(b.tx_hashes.size()+1));
  return blob;
}

And the block header defined:

struct block_header
{
  uint8_t major_version;
  uint8_t minor_version;
  uint64_t timestamp;
  crypto::hash prev_id;
  uint32_t nonce;
  ...
}

So immediately looking at your example I can see the timestamp is not of the same size.

Anyway, you seem to have resolved that part of your question, so let's move on to your following question of how to validate the difficulty.

For this, you can simply divide the base difficulty (2^256-1) by your hash and then compare the result against the block difficulty; it must be greater than or equal to the block difficulty.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.