In the ethereum yellowpaper, about the creation of seedhash, I found that, when height is less 30000, the seedhash S = keccak256({0}32), description is:

Seed hash. The seed hash is different for every epoch. For the first epoch it is the Keccak-256 hash of a series of 32 bytes of zeros. For every other epoch it is always the Keccak-256 hash of the previous seed hash.

but, in the python code, like this:

 def get_seedhash(block):
     s = '\x00' * 32
     for i in range(block.number // EPOCH_LENGTH):
         s = serialize_hash(sha3_256(s))
     return s

And in go-ethereum, the code is:

func seedHash(block uint64) []byte {
    seed := make([]byte, 32)
    if block < epochLength {
        return seed
    keccak256 := makeHasher(sha3.NewKeccak256())
    for i := 0; i < int(block/epochLength); i++ {
        keccak256(seed, seed)
    return seed

So, it seems that some different between the yellow paper and code. In the code, when height is less 30000, the seedHash return {0}32. I'm in a puzzle in this problem. Thank you for anyone can help me!


I think it depends what you mean by "correct". As long as the seedhash for each epoch (i.e. each 30,000 blocks mined) is different, I don't think it actually matters how the hash is generated.

Looking more closely at the Geth code, seedHash() returns a seed which is then fed into generateCache(). In generateCache() the seed is hashed using keccak512() before it is used. So for the first epoch, although the seedHash() function doesn't call keccak256() (at least for Geth), the seed of {0}32 is hashed before use. (There may also be further complexities further down the call chain... )

  • Actually, the python and go-ethereum have the same result. – Chengcheng Zhang Nov 23 '17 at 9:44
  • You're correct - the floor division in the loop prevents it being entered, obviously :-) (It's early here... ) I'll edit my answer so it's not misleading. I think the rest of the answer still stands, i.e. we're never actually using 0 as a seed as it later gets hashed anyway. It just doesn't quite agree with the Yellow Paper (keccak512, done in the next function vs. keccak256 in seedHash()). – Richard Horrocks Nov 23 '17 at 9:48
  • 1
    (Other people closer to the code may know if there's a reason for this disagreement - I don't.) – Richard Horrocks Nov 23 '17 at 9:49
  • But, this disagreement is very strange. – Chengcheng Zhang Nov 23 '17 at 9:59

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.