Skip to content

Signature Replay Attack

SAFE-0044 Signatures Checked automatically by the scanner
1

What goes wrong

A signed message lacks a nonce, expiry, or domain binding, so the same signature can be submitted multiple times (replay) to repeat an action such as a withdrawal or permit.

2

How to fix it

the pattern that is safe
mapping(address=>uint256) public nonces;
function claim(uint256 amt, uint256 nonce, uint256 deadline, bytes calldata sig) external {
    require(block.timestamp <= deadline, "expired");
    require(nonce == nonces[msg.sender]++, "bad nonce");
    bytes32 d = _hashTypedDataV4(keccak256(abi.encode(TYPEHASH, msg.sender, amt, nonce, deadline)));
    require(ECDSA.recover(d, sig) == signer, "bad sig");
    payable(msg.sender).transfer(amt);
}
SWC-121. Use EIP-712 with nonce + deadline.
Check your own contract for this

The SaferICO scanner runs 201 detectors over your Solidity source, SAFE-0044 among them. Paste an address or the source itself — a small per-scan fee, shown before you sign, or unlimited on any plan.

Run the scanner See how it is attacked Read the docs