Closed code423n4 closed 2 years ago
If the value of totalAssets == 0 then there is no value to withdraw. On an edge case that this has somehow rounded down to 0 there would be very little value to withdraw in any case, certainly not enough worth paying the gas cost for the transaction.
I think this should be a QA report.
Consider with #138
Lines of code
https://github.com/code-423n4/2022-06-notional-coop/blob/6f8c325f604e2576e2fe257b6b57892ca181509a/notional-wrapped-fcash/contracts/wfCashERC4626.sol#L52-L61 https://github.com/code-423n4/2022-06-notional-coop/blob/6f8c325f604e2576e2fe257b6b57892ca181509a/notional-wrapped-fcash/contracts/wfCashERC4626.sol#L134-L149
Vulnerability details
Impact
Divide by zero error on convertToShares due to totalAssets() is zero.
This will prevent user from withdrawing their asset.
Proof of Concept
Zero check is not performed on totalAssets().
totalAssets() can be zero on some case that totalSupply is too low, so that getPresentfCashValue return 0. After that, pvExternal will be 0 which mean totalAssets() == 0 while supply != 0.
In this case it will be reverted.
This is used on previewWithdraw
if fCash is matured and totalAssets is zero while having some shares. convertToShares will be reverted causing previewWithdraw to be reverted thus user cannot withdrawal.
Tools Used
Manual
Recommended Mitigation Steps
Check both supply == 0 and totalAssets() == 0 for edge case