-
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
Incorrect handling of revert with a message #3435
Comments
require
statement which includes a message
UPDATE: I've deployed a pair of slightly different contracts, where function These two contracts are deployed at:
As before, we have This time, you can reproduce the problem also on Etherscan's read-contract tab for contract #2. Pass I doubt that Etherscan uses Infura as its Web3 provider, so I am once again inclined to think that the problem is in web3.js. That said, I do understand that Infura is not the actual node type, which is typically either Geth or Parity, so perhaps the problem is in the type or types of nodes used by both Infura and Etherscan. |
I am facing a similar issue as well. The below function doesn't raise an error when passing
|
@barakman @Kapn Thanks for raising this. Revert with reason returns an encoded reason string as data. I'm unsure if using it in Solidity view methods is unproblematic - would like to hear your opinion though. Another approach would be to have defined If you upgrade to 1.2.6 and set the web3.eth.handleRevert property you should see The implementation details are in #3248 and there are usage examples in the unit tests here. |
@cgewecke: |
The node just returns data that has a special signature and form for revert reasons. So it is detectable and Web3 1.2.6 (optionally) implements this. Am pretty sure Ethers does as well. On the other hand, as a contract developer you might worry that there aren't strong assurances the revert return data will be interpreted correctly for view methods since it's not specified by their ABI. |
@cgewecke: I deployed the following contract to Ropsten address
I then executed a
The result implies that the transaction reverts as expected:
I believe that this rules out your speculation of an incorrect value possibly returned when calling the "dubious" function on-chain (more specifically, from a non-constant function). Thanks |
@barakman Going to close because latest version supports revert with reason as an option. Please just ping if you feel like this should stay open and concrete steps to change default behavior should be taken here. |
@cgewecke: |
@cgewecke I'm a bit confused by this issue. Whether or not a smart contract is executed via
This worries me that web3.js might detect failure from the return data and not from a special flag returned by the node. Does the node not return whether or not the call was successful or not? |
This looks client dependent and things are in flux. Until geth 1.9.14, executing Revert
Success
In geth 1.9.14, the revert case returns
And there is an open PR at geth 21083 to make the error explicit. The issue is reported and discussed in geth 19027 There's a reproduction case for this at: https://github.com/cgewecke/geth-revert-reason-repro |
@cgewecke : Thank you for your quick response.
|
@barakman I believe the following holds:
So it will depend on what nodes the remote services are running. Parity has always reported this case as an error fwiw... see geth 19027 (Related: #3520) |
In that case, I am rather puzzled by how come it works correctly when using:
And by correctly I mean, not only does it revert, but it also shows the revert-message. |
Yes, ganache-cli has it's own implementation. If you run with this option it may emulate Geth more closely.
|
And with regards to:
Does that imply that my initial analysis from the top of this thread ("My analysis is that this is a bug in either Web3 or Infura") is more or less accurate, and this is indeed a problem which must be resolved in both places? Thanks BTW, as per your |
Yes, it's a little open to interpretation. The client (or Infura) should error and it looks like that's being addressed. We're waiting for the additional changes in geth 21083 to finalize handling at Web3. |
Hi guys, I'm too having a similar problem, it is described in: https://ethereum.stackexchange.com/questions/83714/contract-not-returning-error-to-react-interface?noredirect=1#comment104346_83714 I'm too using web3 and Infura. I have a require option and instead of reverting the call or returning an error I get an impossible number return. I say impossible because the return should be the amount of ether a certain address has on the contract and the waiting time it need to pass to be able to take it out ( a timelock contract). But if the person has no account in the contract it returns a huge weird number for both variables. Guess is a similar error then. |
Merged a fix for this on Web3's side with #3571. Will be available in |
I am facing no reason issue, v 1.9.20, no reason message. |
Expected behavior
Function call should revert
Actual behavior
Function call completes successfully and returns an impossible value
Steps to reproduce the behavior
I have deployed the following contract to Ropsten, and verified its source-code on Etherscan:
It is at address
0x23335ED6E550726D0bA881a3D1f5b5B1eF411A97
.I then deployed and verified an identical contract with one difference -
require(x, "error");
.It is at address
0xc8A9f997098c81378A000bBa293567b20645EFD9
.Note that in both cases, calling function
func
should revert.Here is a testing script (you'll need an Infura Project-ID):
As expected, the result of running the above is an exception with the following error-message:
As I've mentioned here in the past, you probably want to refine this message, but I've tested the above with web3.js v1.2.1, so perhaps you already have. In either case, that's not the main issue here.
The main issue is this:
When changing the value of
ADDR
in the script above from the address of the first contract to the address of the second contract, the (extremely odd) result is:true
And obviously, neither one of these aspects by itself could not have possibly taken place.
My analysis is that this is a bug in either Web3 or Infura.
But I tested the second contract also with ganache-cli (after deploying that contract on the local network of course), and I got:
Which makes me more inclined to the "Infura option" (since web3.js seems to do the job well when using a different node).
Nevertheless, I am opening this issue here with a hope that you will look into it.
I have a wild speculation that while fetching the return-value of the function-call from the stack, you retrieve the first character of the message string (
'e'
), or perhaps the length of the message string, which you then cast totrue
. Perhaps the appearance of that string has "pushed" the REVERT opcode (0xfd
if I remember correctly) deeper into the stack or something like that?Thanks :)
Versions
Operating System: Windows 10:
node version: 10.16.0
npm version: 6.9.0
web3.js version: 1.2.1
ganache-cli version: 6.7.0
The text was updated successfully, but these errors were encountered: