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.
Submitted by PwnPatrol, also found by datapunk and Lambda
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
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
- Admins deploy an oracle for the ibBTC-wBTC pair and set it as tokenToOracle[ibBTC].
- Later, admins create a new pair for ibBTC-renBTC and deploy a new oracle.
- 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.