2

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.

1

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

0

This code try :

function block_hash_validation(uint blockNumber, bytes32 blockHash) 
        constant returns(bool isValid) 
    {
        return (block.blockhash(blockNumber) == blockHash);
    }

Hope it helps.

  • Sorry, I should have been clear, I meant verification off-chain like with geth, not in Solidity. – k26dr Jan 25 '18 at 23:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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