Skip to content
ecdsa.com
web3.py / eth-account / eth-keys (Python)Web3 wallets and signatures

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

How to fix it

  1. 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

Related errors

Browse the full signature error database