Closed sherlock-admin closed 1 year ago
3 comment(s) were left on this issue during the judging contest.
panprog commented:
invalid, because it's expected behavior - prepare can be called again by anybody to update if protocol fee (uniswap) changes, the 2nd time it will only re-write pool cached metadata, which is as expected, LastWrites won't change
tsvetanovv commented:
Invalid. ChatGPT report
MohammedRizwan commented:
invalid issue
moneyversed
high
Risk of manipulation of implied volatility calculations due to lack of input validation in VolatilityOracle's
prepare
functionSummary
The
VolatilityOracle.sol
CA is responsible for calculating the implied volatility from Uniswap V3 pools. However, there is an issue with theprepare
function, as it lacks proper verification mechanisms, eventually allowing an attacker to manipulate the system by providing malicious input, leading to inaccurate volatility calculations and possibly financial loss.Vulnerability Detail
The
prepare
function in theVolatilityOracle.sol
CA is designed to set up necessary data for a given Uniswap V3 pool. It calculates and stores pool metadata and fee growth globals, which are later used to estimate the implied volatility of the pool's assets.However, this function does not perform adequate verification on the
pool
parameter, allowing an attacker to possibly provide a malicious contract address, which can lead to incorrect data being stored in thecachedMetadata
andfeeGrowthGlobals
mappings, ultimately affecting the volatility calculations.Furthermore, the
liquidate
function in theBorrower
CA is responsible for handling the liquidation of collateral in case a position becomes undercollateralized. This function currently relies on price data from theVolatilityOracle
and does not implement sufficient checks and validations to ensure that the price data is accurate and not manipulated, means that the attacker manages to prepare the pool by passing his malicious CA and accurately manipulated data as the pool right like explained above he would be able to gain advantage from these distorted volatility calculations to make huge profits or either leading to unfair liquidations, where users’ collateral is liquidated even though their position is actually safe and well-collateralized.Impact
If an actor exploits this vulnerability, they could basically manipulate the implied volatility calculations of the Aloe protocol, leading to inaccurate trading and hedging decisions by users, which would in turn result in financial loss for users, unfair liquidations (either in sizeable profit or loss.) and damage the integrity of the entire Aloe protocol.
Code Snippet
Here is the snippet from
VolatilityOracle.sol
showcasing this concern:LINK TO PREPARE
Consequently, the
liquidate
function from theBorrower
:LINK TO LIQUIDATE
Tool used
Manual review.
Recommendation
Maintain a list (whitelist) of approved Uniswap V3 pool addresses and check that the provided pool address is in this list before proceeding with the rest of the function.
Check that the bytecode at the provided pool address matches the expected bytecode of a legitimate Uniswap V3 pool.
If Uniswap V3 pools are created through a factory CA, you could verify that the pool address was created by the factory.
Proof of Concept
IUniswapV3Pool
.prepare
function inVolatilityOracle.sol
, passing the address of the malicious CA.prepare
function executes without error, storing incorrect data in thecachedMetadata
andfeeGrowthGlobals
mappings.VolatilityOracle
contract that rely on the data stored by theprepare
function. Notice that the calculations are now based on the incorrect data, leading to inaccurate volatility estimations.Consider the following script:
Which is interacting with the following malicious CA (MaliciousAloe.sol):
And here's the output showing that data was in fact manipulated:
C:\Users\david\exploits>npx hardhat run scripts/Aloe.js --network hardhat MaliciousAloe deployed at: 0x32cd5ecdA7f2B8633C00A0434DE28Db111E60636 VolatilityOracle deployed at: 0xbeC6419cD931e29ef41157fe24C6928a0C952f0b Fake data has been set prepare function executed successfully Manipulated Data: [ BigNumber { value: "340282366920938463463374607431768211455" }, 0, 1, 10000, 1698503321, 0, BigNumber { value: "1000000000000000000000000" }, BigNumber { value: "0" }, BigNumber { value: "0" }, _fakeSqrtPriceX96: BigNumber { value: "340282366920938463463374607431768211455" }, _fakeCurrentTick: 0, _fakeObservationIndex: 1, _fakeObservationCardinality: 10000, _fakeObservationTimestamp: 1698503321, _fakeFeeProtocol: 0, _fakeLiquidity: BigNumber { value: "1000000000000000000000000" }, _fakeTickCumulative: BigNumber { value: "0" }, _fakeSecondsPerLiquidityX128: BigNumber { value: "0" } ]
As for breaking down the manipulated values that are used within the
prepare
function, after being set in thesetFakeData
call:_fakeSqrtPriceX96
: a very high value to drastically manipulate the square root price._fakeCurrentTick
: a value that corresponds to an extreme price._fakeObservationIndex
: an index._fakeObservationCardinality
: an high value to showcase a large number of observations._fakeObservationTimestamp
: a recent timestamp._fakeFeeProtocol
: a value for simulating a fee bypass._fakeLiquidity
: a very high value to showcase a pool with high liquidity.By following these steps, an attacker could actually manipulate the implied volatility calculations and achieve drastical outcomes within the Aloe protocol, therefore highlighting the need for additional verification and security measures in the
prepare
function.