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

Change JSON-RPC error code response for onchain revert #2457

Closed
mouseless-eth opened this issue May 7, 2024 · 1 comment · Fixed by #2523
Closed

Change JSON-RPC error code response for onchain revert #2457

mouseless-eth opened this issue May 7, 2024 · 1 comment · Fixed by #2523
Assignees
Labels
enhancement New feature or request P1
Milestone

Comments

@mouseless-eth
Copy link

Problem

Some systems like ERC-4337 (Account Abstraction) use eth_call to extract onchain data by forcing a revert. (example). These revert bytes are then parsed using libraries like viem.

Currently viem can't properly parse Hedera's RPC response as the error code for an onchain revert isn't what the library expected.

For context, here is a sample reverting eth_call response that viem can parse (it parses into the viem type ContractFunctionRevertError):

{
  "jsonrpc": "2.0",
  "id": 4337,
  "error": {
    "code": 3,
    "message": "execution reverted",
    "data": "0x6ca7b8060000000000000000000000007152e0855bab82b8e10b8692e584ad034bd22912"
  }
}

This is what Hedera's reverting message looks like and it is being parsed into a CallExecutionError viem type

{
  "error": {
    "code": -32008,
    "message": "[Request ID: bf1be79b-7d2f-42ee-bc82-da42c9ce5e8f] execution reverted: CONTRACT_REVERT_EXECUTED",
    "data": "0x6ca7b8060000000000000000000000007152e0855bab82b8e10b8692e584ad034bd22912"
  },
  "jsonrpc": "2.0",
  "id": 4337
}

viem checks if the error code is 3 and if so treats it as a onchain revert and keeps the data field containing the revert bytes. Although couldn't find any eip or spec that says the error code 3 is a hard requirement.

Solution

Change the error response code from -32008 to 3 when a onchain revert occurs

Alternatives

No response

@mouseless-eth mouseless-eth added the enhancement New feature or request label May 7, 2024
@Nana-EC Nana-EC added the P1 label May 7, 2024
@Nana-EC Nana-EC added this to the 0.48.0 milestone May 7, 2024
@quiet-node quiet-node self-assigned this May 21, 2024
@quiet-node quiet-node linked a pull request May 21, 2024 that will close this issue
2 tasks
@quiet-node
Copy link
Collaborator

Hello @mouseless-eth, appreciate the nice catch! I did some research and indeed the value 3 is well used by other well-known services like Alchemy, Infura, etc. Here are some refferences to it:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P1
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants