I am trying to understand how Monero hashes blocks.
I understand there is something called a "block hashing blob" that is combined with a nonce, but how can I get the block hashing blob for a specific block?
I tried the Monero Daemon JSON API
get_block, which has a field
blob in the return value (Python):
from Crypto.Hash import keccak hash_blob = daemon.get_block(1)["blob"] k = keccak.new(digest_bits=256) hash_bin = bytes.fromhex(hash_blob) k.update(hash_bin) print(k.hexdigest())
The hash blob returned for
and running the above code for it prints:
querying the deamon for block 1, as in
get_block(1)["header"]["hash"], I get hash:
So, obviously this is quite different.
get_block_template seems to produce something that could be combined with a nonce to build a valid hash, but this seems to be only for new blocks.
How do I calculate the hashes for an existing block? Some pseudocode or similar is fine, I tried to read some of the Monero C code, but it jumps around and my C/C++ is a bit limited, so couldn't quite figure it out.
I understand the block hashing blob would need things like coinbase transaction, merkle tree root, nonce, etc. But I also understand I need to combine them in a very specific way to get the exact correct hash. So first to build the block hashing blob, then to combine it with nonce..
An example for a block would be great but anything helps..
EDIT: I modified the daemon to add the block hashing blob to the get_block RPC method. With this I get the block hashing blob for block 1 as:
cn_slow_hash from pycryptonight on this does not give the correct hash:
x is the hash variant, I tried values 0-4. The block hash in the
771fbcd656ec1464d3a02ead5e18644030007a0fc664c0a964d30922821a8148 but the value returned by variant 0 for above is
If I run the same for height 1407480 as in question Can't seem to reconstruct hashing blob for old block, I get the same hashing blob as mentioned in that question (
0606f8e7a8ce05a5449f2dc32fff0730d58751fac5a2b9d58c59622f8a8d58d18e9886eddcdb01bb8c00006b4c34591fb7dd7d6664881f7c7e675aae7709d0acca033c6226727125c2127a17), but hashing it does not give the same hash as given for the block. Just like in that question, not able to get the correct hash.. But also do not understand how the author of that question fixed it.
What could be wrong with the hashing I use here?