Open sherlock-admin2 opened 8 months ago
1 comment(s) were left on this issue during the judging contest.
takarez commented:
invalid
Escalate
Low. Exceeding skewFractionMax is possible only by a fraction of a percent
Escalate
Low. Exceeding skewFractionMax is possible only by a fraction of a percent
You've created a valid escalation!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
Agree with @0xLogos. The withdrawal fee is a tiny amount compared to the total deposited collateral, therefore the impact will be almost imperceptible. The severity should be LOW.
This issue is valid.
The fee maybe a tiny amount compared to the total deposited collateral, but the impact is significant to individual users.
Let's assume stableCollateralTotal is 1000 ether, stableWithdrawFee is 1%, skewFractionMax is 120% and current skewFraction is 60%.
If withdrawal fee is ignored in the calculation of shew fraction, withdrawAmount is calculated as:
If withdrawal fee is considered in the calculation of shew fraction, withdrawAmount is calculated as:
We can notice that 5 ether less collaterals ethers are withdrawable if fee is ignored. Just be realistic, individual user is most likely to deposit a tiny amount of collaterals, this means many users are unable to withdraw any of their collaterals even if it is safe to do so.
Similarly, since tradeFee is ignored when protocol checks a leverage open/adjustment, many traders would be wrongly prevented from opening/adjusting any positions.
In first pic after withdrawing for example 300 eth, fee for that amount will be included in the next withdrawal and so forth so eventually all 505 eth can be withdrawn. Note that it's not work around, just how things work in most cases.
It's not about how much user can withdraw but if user can withdraw whenever it is safe.
Given after withdrawing for example 300 eth, users expect to be able to withdraw 353.5 ether more but are only allowed 350 ether due to the issue.
Incorrect checking is a high risk to the protocol, it is difficult to predict how users will operate but it would eventually cause huge impact if we ignore the risk.
The margin error on the calculation of checkSkewMax
will be equal to the tradeFee
on that operation. When the operation is using a huge amount (500 ETH), the margin error of the calculation will be of 5 ETH (assuming a 1% tradeFee
). But if 10 users withdraw 50 ETH each, the margin error will only be 0.5 ETH on the last withdrawal.
To trigger this issue with a non-trivial margin error, it requires a user that withdraws collateral (or creates or adjusts a position) with a huge amount compared to the total collateral deposited.
Given the low probability of this issue happening with a non-trivial margin error and the impact being medium/low, I'd consider the overall severity of this issue to be LOW.
The probability should be medium as you cannot predict the wild market, the impact can be high since usera may suffer a loss due to price fluncation if they cannot withdraw in time. So it's fair to say the servrity is medium.
The protocol team fixed this issue in PR/commit https://github.com/dhedge/flatcoin-v1/pull/280.
It seems to me that the issue described can negatively affect users and breaks core contract functionality in specific (but not unrealistic) scenarios https://docs.sherlock.xyz/audits/judging/judging#v.-how-to-identify-a-medium-issue
Tentatively planning to reject the escalation and keep the issue state as is, but will revisit it later.
Planning to continue with my judgment as stated in the comment above.
Result: Medium Unique
The Lead Senior Watson signed off on the fix.
HSP
medium
Fees are ignored when checks skew max in Stable Withdrawal / Leverage Open / Leverage Adjust
Summary
Fees are ignored when checks skew max in Stable Withdrawal / Leverage Open / Leverage Adjust.
Vulnerability Detail
When user withdrawal from the stable LP, vault total stable collateral is updated:
Then _withdrawFee is calculated and checkSkewMax(...) function is called to ensure that the system will not be too skewed towards longs:
At the end of the execution, vault collateral is settled again with withdrawFee, keeper receives keeperFee and
(amountOut - totalFee)
amount of collaterals are transferred to the user:The
totalFee
is composed of keeper fee and withdrawal fee:This means withdrawal fee is still in the vault, however this fee is ignored when checks skew max and protocol may revert on a safe withdrawal. Consider the following scenario:
120%
and stableWithdrawFee is1%
;100
collateral and Bob opens a leverage position with size100
;100
collaterals in the Vault, skew is0
and skew fraction is100%
;16.8
collaterals, withdrawFee is0.168
, after withdrawal, it is expected that there is83.368
stable collaterals in the Vault, so skewFraction should be119.5%
, which is less than skewFractionMax;120.19%
, which is higher than skewFractionMax.The same issue may occur when protocol executes a leverage open and leverage adjust, in both executions, tradeFee is ignored when checks skew max.
Please see the test codes:
Impact
Protocol may wrongly prevent a Stable Withdrawal / Leverage Open / Leverage Adjust even if the execution is essentially safe.
Code Snippet
https://github.com/sherlock-audit/2023-12-flatmoney/blob/main/flatcoin-v1/src/StableModule.sol#L130 https://github.com/sherlock-audit/2023-12-flatmoney/blob/main/flatcoin-v1/src/LeverageModule.sol#L101 https://github.com/sherlock-audit/2023-12-flatmoney/blob/main/flatcoin-v1/src/LeverageModule.sol#L166
Tool used
Manual Review
Recommendation
Include withdrawal fee / trade fee when check skew max.