Error message
eth_keys.exceptions.BadSignature: Invalid signature
Also printed as
- BadSignature: Invalid signature
web3.py / eth-account / eth-keys (Python) — BadSignature from public-key recovery
What it means
The signature has the right length, but its values do not describe any valid secp256k1 signature, so no public key can be recovered: r or s is zero or not below the curve order, or r is not the x-coordinate of a point on the curve. This is different from a signature by the wrong key — such a signature recovers a different address without any exception. BadSignature means the bytes are not a signature at all.
Why it happens
A zero-filled or default value
commonZero-filled fixtures, a database column default, or an empty signature padded to 65 bytes by a client.
Corrupted bytes
occasionalSignatures damaged by an encoding round trip (hex ↔ base64, string ↔ bytes) can still be 65 bytes long but no longer represent a curve point.
A signature from another scheme
occasionalA P-256 (WebAuthn/passkey) or Ed25519 signature that happens to be 64 bytes, padded with a v byte. It is not an Ethereum signature.
How to fix it
- 1.
Treat it as a rejected signature
Catch BadSignature together with length and value errors and reject the request; do not retry with other v values.
python from eth_keys.exceptions import BadSignature from eth_utils.exceptions import ValidationError def recover_or_none(message, signature) -> str | None: try: return Account.recover_message(message, signature=signature) except (BadSignature, ValidationError, ValueError): return None # reject the request: the signature is malformed