ERC4626Oracle Vulnerable To Price Manipulation
The ERC4626Oracle contract calculates the price of an ERC4626 vault's LP token using the vault's previewRedeem function, which depends on the current total assets and supply. An attacker can manipulate these values within a single transaction to inflate or deflate the price, potentially increasing borrowing power or forcing premature liquidations.
xiaoming90 Follow with IllIllI
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2022-08-sentiment-judging/tree/main/133-M
Found by
xiaoming90, IllIllI
Summary
ERC4626 oracle is vulnerable to price manipulation. This allows an attacker to increase or decrease the price to carry out various attacks against the protocol.
Vulnerability Detail
The getPrice function within the ERC4626Oracle contract is vulnerable to price manipulation because the price can be increased or decreased within a single transaction/block.
Based on the getPrice function, the price of the LP token of an ERC4626 vault is dependent on the ERC4626.previewRedeem and oracleFacade.getPrice functions. If the value returns by either ERC4626.previewRedeem or oracleFacade.getPrice can be manipulated within a single transaction/block, the price of the LP token of an ERC4626 vault is considered to be vulnerable to price manipulation.
File: ERC4626Oracle.sol
35: function getPrice(address token) external view returns (uint) {
36: uint decimals = IERC4626(token).decimals();
37: return IERC4626(token).previewRedeem(
38: 10 ** decimals
39: ).mulDivDown(
40: oracleFacade.getPrice(IERC4626(token).asset()),
41: 10 ** decimals
42: );
43: }
It was observed that the ERC4626.previewRedeem couldbe manipulated within a single transaction/block. As shown below, the previewRedeem function will call the convertToAssets function. Within the convertToAssets, the number of assets per share is calculated based on the current/spot total assets and current/spot supply that can be increased or decreased within a single block/transaction by calling the vault's deposit, mint, withdraw or redeem functions. This allows the attacker to artificially inflate or deflate the price within a single block/transaction.
File: ERC4626.sol
154: function previewRedeem(uint256 shares) public view virtual returns (uint256) {
155: return convertToAssets(shares);
156: }
File: ERC4626.sol
132: function convertToAssets(uint256 shares) public view virtual returns (uint256) {
133: uint256 supply = totalSupply; // Saves an extra SLOAD if totalSupply is non-zero.
134:
135: return supply == 0 ? shares : shares.mulDivDown(totalAssets(), supply);
136: }
Impact
The attacker could perform price manipulation to make the apparent value of an asset to be much higher or much lower than the true value of the asset. Following are some risks of price manipulation:
- An attacker can increase the value of their collaterals to increase their borrowing power so that they can borrow more assets than they are allowed from Sentiment.
- An attacker can decrease the value of some collaterals and attempt to liquidate another user account prematurely.
Recommendation
Avoid using previewRedeem function to calculate the price of the LP token of an ERC4626 vault. Consider implementing TWAP so that the price cannot be inflated or deflated within a single block/transaction or within a short period of time.
Sentiment Team
Depends on the integration itself, so there's no action that can be taken right now.
Lead Senior Watson
Acknowledged.
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 oracle uses the vault's spot total assets and supply via previewRedeem, which can be manipulated within a single transaction.
Impact
An attacker could manipulate the price to increase their borrowing power or to decrease the value of collateral and liquidate another user prematurely.
What the attacker needed
Ability to deposit/withdraw from the vault; oracle used by a lending protocol
The fix
The oracle should avoid using previewRedeem and instead implement a TWAP so that the price cannot be manipulated within a single block or short period.
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.
This report is about a smart contract that provides price information for a special type of token (an ERC4626 vault share). The price is calculated using the vault's current balance, which can be changed quickly by anyone who deposits or withdraws. An attacker can therefore temporarily change the price to borrow more money or trigger liquidations.
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.