Transaction may revert unexpectedly due to missing allowance for the lending pair asset
The remove leverage function in the LeverageManager contract calculates the borrow shares to repay using a stale interest rate because addInterest does not always update the interest. When repayAsset later accrues interest, the required asset amount exceeds the allowance, causing the transaction to revert. This can prevent a user from reducing leverage and lead to liquidation.
Source: https://github.com/sherlock-audit/2025-01-peapods-finance-judging/issues/504
Found by
TessKimy, X77, pkqs90
Summary
Transaction may revert unexpectedly due to missing allowance for the lending pair asset
Root Cause
In Leverage Manager, remove leverage function firstly updates the interest rate of the lending for proper calculation of repay asset.
&> IFraxlendPair(_lendingPair).addInterest(false);
// if additional fees required for flash source, handle that here
_processExtraFlashLoanPayment(_positionId, _sender);
address _borrowTkn = _getBorrowTknForPod(_positionId);
// needed to repay flash loaned asset in lending pair
// before removing collateral and unwinding
&> IERC20(_borrowTkn).safeIncreaseAllowance(_lendingPair, _borrowAssetAmt);
LeverageFlashProps memory _props;
_props.method = FlashCallbackMethod.REMOVE;
_props.positionId = _positionId;
_props.owner = _owner;
bytes memory _additionalInfo = abi.encode(
&> IFraxlendPair(_lendingPair).totalBorrow().toShares(_borrowAssetAmt, false),
The problem is addInterest function doesn't guarantee interest update because it only updates the interest if utilization rate change threshold is exceed. But in repayAsset function it guarantees interest accrual and the calculations for the share amount will be different than actual.
LeveragePositionProps memory _posProps = positionProps[_props.positionId];
// allowance increases for _borrowAssetAmt prior to flash loaning asset
&> IFraxlendPair(_posProps.lendingPair).repayAsset(_borrowSharesToRepay, _posProps.custodian);
The repayAsset call will revert due to missing allowance because after interest accrual _borrowSharesToRepay value will require more assets than calculated.
Internal Pre-conditions
- Utilization rate change shouldn't exceed the threshold while repayment process
External Pre-conditions
No need
Attack Path
- User is close to liquidation threshold and he wants to reduce leverage for safety
- He calls remove leverage function but it reverts due to issue
- User is liquidated because of price fluctation
Impact
Remove leverage is time-sensitive function because it saves the position from liquidation point and it increases the health of the position. This is why it has to work as expected. In given scenario, user can be liquidated due to unexpected revert in repayment process.
PoC
No response
Mitigation
Instead calculate the share amount using preview interest method
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 uses addInterest which does not guarantee an interest update, leading to an incorrect share calculation that becomes insufficient after repayAsset accrues interest.
Impact
A user attempting to reduce leverage to avoid liquidation may have their transaction revert, potentially leading to liquidation if prices fluctuate.
What the attacker needed
Utilization rate change below threshold
The fix
The share amount should be calculated using a preview interest method that guarantees up-to-date interest accrual.
How it was found
- User calls remove leverage function.
- The function calls addInterest on the lending pair, which may not update interest.
- It calculates borrow shares to repay based on the possibly stale interest.
- It increases allowance for the borrow token by the calculated asset amount.
- The flash loan callback calls repayAsset, which accrues interest and requires more assets than allowed.
- The transaction reverts due to insufficient allowance.
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.
Smart contracts sometimes need to update interest before calculating repayments. Here, the code called a function that only updates interest if a threshold is met, so the calculation used old data. Later, when the actual repayment happened, the interest was updated and the amount needed was higher than what was approved, so the transaction failed.
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.