Skip to content
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

fix: add more explicit account existence checks #158

Merged
merged 2 commits into from
Nov 24, 2023

Conversation

lekhovitsky
Copy link
Collaborator

No description provided.

0xmikko
0xmikko previously approved these changes Nov 22, 2023
/// @dev Reverts if remaining token balances increase during the multicall
function liquidateCreditAccount(address creditAccount, address to, MultiCall[] calldata calls)
external
override
whenNotPausedOrEmergency // U:[FA-2,12]
nonReentrant // U:[FA-4]
{
address borrower = _getBorrowerOrRevert(creditAccount); // U:[FA-5]
Copy link
Collaborator Author

@lekhovitsky lekhovitsky Nov 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

borrower is removed from LiquidateCreditAccount event, and the check is now performed in calcDebtAndCollateral (additional safe-guard is require(debt != 0) below).


(uint256 remainingFunds, uint256 reportedLoss) = ICreditManagerV3(creditManager).liquidateCreditAccount({
creditAccount: creditAccount,
collateralDebtData: collateralDebtData,
to: to,
isExpired: isExpired
}); // U:[FA-16]
isExpired: !isUnhealthy
Copy link
Collaborator Author

@lekhovitsky lekhovitsky Nov 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, since it didn't revert earlier, the account is either unhealthy, expired, or both. Expired liquidation is only performed when it's not unhealthy (this is equivalent to what we had earlier).

Comment on lines +304 to 307
bool isUnhealthy = collateralDebtData.twvUSD < collateralDebtData.totalDebtUSD;
if (collateralDebtData.debt == 0 || !isUnhealthy && !_isExpired()) {
revert CreditAccountNotLiquidatableException(); // U:[FA-13]
}
Copy link
Collaborator Author

@lekhovitsky lekhovitsky Nov 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much cleaner this way. Besides, collateralDebtData.debt == 0 is now checked in all cases, not only in healthy-expired one.

@@ -394,6 +388,8 @@ contract CreditFacadeV3 is ICreditFacadeV3, ACLNonReentrantTrait {
whenNotExpired // U:[FA-3]
nonReentrant // U:[FA-4]
{
_getBorrowerOrRevert(creditAccount); // U:[FA-5]
Copy link
Collaborator Author

@lekhovitsky lekhovitsky Nov 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absence of this could have been a problem with addition of special bots (for normal bots, permissions != 0 implies account existence).

@lekhovitsky lekhovitsky requested a review from 0xmikko November 23, 2023 15:30
function isLiquidatable(address creditAccount, uint16 minHealthFactor) external view override returns (bool) {
getBorrowerOrRevert(creditAccount); // U:[CM-17]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicitly reverting is better than relying on some underflow later.

if (task == CollateralCalcTask.DEBT_COLLATERAL_SAFE_PRICES) {
task = CollateralCalcTask.DEBT_COLLATERAL;
useSafePrices = true;
}

getBorrowerOrRevert(creditAccount); // U:[CM-17]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicitly reverting is better than relying on some underflow later.

@lekhovitsky lekhovitsky dismissed 0xmikko’s stale review November 23, 2023 15:32

additional updates

@lekhovitsky lekhovitsky merged commit 548ee13 into main Nov 24, 2023
2 checks passed
Copy link

🎉 This PR is included in version 1.45.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@lekhovitsky lekhovitsky deleted the account-existence-checks branch November 24, 2023 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants