erc1271-contract-signatures
Skill36 starsChanged 5 months agoMITView on GitHub
Detect ERC-1271 contract-signature bugs — magic-value handling, signature validation edge cases, smart-wallet interactions (Safe, Argent), replay-via-signature-update. Activate on `isValidSignature`, ERC1271 imports, smart-wallet integration, signed orders that may originate from contracts.
In this repository44 other files it gives its agents.
- access-controlSkill
- approval-issuesSkill
- caching-and-incrementalSkill
- centralization-riskSkill
- confidence-scoringSkill
- cosmwasmSkill
- cross-chain-messagingSkill
- cross-contract-stateSkill
- delegatecall-risksSkill
- diamond-eip2535Skill
- dos-vectorsSkill
- erc4337-account-abstractionSkill
- erc4626-inflationSkill
- false-positive-feedback-loopSkill
- fee-on-transferSkill
- flash-loan-attacksSkill
- initializationSkill
- inline-assemblySkill
- integer-issuesSkill
- intents-erc7683Skill
- known-good-comparisonSkill
- liquidation-cascadeSkill
- mev-frontrunningSkill
- mev-pbsSkill
- multi-pass-self-critiqueSkill
- oracle-manipulationSkill
- oracle-redundancySkill
- permit2-patternsSkill
- pragma-and-addressesSkill
- progress-and-streamingSkill
- reentrancySkill
- restaking-eigenlayerSkill
- selfdestruct-eip6780Skill
- signature-malleabilitySkill
- signature-replaySkill
- solana-anchorSkill
- storage-layoutSkill
- stylus-rustSkill
- token-compatibilitySkill
- tx-context-misuseSkill
- unchecked-callsSkill
- ve-lock-governanceSkill
- vyper-specificSkill
- zk-verifier-bugsSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 53
If owner rotates, previously-validated signatures may now be valid by different signer logic.
- Very specific: line 77
Use OZ SignatureChecker.isValidSignatureNow(signer, hash, sig) — handles both EOA and contract paths cleanly.
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
ERC-1271 contract signatures detection
Background
ERC-1271 lets contract accounts (smart wallets, multisigs) sign messages. Verification call:
IERC1271(signer).isValidSignature(hash, sig) returns (bytes4 magicValue);
// magicValue must equal 0x1626ba7eWithout ERC-1271, smart-wallet users can't sign anything (no private key).
When this applies
- Off-chain order signing (Seaport, Blur, X2Y2)
- Permit2 with smart-wallet senders
- EIP-712 verification paths
- Any
ecrecover(...) == signercheck that might accept contract signers
Detection patterns
Bypass via ecrecover for smart wallet (HIGH)
require(ecrecover(hash, v, r, s) == signer, "bad sig");
// ← signer is a smart wallet, ecrecover returns address(0), check fails legitimatelyThe bug: contract owners can't sign at all. Add an ERC-1271 fallback:
if (signer.code.length > 0) {
require(IERC1271(signer).isValidSignature(hash, abi.encodePacked(r, s, v)) == 0x1626ba7e);
} else {
require(ecrecover(hash, v, r, s) == signer);
}Wrong magic value check (HIGH)
require(IERC1271(signer).isValidSignature(hash, sig) == 0x1626ba7c); // ← typo: should be 0x1626ba7ePre-EIP-1271 magic value (HIGH)
Some old impls return 0x20c13b0b (the legacy bytes-based variant). Spec is hash-based 0x1626ba7e. Mixing → reject valid sigs.
Replay via signature-update on smart wallet (HIGH)
A Safe's isValidSignature checks owner approvals. If signature is approved via on-chain approveHash then consumed, can it be re-approved later? Replay risk.
Smart wallet rotation breaks past sigs (LOW-MEDIUM)
If owner rotates, previously-validated signatures may now be valid by different signer logic. Depends on wallet impl.
Returning data length issues (HIGH)
ERC-1271 returns bytes4. Naive callers using staticcall + manual returndata parsing can mis-decode.
Gas griefing in isValidSignature (MEDIUM)
Smart wallet impl can spend unbounded gas in isValidSignature → relayer griefing.
ERC-1271 + Permit2 (HIGH)
Permit2 must handle contract signers. Apps that wrap Permit2 must too.
Severity rubric
| Pattern | Severity |
| App rejects smart-wallet users entirely (no 1271 fallback) | High (usability — but also gives an exploitable bypass if mixed) |
| Wrong magic value | High |
| Pre-EIP magic value not handled | High |
| Replay via approve-on-chain on Safe | High |
| Returning data length not validated | High |
| Unbounded gas in isValidSignature | Medium |
Remediation patterns
- Use OZ
SignatureChecker.isValidSignatureNow(signer, hash, sig)— handles both EOA and contract paths cleanly. - Validate
magicValue == 0x1626ba7eexactly. - For Safe integration: use
SignMessageLiband pre-approval flow. - Bound gas:
(bool ok, bytes memory ret) = signer.staticcall{gas: 100_000}(...).
False-positive notes
- Apps that explicitly don't support contract wallets (e.g. anti-Sybil) may intentionally reject. Confirm intent.
Related
- [[signature-replay]]
- [[permit2-patterns]]
- [[aa-specialist]] (subagent)
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

