sherlock-audit / 2024-04-teller-finance-judging

10 stars 9 forks source link

0xrobsol - Inconsistency in Tracking Total Principal Tokens Lent and Repaid #248

Closed sherlock-admin2 closed 4 months ago

sherlock-admin2 commented 4 months ago

0xrobsol

high

Inconsistency in Tracking Total Principal Tokens Lent and Repaid

Summary

An inconsistency has been identified in the smart contract regarding the tracking of total principal tokens lent and repaid. Specifically, the repayLoanCallback function does not appropriately update the totalPrincipalTokensLended variable, potentially leading to inaccuracies in accounting for lent and repaid tokens.

Vulnerability Detail

The repayLoanCallback function currently updates the totalPrincipalTokensRepaid variable to reflect the amount repaid by the borrower. However, it neglects to adjust the totalPrincipalTokensLended variable to reflect the decrease in the total amount of principal tokens lent out. This oversight could result in discrepancies between the total amount lent and the total amount repaid, leading to inaccurate accounting.

Impact

The failure to adjust the totalPrincipalTokensLended variable when a loan is repaid may have several adverse effects:

Code Snippet

https://github.com/sherlock-audit/2024-04-teller-finance/blob/main/teller-protocol-v2-audit-2024/packages/contracts/contracts/LenderCommitmentForwarder/extensions/LenderCommitmentGroup/LenderCommitmentGroup_Smart.sol#L700

Tool used

Manual Review

Recommendation

To address this issue and ensure accurate tracking of total principal tokens lent and repaid, the following steps are recommended:

nevillehuang commented 3 months ago

Invalid, getTotalPrincipalTokensOutstandingInActiveLoans already subtracts totalPrincipalTokensRepaid from totalPrincipalTokensLended, so an update is not required