[Ethereum] Verifying ethash output Ethereum block hash

dagethashlight-clientsmining

On the Ethash wiki, it mentions that a 16MB verification cache can be used to verify block hashes without generating the full DAG, but there are no further details on how this is done.

What's the verification algorithm?

EDIT: I'm not looking for a solution in Solidity where the blockhash is accessible. I'm looking for a way to validate that an Ethash output is valid off-chain.

Best Answer

I've found an answer here at the Ethash wiki.

def calc_dataset_item(cache, i):
    n = len(cache)
    r = HASH_BYTES // WORD_BYTES
    # initialize the mix
    mix = copy.copy(cache[i % n])
    mix[0] ^= i
    mix = sha3_512(mix)
    # fnv it with a lot of random cache nodes based on i
    for j in range(DATASET_PARENTS):
        cache_index = fnv(i ^ j, mix[j % r])
        mix = map(fnv, mix, cache[cache_index % n])
    return sha3_512(mix)

def hashimoto_light(full_size, cache, header, nonce):
    return hashimoto(header, nonce, full_size, lambda x: calc_dataset_item(cache, x))

Instead of generating the full dataset with calc_dataset_item, just the required dataset items for the single hash cycle are generated dynamically

Related Topic