MetaMask / eth-json-rpc-middleware

Ethereum middleware for composing an Ethereum provider using json-rpc-engine. Intended to replace provider-engine
ISC License
181 stars 88 forks source link

[bug] CCIP read is not working with a provider managed by this middleware #335

Closed mirceanis closed 3 weeks ago

mirceanis commented 1 month ago

ENS resolution sometimes uses CCIP read (eip-3668) to resolve an address. That relies on a reverted execution being interpreted as a redirect. When the provider used to perform such a read is managed by this middleware, the read operation fails. My guess is that the reverted execution is somehow wrapped such that the error is no longer interpretable.

This bug showed up after the upgrade from v13 to v14 of this lib in the MetaMask extension.

The environment to reproduce it has ethers@6.x as a dependency, and a simple test to reproduce would go along the lines of:

const provider = new BrowserProvider(setup.provider); // provider managed by this middleware
const sampleDomain = 'jwt.ro'; // resolving a linked DNS domain uses CCIP read
const ensResolver = await provider.getResolver(sampleDomain);
const ethAddress = await ensResolver?.getAddress();
expect(ethAddress).toBe('0xd08E08a0551575eE6bcE6d56180148EB68Bca061');
FrederikBolding commented 1 month ago

I have looked into this for a bit and I am pretty confident this isn't a bug in this library. Instead it is a symptom of mixing the old and new behaviour of serializeError in eth-rpc-errors / @metamask/rpc-errors.

Most of the stack, including this library is using the new error serialization either directly through @metamask/rpc-errors or through @metamask/json-rpc-engine, but the extension is still using the old version: https://github.com/MetaMask/metamask-extension/blob/develop/app/scripts/metamask-controller.js#L18

As far as I can tell, simply bumping json-rpc-engine in the extension should fix this: https://github.com/MetaMask/metamask-extension/pull/22875

mirceanis commented 3 weeks ago

I just tested this with https://github.com/MetaMask/metamask-extension/pull/22875 and it seems to have fixed it.

Gudahtt commented 3 weeks ago

Since this is not a bug in this library, but rather a result of using it with an incompatible version of json-rpc-engine, I will close this as fixed.