According to the docs on LibWstethEthOracle
the price returned will be either:
the average price(or minimum) when price comparison is < MAX_DIFFERENCE
otherwise the Chainlink price.
Reference from the docs at LibWstethEtheOracle
The assumption above is correct, because:
The Chainlink STETH-ETH is the most reliable source for the STETH
price.
The Uniswap Pool for WSTETH-ETH has low liquidity(only 30m currently - https://etherscan.io/address/0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0) and higher volatility, therefore when the range of price between Chainlink & Uniswap is greater than 1%, Chainlink price should be used.
The problem is that even though the docs is correct, the implementation and the tests aren't.
The problem is whenever the LibOracleHelpers.getPercentDifference(chainlinkPrice, uniswapPrice) >= MAX_DIFFERENCE
, the value returned will be 0.
Another point to consider is stETH is a rebased token so the exchange rate between wstETH-stETH is not 1:1. https://data.chain.link/feeds/arbitrum/mainnet/wsteth-steth exchangerate
Oracle will return 0, even though the price price from Chainlink is valid.
All contracts that rely on the Oracle price will be affected.
Run the PoC below. This PoC contains the block number from today's date(8th April 2024). This will show that if those contracts were deployed today, the Oracle price would be always 0. Try to set different days in the past and you will notice that this will be the result most of the time.
Update the MockWsteth.sol
so it can return the uniswap pool price:
Add the following test onWstethOracle.test.js
:
Then run: npx hardhat test test/WstethOracle.test.js --network hardhat
Output - price difference > 1%, oracle returns 0:
Manual Review & Hardhat
Return the Chainlink price when the difference is greater than 1% on getWstethEthPrice
function:
Also, consider returning the Chainlink price when uniswapPrice
is 0.
(Improve readability) Change the variable name WSTETH_ETH_CHAINLINK_PRICE_AGGREGATOR
to STETH_ETH_CHAINLINK_PRICE_AGGREGATOR
.
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.