erc721DecreaseIsolateSupplyOnLiquidate() missing clear lockerAddr
A liquidation routine that returns an NFT to its owner failed to clear the stored locker address on the token record. Because a later deposit does not check that field, the NFT could be re-deposited in cross mode while still marked as locked, and the withdrawal check would then permanently block the owner from taking it out.
Submitted by bin2chen, also found by oakcobalt
When isolateLiquidate(supplyAsCollateral=false) is executed, finally erc721DecreaseIsolateSupplyOnLiquidate() will be executed and the NFT will be transferred to the user.
function erc721DecreaseIsolateSupplyOnLiquidate(
DataTypes.AssetData storage assetData,
uint256[] memory tokenIds
) internal {
for (uint256 i = 0; i < tokenIds.length; i++) {
DataTypes.ERC721TokenData storage tokenData = assetData.erc721TokenData[tokenIds[i]];
require(tokenData.supplyMode == Constants.SUPPLY_MODE_ISOLATE, Errors.INVALID_SUPPLY_MODE);
assetData.userScaledIsolateSupply[tokenData.owner] -= 1;
tokenData.owner = address(0);
tokenData.supplyMode = 0;
@> //missing tokenData.lockerAddr = address(0);
}
assetData.totalScaledIsolateSupply -= tokenIds.length;
}
We know from the above code that this method does not clear the tokenData.lockerAddr, so now tokenData is:
- erc721TokenData[NFT_1].owner = 0
- erc721TokenData[NFT_1].supplyMode = 0
- erc721TokenData[NFT_1].lockerAddr =
address(poolManager)
User Alice has NFT_1; then Alice executes BVault.depositERC721(NFT_1, supplyMode = SUPPLY_MODE_CROSS) will succeed, deposit() does not check lockerAddr.
So tokenData becomes:
- erc721TokenData[NFT_1].owner = Alice
- erc721TokenData[NFT_1].supplyMode =
SUPPLY_MODE_CROSS - erc721TokenData[NFT_1].lockerAddr =
address(poolManager)- not changed.
After that the user’s NFT_ 1 will be locked because withdrawERC721() -> validateWithdrawERC721() will check that lockerAddr must be address(0):
function validateWithdrawERC721(
...
for (uint256 i = 0; i < inputParams.tokenIds.length; i++) {
DataTypes.ERC721TokenData storage tokenData = VaultLogic.erc721GetTokenData(assetData, inputParams.tokenIds[i]);
require(tokenData.owner == inputParams.onBehalf, Errors.INVALID_CALLER);
require(tokenData.supplyMode == inputParams.supplyMode, Errors.INVALID_SUPPLY_MODE);
@> require(tokenData.lockerAddr == address(0), Errors.ASSET_ALREADY_LOCKED_IN_USE);
}
}
Other Isolate methods cannot be operated either.
Note: erc721DecreaseIsolateSupply() is similar.
Impact
Unable to retrieve NFT.
Recommended Mitigation
function erc721DecreaseIsolateSupplyOnLiquidate(
DataTypes.AssetData storage assetData,
uint256[] memory tokenIds
) internal {
for (uint256 i = 0; i < tokenIds.length; i++) {
DataTypes.ERC721TokenData storage tokenData = assetData.erc721TokenData[tokenIds[i]];
require(tokenData.supplyMode == Constants.SUPPLY_MODE_ISOLATE, Errors.INVALID_SUPPLY_MODE);
assetData.userScaledIsolateSupply[tokenData.owner] -= 1;
tokenData.owner = address(0);
tokenData.supplyMode = 0;
+ tokenData.lockerAddr = address(0);
}
assetData.totalScaledIsolateSupply -= tokenIds.length;
}
function erc721DecreaseIsolateSupply(
DataTypes.AssetData storage assetData,
address user,
uint256[] memory tokenIds
) internal {
for (uint256 i = 0; i < tokenIds.length; i++) {
DataTypes.ERC721TokenData storage tokenData = assetData.erc721TokenData[tokenIds[i]];
require(tokenData.supplyMode == Constants.SUPPLY_MODE_ISOLATE, Errors.INVALID_SUPPLY_MODE);
tokenData.owner = address(0);
tokenData.supplyMode = 0;
+ tokenData.lockerAddr = address(0);
}
assetData.totalScaledIsolateSupply -= tokenIds.length;
assetData.userScaledIsolateSupply[user] -= tokenIds.length;
}
Assessed type
Context
thorseldon (BendDAO) confirmed and commented:
Fixed here.
Other
Isolatemethods cannot be operated either.Points out other instances.
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 liquidation and supply-decrease helpers reset owner and supply mode but omit clearing lockerAddr, leaving stale lock state on the token record.
Impact
The NFT becomes stuck in the vault and cannot be retrieved, and other isolate operations on it also fail.
What the attacker needed
NFT supplied in isolate mode; NFT liquidated with supplyAsCollateral false; owner re-deposits the NFT
The fix
The helpers should also reset lockerAddr to the zero address; the project confirmed a fix was applied.
How it was found
- An NFT is supplied in isolate mode and later liquidated with supplyAsCollateral set to false, so the decrease-on-liquidate helper runs.
- The helper zeroes the owner and supply mode but leaves lockerAddr pointing at the pool manager.
- The owner deposits the same NFT again, this time in cross mode, which succeeds because deposit does not check lockerAddr.
- The owner tries to withdraw, but the withdrawal validation requires lockerAddr to be zero and rejects the call.
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.
Each NFT in this lending vault has a small record saying who owns it, how it is being used, and whether some other contract has it locked. When a liquidation handed an NFT back, the code reset the owner and usage fields but forgot the locked flag. The owner could deposit the NFT again, but the vault still thought it was locked, so every attempt to withdraw it was refused.
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.