Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

zero-length unformatted data fields should return 0x, not 0x0 #51

Closed
aakilfernandes opened this issue Jan 10, 2018 · 6 comments · Fixed by #171
Closed

zero-length unformatted data fields should return 0x, not 0x0 #51

aakilfernandes opened this issue Jan 10, 2018 · 6 comments · Fixed by #171

Comments

@aakilfernandes
Copy link
Contributor

Not sure if this is an issue or not, but eth_getCode returns 0x0 for non-contract accounts. My assumption is that it should return 0x.

@benjamincburns
Copy link
Contributor

benjamincburns commented Jan 16, 2018

Hi @aakilfernandes! Funny story. I just started writing up a nice polite response telling you how wrong your assumption is, and then I went to grab a reference link from the Ethereum RPC wiki and discovered what an incorrect, smug jerk I am! 😂

You're absolutely correct - unformatted data values which are zero length should be returned as 0x.

Does this break anything for you?

@benjamincburns benjamincburns changed the title getCode returns 0x0 zero-length unformatted data fields should return 0x, not 0x0 Jan 16, 2018
@benjamincburns benjamincburns changed the title zero-length unformatted data fields should return 0x, not 0x0 zero-length unformatted data fields should return 0x, not 0x0 Jan 16, 2018
benjamincburns added a commit that referenced this issue Jan 16, 2018
@benjamincburns
Copy link
Contributor

Was hoping to knock this out quickly, but I hit some snags. Will need to come back to it later. PRs welcome.

@jordanschalm
Copy link

A possible side-effect of this issue is sometimes non-zero fields are prefixed with a zero, which Geth no longer accepts as valid. For example 0x1234 would be returned by Ganache as 0x01234.

I have seen this occurring with eth_getBlockByNumber. Ganache returns the following transaction within the JSON response:

{  
    "hash":"0x3f8d3b83b6b14a020d8bb0a088027fc0ae5004feeb063e11841103ce6a331153",
    "nonce":"0x0",
    "blockHash":"0xcf57c1d749ce9c28cb6424c99e50f67641ebe78cc27f43a9751de64344f66df8",
    "blockNumber":"0x01",
    "transactionIndex":"0x00",
    "from":"0x627306090abab3a6e1400e9345bc60c78a8bef57",
    "to":"0xf17f52151ebef6c7334fad080c5704d77216b732",
    "value":"0x5af3107a4000",
    "gas":"0x5208",
    "gasPrice":"0x04a817c800",
    "input":"0x0"
}

gasPrice (non-zero) and nonce/input (zero) are both prefixed by a zero. This causes Geth's standard ethclient to fail while unmarshalling the response with the following error:

json: cannot unmarshal hex number with leading zero digits into Go struct field rpcBlock.transactions of type *hexutil.Big

@crzndx
Copy link

crzndx commented Mar 5, 2018

i also realized, that empty arrays return inconsistent results if empty, e.g. [0x0, 0x, 0x, ...]

@benjamincburns
Copy link
Contributor

This should be fixed in develop by #92. Thanks for the contribution @AusIV!

@HowardBraham
Copy link
Contributor

I don't think this issue was completely fixed before. I have submitted #171 to try to resolve it.

benjamincburns pushed a commit to HowardBraham/ganache-core that referenced this issue Sep 27, 2018
benjamincburns added a commit that referenced this issue Sep 27, 2018
Additional fix to #51 (eth_getCode on a non-contract should return 0x)
@benjamincburns benjamincburns removed their assignment Jul 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants