Coin Brief ENDE

Geth's pure-Go ecrecover accepted recovery IDs from 4 to 7, which the default cgo build rejects

The go-ethereum team merged a fix on 13 November that makes Geth built without cgo reject the same malformed signatures as the default build. Pull request 36132 adds a check to the pure-Go signature recovery path so that any recovery ID of 4 or higher is refused with the same error text as the libsecp256k1 backend.

The description explains the mismatch. When Geth is built with CGO_ENABLED=0, sigToPub converts Ethereum's [R || S || V] signature into the compact format used by the decred library by setting the header byte to V + 27, then calls RecoverCompact. Compact signatures also use header codes 31 to 34 to flag a compressed key, so RecoverCompact accepts V values from 0 to 7. The cgo backend, built on libsecp256k1, rejects any V of 4 or more with "invalid signature recovery id".

The two builds therefore disagreed on which signatures recover. Using the existing test vector with V = 1, setting V = 5 made Ecrecover and SigToPub return the same public key as V = 1 under the pure-Go build, and V = 4 returned a key too, while the cgo build returned an error for both.

Which code paths care depends on whether the caller checks V first. According to the pull request, transaction senders, EIP-7702 authorisations and the ecrecover precompile validate V before recovering, so the EVM is not affected. Some callers pass it through unchecked: the Clique consensus seal, recoverNodeKey in the discovery v4 wire protocol and the RLPx authentication handshake. On a Clique network, a node built without cgo would accept a block header whose seal used V + 4, which cgo nodes reject, and that header would have a different hash but the same signer as the original.

The fix adds five lines to crypto/signature_nocgo.go and a test that runs Ecrecover and SigToPub with every recovery ID from 4 to 255. The test fails with CGO_ENABLED=0 on the previous code and passes in both build modes with the change. The description says it follows earlier nocgo parity fixes in pull requests 33104 and 33839.

Geth's pure-Go ecrecover accepted recovery IDs from 4 to 7, which the default cgo build rejects
Geth's pure-Go ecrecover accepted recovery IDs from 4 to 7, which the default cgo build rejects — Coin Brief

Why it matters

Two builds of the same client should accept exactly the same inputs, otherwise a network of mixed builds can disagree about validity. Mainnet transaction processing was protected by earlier checks, but private Clique networks and the peer-to-peer layer were not, and anyone building Geth with CGO_ENABLED=0 should take the update.

Primary source
go-ethereum pull requests
https://github.com/ethereum/go-ethereum/pull/36132