Skip to content
Smart contracts Audit finding Intermediate

Uniswap oracle validateprice can be griefed per block via sync()

The oracle's price validation rejects any call made in the same block that the Uniswap V2 pair's reserves were last updated. An attacker can front-run a victim's transaction with a permissionless sync() call so the check always fails in that block, repeatedly griefing the victim.

Silvermist Follow with BenRai, edantes and 5 others

Originally disclosed on Code4rena

Submitted by Silvermist, also found by BenRai, edantes, edoscoba, mrdafidi, Nyx, Valves, and yaractf

autonolas-tokenomics/../contracts/oracles/UniswapPriceOracle.sol #L68-L72

validatePrice() returns false if the Uniswap V2 pair’s blockTimestampLast equals the current block.timestamp.

Because Uniswap V2 pairs have a permissionless sync() that updates the pair reserves state and sets blockTimestampLast to the current block timestamp, a mempool attacker can front-run a victim transaction in the same block by calling sync() first.

When the victim later executes in that same block, blockTimestampLast == block.timestamp, so validatePrice() returns false.

(, , uint256 blockTimestampLast) = IUniswapV2(pair).getReserves();
if (block.timestamp == blockTimestampLast) {
    return false;
}

This is “per-block” because the failure is tied to the block timestamp: if the victim retries in the next block (different block.timestamp), the check can succeed again. But the attacker can repeat the same sync() front-run each time the victim tries, causing consistent failures for any public-mempool execution.

The victim can succeed in a later block, but the attacker can keep repeating the same front-run sync() whenever the action is attempted via the public mempool.

Recommended mitigation steps

Avoid making validation fail solely because the pair was updated in the same block.

Proof of Concept

View detailed Proof of Concept


The original report as published on Code4rena, by Silvermist. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 validation treats a same-block reserve update as a failure condition, which is trivially triggerable by anyone through the permissionless sync() function.

Impact

The victim's action can be made to fail consistently whenever it is submitted through the public mempool, though it could still succeed in a later block if the attacker does not repeat the front-run.

What the attacker needed

Attacker can see pending transactions; victim submits via public mempool

The fix

The validation should not fail solely because the pair was updated in the same block.

How it was found

  1. Attacker watches the public mempool for a victim transaction that calls validatePrice().
  2. Attacker front-runs it in the same block by calling sync() on the Uniswap V2 pair.
  3. The victim's transaction executes in that block and validatePrice() returns false.
  4. Attacker repeats the same front-run each time the victim retries.

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.

A price oracle is a contract that reports an asset's price, and this one refuses to answer if the trading pair was touched in the same block. Anyone can call a public function called sync() on a Uniswap pair to refresh its stored reserves, which also stamps the current block time. Because the attacker can see pending transactions before they are confirmed, they can slip their sync() in first, making the victim's call fail every time.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by Silvermist

View all

4 more disclosed reports, best first.

More from Olas

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.