Dandy Caramel Tortoise - Using original principal amount as due amount inside liquidateDefaultedLoanWithIncentive
breaks contract accounting leading to lost assets/broken functionalities
#43
Labels
Sponsor Confirmed
The sponsor acknowledged this issue is valid
Will Fix
The sponsor confirmed this issue will be fixed
Dandy Caramel Tortoise
High
Using original principal amount as due amount inside
liquidateDefaultedLoanWithIncentive
breaks contract accounting leading to lost assets/broken functionalitiesSummary
Using original principal amount as due amount inside
liquidateDefaultedLoanWithIncentive
breaks contract accounting leading to lost assets/broken functionalitiesRoot Cause
In
liquidateDefaultedLoanWithIncentive
, the amount due is taken as the original principal amount of the bid rather than the remaining to be repaid principal which is incorrect as part of this principal could have already been paid backParts of the original principal could have been repaid and accounted via this function leading to double counting of principal in
totalPrincipalTokensRepaid
This leads to several problems:
totalPrincipalTokensLended - totalPrincipalTokensRepaid
astotalPrincipalTokensRepaid
can double count repaid tokens causing bids to reverttokenDifferenceFromLiquidations
calculating difference fromtotalPrincipal
without considering the repaid assetsInternal pre-conditions
No response
External pre-conditions
No response
Attack Path
tokenBalanceOfContract == 0
totalPrincipalTokensCommitted == 100
totalPrincipalTokensWithdrawn == 0
totalPrincipalTokensLended == 100
totalPrincipalTokensRepaid == 0
tokenDifferenceFromLiquidations == 0
tokenBalanceOfContract == 80
totalPrincipalTokensCommitted == 100
totalPrincipalTokensWithdrawn == 0
totalPrincipalTokensLended == 100
totalPrincipalTokensRepaid == 80
tokenDifferenceFromLiquidations == 0
tokenBalanceOfContract == 80 + 50 == 130
totalPrincipalTokensCommitted == 100
totalPrincipalTokensWithdrawn == 0
totalPrincipalTokensLended == 100
totalPrincipalTokensRepaid == 80 + 100 == 180 => incorrect
tokenDifferenceFromLiquidations == (100 - 50 == -50) => incorrect
Now:
There are more scenarios that arise from the same root cause such as estimated value becoming 0 incorrectly, which will cause division by 0 and hence revert on withdrawals, deposits will be lost or 0 shares will be minted etc.
Impact
Lost assets for users, broken functionalities
PoC
No response
Mitigation
Instead of the totalPrincipal consider the remaining principal ie.
totalPrincipal - repaidPrincipal
The text was updated successfully, but these errors were encountered: