agents/skills/evm/oracle-analysis/SKILL.md
Trigger Pattern ORACLE flag (required) - Inject Into Breadth agents, depth-external, depth-edge-case
npx skillsauth add plamentsv/plamen oracle-analysisInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Trigger Pattern: ORACLE flag (required) Inject Into: Breadth agents, depth-external, depth-edge-case
For every oracle the protocol consumes:
⚠ STEP PRIORITY: Steps 6 (Failure Modes) and 5c (Deviation Reference) are where HIGH/CRITICAL severity findings most commonly hide. Do NOT rush these steps. If constrained, skip conditional sections (4a-4d, 5a) before skipping 5c or 6.
Enumerate ALL oracle data sources the protocol reads:
| Oracle | Type | Source Contract | Functions Called | Consumers (protocol functions) | Update Frequency | Heartbeat | |--------|------|-----------------|-----------------|-------------------------------|-----------------|-----------| | {name} | Chainlink / TWAP / Spot / Custom / Band / Pyth | {address} | {latestRoundData / observe / etc.} | {list all} | {expected} | {documented or UNKNOWN} |
For each oracle: What decision does the protocol make based on this data? (pricing, liquidation threshold, reward rate, rebase trigger, etc.)
Hardcoded stablecoin pricing check: Does the protocol skip oracle lookup for any asset and hardcode its price to a constant (e.g., 1e8 for USDC, 1e18 for DAI)? If yes → FINDING. All assets require dynamic oracle pricing — stablecoins depeg, and hardcoded pricing fails silently when they do. Check: return 1e8, return 1e18, price = PRECISION, or an oracle mapping that excludes specific tokens.
For each oracle identified in Step 1:
| Oracle | updatedAt Checked? | Max Staleness Enforced? | Staleness Threshold | Appropriate? |
|--------|---------------------|------------------------|--------------------:|-------------|
| {name} | YES/NO | YES/NO | {seconds or NONE} | {analysis} |
If NO staleness check: What happens when the oracle returns stale data?
For each consumer function, trace the impact of receiving data that is {heartbeat × 2} old:
| Consumer Function | Data Used | If Stale By {X}: Impact | Severity | |-------------------|-----------|------------------------|----------| | {function} | {price/rate} | {specific impact} | {H/M/L} |
| Check | Code Reference | Status |
|-------|---------------|--------|
| latestRoundData() return values ALL checked? | {location} | YES/NO |
| answeredInRound >= roundId verified? | {location} | YES/NO |
| price > 0 validated? | {location} | YES/NO |
| updatedAt != 0 validated? | {location} | YES/NO |
| Sequencer uptime feed checked? (L2 only) | {location} | YES/NO/N/A |
If the protocol uses a pull-based oracle where users supply price data in the transaction:
Processing: ENUMERATE all pull-based oracle update/read sites → PROCESS each against the checks below → verify coverage before proceeding to Section 3.
| Check | Code Reference | Status |
|-------|---------------|--------|
| Timestamp monotonicity: Does the protocol verify the new update's timestamp >= the previously stored timestamp? | {location} | YES/NO |
| Pyth confidence interval: Is price.conf checked relative to price.price? (e.g., reject if conf/price > threshold) | {location} | YES/NO |
| Pyth price sign: Is price.price validated as > 0? (Pyth returns int64) | {location} | YES/NO |
| Pyth exponent handling: Is price.expo (typically negative, e.g., -8) correctly applied when converting to protocol decimals? | {location} | YES/NO |
Timestamp monotonicity attack (Redstone, Pyth, any pull model): If the protocol stores a price at timestamp T and accepts a later update at timestamp T-Δ (within the allowed staleness window), an attacker can roll back the price. Example: price is $3000 at T=now; attacker updates to $2900 at T=now-3min (within Redstone's 3-min window); borrower is liquidated at the stale-but-accepted price. Defense: require(newTimestamp >= lastStoredTimestamp).
Pyth confidence interval attack: Pyth returns price ± confidence bracket. If the protocol uses the raw price without accounting for confidence, it may allow borrowing/liquidation at a price that is up to conf away from the true price. Defense: for collateral pricing use price - conf (pessimistic), for debt pricing use price + conf (pessimistic), always favoring protocol safety over user benefit.
For each oracle data flow:
| Oracle | Oracle Decimals | Consumer Expects | Normalization Applied? | Correct? | |--------|----------------|-----------------|----------------------|----------| | {name} | {decimals()} | {expected by math} | YES/NO | {analysis} |
Check: Does the protocol call decimals() dynamically or hardcode it? If hardcoded → what if oracle upgrades and changes decimals?
MANDATORY GREP: Search all oracle consumer files for 1e18, 1e8, 1e6, 10**18, 10**8, 10**6, 1e10, 10**10. For each hit: (1) Is this a decimal normalization constant? (2) Does it match the ACTUAL oracle's decimals() return value? (3) If the oracle is swapped or upgraded, does this constant break?
Decimal chain trace: For each arithmetic operation using oracle data, trace the full decimal chain: oracle_output_decimals → normalization_step → consumer_expected_decimals. If any step uses a hardcoded constant rather than reading decimals() dynamically → FINDING.
Common decimal mismatches:
price * amount where price and amount have different decimal basesTrace: For each arithmetic operation using oracle data, verify dimensional consistency:
result_decimals = oracle_decimals + token_decimals - normalization_decimals
Expected: result_decimals == output_decimals
Grep ALL oracle consumer files for 10**|decimals()|1e[0-9]|normaliz. For each match, fill:
| File:Line | Pattern | Hardcoded Value | Oracle's Actual Decimals | Match? | |-----------|---------|-----------------|-------------------------|--------|
If ANY row shows Match=NO or oracle decimals UNKNOWN with hardcoded constant → FINDING (R16). Skipping this step is a Step Execution violation (✗3d).
<!-- LOAD_IF: TWAP -->If protocol uses any TWAP oracle (Uniswap V3 observe(), custom TWAP, etc.):
| TWAP Oracle | Window Length | Pool Liquidity | Manipulation Cost (est.) | Sufficient? | |-------------|-------------|----------------|-------------------------|-------------| | {oracle} | {seconds} | {USD value} | {estimated} | YES/NO |
Rule of thumb: TWAP window < 30 min AND pool TVL < $10M → potentially manipulable.
| Check | Status | Impact if Wrong |
|-------|--------|-----------------|
| Overflow protection on tickCumulatives difference? | YES/NO | {impact} |
| Geometric vs arithmetic mean - correct for use case? | {which used} | {impact if wrong} |
| Time-weighted vs block-weighted - which is used? | {which} | {manipulation vector} |
| Empty observation slots handled? | YES/NO | {impact} |
During rapid price movements, TWAP lags spot price. Trace:
Check oracle behavior when history is insufficient: (1) zero snapshots, (2) single snapshot, (3) window period not yet elapsed.
| Cold-Start State | Oracle Return Value | Protocol Behavior | Exploitable? | |------------------|--------------------:|-------------------|-------------|
For each exploitable state: can attacker act during cold-start window at manipulated price? Tag: [BOUNDARY:snapshots=0], [BOUNDARY:snapshots=1]. If TWAP returns 0 or reverts during cold-start with no fallback → FINDING (R16, minimum Medium).
<!-- END_LOAD_IF: TWAP -->For multi-oracle systems or oracle-based thresholds:
<!-- LOAD_IF: MULTI_ORACLE -->| Oracle System | Aggregation Method | Oracle Count | Agreement Required | What if Disagreement? | |---------------|-------------------|-------------|-------------------|----------------------| | {system} | Median / Mean / Weighted / First-valid | {N} | {M of N} | {fallback behavior} |
Check: What happens at exact threshold boundaries?
| Threshold | Oracle Data Used | Threshold Value | At Exact Boundary | Off-by-One? | |-----------|-----------------|----------------|-------------------|-------------| | {name} | {oracle field} | {value} | {behavior at exact value} | YES/NO |
Check > vs >=: At the exact threshold value, does the protocol behave as intended?
For each deviation check in the protocol (maxDeviation, priceDeviation, deviationThreshold, etc.):
| Parameter | Measured Against | Reference Source | Reference Manipulable? | Reference Staleable? | |-----------|-----------------|-----------------|----------------------|---------------------|
Checks:
[TRACE:deviation check: current vs {reference} → reference source: {X} → manipulable: {Y/N}]For each oracle, model failure scenarios:
| Failure Mode | Oracle Behavior | Protocol Response | Impact | Mitigation Present? | |-------------|-----------------|-------------------|--------|-------------------| | Zero return | Returns 0 | {what happens} | {impact} | YES/NO | | Revert | Call reverts | {what happens} | {impact} | YES/NO - try/catch? | | Stale (heartbeat exceeded) | Returns old data | {what happens} | {impact} | YES/NO - staleness check? | | Extreme value | Returns outlier | {what happens} | {impact} | YES/NO - bounds check? | | Negative price (Chainlink int256) | Returns < 0 | {what happens} | {impact} | YES/NO - sign check? | | Sequencer down (L2) | Stale + backlog | {what happens} | {impact} | YES/NO - uptime feed? |
For each unmitigated failure mode: What is the worst-case impact? Can it lead to fund loss?
Circuit breaker check: Does the protocol have a mechanism to pause oracle-dependent operations if the oracle enters a failure state?
**ID**: [OR-N]
**Severity**: [based on fund impact and likelihood of oracle failure/manipulation]
**Step Execution**: ✓1,2,3,4,5,6 | ✗(reasons) | ?(uncertain)
**Rules Applied**: [R1:✓, R4:✓, R10:✓, R16:✓]
**Location**: Contract.sol:LineN
**Title**: Oracle [issue type] in [function] enables [attack/failure]
**Description**: [Specific oracle issue with data flow trace]
**Impact**: [Quantified impact under worst-case oracle scenario]
| Section | Required | Completed? | Notes | |---------|----------|------------|-------| | 1. Oracle Inventory | YES | ✓/✗/? | | | 2. Staleness Analysis | YES | ✓/✗/? | For each oracle | | 3. Decimal Normalization Audit | YES | ✓/✗/? | | | 3d. Decimal Grep Sweep | YES | ✓/✗/? | MANDATORY mechanical step | | 4. TWAP-Specific Analysis | IF TWAP used | ✓/✗(N/A)/? | | | 4d. TWAP Cold-Start Analysis | IF TWAP used | ✓/✗(N/A)/? | Zero/single snapshot states | | 5. Oracle Weight / Threshold Boundaries | IF multi-oracle or thresholds | ✓/✗(N/A)/? | | | 5c. Deviation Reference Point Audit | IF deviation checks exist | ✓/✗(N/A)/? | Reference manipulability | | 6. Oracle Failure Modes | YES | ✓/✗/? | For each oracle |
development
Prepare Solidity projects for a security audit — test coverage, test quality, NatSpec docs, code hygiene, dependency health, best-practice enforcement, deployment readiness, and project documentation checks. Generates a scored Audit Readiness Report and optionally runs static analysis. Trigger on: "prepare for audit", "audit readiness", "pre-audit check", "audit prep", "NatSpec check", or any request to review a Solidity codebase before a security review.
development
Launch the Plamen deterministic Web3 security audit pipeline
development
Run the Plamen smart-contract audit wizard in Codex
testing
Launch the Plamen deterministic L1 infrastructure audit pipeline