I'm trying to run Ethash algorithm from the Python-code provided over here: https://eth.wiki/concepts/ethash/ethash, and have some troubles comparing the produced cache-file with the actual cache-file from the real network, running by geth.
As the first step, I'm generating a cache file from the given block_number and the seed. The algorithm for cache-generation is described in the corresponding
mkcache(cache_size, seed) function from the link above.
After running the function, I'm ending up with 16x995326 list, with 32-bit integer in every element. After the serialization of this list into a binary file (using Python
struct module), I'm getting a 61-megabyte file.
Now, the question is: How can I verify that the generated cache-file is actually correct and it is intact with the current Ethereum network? Do you guys have any thoughts on that?
The way I'm doing this verification now is by comparing my cache-file with the cache-file from the actual ethereum-node running by geth.
- let's take a block number: 10757149
- for this block number, we can get the corresponding seed (please, check if the seed is correct): 0xf7f6e04564e6b37fb9017324dc2577bd24cd25977037cfe8cd95b590009e2391
- from the fully-synced ethereum node running geth, I can find the actual cache file, located in .ethereum/geth/ethash/cache-R23-f7f6e04564e6b37f
- executing md5sum on that cache-file, I'm getting the following checksum: d767fc7d317c78c6ac2e8b0a111d5dc0 (btw, if you're running fully-synced geth, you should get the identical md5hash for the R23-f7f6e04564e6b37f cache)
Now, given the block_number and the seed, I'm executing a Python-script from the example in the link above, and the md5sum on my cache-file is different!
On that point, I'm really stuck and have no idea how to check the cache-file correctness so far. Some other questions are coming up to my head, maybe you could clarify something:
Are the algorithms from eth.wiki/concepts/ethash/ethash actually followed by the official go-implementation of Ethereum (geth)?
Looking at the source-code of geth, I suspect that the cache-generation algorithm is different. I'm not good at parsing the go-syntax, so maybe some of you could check the Python-version of the
mkcachefunction from here: eth.wiki/concepts/ethash/ethash, and the corresponding function from geth over here: github.com/ethereum/go-ethereum/blob/master/consensus/ethash/algorithm.go#L139. Would be very glad if someone could see the actual differences in the algorithms (if they exist).
Could it be due to a difference in cache serialization (when the generated array is being written to a file)?
Would really appreciate any hints on that topic. You may find the Python2.7 script I'm using over here: github.com/dugdmitry/ethash_python/blob/master/run_miner.py