-
Notifications
You must be signed in to change notification settings - Fork 8
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -234,7 +234,7 @@ contract CreditFacadeV3 is ICreditFacadeV3, ACLNonReentrantTrait { | |
/// - Erases all bots permissions | ||
/// @param creditAccount Account to close | ||
/// @param calls List of calls to perform before closing the account | ||
/// @dev Reverts if caller is not `creditAccount`'s owner | ||
/// @dev Reverts if `creditAccount` is not opened in connected credit manager by caller | ||
/// @dev Reverts if facade is paused | ||
/// @dev Reverts if account has enabled tokens after executing `calls` | ||
/// @dev Reverts if account's debt is not zero after executing `calls` | ||
|
@@ -296,7 +296,7 @@ contract CreditFacadeV3 is ICreditFacadeV3, ACLNonReentrantTrait { | |
whenNotPausedOrEmergency // U:[FA-2,12] | ||
nonReentrant // U:[FA-4] | ||
{ | ||
address borrower = _getBorrowerOrRevert(creditAccount); // U:[FA-5] | ||
_getBorrowerOrRevert(creditAccount); // U:[FA-5] | ||
|
||
uint256 skipCalls = _applyOnDemandPriceUpdates(calls); | ||
|
||
|
@@ -343,7 +343,7 @@ contract CreditFacadeV3 is ICreditFacadeV3, ACLNonReentrantTrait { | |
isExpired: isExpired | ||
}); // U:[FA-16] | ||
|
||
emit LiquidateCreditAccount(creditAccount, borrower, msg.sender, to, remainingFunds); // U:[FA-14,16,17] | ||
emit LiquidateCreditAccount(creditAccount, msg.sender, to, remainingFunds); // U:[FA-14,16,17] | ||
|
||
if (reportedLoss != 0) { | ||
maxDebtPerBlockMultiplier = 0; // U:[FA-17] | ||
|
@@ -364,7 +364,7 @@ contract CreditFacadeV3 is ICreditFacadeV3, ACLNonReentrantTrait { | |
/// - Runs the collateral check | ||
/// @param creditAccount Account to perform the calls on | ||
/// @param calls List of calls to perform | ||
/// @dev Reverts if caller is not `creditAccount`'s owner | ||
/// @dev Reverts if `creditAccount` is not opened in connected credit manager by caller | ||
/// @dev Reverts if credit facade is paused or expired | ||
function multicall(address creditAccount, MultiCall[] calldata calls) | ||
external | ||
|
@@ -386,6 +386,7 @@ contract CreditFacadeV3 is ICreditFacadeV3, ACLNonReentrantTrait { | |
/// @param creditAccount Account to perform the calls on | ||
/// @param calls List of calls to perform | ||
/// @dev Reverts if credit facade is paused or expired | ||
/// @dev Reverts if `creditAccount` is not opened in connected credit manager | ||
/// @dev Reverts if calling bot is forbidden or has no permissions to manage `creditAccount` | ||
function botMulticall(address creditAccount, MultiCall[] calldata calls) | ||
external | ||
|
@@ -394,6 +395,8 @@ contract CreditFacadeV3 is ICreditFacadeV3, ACLNonReentrantTrait { | |
whenNotExpired // U:[FA-3] | ||
nonReentrant // U:[FA-4] | ||
{ | ||
_getBorrowerOrRevert(creditAccount); // U:[FA-5] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, |
||
|
||
(uint256 botPermissions, bool forbidden, bool hasSpecialPermissions) = IBotListV3(botList).getBotStatus({ | ||
bot: msg.sender, | ||
creditManager: creditManager, | ||
|
@@ -414,7 +417,7 @@ contract CreditFacadeV3 is ICreditFacadeV3, ACLNonReentrantTrait { | |
/// @param creditAccount Account to set permissions for | ||
/// @param bot Bot to set permissions for | ||
/// @param permissions A bit mask encoding bot permissions | ||
/// @dev Reverts if caller is not `creditAccount`'s owner | ||
/// @dev Reverts if `creditAccount` is not opened in connected credit manager by caller | ||
/// @dev Reverts if `permissions` has unexpected bits enabled | ||
/// @dev Reverts if account has more active bots than allowed after changing permissions | ||
/// @dev Changes account's `BOT_PERMISSIONS_SET_FLAG` in the credit manager if needed | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -211,7 +211,7 @@ contract CreditManagerV3 is ICreditManagerV3, SanityCheckTrait, ReentrancyGuardT | |
|
||
/// @notice Closes a credit account | ||
/// @param creditAccount Account to close | ||
/// @custom:expects Account is opened in this credit manager | ||
/// @custom:expects Credit facade ensures that `creditAccount` is opened in this credit manager | ||
function closeCreditAccount(address creditAccount) | ||
external | ||
override | ||
|
@@ -249,7 +249,7 @@ contract CreditManagerV3 is ICreditManagerV3, SanityCheckTrait, ReentrancyGuardT | |
/// @param to Address to transfer underlying left after liquidation | ||
/// @return remainingFunds Total value of assets left on the account after liquidation | ||
/// @return loss Loss incurred on liquidation | ||
/// @custom:expects Account is opened in this credit manager | ||
/// @custom:expects Credit facade ensures that `creditAccount` is opened in this credit manager | ||
/// @custom:expects `collateralDebtData` is a result of `calcDebtAndCollateral` in `DEBT_COLLATERAL` mode | ||
function liquidateCreditAccount( | ||
address creditAccount, | ||
|
@@ -630,7 +630,10 @@ contract CreditManagerV3 is ICreditManagerV3, SanityCheckTrait, ReentrancyGuardT | |
/// @notice Whether `creditAccount`'s health factor is below `minHealthFactor` | ||
/// @param creditAccount Credit account to check | ||
/// @param minHealthFactor Health factor threshold in bps | ||
/// @dev Reverts if account is not opened in this credit manager | ||
function isLiquidatable(address creditAccount, uint16 minHealthFactor) external view override returns (bool) { | ||
getBorrowerOrRevert(creditAccount); // U:[CM-17] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Explicitly reverting is better than relying on some underflow later. |
||
|
||
uint256[] memory collateralHints; | ||
CollateralDebtData memory cdd = _calcDebtAndCollateral({ | ||
creditAccount: creditAccount, | ||
|
@@ -648,6 +651,7 @@ contract CreditManagerV3 is ICreditManagerV3, SanityCheckTrait, ReentrancyGuardT | |
/// @param creditAccount Credit account to return data for | ||
/// @param task Calculation mode, see `CollateralCalcTask` for details, can't be `FULL_COLLATERAL_CHECK_LAZY` | ||
/// @return cdd A struct with debt and collateral data | ||
/// @dev Reverts if account is not opened in this credit manager | ||
/// @custom:invariant From `creditAccountInfo[creditAccount].debt == 0` it follows that `cdd.totalDebtUSD == 0` | ||
function calcDebtAndCollateral(address creditAccount, CollateralCalcTask task) | ||
external | ||
|
@@ -660,12 +664,13 @@ contract CreditManagerV3 is ICreditManagerV3, SanityCheckTrait, ReentrancyGuardT | |
} | ||
|
||
bool useSafePrices; | ||
|
||
if (task == CollateralCalcTask.DEBT_COLLATERAL_SAFE_PRICES) { | ||
task = CollateralCalcTask.DEBT_COLLATERAL; | ||
useSafePrices = true; | ||
} | ||
|
||
getBorrowerOrRevert(creditAccount); // U:[CM-17] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Explicitly reverting is better than relying on some underflow later. |
||
|
||
uint256[] memory collateralHints; | ||
cdd = _calcDebtAndCollateral({ | ||
creditAccount: creditAccount, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
borrower
is removed fromLiquidateCreditAccount
event, and the check is now performed incalcDebtAndCollateral
(additional safe-guard isrequire(debt != 0)
below).