Open sherlock-admin opened 7 months ago
1 comment(s) were left on this issue during the judging contest.
takarez commented:
valid: checkSkewMax should be adjusted; medium(6)
The protocol team fixed this issue in PR/commit https://github.com/dhedge/flatcoin-v1/pull/266.
Resolved here: https://github.com/dhedge/flatcoin-v1/pull/266
Because collateral is no longer settled in updateGlobalPositionData
The Lead Senior Watson signed off on the fix.
nobody2018
medium
In LeverageModule.executeOpen/executeAdjust, vault.checkSkewMax should be called after updating the global position data
Summary
[checkSkewMax](https://github.com/sherlock-audit/2023-12-flatmoney/blob/main/flatcoin-v1/src/FlatcoinVault.sol#L296) is used to assert that the system will not be too skewed towards longs after additional skew is added. However, the
stableCollateralTotal
used by this function is a variable that will [be updated by updateGlobalPositionData](https://github.com/sherlock-audit/2023-12-flatmoney/blob/main/flatcoin-v1/src/FlatcoinVault.sol#L205). Therefore,checkSkewMax
should be executed afterupdateGlobalPositionData
. Otherwise, there is no guarantee whether newly opened positions will make the system more skew towards long side.Vulnerability Detail
L101, [vault.checkSkewMax](https://github.com/sherlock-audit/2023-12-flatmoney/blob/main/flatcoin-v1/src/FlatcoinVault.sol#L296-L307) internally calculates
longSkewFraction
by the formula((_globalPositions.sizeOpenedTotal + _additionalSkew) * 1e18) / stableCollateralTotal
. This function guarantees thatlongSkewFraction
will not exceedskewFractionMax
([120%](https://github.com/sherlock-audit/2023-12-flatmoney/blob/main/flatcoin-v1/scripts/deployment/configs/FlatcoinVault.config.js#L9)).However,
stableCollateralTotal
will [be updated in updateGlobalPositionData](https://github.com/sherlock-audit/2023-12-flatmoney/blob/main/flatcoin-v1/src/FlatcoinVault.sol#L205).profitLossTotal
is positive value, thenstableCollateralTotal
will decrease.profitLossTotal
is negative value, thenstableCollateralTotal
will increase.Assume the following:
We explain it in two situations:
checkSkewMax
is called beforeupdateGlobalPositionData
.checkSkewMax
is called afterupdateGlobalPositionData
.Therefore, this new position should not be allowed to open, as this will only make the system more skewed towards the long side.
Impact
The
stableCollateralTotal
used bycheckSkewMax
is the value of the total profit that has not yet been settled, which is old value. In this way, when the price of collateral rises, it will cause the system to be more skewed towards the long side.Code Snippet
https://github.com/sherlock-audit/2023-12-flatmoney/blob/main/flatcoin-v1/src/LeverageModule.sol#L101-L109
https://github.com/sherlock-audit/2023-12-flatmoney/blob/main/flatcoin-v1/src/LeverageModule.sol#L166
Tool used
Manual Review
Recommendation
Also, if
announcedAdjust.additionalSizeAdjustment
is greater than 0 in [executeAdjust](https://github.com/sherlock-audit/2023-12-flatmoney/blob/main/flatcoin-v1/src/LeverageModule.sol#L166), similar fix is required.