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.

1 Answer 1


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. Sep 4, 2017 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. Sep 4, 2017 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, 2017 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. Sep 9, 2017 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. Oct 16, 2017 at 11:56

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.