tx-context-misuse
Skill36 starsChanged 5 months agoMITView on GitHub
Detect misuse of tx.origin, block.timestamp, block.number — phishing via tx.origin, timestamp dependence, L2-block-number assumptions. Activate on `tx.origin`, `block.timestamp`, `block.number`, `blockhash`, `block.prevrandao`, `block.coinbase`.
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
- erc1271-contract-signaturesSkill
- 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
- unchecked-callsSkill
- ve-lock-governanceSkill
- vyper-specificSkill
- zk-verifier-bugsSkill
The file
Files
tx.origin / timestamp / block-number misuse
When this applies
- Auth checks using
tx.origin - Time-based logic (lockups, deadlines, vesting, auctions)
- Block-number-based rate limits or cooldowns
- L2 deployments where block semantics differ from L1
- Randomness derived from block data
Detection patterns
tx.origin for authorization (HIGH)
require(tx.origin == owner); // ← phishable via intermediate contractA contract the owner has interacted with can drain by calling back into this function — owner-EOA is tx.origin even if direct caller is the malicious contract.
Exception: tx.origin == msg.sender check to enforce EOA-only is sometimes valid for limiting bots — but EIP-7702 will invalidate even this. Flag as outdated pattern.
block.timestamp for high-precision deadlines (MEDIUM)
Miners (post-merge: validators) can skew timestamp ±~15s. Don't use for sub-15s precision.
block.timestamp as randomness (HIGH)
uint r = uint(keccak256(abi.encode(block.timestamp, msg.sender))); // ← validator can simulateblock.number on L2 (HIGH)
Arbitrum: block.number is L1 block number, NOT L2. block.timestamp is L2. Optimism: block.number is L2. Get this wrong and rate limits fire 12x too fast (or too slow).
blockhash(n) with n outside [block.number-256, block.number-1] returns 0 (MEDIUM)
Random distribution becomes biased / predictable.
block.coinbase (validator address) used in logic (HIGH)
Validator can rotate addresses; using coinbase for auth or whitelisting is unsafe.
block.prevrandao for high-value randomness (HIGH)
Post-merge prevrandao is the previous block's randao; validators can sometimes choose to skip producing a block to influence it (limited but real). Don't use for valuable mints.
block.basefee as anti-MEV gate (LOW-MEDIUM)
Basefee can be manipulated within bounds by miners. Use sparingly.
Timestamp-based vesting cliffs (LOW)
Generally fine, but document tolerance for ±15s.
Severity rubric
| Pattern | Severity |
tx.origin == admin for sensitive auth | High |
block.timestamp as RNG seed for valuable outcomes | High |
block.number confused L1-vs-L2 on Arbitrum | High |
block.coinbase for auth | High |
block.prevrandao for high-value mint | High |
| Timestamp deadline with <30s precision | Medium |
blockhash with out-of-range input | Medium |
EOA-only check via tx.origin == msg.sender | Medium (EIP-7702 invalidates) |
Remediation patterns
- Auth: always
msg.sender. If you need to know "is this caller a contract", checkcaller.code.length > 0but understand its limits. - Randomness: Chainlink VRF or commit-reveal.
- L2 block-number: use chain-specific helper (
ArbSys.arbBlockNumber()on Arbitrum,block.numberon Optimism). - Timestamps: round to ~minute granularity for fairness-sensitive flows.
- Validators-can-skew tolerance: bake in slack in deadlines (≥1 minute).
False-positive notes
block.timestampfor week/month-scale vesting → fine.tx.originin events for analytics → fine, not used for auth.- L2 chain-id detection via
block.chainidis correct (always returns the canonical chain id).
Related
- [[mev-frontrunning]] — randomness/RNG
- [[access-control]]
- [[signature-replay]]
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.

