Ethers.js: AbiCoder: decode revert errors

Created on 1 Sep 2019  Â·  5Comments  Â·  Source: ethers-io/ethers.js

Related to https://github.com/ethers-io/ethers.js/issues/368, https://github.com/ethereum/web3.js/issues/1707.

Even though transaction receipts do not give us revert error strings, eth_calls do, and it would be nice if the AbiCoder knew how to decode them (and likely, throw an error with the string).

In particular, there was a situation where I wanted to query a contract for boolean value. Some times, this check reverts (perhaps the contract is not completely done being set up yet), but ethers' AbiCoder takes the 0x08c379a0...<revert string> result from the eth_call and says, yes, that's a boolean (and a true one at that!).

discussion

Most helpful comment

@ricmoo
We haven't implemented the revert handling at all in web3.js. I will prioritize this open task higher.

Btw.: 1.2.1 is also not using the latest version of the AbiCoder but it's on our todo list (we have to update all the ABI related test cases and some utility functions (adding of the correct padding)).

All 5 comments

This shouldn’t be handled by the ABI library, but by the Contract library (which performs the eth_call). The ABI library cannot know what the underlying data represents. The result of the call will be a bytes of length congruent to 4 mod 32, and the ABI coder doesn’t work with signature prefixed data.

Is the contract using the standard “Error(string)” for its revert? If so, you should have got a CALL_REVERT error with the error message already parsed. How are you calling the contract?

Is the contract using the standard “Error(string)” for its revert?

Yes.

If so, you should have got a CALL_REVERT error with the error message already parsed. How are you calling the contract?

I'm using [email protected], so then the problem may lie there. web3's contract module just passes the output data into ethers' AbiCoder for output, but perhaps it should first detect and decode these errors before trying to abi decode the output?

Yes, the Web3 caller should detect that the return value has a length congruent to 4 modulo 32, which indicates it is an error condition (with the leading 4-bytes indicating the error signature).

Pinging @nivida; is this still a problem? I know you've been fixing a bunch of things. :)

@ricmoo
We haven't implemented the revert handling at all in web3.js. I will prioritize this open task higher.

Btw.: 1.2.1 is also not using the latest version of the AbiCoder but it's on our todo list (we have to update all the ABI related test cases and some utility functions (adding of the correct padding)).

I'm going to close this now, as it isn't related to ethers, I don't believe. But please feel free to re-open. :)

Thanks! :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

moshebeeri picture moshebeeri  Â·  3Comments

GFJHogue picture GFJHogue  Â·  3Comments

adamdossa picture adamdossa  Â·  3Comments

jochenonline picture jochenonline  Â·  3Comments

ricmoo picture ricmoo  Â·  3Comments