Borrower can prevent yield position repayment and closure by the bot
A borrower can revoke the ERC20 approval that the yield contract relies on to pull extra funds needed to cover the debt and fines, preventing the botAdmin from repaying and closing the position. As a result, the debt remains unpaid and continues to accrue interest, causing a loss to the protocol.
SpicyMeatball Follow with 0x73696d616f
Originally disclosed on Code4rena
Submitted by SpicyMeatball, also found by 0x73696d616f
User may revoke the underlying asset approval from the yield contract and prevent the botAdmin from repaying and closing his position. As a result, the debt will not be repaid, leaving the protocol at a loss.
Proof of Concept
Let’s take a closer look at the _repay function:
function _repay(uint32 poolId, address nft, uint256 tokenId) internal virtual {
RepayLocalVars memory vars;
---SNIP---
// withdraw yield from protocol and repay if possible
vars.claimedYield = protocolClaimWithdraw(sd);
vars.nftDebt = _getNftDebtInUnderlyingAsset(sd);
vars.nftDebtWithFine = vars.nftDebt + sd.unstakeFine;
// compute repay value
if (vars.claimedYield >= vars.nftDebtWithFine) {
vars.remainAmount = vars.claimedYield - vars.nftDebtWithFine;
} else {
>> vars.extraAmount = vars.nftDebtWithFine - vars.claimedYield;
}
// transfer eth from sender
if (vars.extraAmount > 0) {
>> underlyingAsset.safeTransferFrom(vars.nftOwner, address(this), vars.extraAmount);
}
if (vars.remainAmount > 0) {
underlyingAsset.safeTransfer(vars.nftOwner, vars.remainAmount);
}
// repay lending pool
poolYield.yieldRepayERC20(poolId, address(underlyingAsset), vars.nftDebt);
poolYield.yieldSetERC721TokenData(poolId, nft, tokenId, false, address(underlyingAsset));
// update shares
accountYieldInWithdraws[address(vars.yieldAccout)] -= sd.withdrawAmount;
totalDebtShare -= sd.debtShare;
delete stakeDatas[nft][tokenId];
emit Repay(msg.sender, nft, tokenId, vars.nftDebt);
}
If the yield collected by the position is not enough to cover the entire debt and fines, the protocol will attempt to collect extraAmount from the position owner, but he may revoke ERC20 approval and cancel the safeTransferFrom function call. As a result, nftDebt will not be repaid and will continue to collect interest, increasing the protocol’s losses.
Recommended Mitigation Steps
It is recommended to separate the logic of debt repayment and NFT unlocking. The _repay function will reduce the debt of the position using the collected yield and unlock the NFT only if extraAmount is zero. In case extraAmount is greater than zero, leave the token locked and allow the NFT owner to unlock it only after he has repaid the remaining debt.
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 repayment logic assumes the borrower's ERC20 approval will remain in place, so a borrower can block the extra transfer by revoking approval.
Impact
The debt will not be repaid and will continue to collect interest, increasing the protocol's losses.
What the attacker needed
Borrower has a yield position with debt; borrower can revoke ERC20 approval
The fix
The repayment and NFT unlocking logic should be separated: reduce debt with collected yield and only unlock the NFT when no extra amount is needed; otherwise keep the token locked until the remaining debt is repaid.
How it was found
- The borrower has a yield position with debt and fines exceeding the collected yield.
- The borrower revokes the ERC20 approval for the underlying asset.
- The botAdmin attempts to repay and close the position.
- The safeTransferFrom call for the extra amount fails, so the debt is not repaid.
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.
When a borrower's yield earnings are not enough to cover their debt, the protocol tries to take the extra amount from the borrower's wallet using a pre-approved transfer. The borrower can cancel that approval, so the transfer fails and the debt is never repaid. The protocol then loses money because the debt keeps growing with interest.
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.