Closed Ed-Marcavage closed 5 months ago
Yep! This is a known issue with the protocol :)
Great find though! I hope you do the security and auditing course, your eye will do well there.
(Keep in mind, this is a suuppppeerrr minimized dummy stablecoin codebase!)
Thank you! I completed your HH course a while back and the auditing course as well; but realized in the process of the auditing course, I need a deeper understanding of solidity & blockchain SWE principles in general, so I am currently going through the 'Advanced Foundry' course, submitting findings for code hacks first flights, and will rewatch the auditing course again in the near future.
Seriously, thank you so much for all this content. I want to get into smart contract security and software security in general, and your content has been a blessing.
Please let me know if this is a known issue, if not, I will be happy to propose a PR/solution. Here is the finding:
In
function liquidate
whentokenAmountFromDebtCovered + bonusCollateral
is greater than the under-collateralized user's balance (i.e.s_collateralDeposited[from][tokenCollateralAddress]
), this causes_redeemCollateral
to throw anarithmetic underflow or overflow error
here:s_collateralDeposited[from][tokenCollateralAddress]-= amountCollateral;
.If prices drop suddenly, this may prevent liquidations.
Test Case (see @see-here comment):
In the test case above, when
ethUsdUpdatedPrice
is set to1100e8
the following variables subtract without issue (in_redeemCollateral
):s_collateralDeposited[from][tokenCollateralAddress] -> 10e18
amountCollateral -> ~99e17
However, when
ethUsdUpdatedPrice
is set to1099e8
, an integer underflow occurs as the reward + collateral is greater than the under-collateralized user's balances_collateralDeposited[from][tokenCollateralAddress] -> 10e18
amountCollateral -> 1000.9e16