This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
Fix (most) incorrect reports of custom errors #5903
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Partially addresses #5881. This is not a total fix, but it fixes the bulk of the problem.
Let's suppose you send a transaction, and it fails due to OOG, or, say, never even happens in the first place (like, intrinsic gas too low, or refused by the user in MetaMask). In this case, the eth_call to determine the revert reason can succeed and get a return value instead of the intended error. Since we can't decode it as an error, we treat it as a custom error. Oops!
This PR fixes this by checking the length; if it's 4 mod 32, we treat it as an error, if it's not, we don't. Assuming the Solidity ABI is being used, then error responses will have length 4 mod 32 (unless they're empty), while return value responses will have length 0 mod 32.
(Well, except for when we're dealing with contract creations, in which case successful responses can have any length, but, uh, I'm just going to not worry about that...)
This is arguably not a total fix for two reasons. Firstly, there's the case of contract creations as mentioned above; in that case we could still hit the bug if the length of the returned contract just happends to be 4 mod 32. Secondly, what if the transaction never happens -- e.g. it was refused by the user in MetaMask -- but the subsequent
eth_call
reverts with a valid error? In this case, we'll append a revert string where it doesn't make sense, and it will be confusing for the user.In order to address these cases, we should probably go, like, actually checking error codes and such. However, that would take some actual research, and I thought I should at least start by putting up this quick fix that handles the most frequent cases. We can do a more comprehensive fix later.
Testing instructions
I added two tests in
contract-tests
to test this PR. You might also want to see the original issue if you want to test it manually.