Calculating the total borrowed credit may encounter underflow, potentially preventing any borrowing activity in the market. #160
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
downgraded by judge
Judge downgraded the risk level of this issue
duplicate-1170
satisfactory
satisfies C4 submission criteria; eligible for awards
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2023-12-ethereumcreditguild/blob/2376d9af792584e3d15ec9c32578daa33bb56b43/src/governance/ProfitManager.sol#L172-L176
Vulnerability details
Impact
We determine the borrowed credit by subtracting the pegged amount linked to underlying tokens from the total supply of credit tokens.
While the logic is correct, there's a potential for underflow in the
totalBorrowedCredit
function.If such an underflow occurs, any borrowing attempt across all terms in the market will be reverted, as this function is invoked whenever someone attempts to borrow from a term.
I marked this as high because if such a case occurs, this market would become unusable.
Proof of Concept
The function responsible for calculating the total borrowed credit is as below:
https://github.com/code-423n4/2023-12-ethereumcreditguild/blob/2376d9af792584e3d15ec9c32578daa33bb56b43/src/governance/ProfitManager.sol#L172-L176
When borrowers repay their debts or their debts are called by others, the total borrowed credit is reduced to
0
.However, there is no guarantee that the following statement is always true:
I will illustrate one example to demonstrate such a case.
While this scenario is both simple and uncommon, it serves as an illustration of potential underflow, and there may be other cases leading to similar issues.
A lender initially lends
10^20
credit tokens.Borrower
A
borrows10^20
from aterm
, followed by borrowerB
also borrowing10^20
from the sameterm
.At this point, the total supply is
3 * 10^20
, and thecreditMultiplier
is 10^18.Subsequently, the debt for borrower
A
is either called or forgiven, leading to a newcreditMultiplier
of666,666,666,666,666,666
.Afterward, borrower
B
's debt is similarly called or forgiven, resulting in a newcreditMultiplier
of333,333,333,333,333,332
.The target total supply remains at
3 * 10^20
, with aredeemableCredit
of300,000,000,000,000,001,200
.The result of the PoC test is as follows:
And the PoC for this is as below:
Tools Used
https://www.calculator.net/big-number-calculator.html
Recommended Mitigation Steps
In the
totalBorrowedCredit
function, please incorporate a check forunderflow
.In such a case, return
0
.This adjustment won't impact the protocol, as the value is negligible and can be safely ignored.
Assessed type
Under/Overflow
The text was updated successfully, but these errors were encountered: