An attacker can manipulate oracle easily
The oracle update function can be called by anyone and only accepts one update per 64-second epoch, so an attacker can frontrun legitimate updates with a flash-loan-manipulated tick and lock that value in for the rest of the epoch. Repeating this across epochs lets the attacker shift the oracle by up to 149 ticks each time, distorting pricing and solvency checks for all positions.
Submitted by Tupaia
Finding description
This is a critical oracle manipulation vulnerability where any user can call PanopticPool::pokeOracle() to update the internal oracle with a manipulatable currentTick, and once the oracle is updated in an epoch, it cannot be corrected for the remainder of that 64-second epoch period, allowing attackers to frontrun legitimate oracle updates and gradually manipulate the oracle across multiple epochs using flash loans.
The root cause lies in the design of OraclePack::computeInternalMedian() which only updates the oracle pack when the current epoch differs from the recorded epoch. The function checks if enough time has passed by comparing epochs.
// File: contracts/types/OraclePack.sol, lines 546-565
uint256 currentEpoch;
bool differentEpoch;
int256 timeDelta;
{
currentEpoch = (block.timestamp >> 6) & 0xFFFFFF; // 64-long epoch, taken mod 2**24
uint256 recordedEpoch = oraclePack.epoch();
differentEpoch = currentEpoch != recordedEpoch;
timeDelta = int256(uint256(uint24(currentEpoch - recordedEpoch))) * 64; // take a rought time delta, based on the epochs
}
// only proceed if last entry is in a different epoch
if (differentEpoch) {
int24 clampedTick = clampTick(currentTick, oraclePack, clampDelta);
_updatedOraclePack = insertObservation(
oraclePack,
clampedTick,
currentEpoch,
timeDelta,
EMAperiods
);
}
Once differentEpoch is true and the oracle is updated, subsequent calls to computeInternalMedian() within the same epoch will return an unchanged oracle pack because differentEpoch remains false until the next 64-second epoch boundary. The PanopticPool::pokeOracle() function is publicly accessible without any access controls, allowing any user to trigger oracle updates.
// File: contracts/PanopticPool.sol, lines 552-558
function pokeOracle() external {
int24 currentTick = getCurrentTick();
(, OraclePack oraclePack) = riskEngine().computeInternalMedian(s_oraclePack, currentTick);
if (OraclePack.unwrap(oraclePack) != 0) s_oraclePack = oraclePack;
}
The currentTick used in pokeOracle() is obtained from getCurrentTick(), which reads the current tick from the Uniswap pool. This tick can be manipulated using flash loans to create large price movements. While clampTick() limits the maximum change per update to MAX_CLAMP_DELTA (149 ticks), this protection only applies within a single update.
// File: contracts/types/OraclePack.sol, lines 511-528
function clampTick(
int24 newTick,
OraclePack _oraclePack,
int24 clampDelta
) internal pure returns (int24 clamped) {
unchecked {
int24 _lastTick = _oraclePack.lastTick();
// Clamp lastObservedTick to be within clampDelta of lastTick
if (newTick > _lastTick + clampDelta) {
clamped = _lastTick + clampDelta;
} else if (newTick < _lastTick - clampDelta) {
clamped = _lastTick - clampDelta;
} else {
clamped = newTick;
}
}
}
An attacker can exploit this by frontrunning legitimate pokeOracle() calls. When a new epoch begins, the attacker uses a flash loan to manipulate the Uniswap pool price, then calls pokeOracle() to update the oracle with the manipulated tick. Since the oracle can only be updated once per epoch, legitimate calls to pokeOracle() later in the same epoch will have no effect, leaving the manipulated value in place for the entire 64-second epoch.
The attacker can repeat this process across multiple epochs, gradually moving the oracle in their desired direction by up to 149 ticks per epoch. Over several epochs, this cumulative manipulation can significantly distort the oracle price, affecting all positions that rely on the oracle for pricing and solvency checks.
Impact
Attackers can manipulate the oracle by frontrunning legitimate updates and using flash loans to gradually move the oracle price across multiple epochs, causing all positions to be evaluated at incorrect prices and leading to incorrect solvency validations, unfair liquidations, or allowing insolvent positions to remain active.
Recommended mitigation steps
Modify the oracle mechanism so that the oracle is updated continuously with the current tick as time progresses, similar to Uniswap TWAP, rather than allowing only one update per epoch. This would prevent attackers from locking in manipulated values for an entire epoch period.
// File: contracts/types/OraclePack.sol, lines 536-567
function computeInternalMedian(
OraclePack oraclePack,
int24 currentTick,
uint96 EMAperiods,
int24 clampDelta
) internal view returns (int24 _medianTick, OraclePack _updatedOraclePack) {
unchecked {
_medianTick = getMedianTick(oraclePack);
uint256 currentEpoch;
bool differentEpoch;
int256 timeDelta;
{
currentEpoch = (block.timestamp >> 6) & 0xFFFFFF;
uint256 recordedEpoch = oraclePack.epoch();
differentEpoch = currentEpoch != recordedEpoch;
- timeDelta = int256(uint256(uint24(currentEpoch - recordedEpoch))) * 64;
+ // Calculate actual time delta in seconds
+ timeDelta = int256(block.timestamp) - int256(oraclePack.timestamp());
}
- // only proceed if last entry is in a different epoch
- if (differentEpoch) {
+ // Update oracle if enough time has passed (e.g., at least 64 seconds)
+ if (timeDelta >= 64) {
int24 clampedTick = clampTick(currentTick, oraclePack, clampDelta);
_updatedOraclePack = insertObservation(
oraclePack,
clampedTick,
currentEpoch,
timeDelta,
EMAperiods
);
+ // Allow multiple updates within the same epoch if enough time has passed
}
}
}
Alternatively, restrict pokeOracle() to only be callable by trusted addresses or implement a commit-reveal scheme to prevent frontrunning.
Proof of Concept
The following test demonstrates the vulnerability by showing that an attacker can manipulate the oracle by frontrunning pokeOracle() calls and gradually moving the oracle across multiple epochs, with the manipulated value locked in for the entire 64-second epoch period.
To run this PoC, add the following test function to test/foundry/core/Misc.t.sol:
View detailed Proof of Concept
This test can be run with forge test --match-test test_PoC_OracleManipulation -vvv to demonstrate the vulnerability. The test shows that:
- An attacker can manipulate the pool price using swaps (simulating flash loans) and call
pokeOracle()to update the oracle. - Once updated in an epoch, the oracle cannot be corrected for the remainder of that 64-second epoch, even if a legitimate user attempts to update it with the correct price.
- The attacker can repeat this process across multiple epochs to gradually manipulate the oracle by up to 149 ticks per epoch (limited by
MAX_CLAMP_DELTA). - The cumulative manipulation affects all positions that rely on the oracle for pricing, causing incorrect solvency validations and potentially unfair liquidations.
Panoptic disputed
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the oracle only accepts one observation per 64-second epoch and the update function is permissionless, so whoever calls first in an epoch sets the value for that whole period.
Impact
Positions could be priced incorrectly, leading to wrong solvency checks, unfair liquidations, or insolvent positions staying active; the clamp limits each step to 149 ticks but does not stop cumulative drift.
What the attacker needed
Permissionless pokeOracle(); flash loan for pool manipulation; ability to frontrun updates
The fix
The report recommends updating the oracle continuously based on elapsed time rather than once per epoch, or restricting pokeOracle() to trusted callers or a commit-reveal scheme; the program disputed the finding.
How it was found
- Manipulate the Uniswap pool price using swaps that simulate a flash loan.
- Call pokeOracle() so the manipulated tick is written into the oracle pack.
- Observe that further calls in the same epoch do not change the stored value.
- Repeat across epochs to move the oracle by up to 149 ticks each time.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
An oracle is a contract that feeds a price into other contracts. Here the price is taken from a trading pool that anyone can briefly push around by borrowing a large amount of money (a flash loan) and swapping. Because the oracle only records one value per short time window, an attacker can be the first to submit a skewed value and it stays in place until the next window.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.