Skip to content

Commit

Permalink
fix: reentrancy on withdraw
Browse files Browse the repository at this point in the history
  • Loading branch information
The-3D committed Aug 8, 2022
1 parent 9916947 commit 8e6cbc8
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions contracts/protocol/libraries/logic/SupplyLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,22 @@ library SupplyLogic {

reserve.updateInterestRates(reserveCache, params.asset, 0, amountToWithdraw);

bool isCollateral;

if ((isCollateral = userConfig.isUsingAsCollateral(reserve.id))) {
if (amountToWithdraw == userBalance) {
userConfig.setUsingAsCollateral(reserve.id, false);
emit ReserveUsedAsCollateralDisabled(params.asset, msg.sender);
}
}
IAToken(reserveCache.aTokenAddress).burn(
msg.sender,
params.to,
amountToWithdraw,
reserveCache.nextLiquidityIndex
);

if (userConfig.isUsingAsCollateral(reserve.id)) {
if (isCollateral) {
if (userConfig.isBorrowingAny()) {
ValidationLogic.validateHFAndLtv(
reservesData,
Expand All @@ -149,11 +157,6 @@ library SupplyLogic {
params.userEModeCategory
);
}

if (amountToWithdraw == userBalance) {
userConfig.setUsingAsCollateral(reserve.id, false);
emit ReserveUsedAsCollateralDisabled(params.asset, msg.sender);
}
}

emit Withdraw(params.asset, msg.sender, params.to, amountToWithdraw);
Expand Down Expand Up @@ -264,7 +267,12 @@ library SupplyLogic {

if (useAsCollateral) {
require(
ValidationLogic.validateUseAsCollateral(reservesData, reservesList, userConfig, reserveCache.reserveConfiguration),
ValidationLogic.validateUseAsCollateral(
reservesData,
reservesList,
userConfig,
reserveCache.reserveConfiguration
),
Errors.USER_IN_ISOLATION_MODE
);

Expand Down

0 comments on commit 8e6cbc8

Please sign in to comment.