oracle-manipulation
它能做什么
这项手册指导审查 DeFi 合约中的价格预言机。适合需要确认价格不易被操纵的审计人员和开发者。
适用场景
- ✓当借贷或交易合约直接读取某个池子当前储备的价格时。
- ✓当你想确认时间加权价格使用了足够长的时间窗口时。
- ✓当预言机数据源没有检查数据是否过期或排序器是否停机时。
技能链接
https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/contracts/oracle-manipulation/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我检查,我们借贷协议的价格源能否被一笔大额交易在一个区块内操纵?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体找到每一处价格读取,检查来源是即时价格还是较长时间的平均值,并测试是否会拒绝过期或为零的数值。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Oracle Manipulation Playbook
DeFi protocols that read a price from an on-chain source are vulnerable when the source can be moved within a single transaction or block. Classic vectors:
- Spot-price AMM oracle —
reserve1 / reserve0of a Uniswap V2 pool. Anyone with enough capital (or a flash loan) can push the price for one block. - Manipulable TWAP — short window TWAP, or TWAP over a low-liquidity pool.
- Single Chainlink feed without staleness check — feed returns 0 / stale → uses 0 in math.
- Custom oracle reading from manipulable storage — e.g., a "fair-price" oracle that reads
totalSupply()of an LP token alongside reserves. - L2 sequencer offline — L2 oracles need a "is sequencer up?" check or attacker can exploit when sequencer downs and feeds freeze.
Audit steps
1. Locate price-reading code
# Common patterns
grep -rn 'getReserves\|getAmountsOut\|getPriceFromSqrtPriceX96\|latestAnswer\|latestRoundData' src/
# Custom oracle reads
grep -rn 'IPriceOracle\|getPrice\|consult' src/
2. Trace each price use
For each call:
- Is the price read from a Uniswap V2 / Sushi / Camelot pool's reserves? → spot price = manipulable
- Is the price read from a Uniswap V3 pool's
slot0.sqrtPriceX96? → manipulable - Is it a Uniswap V3 TWAP via
OracleLibrary.consult? → check the secondsAgo window (>= 1800s = 30 min is the safe minimum) - Is it a Chainlink
latestRoundData()call? → check: isupdatedAtvalidated? IsansweredInRound >= roundId? Isanswer > 0? Are L2 sequencer feeds checked?
3. Validate staleness handling
// MISSING — vulnerable
(, int256 price, , , ) = priceFeed.latestRoundData();
// GOOD — explicit staleness + sequencer
(uint80 roundId, int256 price, , uint256 updatedAt, uint80 answeredInRound) = priceFeed.latestRoundData();
require(price > 0, "ORACLE_NEGATIVE");
require(updatedAt > block.timestamp - MAX_DELAY, "ORACLE_STALE");
require(answeredInRound >= roundId, "ORACLE_OLD_ROUND");
// On L2: also check sequencer uptime feed (L2 SequencerUptimeFeed)
4. Trace the price's use
The bug isn't oracle-reading — it's oracle-trusting. Find where the price drives a state change:
- Liquidation thresholds
- Collateral valuation
- Borrow limits
- Swap output amounts (slippage check)
- LP token pricing for vaults
PoC via Foundry
Flash-loan price push (Uniswap V2 reserves)
// Pseudo:
contract Test_oracle is Test {
function test_manipulate() public {
// 1. Flash-loan WETH from Aave / Balancer / Uniswap V3
// 2. Swap WETH → token in target pool, draining one side
// 3. Reserves now skewed → spot price way off
// 4. Call vulnerable protocol's price-dependent function
// (e.g., borrow USDC against overvalued collateral)
// 5. Reverse the swap, repay flash loan
// 6. Profit = whatever was extracted in step 4
assertGt(USDC.balanceOf(attacker), 0, "should profit");
}
}
Decepticon helper:
foundry_oracle_test(target="LendingPool", price_feed="UniV2Pair",
token0="WETH", token1="TARGETTOKEN", target_path="src/LendingPool.sol")
Chainlink stale check missing
function test_stale_price() public {
// mock the feed to return updatedAt that's 24h old
vm.mockCall(
address(priceFeed),
abi.encodeWithSignature("latestRoundData()"),
abi.encode(uint80(1), int256(STALE_PRICE), uint256(0), block.timestamp - 86400, uint80(1))
);
// call function — should revert if staleness checked, should proceed if not
target.priceDependentFunction();
// If we reach here w/o revert → bug
}
Severity calibration
| Manipulation surface | Typical impact | Severity |
|---|---|---|
| Spot-price oracle drives liquidation | Drain LPs via fake liquidations | Critical |
| Spot-price drives borrow limit | Borrow more than collateral worth | Critical |
| TWAP < 30 min | Still manipulable on low-liquidity pairs | High |
| TWAP 30 min+ on high-liquidity ETH-USDC | Hard to exploit profitably | Medium-Low |
| Missing staleness check, but feed updates often | Edge-case impact during outages | Medium |
| L2 sequencer not checked | Exploitable during sequencer downtime | High (timing-dependent) |
CVSS
- Spot-oracle + flash-loan available + drains protocol:
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H= 10.0 (Crit) - 30-min TWAP on illiquid pair: 7-8 (High)
- Missing staleness + Chainl
常见问题
即时价格为什么有风险?
它反映的是池子当前的余额,而一笔大额交易可以暂时改变这一余额。
更安全的平均时间窗口是多久?
该手册建议时间加权价格使用较长的窗口,大约 30 分钟或更长。
为什么要检查数据是否过期?
停止更新或为零的数据源会让计算使用错误的数值。
详情
作者的原始描述
Hunt single-block oracle manipulation — spot-price AMM oracles, manipulable TWAP, dependent calculations, missing staleness checks.
热度
- GitHub 星标
- 6.5k
- 排名
- #14010
- 许可证
- Apache-2.0
- 更新时间
- 2026/11/1
评论
- …