Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Nonce should never be 0 bytes #42

Merged
merged 1 commit into from
Apr 27, 2018

Conversation

AusIV
Copy link
Contributor

@AusIV AusIV commented Mar 29, 2018

I have a project where we're trying to use Ganache to test our services that
are written in Go. The RPC client that ships with Geth ignores the
hash provided by RPC and recalculates it instead. Due to some discrepancies
between the value used to calculate the hash and the values served over
RPC, the Go client is unable to compute the same hash as Ganache.

One of the issues we ran into was that ethereumjs-block defaults to
an empty nonce, while according to the spec a nonce should be 8 bytes.
When computing the hash, the difference between a 0 byte nonce and
a nonce with 8 null bytes is obviously significant.

With this change along with a couple of changes to Ganache's RPC
encoding, the Ethereum client within Geth computes the same block
hashes as Ganache.

At OpenRelay, we're trying to use Ganache to test our services that
are written in Go. The RPC client that ships with Geth ignores the
hash provided by RPC and recalculates it instead. Due to some discrepancies
between the value used to calculate the hash and the values served over
RPC, the Go client is unable to compute the same hash as Ganache.

One of the issues we ran into was that ethereumjs-block defaults to
an empty nonce, while according to the spec a nonce should be 8 bytes.
When computing the hash, the difference between a 0 byte nonce and
a nonce with 8 null bytes is obviously significant.

With this change along with a couple of changes to Ganache's RPC
encoding, the Ethereum client within Geth computes the same block
hashes as Ganache.
@coveralls
Copy link

Coverage Status

Coverage remained the same at 70.213% when pulling 4833c54 on NoteGio:full-size-nonce into 8641dc9 on ethereumjs:master.

@holgerd77
Copy link
Member

Could you link to the specification where this is defined? (And what is with the other default values?)

@AusIV
Copy link
Contributor Author

AusIV commented Mar 30, 2018

Page 5 of the yellow paper defines the nonce as :

A 64-bit value which, combined with the mixhash, proves that a sufficient amount of computation has been carried out on this block; formally Hn.

No default is specified, but the current default in ethereumjs-block is not 64 bits.

For my purposes it doesn't matter what the default is, so long as it's the right number of bits. Ultimately the geth ethereum client reads whatever it is provided into an 8 byte array. If no value is provided it ends up with eight null bytes, which it uses when computing the hash. If ethereumjs-block decides to use some other default, I'll pass that value to the geth ethereum client and it will still compute the same hash. The problem right now is that ethereumjs-block is using 0 bits for the nonce, and the ethereum geth client always uses a 64 bit nonce.

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your extensive explanations, this all makes very much sense, will merge.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants