fix(eth-json-rpc-middleware): detect EIP-1474 / Infura-style revert errors#8597
Draft
matthewwalsh0 wants to merge 1 commit intomainfrom
Draft
fix(eth-json-rpc-middleware): detect EIP-1474 / Infura-style revert errors#8597matthewwalsh0 wants to merge 1 commit intomainfrom
matthewwalsh0 wants to merge 1 commit intomainfrom
Conversation
…rrors isExecutionRevertedError previously required code -32000 and an exact 'execution reverted' message, but every Infura RPC (and most production providers) returns the EIP-1474 form: code 3 with a suffixed message like 'execution reverted: ERC20: transfer amount exceeds balance'. Neither condition matched. The result: RetryOnEmptyMiddleware treated every reverted eth_call with a numeric block tag as a transient empty response, retried 10 times (~10s latency), and threw a generic 'retries exhausted' error that discarded the original revert payload. The check now accepts code 3 in addition to -32000, and matches messages that start with 'execution reverted' rather than requiring exact equality. Geth-style responses continue to work.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Explanation
`isExecutionRevertedError` (introduced in #254, Oct 2023) is too strict to match the response shape that Infura, Alchemy, QuickNode, and most production providers actually return:
```ts
return isJsonRpcError(error) &&
error.code === errorCodes.rpc.invalidInput && // -32000
error.message === 'execution reverted'; // exact match
```
The real-world EIP-1474 response is:
```json
{
"code": 3,
"message": "execution reverted: ERC20: transfer amount exceeds balance",
"data": "0x08c379a0..."
}
```
Neither `code === -32000` nor `message === 'execution reverted'` matches, so the function returns `false` for the most common case it's supposed to detect.
Verification
I tested the same reverted USDC `transfer` call against Infura's RPC for 6 chains. All return identical EIP-1474 shape:
Impact
Limited in practice. `RetryOnEmptyMiddleware` only intercepts methods with a block-ref param (`eth_call`, `eth_getBalance`, `eth_getCode`, `eth_getTransactionCount`, `eth_getStorageAt`, `eth_getBlockByNumber`), and only when the block ref is a numeric value — `'latest'` and `'pending'` are skipped. Most consumer `eth_call`s in the monorepo use `'latest'`, so the bug doesn't fire.
The cases where it does fire:
Fix
```ts
const EXECUTION_REVERTED_ERROR_CODE = 3; // EIP-1474
const isExpectedCode =
error.code === errorCodes.rpc.invalidInput ||
error.code === EXECUTION_REVERTED_ERROR_CODE;
return isExpectedCode &&
typeof error.message === 'string' &&
error.message.startsWith('execution reverted');
```
The new check is a strict superset of the old one — geth-style responses (`code: -32000`, exact message) still match.
References
Changelog
```
Fixed
```
Checklist