Skip to content
Audit finding Intermediate

Oracle is tracked per token instead of per pair, leading to surprise results

The protocol stores oracles keyed only by a single token rather than by the token pair, so when a new pair is created with a different oracle, the assignment is silently skipped and the old oracle is reused. This can produce incorrect price comparisons for the new pair, leading to wrong results if the assets move relative to each other.

PwnPatrol Follow

Originally disclosed on Code4rena

Submitted by PwnPatrol, also found by datapunk and Lambda

https://github.com/code-423n4/2022-09-y2k-finance/blob/2175c044af98509261e4147edeb48e1036773771/src/VaultFactory.sol#L121

https://github.com/code-423n4/2022-09-y2k-finance/blob/2175c044af98509261e4147edeb48e1036773771/src/VaultFactory.sol#L221-L223

Impact

Oracles are tracked by individual token, instead of by pair. Because for some tokens (ie BTC) it is unclear which implementation is the canonical one to compare others to, this can result in a situation where different pairs (ie ibBTC-wBTC and ibBC-renBTC) using the same oracle, which will be incorrect for one of them.

Proof of Concept

The protocol assumes that there is a canonical asset to compare pegged assets to, so oracles are tracked only by the pegged asset. However, for some assets (like BTC), there is no clear canonical asset, and the result is that tracking tokenToOracle is not sufficient.

When there is a conflict in tokenToOracle, the protocol responds by skipping the assignment and keeping the old value:

if (tokenToOracle[_token] == address(0)) {
    tokenToOracle[_token] = _oracle;
}

The result of this is that the protocol may define a new pair with a new oracle, and have it silently skip it and use a non-matching oracle. As an example:

  • The admins start with an implementation of ibBTC-wBTC, deploying the oracle
  • This is set as tokenToOracle[ibBTC]
  • Later, the admins create a new pair for ibBTC-renBTC, deploying a new oracle
  • The protocol silently skips this assignment and uses the ibBTC-wBTC oracle

This can produce incorrect results, for example if wBTC appreciates relative to the other two, or if both ibBTC and renBTC depeg.

Tools Used

Foundry

Recommended Mitigation Steps

Change tokenToOracle to represent the pair of tokens, either by creating a Pair struct as the key, or by nesting a mapping inside of another mapping.

MiguelBit (Y2K Finance) disputed


The original report as published on Code4rena, by PwnPatrol. 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 mapping tokenToOracle is keyed only by a single token, and the code only sets it if empty, so a second pair involving the same token cannot register its own oracle.

Impact

This can produce incorrect results, for example if wBTC appreciates relative to the other two, or if both ibBTC and renBTC depeg.

What the attacker needed

Admin creates a second pair with same token; new oracle deployed for that pair

The fix

Change tokenToOracle to represent the pair of tokens, either by creating a Pair struct as the key, or by nesting a mapping inside of another mapping.

How it was found

  1. Admins deploy an oracle for the ibBTC-wBTC pair and set it as tokenToOracle[ibBTC].
  2. Later, admins create a new pair for ibBTC-renBTC and deploy a new oracle.
  3. The protocol silently skips the new oracle assignment and keeps the old ibBTC-wBTC oracle.

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 service that tells a smart contract how much an asset is worth. This protocol saved one oracle per token, not per trading pair, so when a new pair was added it kept using the old oracle. That could give wrong prices for the new pair.

More by PwnPatrol

View all

4 more disclosed reports, best first.

More from Y2k Finance contest

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.