Skip to content
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

Return Revert Data #30653

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Return Revert Data #30653

wants to merge 2 commits into from

Conversation

Confucian-e
Copy link

@Confucian-e Confucian-e commented Oct 22, 2024

fix: #26823

The return value would be like this:

execution reverted: 0x96c6fd1e000000000000000000000000f805dfc724dcd7288b04d8ea7a5b0a9cda8f25cc

which is error ERC20InvalidSender(address sender); in solidity

Summary (Generated by copilot):

This pull request includes a small but significant change to the error handling in the rpc/json.go file. The change enhances the error message formatting for specific conditions.

Error handling improvement:

  • rpc/json.go: Modified the Error method of the jsonError struct to include additional details in the error message when the message is "execution reverted" and there is data available.

@namiloh
Copy link

namiloh commented Oct 22, 2024

The change is a bit awkward. The existing error-string method is this:

func (err *jsonError) Error() string {
	if err.Message == "" {
		return fmt.Sprintf("json-rpc error %d", err.Code)
	}
	return err.Message

The change in this PR just blindly assumes that the error was execution reverted -- couldn't it be 100 other things, e.g. connection torn down while making the request?

The idea might be good, but I think the change will have to be a bit more involved, and most likely be implemented closer to the evm, not this far out. Not sure

@Confucian-e
Copy link
Author

Confucian-e commented Oct 22, 2024

The change is a bit awkward. The existing error-string method is this:

func (err *jsonError) Error() string {
	if err.Message == "" {
		return fmt.Sprintf("json-rpc error %d", err.Code)
	}
	return err.Message

The change in this PR just blindly assumes that the error was execution reverted -- couldn't it be 100 other things, e.g. connection torn down while making the request?

The idea might be good, but I think the change will have to be a bit more involved, and most likely be implemented closer to the evm, not this far out. Not sure

Sorry my mistake. I have modified the code.

@rjl493456442
Copy link
Member

Couldn't you extract the data from the returned error?

@Confucian-e
Copy link
Author

Confucian-e commented Oct 23, 2024

Couldn't you extract the data from the returned error?

Yes, for now. We can't get revert data when using EstimateGas() or CallContract() because CallContext() only return Error. So what we get is only "execution reverted".

go-ethereum/rpc/client.go

Lines 367 to 368 in a5fe735

case resp.Error != nil:
return resp.Error

@Confucian-e
Copy link
Author

I think my code modification is the simplest and most effective way to solve this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

solidity custom error support
3 participants