MetaMask / metamask-extension

:globe_with_meridians: :electric_plug: The MetaMask browser extension enables browsing Ethereum blockchain enabled websites
https://metamask.io
Other
11.87k stars 4.85k forks source link

eth.getCode returns incorrect values for empty addresses #4525

Closed levino closed 5 years ago

levino commented 6 years ago

The injected web3 instance retuns 0x when one calls web3.eth.getCode(address) when address has no contract deployed to it. The normal web3 however returns 0x0. This inconsistency is not only annoying but very dangerous. See also https://github.com/Neufund/TypeChain/issues/50 and https://github.com/MetaMask/metamask-extension/issues/1789. I think this issue should be addressed quickly and is a low hanging fruit. Happy to write a test and possibly fix for this but I am not sure where this is actually generated in the code.

nvonpentz commented 6 years ago

Could this be a problem with Infura?

When connected to any of the metamask provided networks, running web3.eth.getCode(emptyAddress, (err, result) => console.log(result)) in my browser console returns 0x.

When I switch to metamask to localhost:8545 and use my local blockchain instance with ganache-cli, it returns 0x0.

When I connect to Infura on my own by setting the provider to https://mainnet.infura.io/v3/<api-key>, it returns 0x.

levino commented 6 years ago

So the issue is upstream at infura, which MetaMask is using. Metamask should check the result it gets from infura or any rpc server for the correct format anyhow. Does anyone want to report this to infura?

levino commented 5 years ago

Why was this closed?

HowardBraham commented 5 years ago

@Levino, I fixed it here in MetaMask #5283

And also here in Ganache: trufflesuite/ganache-core#171

0x is the standard, not 0x0. But in the future, Ganache will return 0x, and MetaMask will handle both.

levino commented 5 years ago

Thanks for clarifying.