wise-foundation / lending-audit

5 stars 4 forks source link

[MHR-07C] Weak Validation of Non-Zero Fees #92

Open vm06007 opened 1 year ago

vm06007 commented 1 year ago

MHR-07C: Weak Validation of Non-Zero Fees

Type Severity Location
Gas Optimization MainHelper.sol:L428-L430, L432-L434

Description:

The MainHelper::_updatePseudoTotalAmounts function will ensure that a non-zero feeAmount is extracted, however, a non-zero feeAmount does not necessarily guarantee a non-zero amount of feeShares as shares may become over-valued as the project grows.

Example:

if (feeAmount == 0) {
    return;
}

uint256 feeShares = feeAmount
    * getTotalDepositShares(_poolToken)
    / (getPseudoTotalPool(_poolToken) - feeAmount);

Recommendation:

We advise the code to instead ensure that feeShares is non-zero and to return early if it is zero, optimizing the gas cost of the function significantly.

vm06007 commented 1 year ago

Resolved in: https://github.com/wise-foundation/lending-audit/pull/91