-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A large enough loss will brick the protocol #1232
Comments
0xSorryNotSorry marked the issue as sufficient quality report |
0xSorryNotSorry marked the issue as duplicate of #1170 |
Trumpero changed the severity to 2 (Med Risk) |
This issue has a valid description and root cause of an underflow vulnerability in the totalBorrowedCredit() function. However, the scenario of the PoC cannot happen in an operational context: for a loss of 150 CREDIT to occur, a loan of 150 CREDIT has to be opened. But if totalSupply is 300 and psm mints are 200, the maximum loan size and loss that can happen is 100. So I believe 75% partial credit is appropriate for this issue. |
Trumpero marked the issue as satisfactory |
Trumpero marked the issue as partial-75 |
Lines of code
https://github.com/code-423n4/2023-12-ethereumcreditguild/blob/main/src/governance/ProfitManager.sol#L172
Vulnerability details
Impact
The
totalBorrowedCredit
function in theProfitManager
contract may revert if thecreditMultiplier
is low. This is becauseredeemableCredit
is scaled by thecreditMultiplier
, buttargetTotalSupply
isn't. This can potentially brick core protocol functionality as no one would be able to unstake or borrow.https://github.com/code-423n4/2023-12-ethereumcreditguild/blob/main/src/governance/ProfitManager.sol#L172-L176
https://github.com/code-423n4/2023-12-ethereumcreditguild/blob/main/src/loan/SimplePSM.sol
The
totalBorrowedCredit
function is reachable from several entry points includingborrow()
,unstake()
,updateMintRatio()
, andapplyGaugeLoss()
. If a large enough loss occurs, all these functions will revert, effectively bricking the protocol.The root cause of this issue is the way
totalBorrowedCredit
is calculated. It subtractsredeemableCredit
fromtargetTotalSupply
. However,redeemableCredit
is calculated using thecreditMultiplier
, which can decrease in the event of a loss. This is incorrect and was not the intention of the developers, as can be understood fromtotalBorrowedCredit()
's documentation. If thecreditMultiplier
is low enough,redeemableCredit
can exceedtargetTotalSupply
, causing the subtraction to underflow and the function to revert.Proof of Concept
Consider the following scenario:
targetTotalSupply
of 300 CREDIT and apegTokenBalance
of 200.creditMultiplier
to decrease to 0.5.redeemableCredit
is 400 (≈pegTokenBalance / creditMultiplier
), which is greater thantargetTotalSupply
.totalBorrowedCredit
now causes an underflow and reverts.This scenario is illustrated in the
testTotalBorrowedCredit_breaks
test below:Tools Used
Foundry
Recommended Mitigation Steps
Do not use the value returned by
redeemableCredit
to calculate thetotalBorrowedCredit
. Instead, use the amount that has been minted through the PSM without scaling.Assessed type
Under/Overflow
The text was updated successfully, but these errors were encountered: