# Signature replay: how one valid signature gets used again

URL: https://shield.quillaudits.com/learn/vulnerabilities/signature-replay/

A signature replay is when a contract accepts a valid signature more than once, or in a place the signer never meant it for: another chain, another contract or a later moment. It happens when the signed message leaves out a nonce, the chain ID, the verifying contract or an expiry, or when the contract tracks used signatures by their bytes rather than by the message. Sign typed data that names the chain and the contract, include a nonce that the contract consumes, add a deadline, and reject malleable signatures.

Last updated 3 December 2026. 6 minute read. By the QuillAudits Team.

## How does a signature replay attack work?

Contracts check signatures so that someone can act for a signer without the signer sending the transaction: a gasless transfer, a token approval by permit, a withdrawal approved by a bridge's validators, an order from an off-chain book. The contract hashes the message, recovers the signer with `ecrecover` and compares. Nothing in that check says the message is new, or that it was meant for this contract on this chain.

So the signature escapes its context in five ways:

- **Same contract, same chain.** There is no nonce and no record of used messages, so the same signature works again.
- **Another chain.** The message doesn't include the chain ID. Teams often deploy the same code at the same address on several EVM chains, so a signature for one is valid on all of them.
- **Another contract.** The message doesn't name the contract that should accept it, so it works on any contract that trusts the same signer.
- **A chain split.** The domain separator was computed once at deployment and kept the old chain ID. [EIP-2612](https://eips.ethereum.org/EIPS/eip-2612) warns that a separator defined at deployment risks 'possible replay attacks between chains in the event of a future chain split'.
- **A malleable copy.** [SWC-117](https://swcregistry.io/docs/SWC-117/) explains that an attacker can 'slightly modify the three values v, r and s to create other valid signatures'. A contract that marks signature bytes as used accepts the modified copy.

## What does vulnerable code look like?

This contract pays out ETH when an operator signs the recipient and the amount. The message names no nonce, no chain, no contract and no expiry.

**Vulnerable: a signed payout that never expires and never gets used up (illustrative, not audited code)** `SignedPayouts.sol`

```
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

contract SignedPayouts {
    address public immutable signer;

    constructor(address signer_) payable {
        signer = signer_;
    }

    // The signed message says who and how much. It says nothing about
    // which chain, which contract, which attempt or until when.
    function claim(address payable to, uint256 amount, uint8 v, bytes32 r, bytes32 s) external {
        bytes32 message = keccak256(abi.encodePacked(to, amount));
        bytes32 digest = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", message));
        require(ecrecover(digest, v, r, s) == signer, "bad signature");
        (bool ok, ) = to.call{value: amount}("");
        require(ok, "payment failed");
    }
}
```

Anyone who has seen one valid claim, in the mempool or on a block explorer, can submit it again until the contract is empty. If the same contract runs on another chain with the same signer, the claim works there too.

## How do you fix it?

Use typed structured data in the EIP-712 style: a domain that names the contract and the chain, a nonce the contract increments, and a deadline. Rebuild the domain separator if the chain ID changes, and refuse signatures that `ecrecover` would accept twice.

**Fixed: domain, nonce, deadline and a low-s check (illustrative, not audited code)** `ReplaySafePayouts.sol`

```
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

contract ReplaySafePayouts {
    address public immutable signer;
    bytes32 private constant DOMAIN_TYPEHASH =
        keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
    bytes32 private constant CLAIM_TYPEHASH =
        keccak256("Claim(address to,uint256 amount,uint256 nonce,uint256 deadline)");
    // Half the secp256k1 curve order: signatures with a larger s are refused.
    uint256 private constant MAX_S = 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0;

    bytes32 private immutable cachedDomainSeparator;
    uint256 private immutable cachedChainId;
    mapping(address => uint256) public nonces;

    constructor(address signer_) payable {
        require(signer_ != address(0), "zero signer");
        signer = signer_;
        cachedChainId = block.chainid;
        cachedDomainSeparator = _buildDomainSeparator();
    }

    function _buildDomainSeparator() private view returns (bytes32) {
        return keccak256(
            abi.encode(DOMAIN_TYPEHASH, keccak256("SignedPayouts"), keccak256("1"), block.chainid, address(this))
        );
    }

    // Rebuilt when the chain ID changes, so a fork can't reuse signatures made for the original chain.
    function domainSeparator() public view returns (bytes32) {
        return block.chainid == cachedChainId ? cachedDomainSeparator : _buildDomainSeparator();
    }

    function claim(address payable to, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external {
        require(block.timestamp <= deadline, "expired");
        uint256 nonce = nonces[to]++; // consumed before anything else happens
        bytes32 structHash = keccak256(abi.encode(CLAIM_TYPEHASH, to, amount, nonce, deadline));
        bytes32 digest = keccak256(abi.encodePacked("\x19\x01", domainSeparator(), structHash));
        require(_recover(digest, v, r, s) == signer, "bad signature");
        (bool ok, ) = to.call{value: amount}("");
        require(ok, "payment failed");
    }

    function _recover(bytes32 digest, uint8 v, bytes32 r, bytes32 s) private pure returns (address recovered) {
        require(uint256(s) <= MAX_S, "high s");
        require(v == 27 || v == 28, "bad v");
        recovered = ecrecover(digest, v, r, s);
        require(recovered != address(0), "invalid signature");
    }
}
```

- **Consume a nonce, or record the message hash.** [SWC-121](https://swcregistry.io/docs/SWC-121/) says to store every processed message hash and to include the address of the contract that processes the message. It also says never to build the message hash from the signature itself.
- **Name the chain and the contract.** EIP-2612 describes a domain separator that 'should be unique to the contract and chain to prevent replay attacks from other domains', built from the chain ID and `address(this)`.
- **Compare \`block.chainid\` with the deployment value every time a signature is checked,** as `domainSeparator()` does above.
- **Add a deadline,** so a signature that was never used doesn't stay valid forever.
- **Reject the second form of a signature.** Refuse an `s` above half the curve order and any `v` other than 27 or 28, and treat a zero address from `ecrecover` as a failure.
- **Decide who may submit.** If anyone may relay the signature, the message must name the recipient; if only the recipient may, check `msg.sender` too.

## How has a missing chain ID been exploited?

| Protocol | Wintermute's 20 million OP |
| --- | --- |
| Date | 8 June 2022 |
| Chain | Optimism |
| Loss | 20 million OP, of which the attacker returned 17 million on 10 June 2022 |
| What happened | Optimism sent 20 million OP to an address Wintermute had given it: a Gnosis Safe that Wintermute had deployed on Ethereum but not on Optimism. The attacker replayed Gnosis Safe deployment transactions from Ethereum mainnet on Optimism. They had been signed without an EIP-155 chain ID, which SlowMist explains is what lets a signed transaction run on another chain. With the Safe contracts recreated, the attacker deployed Safes and took control of Wintermute's address on Optimism, and with it the tokens. Wintermute disclosed the loss on 8 June 2022 and called the initial error its own. |
| Sources | [SlowMist](https://slowmist.medium.com/slowmist-key-to-the-theft-of-20-million-op-tokens-transaction-replay-490baaf45f26), [The Block](https://www.theblock.co/post/151344/hacker-returns-17-million-op-tokens), [Wintermute](https://gov.optimism.io/t/message-to-optimism-community-from-wintermute/2595) |

The replayed signatures belonged to transactions rather than to a message a contract checked, but the gap is the one this page is about: the signed data didn't name a chain. [SlowMist](https://slowmist.medium.com/slowmist-key-to-the-theft-of-20-million-op-tokens-transaction-replay-490baaf45f26) notes that EIP-155 transactions can't be replayed on other chains while transactions without chain ID protection can; a domain separator built from `block.chainid` gives the messages your contract verifies the same protection.

## What should a reviewer check?

- Find every `ecrecover`, signature library call and `permit` in scope, including in inherited contracts.
- Does each signed message include a nonce or an ID that the contract marks as used before it acts?
- Does each message, or its domain, include the chain ID and the verifying contract's address?
- Is the domain separator recomputed when `block.chainid` differs from the value at deployment?
- Is there a deadline, and is it checked?
- Are high-s signatures, unexpected `v` values and a zero recovered address rejected?
- Is used-ness tracked by message or nonce, never by signature bytes?
- Does a test submit the same signature twice, and once more with the high-s twin, and expect both to revert?

## Which SWC entries cover signature replay?

| Entry | Title | What it asks for |
| --- | --- | --- |
| [SWC-121](https://swcregistry.io/docs/SWC-121/) | Missing Protection against Signature Replay Attacks | Store processed message hashes, include the processing contract's address, never hash the signature into the message |
| [SWC-117](https://swcregistry.io/docs/SWC-117/) | Signature Malleability | Don't use the signature to decide whether a message was already processed |
| [SWC-122](https://swcregistry.io/docs/SWC-122/) | Lack of Proper Signature Verification | Don't replace real signature checks with alternate verification schemes |

The [SWC Registry](https://swcregistry.io/) says it has not been thoroughly updated since 2020, so treat it as a naming reference and the checklist above as the working list.

## How does QuillShield check for signature replay?

Replay bugs live in what a message leaves out, and a reviewer can only see that by comparing the signed fields with every place the signature is accepted. QuillShield builds a security graph of the Solidity code in your Foundry project during a full audit, lists the invariants the code must keep, and passes each finding to a separate reviewer agent that tries to disprove it. What survives comes with the exact lines, the impact and a recommended fix, and a full audit adds a proof of concept.

Write down in the audit context which chains you deploy to and who may sign or relay each message; you can add context such as the whitepaper, trust assumptions, privileged roles and previous audit reports. After the audit, every pull request on GitHub or GitLab.com is checked against the security graph, so a pull request that adds a new signed action gets the same review.

A signing scheme that guards a bridge or a treasury deserves two kinds of review. [Start free](https://shield.quillaudits.com/register) with a full audit, and [request a manual audit from QuillAudits](https://www.quillaudits.com/smart-contract-audit) for the scheme itself. New accounts get $50 in credit, good for up to half of an order.

## FAQ

### Does EIP-712 prevent replay on its own?

No. Its domain stops a signature from working on another chain or contract, but a nonce or a record of used messages is still what stops the same signature working twice on the same contract.

### Why not mark the signature itself as used?

Because a modified copy of a valid signature is also valid, as SWC-117 explains, so a check on signature bytes can be passed with the copy. Mark the message hash or the nonce instead.

### What happens to signatures after a chain splits?

If the domain separator was fixed at deployment, it still carries the old chain ID, and signatures made for one side work on the other. Compare `block.chainid` with the deployment value and rebuild the separator when they differ.

### Can an EIP-2612 permit be replayed?

Not on a token that follows the standard. EIP-2612 lets a permit succeed only when the owner's nonce matches, and the nonce then increases. A permit can still be front-run, which is a different problem.

## Sources

- [Hacker returns 17 million OP tokens, The Block](https://www.theblock.co/post/151344/hacker-returns-17-million-op-tokens) · checked 3 December 2026
- [SWC-121: Missing Protection against Signature Replay Attacks, SWC Registry](https://swcregistry.io/docs/SWC-121/) · checked 3 December 2026
- [SWC-117: Signature Malleability, SWC Registry](https://swcregistry.io/docs/SWC-117/) · checked 3 December 2026
- [SWC-122: Lack of Proper Signature Verification, SWC Registry](https://swcregistry.io/docs/SWC-122/) · checked 3 December 2026
- [Smart Contract Weakness Classification Registry, SWC Registry](https://swcregistry.io/) · checked 3 December 2026
- [ERC-2612: Permit Extension for EIP-20 Signed Approvals, Ethereum Improvement Proposals](https://eips.ethereum.org/EIPS/eip-2612) · checked 3 December 2026
- [SlowMist: Key to the Theft of 20 Million OP Tokens, Transaction Replay, SlowMist](https://slowmist.medium.com/slowmist-key-to-the-theft-of-20-million-op-tokens-transaction-replay-490baaf45f26) · checked 3 December 2026
- [Message to Optimism community from Wintermute, Wintermute](https://gov.optimism.io/t/message-to-optimism-community-from-wintermute/2595) · checked 3 December 2026
