Open c4-bot-3 opened 10 months ago
0xSorryNotSorry marked the issue as primary issue
0xSorryNotSorry marked the issue as sufficient quality report
eswak (sponsor) confirmed
Confirming this issue.
I don't know what rules are used to determine high/medium, but this would only prevent new borrows in a market, and doesn't prevent a safe wind down of a market, and does not prevent users from withdrawing their funds, so I'd qualify as Medium, even though it definitely needs a fix.
Thanks for the quality of the report.
eswak marked the issue as disagree with severity
I agree that this should be a medium based on both its impact and likelihood.
Trumpero changed the severity to 2 (Med Risk)
Trumpero marked the issue as satisfactory
Trumpero marked the issue as selected for report
Lines of code
https://github.com/code-423n4/2023-12-ethereumcreditguild/blob/2376d9af792584e3d15ec9c32578daa33bb56b43/src/governance/ProfitManager.sol#L172-L176
Vulnerability details
Impact
The function
totalBorrowedCredit
is used to get an estimate of the amount of credit borrowed out by the system. The issue is that changes increditMultiplier
affect this value and can even lead to a revert due to underflow.The function
totalBorrowedCredit
is defined as follows:The first term is the total supply of the credit tokens including rebasing rewards. The second part is the amount of credit tokens that can be redeemed, and is defined as shown below:
If
creditMultiplier
decreases due to a realized loss, the value returned byredeemableCredit
goes up. If this value exceeds thetargetTotalSupply()
value, this function call will revert.Assume a fresh market deployment. There are no loans at all. Alice now mints 1e18 credit tokens via the PSM, so the
targetTotalSupply()
is 1e18 andredeemableCredit
is also 1e18. If the same situation is realized after the market has incurred a loss, thecreditMultiplier
will be less than 1e18, and theredeemableCredit
will be greater than 1e18. This will cause the function to revert. A malicious borrower can also burn some of their credit tokens to help brick this function.The
totalBorrowedCredit
function is used indebtCeiling
calculations, and thus when it reverts it will also break term borrow operations, breaking functionality.Proof of Concept
In this POC the following steps are demonstrated:
creditMultiplier
to decreasetotalSupply
to droptotalBorrowedCredit
function call reverts.Put this in the
ProfitManager.t.sol
file.The expectRevert in the end shows the revert. Consequences due to this failure is evident since this function is used in the
debtCeiling
calculations in lending terms.Since this breaks lending terms, it is a critical issue.
Tools Used
Foundry
Recommended Mitigation Steps
The
totalBorrowedCredit
function should never fail. Either cap it to 0 to prevent underflows. Or a better way to is to track the total tokens minted by the PSM module with a variable which is incremented every mint and decremented every burn. This removes the dependence oncreditMultiplier
which can change over time even if PSM module users haven't minted or burnt any excess tokens.Assessed type
Under/Overflow