4

I just started looking into the Ethash algorithm and I saw this:

s = sha3_512(header + nonce[::-1])

The thing is that here, nonce is an integer, and they used [::-1] to bitswap it from big endian to little endian? My question is what python version allows this? Every single one I tested gave me an __getitem__ not defined. As I also want to see in which version of python we can manipulate bits like this, I'm not searching for an alternative big to little endian conversion, I just want to know how did they get this working?

Also, in the algorithm, they say they combine header and nonce into a 64bit seed through this sha3_512 call. So how should header and nonce be? as hex string? integers? Should I convert nonce to an hex string so it can easily be added to header? This line lost me in their algorithm :/

Source : https://github.com/ethereum/wiki/wiki/Ethash

2

The thing is that here, nonce is an integer

I think it's actually of type bytes - it's not a true numeric type like int is. So here nonce is being treated as a byte array.

So how should header and nonce be? as hex string? integers?

As above. You could try using the bytes() or bytearray() to convert what you have.

  • Ok, I got confused as they wrote nonce = randint(0, 2**64) , but I guess their code is given as an illustration only. Thanks ! – Iulian Rotaru Oct 11 '16 at 8:52

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.