Omniscia Myso Finance Audit

LoanProposalImpl Code Style Findings

LoanProposalImpl Code Style Findings

LPI-01C: Generic Typographic Mistake

TypeSeverityLocation
Code StyleLoanProposalImpl.sol:L276

Description:

The referenced line contains a typographical mistake (i.e. private variable without an underscore prefix) or generic documentational error (i.e. copy-paste) that should be corrected.

Example:

contracts/peer-to-pool/LoanProposalImpl.sol
276function checkAndupdateStatus() external {

Recommendation:

We advise this to be done so to enhance the legibility of the codebase.

Alleviation (c740f7c6b5ebd365618fd2d7ea77370599e1ca11):

The referenced function's typographic mistake has been corrected as per our recommendation.

LPI-02C: Inefficient mapping Lookups

TypeSeverityLocation
Gas OptimizationLoanProposalImpl.sol:L306, L312, L314, L320, L348, L361, L366, L409, L420

Description:

The linked statements perform key-based lookup operations on mapping declarations from storage multiple times for the same key redundantly.

Example:

contracts/peer-to-pool/LoanProposalImpl.sol
292function exerciseConversion() external {
293 address fundingPool = staticData.fundingPool;
294 uint256 lenderContribution = IFundingPool(fundingPool)
295 .subscribedBalanceOf(address(this), msg.sender);
296 if (lenderContribution == 0) {
297 revert Errors.InvalidSender();
298 }
299 if (
300 dynamicData.status != DataTypesPeerToPool.LoanStatus.LOAN_DEPLOYED
301 ) {
302 revert Errors.InvalidActionForCurrentStatus();
303 }
304 uint256 repaymentIdx = dynamicData.currentRepaymentIdx;
305 checkCurrRepaymentIdx(repaymentIdx);
306 if (lenderExercisedConversion[msg.sender][repaymentIdx]) {
307 revert Errors.AlreadyConverted();
308 }
309 // must be after when the period of this loan is due, but before borrower can repay
310 if (
311 block.timestamp <
312 _loanTerms.repaymentSchedule[repaymentIdx].dueTimestamp ||
313 block.timestamp >
314 _loanTerms.repaymentSchedule[repaymentIdx].dueTimestamp +
315 staticData.conversionGracePeriod
316 ) {
317 revert Errors.OutsideConversionTimeWindow();
318 }
319 uint256 conversionAmount = (_loanTerms
320 .repaymentSchedule[repaymentIdx]
321 .collTokenDueIfConverted * lenderContribution) /
322 IFundingPool(fundingPool).totalSubscribed(address(this));
323 collTokenConverted[repaymentIdx] += conversionAmount;
324 totalConvertedSubscriptionsPerIdx[repaymentIdx] += lenderContribution;
325 lenderExercisedConversion[msg.sender][repaymentIdx] = true;
326 IERC20Metadata(staticData.collToken).safeTransfer(
327 msg.sender,
328 conversionAmount
329 );
330
331 emit ConversionExercised(msg.sender, repaymentIdx, conversionAmount);
332}

Recommendation:

As the lookups internally perform an expensive keccak256 operation, we advise the lookups to be cached wherever possible to a single local declaration that either holds the value of the mapping in case of primitive types or holds a storage pointer to the struct contained.

Alleviation (c740f7c6b5):

The referenced mapping lookups have been partially optimized as certain pairs (i.e. lenderClaimedRepayment in LoanProposalImpl::claimRepayment) do not make use of the capability to cache interim mapping lookups (i.e. mapping(uint256 => bool) storage lenderClaimsPerRepayment = lenderClaimedRepayment[msg.sender]). As such, we consider this exhibit partially alleviated.

Alleviation (37cf23668b):

Any potential caching operations for interim mapping lookups have been properly applied to the referenced lines of code within the exhibit in the latest commit hash of the report, applying this exhibit's optimization in full.

LPI-03C: Redundant Parenthesis Statement

TypeSeverityLocation
Code StyleLoanProposalImpl.sol:L415-L417

Description:

The referenced statement is redundantly wrapped in parenthesis (()).

Example:

contracts/peer-to-pool/LoanProposalImpl.sol
415uint256 subscriptionsEntitledToRepayment = (IFundingPool(fundingPool)
416 .totalSubscribed(address(this)) -
417 totalConvertedSubscriptionsPerIdx[repaymentIdx]);

Recommendation:

We advise them to be safely omitted, increasing the legibility of the codebase.

Alleviation (c740f7c6b5ebd365618fd2d7ea77370599e1ca11):

The redundant parenthesis statement has been omitted as advised.