Rules › Solidity
Price read from AMM reserves
getReserves() spot prices can be moved inside one transaction with a flash loan; use a TWAP or an oracle.
Why it matters
An AMM pool's reserves can be moved by any large trade, and flash loans make large trades free within one transaction. A contract that prices collateral, mints or liquidates from getReserves() (or Uniswap v3 slot0) can be manipulated: borrow, skew the pool, exploit the bad price, unwind, repay. Use a time-weighted average price or an oracle network, with staleness and bounds checks.
Vulnerable
function price() public view returns (uint256) {
(uint112 r0, uint112 r1, ) = pair.getReserves();
return uint256(r1) * 1e18 / r0;
}
Fixed
function price() public view returns (uint256) {
(, int256 answer, , uint256 updatedAt, ) = feed.latestRoundData();
if (answer <= 0 || block.timestamp - updatedAt > MAX_AGE) revert StalePrice();
return uint256(answer);
}
Check your code
Paste a contract into the in-browser checker, or let the Claude Code plugin scan before every deploy. The quick check for this rule is a pattern match: treat a hit as "look here", and a miss as no guarantee.
Related rules
- tx.origin used for authorization
- State written after an external call (reentrancy)
- Return value of a low-level call is ignored
- delegatecall to an address the caller controls
- Initializer anyone can call
- Privileged function without access control
Static analysis finds known bug classes; it can't prove code is safe and isn't an audit. Get a professional audit before deploying code that will hold value.