User are forced to borrow again in order to unlock their NFTs from IsolateLending.sol
When a borrower redeems their NFT with a redemption threshold set to the maximum, the loan's scaled amount becomes zero but the loan status remains active and the NFT locker address is not cleared. This forces the user to borrow again to unlock their NFT, exposing them to further liquidation risk.
Submitted by Ch_301
Isolated Margin Lending the BendDAO protocol will calculate the health factor based on a single collateral (one NFT), the liquidation of collateral will be achieved by selling the NFT through an auction mechanism.
However, the borrower who gets liquidated (his NFT is in the auction state) still able to repay his loan and close the auction, by triggering IsolateLiquidation.sol#isolateRedeem(). Each asset has a redemption threshold redeemThreshold to define the minimum debt repayment amount by the borrower.
File: IsolateLogic.sol#executeIsolateRedeem()
vars.redeemAmounts[vars.nidx] = vars.borrowAmount.percentMul(nftAssetData.redeemThreshold);
The redeemThreshold is updateable from Configurator.sol#setAssetAuctionParams() with a max value of 10_000. In case the user calls IsolateLiquidation.sol#isolateRedeem() and nftAssetData.redeemThreshold is 10_000 (MAX_REDEEM_THRESHOLD). This will be set scaledAmount to zero.
File: IsolateLogic.sol#executeIsolateRedeem()
loanData.scaledAmount -= vars.amountScaled;
This means the debt is fully paid; however,
- The
loanData.loanStatuswill still be in active stateConstants.LOAN_STATUS_ACTIVE. - The
erc721TokenData.LockerAddris not updated toaddress(0).
So, the user is not able to withdraw his NFT from BVault.sol or even update the loan state and LockerAddr values through IsolateLending.sol#isolateRepay() due to this check
Note: The only way the user can unlock his NFT is by borrowing again. This will increase loanData.scaledAmount again to greater than zero, and then he needs to repay that loan IsolateLending.sol#isolateRepay() to update the erc721TokenData.LockerAddr to address(0). This will expose the user to the unnecessary risk of being liquidated again.
Impact
Users are forced to borrow again to unlock their NFTs after Isolate Redeem.
Proof of Concept
Foundry PoC - Please copy the following POC in TestIntIsolateRedeem.t.sol:
function test_Withdraw_After_Full_Redeem_Should_Revert() public {
TestCaseLocalVars memory testVars;
tsHEVM.startPrank(tsPoolAdmin);
tsConfigurator.setAssetAuctionParams(tsCommonPoolId, address(tsBAYC), 10000, 500, 2000, 1 days);
tsHEVM.stopPrank();
// deposit
prepareUSDT(tsDepositor1);
uint256[] memory tokenIds = prepareIsolateBAYC(tsBorrower1);
// borrow
prepareBorrow(tsBorrower1, address(tsBAYC), tokenIds, address(tsUSDT));
// make some interest
advanceTimes(365 days);
// drop down nft price
actionSetNftPrice(address(tsBAYC), 5000);
// auction
prepareAuction(tsLiquidator1, address(tsBAYC), tokenIds, address(tsUSDT));
uint256[] memory redeemAmounts = new uint256[](tokenIds.length);
testVars.loanDataBefore = getIsolateLoanData(tsCommonPoolId, address(tsBAYC), tokenIds);
for (uint256 i = 0; i < tokenIds.length; i++) {
testVars.totalBidAmount += testVars.loanDataBefore[i].bidAmount;
testVars.totalBidFine += testVars.loanDataBefore[i].bidFine;
testVars.totalRedeemAmount += testVars.loanDataBefore[i].redeemAmount;
redeemAmounts[i] = testVars.loanDataBefore[i].redeemAmount;
}
testVars.poolBalanceBefore = tsUSDT.balanceOf(address(tsPoolManager));
testVars.walletBalanceBefore1 = tsUSDT.balanceOf(address(tsLiquidator1));
testVars.walletBalanceBefore2 = tsUSDT.balanceOf(address(tsBorrower1));
// redeem
tsBorrower1.approveERC20(address(tsUSDT), type(uint256).max);
tsBorrower1.isolateRedeem(tsCommonPoolId, address(tsBAYC), tokenIds, address(tsUSDT), redeemAmounts);
testVars.txAuctionTimestamp = block.timestamp;
// check results
testVars.loanDataAfter = getIsolateLoanData(tsCommonPoolId, address(tsBAYC), tokenIds);
for (uint256 i = 0; i < tokenIds.length; i++) {
assertEq(testVars.loanDataAfter[i].bidStartTimestamp, 0, 'bidStartTimestamp');
assertEq(testVars.loanDataAfter[i].firstBidder, address(0), 'firstBidder');
assertEq(testVars.loanDataAfter[i].lastBidder, address(0), 'lastBidder');
assertEq(testVars.loanDataAfter[i].bidAmount, 0, 'bidAmount');
assertEq(testVars.loanDataAfter[i].scaledAmount, 0, 'scaledAmount');
}
tsHEVM.expectRevert(bytes(Errors.ASSET_ALREADY_LOCKED_IN_USE));
tsBorrower1.withdrawERC721(
tsCommonPoolId,
address(tsBAYC),
tokenIds,
Constants.SUPPLY_MODE_ISOLATE,
address(tsBorrower1),
address(tsBorrower1)
);
}
Tools Used
Foundry
Recommended Mitigation Steps
In case loanData.scaledAmount == 0 call VaultLogic.erc721SetTokenLockerAddr(nftAssetData, params.nftTokenIds[vars.nidx], address(0));.
thorseldon (BendDAO) confirmed and commented:
Fixed here.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely, the code does not clear the loan status and the NFT locker address when the scaled amount becomes zero after a full redemption.
Impact
Users are forced to borrow again to unlock their NFTs after Isolate Redeem, exposing them to unnecessary risk of being liquidated again.
What the attacker needed
RedeemThreshold set to 10,000; borrower has an active isolate loan; NFT is in auction state
The fix
The code was fixed to clear the NFT locker address when the scaled amount is zero.
How it was found
- Set the asset auction parameters so that redeemThreshold is 10,000 (the maximum).
- Deposit USDT and prepare an isolate BAYC NFT for borrowing.
- Borrow USDT using the NFT as collateral.
- Advance time to accrue interest and drop the NFT price to trigger an auction.
- Prepare an auction by a liquidator.
- Call isolateRedeem to repay the loan and close the auction.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In this lending system, when a borrower repays enough to redeem their NFT, the system should mark the loan as closed and release the NFT. But if the repayment percentage is set to 100%, the system zeroes the debt but forgets to update the loan status and the record that locks the NFT. So the NFT stays locked, and the only way to unlock it is to take another loan and repay it.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.