$npx -y skills add quillai-network/quillshield_skills --skill signature-replay-analysisDetects signature replay vulnerabilities in smart contracts — affecting 19.63% of signature-using contracts. Covers five replay types (same-chain, cross-chain, cross-contract, nonce-skip, expired-signature), EIP-712 domain separator verification, nonce management analysis, ecreco
| 1 | # Signature & Replay Analysis |
| 2 | |
| 3 | Detect vulnerabilities where **cryptographic signatures can be reused**, replayed across chains/contracts, or exploited through implementation flaws. Research shows 19.63% of Ethereum contracts using signatures contain replay vulnerabilities. |
| 4 | |
| 5 | ## When to Use |
| 6 | |
| 7 | - Auditing contracts that verify signatures (`ecrecover`, ECDSA, EIP-712) |
| 8 | - Reviewing ERC-20 `permit()` / Uniswap Permit2 implementations |
| 9 | - Analyzing meta-transaction / gasless relay systems |
| 10 | - Verifying multi-sig signature aggregation |
| 11 | - Checking off-chain order books or signed message execution |
| 12 | |
| 13 | ## When NOT to Use |
| 14 | |
| 15 | - Contracts without any signature verification |
| 16 | - Pure on-chain access control (use semantic-guard-analysis) |
| 17 | - Token standard compliance (use external-call-safety) |
| 18 | |
| 19 | ## Core Concept: The Signature Trust Model |
| 20 | |
| 21 | A signature proves that a specific private key holder authorized a specific action. For this to be secure, the signature must be: |
| 22 | |
| 23 | 1. **Bound to context** — specific chain, contract, and version (domain separation) |
| 24 | 2. **Used exactly once** — nonce prevents replay |
| 25 | 3. **Time-limited** — deadline/expiry prevents late execution |
| 26 | 4. **Correctly verified** — ecrecover edge cases handled |
| 27 | |
| 28 | Any gap in this model creates a replay vulnerability. |
| 29 | |
| 30 | ## The Five Replay Types |
| 31 | |
| 32 | ### Type 1: Same-Chain Replay |
| 33 | |
| 34 | The exact same signature is submitted multiple times to the same contract on the same chain. |
| 35 | |
| 36 | ```solidity |
| 37 | // VULNERABLE: No nonce — same signature works forever |
| 38 | function executeWithSig(address to, uint256 amount, bytes memory signature) external { |
| 39 | bytes32 hash = keccak256(abi.encodePacked(to, amount)); |
| 40 | address signer = ECDSA.recover(hash, signature); |
| 41 | require(signer == admin, "Invalid signer"); |
| 42 | token.transfer(to, amount); |
| 43 | // Attacker can submit this same signature again and again! |
| 44 | } |
| 45 | |
| 46 | // SAFE: Use nonce |
| 47 | mapping(address => uint256) public nonces; |
| 48 | |
| 49 | function executeWithSig(address to, uint256 amount, uint256 nonce, bytes memory signature) external { |
| 50 | require(nonce == nonces[admin], "Invalid nonce"); |
| 51 | bytes32 hash = keccak256(abi.encodePacked(to, amount, nonce)); |
| 52 | address signer = ECDSA.recover(hash, signature); |
| 53 | require(signer == admin, "Invalid signer"); |
| 54 | nonces[admin]++; |
| 55 | token.transfer(to, amount); |
| 56 | } |
| 57 | ``` |
| 58 | |
| 59 | ### Type 2: Cross-Chain Replay |
| 60 | |
| 61 | A signature valid on one chain (e.g., Ethereum) is replayed on another chain (e.g., Polygon, Arbitrum) where the same contract is deployed. |
| 62 | |
| 63 | ```solidity |
| 64 | // VULNERABLE: No chainId in signed message |
| 65 | bytes32 hash = keccak256(abi.encodePacked(to, amount, nonce)); |
| 66 | // This hash is identical on Ethereum, Polygon, Arbitrum, etc. |
| 67 | |
| 68 | // SAFE: Include chainId (via EIP-712 domain separator) |
| 69 | bytes32 DOMAIN_SEPARATOR = keccak256(abi.encode( |
| 70 | keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"), |
| 71 | keccak256(bytes("MyContract")), |
| 72 | keccak256(bytes("1")), |
| 73 | block.chainid, |
| 74 | address(this) |
| 75 | )); |
| 76 | ``` |
| 77 | |
| 78 | ### Type 3: Cross-Contract Replay |
| 79 | |
| 80 | A signature for Contract A is replayed on Contract B (same chain) if both accept the same message format without contract-specific binding. |
| 81 | |
| 82 | ```solidity |
| 83 | // VULNERABLE: No contract address in signed message |
| 84 | bytes32 hash = keccak256(abi.encodePacked(to, amount, nonce, block.chainid)); |
| 85 | // Same hash for any contract on this chain |
| 86 | |
| 87 | // SAFE: Include verifyingContract (via EIP-712) |
| 88 | // The domain separator includes address(this), binding to this specific contract |
| 89 | ``` |
| 90 | |
| 91 | ### Type 4: Nonce-Skip Replay |
| 92 | |
| 93 | Nonce implementation allows gaps or out-of-order execution, enabling skipped nonces to be replayed later. |
| 94 | |
| 95 | ```solidity |
| 96 | // VULNERABLE: Bitmap nonce without invalidation |
| 97 | mapping(uint256 => bool) public usedNonces; |
| 98 | |
| 99 | function execute(uint256 nonce, ...) external { |
| 100 | require(!usedNonces[nonce], "Used"); |
| 101 | usedNonces[nonce] = true; |
| 102 | // If nonces 1, 2, 3 are used but 4 is skipped, |
| 103 | // nonce 4 can be used anytime in the future |
| 104 | // This may be intentional OR a vulnerability depending on context |
| 105 | } |
| 106 | |
| 107 | // SAFER for strict ordering: Sequential nonce |
| 108 | mapping(address => uint256) public nonces; |
| 109 | |
| 110 | function execute(uint256 nonce, ...) external { |
| 111 | require(nonce == nonces[signer], "Invalid nonce"); |
| 112 | nonces[signer]++; |
| 113 | } |
| 114 | ``` |
| 115 | |
| 116 | ### Type 5: Expired-Signature Replay |
| 117 | |
| 118 | A signature without a deadline can be held and executed at an arbitrary future time when conditions have changed. |
| 119 | |
| 120 | ```solidity |
| 121 | // VULNERABLE: No deadl |