-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Warn when attempting to send tx with data to non-contract #5283
Conversation
Infura dosent manipulate responses for getCode so most likely is coming directly from the client code i just want to verify this behavior and will come back to this PR after that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a bug with metamask/infura but a bug with ganache and ethjs 0x
is nil
and 0x0
or 0x00
as it should be is 0 my recommendation is to fix the bug directly in ganache and have ethjs handle 0x
as null
What's the standard? Returning |
|
Ahah, okay. I previously thought |
I found this issue mentioned at Ganache at trufflesuite/ganache#51, and interestingly, they claimed to have closed the issue on April 12. I submitted a new pull request to Ganache at trufflesuite/ganache#171 that I believe should actually close that issue. Does anyone happen to know which package in ethjs contains the relevant |
@HowardBraham your looking at https://github.com/ethjs ? |
@frankiebee Yes, exactly, MetaMask has a dependency on ethjs, ethjs-contract, ethjs-ens, and ethjs-query. Do we know where this problem might be located? |
@frankiebee Actually, I have a feeling it might be in https://github.com/ethjs/ethjs-format. There are probably hundreds of projects that depend on this code, so fixing it is probably not that simple. I'm going to open an issue over there. |
@frankiebee After further investigation, I'm not so sure anymore that there's a problem with ethjs. I think the If you POST an This will come back as an error in MetaMask. On the other hand, when you try So we can't always trust the remote node to give an accurate Instead, we must:
My pull request already does this, and thus fixes the issues. |
11178dc
to
1790efb
Compare
@frankiebee: ganache-core merged my PR trufflesuite/ganache#171 So now future versions of Ganache will no longer return the non-standard But I think we should keep the functionality in MetaMask to parse |
… ganache-core v2.2.1 and below will return the non-standard '0x0'
// if there's data in the params, but there's no contract code, it's not a valid transaction | ||
if (txParams.data) { | ||
const err = new Error() | ||
err.errorKey = TRANSACTION_NO_CONTRACT_ERROR_KEY |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with this style of instantiating errors - is this correct? How does the error message get set?
is it appropriate to throw errors in this estimateTxGas
function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The errorKey is converted to 'transactionErrorNoContract'
in ui\app\constants\error-keys.js
, and then "Trying to call a contract function at an address that is not a contract address."
in app\_locales\en\messages.json
.
This generally looks good. This PR does include any tests that guarantee the new behavior |
@HowardBraham can you expand on why you think sending eth to a payable contract requires a warning? |
Perhaps we can improve the language here to something less technical users can understand:
|
@kumavis
When sending ETH to a payable contract, I think there should at least be an indication that it's a contract and not an individual. Just a little reminder for the user to think twice and make sure they're doing what they expect. Currently, there's no indication whatsoever. |
I don't know if you were able to test this, but the correct error message does show up in the UI. Would a unit test for this actually connect to Infura or geth, or just simulate the connection? Simply connecting to the internal Ganache might not be enough, because Ganache did not exhibit this bug. Can someone show me an example of a similar unit test? |
@kumavis, can you help me figure out how to finish this PR and get it merged? I answered your questions and asked one above (about unit test examples). Thanks! |
@HowardBraham i guess my primary concern at this point is the creation of an error without a message (even though the message gets set via the localization). @bitpshr @whymarrh do we do this anywhere else? |
@kumavis @bitpshr @whymarrh I based it on this code, which I know is not exactly the same, because it's not throwing an Error object: Lines 124 to 129 in 600f755
If there's a better pattern to follow, in order to throw an error with a localized message, I'm happy to change it. |
Thanks again @HowardBraham this file+method have evolved, |
Fixes #1789
Fixes #4525
I think this is technically an issue between Infura and the ethjs library. When you call
getCode()
on an address that does not have a contract, Ganache will return0x0
and Infura will return0x
. The ethjs library correctly parses the0x0
, but does not know how to deal with the0x
. But absent fixes from Infura and ethjs, it is now fixed in MetaMask.I have also improved the error message, which used to say
And now says the clearer
(This does have to be translated to additional languages.)
I have done regression tests against the following 12 test cases in the table below:
Two opportunities for additional improvement (as mentioned in the table above) are the alert when you send ETH to a contract without payable, and a possible warning when you send ETH to a contract with payable (as this is a special case with pitfalls the user should be aware of).
Please let me know if I overlooked any test cases.