<!-- canonical: https://0xsimao.com/findings/maple-finance-iii-optimizations-redundant-impairment-functions -->

# LoanManager code optimizations: redundant impairment functions.

Low/Info · Three Sigma · Institutional lending · 10th April, 2024

Finding 3S-MAPLE-N07 of the Maple Finance security review.

- Protocol: https://maple.finance/
- Report: /reports/maple-finance-iii-2024
- Source: https://cdn.sanity.io/files/qoqld077/production/36dbe5ca76da3d2392bcee581548067705b8bd36.pdf

---

### Description

The LoanManager contract has the following code:

```solidity
function impairLoan(address loan_) {
    bool isGovernor_ = msg.sender == _governor();
    (...)
    if (isGovernor_) {
        _accountForLoanImpairmentAsGovernor(loan_);
    } else {
        _accountForLoanImpairment(loan_);
    }
}
function _accountForLoanImpairment(address loan_) {
    impairedDate_ = _accountForLoanImpairment(loan_, false);
}
function _accountForLoanImpairmentAsGovernor(address loan_) {
    impairedDate_ = _accountForLoanImpairment(loan_, true);
}
```

In this code, functions _accountForLoanImpairment(loan) and
_accountForLoanImpairmentAsGovernor(loan) add unneeded redundancy and make the
code more cluttered, therefore more difficult to read and less gas efficient.

### Recommendation

Function impairLoan() can call directly accountForLoanImpairment(loan, isGovernor),
and functions _accountForLoanImpairment(loan) and
_accountForLoanImpairmentAsGovernor(loan) can be removed. Changing the same
code to just:

```solidity
function impairLoan(address loan_){
    bool isGovernor_ = msg.sender == _governor();
    (...)
    _accountForLoanImpairment(loan_, isGovernor_);
}
```

Note: This suggestion would require a minor change to triggerDefault(), sending false
as the second function parameter on the call to function _accountForLoanImpairment.

### Status

Acknowledged by the team.

---

Related findings:

- [MerkleRoot is not validated in all StakingAssetManager functions](https://0xsimao.com/findings/singularity-merkle-root-validated-staking): Singularity
- [`FlashRolloverLoan_G5` will fail for `LenderCommitmentGroup_Smart` due to `CollateralManager` pulling collateral from `FlashRolloverLoan_G5`](https://0xsimao.com/findings/teller-finance-flash-rollover-collateral-pulling): Teller Finance
