Submitted by hyh
Actual available fees are less than recorded. Thats because a part of them corresponds to underwater positions, and will not have the correct amount stored with the contract: when calculation happens the fee is recorded first, then there is a check for position health, and the funds are channeled to cover the debt firsthand. This way in a case of unfunded position the fee is recorded, but cannot be allocated, so the fees accounted can be greater than the value of fees stored.
This can lead to fee withdrawal malfunction, i.e. disburse() will burn more and attempt to transfer more than needed. This leads either to inability to withdraw fees when disburse is failing due to lack of funds, or funds leakage to fees and then inability to perform other withdrawals because of lack of funds.
The fees are accounted for before position health check and arent corrected thereafter when there is a shortage of funds.
https://github.com/code-423n4/2021-11-overlay/blob/main/contracts/collateral/OverlayV1OVLCollateral.sol#L311
Adjust fees after position health check: accrue fees only on a remaining part of position that is available after taking debt into account.
Now:
To be:
mikeyrf (Overlay) confirmed
