assets will be stuck in PositionManager.sol if params.strike is not equal to DVP.currentStrike()
Summary
PositionManager.sol acts as a middleman between the user and the DVP. While calling PositionManager.mint, the function needs user to provide IPositionManager.MintParams calldata params, within params, there is a member called params.strike, if its vaule is not equal to IG.currentStrike(), PositionManager.sell/sellAll will revert, which means user's asset will be stuck.
Vulnerability Detail
While PositionManager.mint is called, the user need to provide IPositionManager.MintParams calldata params, and then the function calls dvp.mint, the code flow will arrive at IG.mint.
In IG.mint, the user supplied params.strike is ignored, instead the function calls _mint with financeParameters.currentStrike
Within DVP._mint, the strike will be financeParameters.currentStrike. And in DVP.sol#L187-L192, a position is created for PositionManager.
After IG.mint returns, a position will be created for the user, and in the position, user supplied params.strike will be stored in PositionManager.sol#L153
Then in IG.burn, strike is passed to DVP._burn.
And at the begin of the function, position is fetched in DVP.sol#L240, when calling _getPosition, strike is the user supplied value in PositionManager.sol#L153.
And if the position doesn't exist, the function will revert.
231 function _burn(
232 uint256 expiry,
233 address recipient,
234 uint256 strike,
235 Amount memory amount,
236 uint256 expectedMarketValue,
237 uint256 maxSlippage
238 ) internal returns (uint256 paidPayoff) {
239 _requireNotPaused();
240 Position.Info storage position = _getPosition(expiry, msg.sender, strike); <<<--- here strike is user supplied
241 if (!position.exists()) { <<<--- here if the position doesn't exists, the function will revert
242 revert PositionNotFound();
243 }
...
So if the params.strike is not equal to financeParameters.currentStrike, the PositionNotFound.sell/sellAll will revert.
For PoC, please add the following code to test/PositionManager.t.sol and run forge test --mc PositionManagerTest --mt testMintAndBurnStrike -vv
jasonxiale
high
assets will be stuck in
PositionManager.sol
ifparams.strike
is not equal toDVP.currentStrike()
Summary
PositionManager.sol
acts as a middleman between the user and the DVP. While callingPositionManager.mint
, the function needs user to provideIPositionManager.MintParams calldata params
, withinparams
, there is a member calledparams.strike
, if its vaule is not equal toIG.currentStrike()
,PositionManager.sell/sellAll
will revert, which means user's asset will be stuck.Vulnerability Detail
While PositionManager.mint is called, the user need to provide
IPositionManager.MintParams calldata params
, and then the function calls dvp.mint, the code flow will arrive atIG.mint
. In IG.mint, the user suppliedparams.strike
is ignored, instead the function calls_mint
with financeParameters.currentStrike Within DVP._mint, thestrike
will befinanceParameters.currentStrike
. And in DVP.sol#L187-L192, a position is created forPositionManager
.After
IG.mint
returns, a position will be created for the user, and in the position, user suppliedparams.strike
will be stored in PositionManager.sol#L153After
PositionManager.mint
, when the user calls PositionManager.sell to withdraw his position, the PositionManager._sell will the user's position to callDVP.burn
, while calling DVP.burn,position.strike
(which is set in PositionManager.sol#L153) is used in PositionManager.sol#L238Then in IG.burn,
strike
is passed to DVP._burn. And at the begin of the function,position
is fetched in DVP.sol#L240, when calling _getPosition,strike
is the user supplied value in PositionManager.sol#L153.And if the position doesn't exist, the function will revert.
So if the
params.strike
is not equal tofinanceParameters.currentStrike
, thePositionNotFound.sell/sellAll
will revert.For PoC, please add the following code to
test/PositionManager.t.sol
and runforge test --mc PositionManagerTest --mt testMintAndBurnStrike -vv
Impact
If user calls
PositionManager.mint
withparams.strike
isn't equal toIG.currentStrike()
,PositionManager.sell/sellAll
will revertCode Snippet
https://github.com/sherlock-audit/2024-02-smilee-finance/blob/3241f1bf0c8e951a41dd2e51997f64ef3ec017bd/smilee-v2-contracts/src/periphery/PositionManager.sol#L153
Tool used
VS
Recommendation
Duplicate of #65