addFeedFor should check if inverse feed already exists
The addFeedFor function only checked whether a price feed for the given currency pair already existed in one direction, but not the inverse direction. This allowed two different oracles to be set for the same pair in opposite directions, potentially causing inconsistent currency conversions.
Submitted by 0x52, also found by DimitarDimitrov
Potentially inconsistent currency conversions.
Proof of Concept
addFeedFor requires that a price feed for the _currency _base doesn’t exist when adding a new price feed but doesn’t check if the inverse already exists. This means that two different oracles (potentially with different prices) could be used for _currency -> _base vs. _base -> _currency. Different prices would lead to inconsistent between conversion ratios depending on the direction of the conversion.
Recommended Mitigation Steps
Change L115 to: if (feedFor\[\_currency]\[\_base] != IJBPriceFeed(address(0)) || feedFor\[\_base]\[\_currency] != IJBPriceFeed(address(0))) revert PRICE_FEED_ALREADY_EXISTS()
mejango (Juicebox) resolved:
PR with fix: PR #1
berndartmueller (warden) reviewed mitigation:
An additional check has been added to prevent adding a price feed for the inverse pair.
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
The function only checked one direction of the currency pair when verifying if a feed already exists, missing the inverse pair.
Impact
Two different oracles could be used for the same currency pair in opposite directions, leading to inconsistent conversion ratios depending on the direction of the conversion.
What the attacker needed
Ability to call addFeedFor
The fix
The check was updated to also verify the inverse pair before allowing a new feed, and this was fixed in a pull request.
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 smart contract lets you add price feeds for currency pairs. It checked if a feed for A-to-B already existed, but forgot to check if a feed for B-to-A existed. So you could add two different feeds for the same pair, and the contract might use different prices depending on which way you convert.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.