Transferring of _userProvidedDebtAmtMax does not work in _acquireBorrowTokenForRepayment because _props.sender is never set, which leads to a transferFrom call from address(0), causing the transaction to revert
The function `_acquireBorrowTokenForRepayment` attempts to transfer tokens from `_props.sender`, which is never set, so the transfer is from the zero address and reverts. This prevents users from providing their own tokens to repay a flash loan, causing `removeLeverage` to fail when the alternative swap method is unavailable.
Source: https://github.com/sherlock-audit/2025-01-peapods-finance-judging/issues/299
Found by
Schnilch, X77, bretzel, ck
Summary
In _acquireBorrowTokenForRepayment, a user can specify how many tokens they are willing to provide using _userProvidedDebtAmtMax if there are not enough tokens to repay the flash loan. However, this does not work because the transfer is attempted from _props.sender, which was never set. As a result, removeLeverage, which relies on this function, reverts.
Root Cause
removeLeverage in the LeverageManager uses _acquireBorrowTokenForRepayment to obtain tokens for repaying the flash loan if there are currently not enough. Here, a user can specify a maximum amount they are willing to provide:
https://github.com/sherlock-audit/2025-01-peapods-finance/blob/main/contracts/contracts/lvf/LeverageManager.sol#L423-L430
Here, you can see that the amount the user is willing to provide is transferred from _props.sender. The problem is that _props.sender is never set. Only _props.owner is set at the beginning of the removeLeverage function:
https://github.com/sherlock-audit/2025-01-peapods-finance/blob/main/contracts/contracts/lvf/LeverageManager.sol#L177-L180
This causes _props.sender in _acquireBorrowTokenForRepayment to be address(0), which leads to the transfer reverting since nothing can be transferred from address(0).
It is also important to note that there is another way to acquire the borrow tokens, but it does not always work, as I explained in Issue "Swapping in _acquireBorrowTokenForRepayment is not working when the sell fee is enabled because the swap does not support fee-on-transfer tokens". This makes this issue even more critical.
Internal Pre-conditions
No preconditions, this feature does not work regardless of how the protocol is configured.
External Pre-conditions
No external pre-conditions
Attack Path
- Alice bonds PEAS tokens
- With the received pTKNs, Alice calls
addLeverage - Alice wants to call removeLeverage and provides a
_userProvidedDebtAmtMax. The call reverts because the transfer fails
Impact
A feature of the protocol is not working, which prevents users from providing a portion of the repayment amount for the flash loan themselves. This can lead to users being unable to remove their leverage, especially if the swap doesn't work, for example, due to slippage or the other issue I mentioned above.
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 `_props.sender` to identify the user providing tokens, but only `_props.owner` is set, leaving `_props.sender` as the zero address.
Impact
A feature of the protocol is not working, which prevents users from providing a portion of the repayment amount for the flash loan themselves. This can lead to users being unable to remove their leverage, especially if the swap doesn't work, for example, due to slippage or the other issue I mentioned above.
What the attacker needed
User has leveraged position; User calls removeLeverage with _userProvidedDebtAmtMax
The fix
The code should set `_props.sender` to the user's address (e.g., `msg.sender`) before calling `_acquireBorrowTokenForRepayment`.
How it was found
- Alice bonds PEAS tokens
- With the received pTKNs, Alice calls `addLeverage`
- Alice wants to call removeLeverage and provides a `_userProvidedDebtAmtMax`. The call reverts because the transfer fails
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 you remove leverage, the contract sometimes needs you to supply extra tokens to repay a flash loan. The code tries to take those tokens from an address that was never filled in, so the transfer fails and the whole action is cancelled. This means you cannot use that feature at all.
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.