Is there an easy way to validate an implementation of the cryptonight hash function? I wrote an implementation just to explore the features of various hash functions, but I'd like to validate that I'm producing the same result as the core implementation.


The Monero blockchain is full of test cases: for every block, you can assemble the hashing blob for that block, hash it with your new implementation, and check the resulting hash is below the target for that block. This will be done automatically if you replace monerod's Cryptonight implementation with your own, and try to sync the chain from scratch.

Another way is to replace a pool miner's Cryptonight code with your own, and try to mine. For example, https://github.com/OhGodAPet/cpuminer-multi/

  • Shouldn't the values be exactly the same? If the algorithms match? There isn't any element of randomness in the algorithm, that I can see. – The Shoe Shiner Sep 4 '17 at 19:34
  • Also, I just realized there is an example hash at the very end of the whitepaper. So I should be able to use that to validate my code as well. – The Shoe Shiner Sep 4 '17 at 19:36
  • The values should be exactly the same as a correct implementation. The reason for "less or equal" is that this is what gets accepted by the network, so that's what you can check using this method. Difficulty is such that there's a pretty low chance to get a "lower than difficulty" hash matching a block for a several blocks if your algorithm works, Maybe not quite cryptographicaly low, but it is a useful check until you find test vectors. – user36303 Sep 4 '17 at 21:54
  • FWIW - I was able to validate against an existing implementation. However I should point out that the examples at the end of the original whitepaper (cryptonote.org/cns/cns008.txt) do not seem to be valid hashes. Not sure why. – The Shoe Shiner Sep 9 '17 at 14:52
  • FWIW - Part of my problem here is that assembling the "hashing blob" from a block blob isn't arbitrary. It's not necessarily difficult, but I had to mimic the binary serialization logic from the monero source code in my local java app. Essentially I have a Java API for daemon now that can reassemble blocks from their blobs and vice versa, as well as reproduce the hashing blob for verification. – The Shoe Shiner Oct 16 '17 at 11:56

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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