Whenever swapPrice > oraclePrice, minting via PositionManager will revert, due to not enough funds being obtained from user
The PositionManager contract calculates the premium for minting a position using only the oracle price, while the DVP contract uses the higher of the oracle and swap prices. When the swap price exceeds the oracle price, the PositionManager transfers insufficient funds, causing the mint to revert and denying service to users.
Source: https://github.com/sherlock-audit/2024-02-smilee-finance-judging/issues/32
Found by
cawfree, juan, panprog
Summary
In PositionManager::mint(), obtainedPremium is calculated in a different way to the actual premium needed, and this will lead to a revert, denying service to users.
Vulnerability Detail
In PositionManager::mint(), the PM gets obtainedPremium from DVP::premium():
(obtainedPremium, ) = dvp.premium(params.strike, params.notionalUp, params.notionalDown);
Then the actual premium used when minting by the DVP is obtained via the following code:
<details> <summary>Determining option premium</summary> uint256 swapPrice = _deltaHedgePosition(strike, amount, true);
uint256 premiumOrac = _getMarketValue(strike, amount, true, IPriceOracle(_getPriceOracle()).getPrice(sideToken, baseToken));
uint256 premiumSwap = _getMarketValue(strike, amount, true, swapPrice);
premium_ = premiumSwap > premiumOrac ? premiumSwap : premiumOrac;
From the code above, we can see that the actual premium uses the greater of the two price options. However, DVP::premium() only uses the oracle price to determine the obtainedPremium.
This leads to the opportunity for premiumSwap > premiumOrac, so in the PositionManager, obtainedPremium is less than the actual premium required to mint the position in the DVP contract.
Thus, when the DVP contract tries to collect the premium from the PositionManager, it will revert due to insufficient balance in the PositionManager:
IERC20Metadata(baseToken).safeTransferFrom(msg.sender, vault, premium_ + vaultFee);
Impact
Whenever swapPrice > oraclePrice, minting positions via the PositionManager will revert. This is a denial of service to users and this disruption of core protocol functionality can last extended periods of time.
Code Snippet
Tool used
Manual Review
Recommendation
When calculating obtainedPremium, consider also using the premium from swapPrice if it is greater than the premium calculated from oraclePrice.
Discussion
sherlock-admin2
2 comment(s) were left on this issue during the judging contest.
panprog commented:
valid high, dup of #42
takarez commented:
valid, the calculation should consider the swapPrice; medium(1)
metadato-eth
MEDIUM DoS but 1) no fund at risk, 2) overcome easily by changing the position manager, 3) immediately identifiable by internal testing before official release
sherlock-admin4
The protocol team fixed this issue in PR/commit https://github.com/dverso/smilee-v2-contracts/commit/84174d20544970309c862a2bf35ccfa3046d6bd9.
panprog
Fix review; Fixed
sherlock-admin4
The Lead Senior Watson signed off on the fix.
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
Impact
Minting positions via the PositionManager reverts whenever the swap price exceeds the oracle price, causing a denial of service that can last extended periods.
What the attacker needed
SwapPrice > oraclePrice
The fix
The issue was fixed by considering the swap price when calculating the premium in PositionManager.
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 is a smart contract bug where two parts of the system calculate the cost of an option differently. One part expects a higher payment than the other provides, so the transaction fails and users cannot create new positions.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.