ethers.js icon indicating copy to clipboard operation
ethers.js copied to clipboard

fix: correctly handle V check for big chain IDs

Open smartcontracts opened this issue 3 years ago • 3 comments

Fixes a bug in @ethersproject/transactions where certain valid signature V parameters would be considered invalid when a sufficiently large chain ID is used. Signature V parameter will always be just one byte, so has a potential value of 0 to 255. Check in question would do the calculation (sig.v ?== 27 + sig.recoveryParam + chainId * 2 + 8). When chainId is >= 111, the right-hand side of the formula will always be greater than 255 and therefore the check will always fail. Fix is to add a modulo 256 to the right-hand side of the equation.

A quick note: causes signing with Ledger wallets on networks with big chain IDs to fail consistently. ethers.Wallet is not subject to this problem because it always returns a signature with a V parameter of 27 or 28 (considered a "maybe protected" signature). I believe either is technically fine. Geth handles both cases.

smartcontracts avatar Apr 20 '22 17:04 smartcontracts

This fixes https://github.com/ethers-io/ext-signer-ledger/issues/6

tynes avatar Apr 26 '22 03:04 tynes

Fix in ethers-rs: https://github.com/gakonst/ethers-rs/commit/da3808301386a4a05a99f2b0bdc6ee5edc1cb02e

tynes avatar May 02 '22 22:05 tynes

Issue still seems to be present in latest versions of Ethers. We're running into this issue again because ethers+ledger doesn't work out of the box with our new Optimism Goerli testnet which has a chain ID of 420. I think the fix is pretty straightforward, but let me know if anything is confusing.

smartcontracts avatar Aug 12 '22 23:08 smartcontracts

Issue still seems to be present in latest versions of Ethers. We're running into this issue again because ethers+ledger doesn't work out of the box with our new Optimism Goerli testnet which has a chain ID of 420. I think the fix is pretty straightforward, but let me know if anything is confusing.

Confirmed still an issue.

bghughes avatar Jun 08 '23 18:06 bghughes

Have you tried using v6? It separates chain ID when passed as a EIP-155 v into a .v and .networkV.

ricmoo avatar Jun 08 '23 20:06 ricmoo