chfast / ethash

C/C++ implementation of Ethash and ProgPoW – the Ethereum Proof of Work algorithms
Apache License 2.0
142 stars 128 forks source link

The generated cache is different from that generated in go-ethereum #223

Closed alicebobscorpio closed 2 years ago

alicebobscorpio commented 2 years ago

In build_light_cache() function, the address of variable `cache' changes in each loop for (int i = 0; i < num_items; ++i) { const uint32_t index_limit = static_cast(num_items);

        // Fist index: 4 first bytes of the item as little-endian integer.
        const uint32_t t = le::uint32(cache[i].word32s[0]);
        const uint32_t v = t % index_limit;

        // Second index.
        const uint32_t w = static_cast<uint32_t>(num_items + (i - 1)) % index_limit;

        cache[i] = keccak512(bitwise_xor(cache[v], cache[w]));
    }

In particular, for i=0, cache[0] is the first element of array cache (as expected). However, for i=1, cache[0] is the second element of array cache, and for i=2, cache[0] is the third element of array cache, ... By observing the address of cache, I found that the address of cache changes each time when arriving at " const uint32_t t = le::uint32(cache[i].word32s[0]);".

As a result, the generated cache is different from that generated in go-ethereum.

alicebobscorpio commented 2 years ago

The codes seem good. I am wondering why this happens.

alicebobscorpio commented 2 years ago

It seems due to the CLion debug tool.