LibUsdOracle.sol is passing the wrong token as base token which leads to complete bogus price calculations and loss of funds
in the marked lines baseToken & quoteToken are interchanged. Which leads to totally wrong price. Lets understand with an example
Lets suppose uni pool of BAL/DAI is used to calculate price of BAL , assume legit 1 BAL = 2.5 DAI
chainLinkToken = DAI as its a USD stable
so now looking at
https://github.com/Cyfrin/2024-05-beanstalk-the-finale/blob/4e0ad0b964f74a1b4880114f4dd5b339bc69cd3e/protocol/contracts/libraries/Oracle/LibUniswapOracle.sol#L38
&
https://github.com/Uniswap/v3-periphery/blob/697c2474757ea89fec12a4e6db16a574fe259610/contracts/libraries/OracleLibrary.sol#L49-L69
we can see that chainlinkToken = token1 & token = token2 which in turn leads to
ChainlinkToken being the base token & token being the quote token in OracleLibrary
So it would return the price of DAI in terms of BAL
leading to token price = 0.4
Now price DAI is fetched from chainlink which equal 1e6(as its stablecoin assumed)
hence the final price of token(BAL) would be returned 0.4 usd which is wrong
Incorrect price, loss of funds
Manual review
which leads to correct prices.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.