PositionAction4626::increaseLever will always revert
The increaseLever function for ERC4626 collateral positions always reverts because the flash loan callback deposits collateral into the vault under the wrong address, leaving no funds for a second deposit attempt. This blocks users from increasing leverage on their positions.
0xAlix2 Follow with web3km, zhaojohnson and 6 others
Originally disclosed on Code4rena
Submitted by 0xAlix2, also found by web3km, zhaojohnson, Nyx, 0xbepresent, joaovwfreire, hash, pkqs90, and nnez
Users can use PositionAction::increaseLever to increase their positions’ leverage, i.e., increasing both the collateral and debt, by taking a flash loan and doing some swaps. At the end of the process, after swapping “borrow” tokens to underlying tokens they should be returned to the vault under the position’s “name”.
For ERC20 collateral positions, this is happening in PositionAction20::_onIncreaseLever (that gets called in PositionAction::onFlashLoan) which approves the vault to spend some amount and then returns the amount to be later sent using the following in PositionAction::onFlashLoan:
// add collateral and debt
ICDPVault(leverParams.vault).modifyCollateralAndDebt(
leverParams.position,
address(this),
address(this),
toInt256(collateral),
toInt256(addDebt)
);
However, for ERC4626 collateral positions, PositionAction4626::_onIncreaseLever is both approving the amount and depositing it into the vault under address(this) which IS NOT the position’s proxy but PositionAction4626 contract as it is the flash loan callback function and isn’t delegated like increaseLever. When _onIncreaseLever finishes, it’ll try to deposit the collateral AGAIN in the vault using this; which will for sure revert, as the approval was spent and no funds are left to make the deposit.
This will cause PositionAction4626::increaseLever to always revert and never work, blocking users from leveraging their positions.
Proof of Concept
contract PositionAction4626_Lever_Test is IntegrationTestBase {
using SafeERC20 for ERC20;
PRBProxy userProxy;
address user;
uint256 constant userPk = 0x12341234;
CDPVault vault;
StakingLPEth stakingLPEth;
PositionAction4626 positionAction;
PermitParams emptyPermitParams;
SwapParams emptySwap;
PoolActionParams emptyPoolActionParams;
bytes32[] weightedPoolIdArray;
function setUp() public override {
super.setUp();
setGlobalDebtCeiling(15_000_000 ether);
stakingLPEth = new StakingLPEth(address(token), "Staking LP ETH", "sLPETH");
vault = createCDPVault(stakingLPEth, 5_000_000 ether, 0, 1.25 ether, 1.0 ether, 1.05 ether);
createGaugeAndSetGauge(address(vault));
gauge.addQuotaToken(address(stakingLPEth), 10, 100);
user = vm.addr(0x12341234);
userProxy = PRBProxy(payable(address(prbProxyRegistry.deployFor(user))));
positionAction = new PositionAction4626(
address(flashlender),
address(swapAction),
address(poolAction),
address(vaultRegistry)
);
oracle.updateSpot(address(token), 1 ether);
oracle.updateSpot(address(stakingLPEth), 1 ether);
weightedPoolIdArray.push(weightedUnderlierPoolId);
}
function test_increaseLeverDOS() public {
uint256 amount = 200 ether;
deal(address(token), user, amount);
address[] memory assets = new address[](2);
assets[0] = address(underlyingToken);
assets[1] = address(token);
vm.startPrank(user);
// Approvals
token.approve(address(stakingLPEth), amount);
stakingLPEth.approve(address(vault), amount);
// Deopsit token to get sLPETH
stakingLPEth.deposit(amount, user);
// Deposit sLPETH to vault
vault.deposit(address(userProxy), amount);
// Borrow underlying tokens
userProxy.execute(
address(positionAction),
abi.encodeWithSelector(
positionAction.borrow.selector,
address(userProxy),
address(vault),
CreditParams({amount: amount / 2, creditor: user, auxSwap: emptySwap})
)
);
// Increase leverage will always revert
vm.expectRevert(bytes("ERC20: insufficient allowance"));
userProxy.execute(
address(positionAction),
abi.encodeWithSelector(
positionAction.increaseLever.selector,
LeverParams({
position: address(userProxy),
vault: address(vault),
collateralToken: address(stakingLPEth),
primarySwap: SwapParams({
swapProtocol: SwapProtocol.BALANCER,
swapType: SwapType.EXACT_IN,
assetIn: address(underlyingToken),
amount: amount / 2,
limit: 0,
recipient: address(positionAction),
deadline: block.timestamp,
args: abi.encode(weightedPoolIdArray, assets)
}),
auxSwap: emptySwap,
auxAction: emptyPoolActionParams
}),
address(0),
0,
address(user),
emptyPermitParams
)
);
}
}
Recommended Mitigation Steps
In PositionAction4626::_onIncreaseLever, replace:
return ICDPVault(leverParams.vault).deposit(address(this), addCollateralAmount);
with:
return addCollateralAmount;
Assessed type
DoS
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 ERC4626-specific increaseLever handler deposits the collateral into the vault under the PositionAction4626 contract's address instead of returning the amount for the caller to deposit under the position's proxy, causing a double-deposit attempt that fails.
What the attacker needed
User has an ERC4626 collateral position; User attempts to increase leverage
How it was found
- User deposits tokens to get sLPETH and then deposits sLPETH into the vault.
- User borrows underlying tokens via the position proxy.
- User calls increaseLever on the position action with a flash loan and swap parameters.
- The transaction reverts with an insufficient allowance error.
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 use a flash loan to increase leverage, the contract temporarily borrows tokens, swaps them, and then tries to add them as collateral. For a special type of collateral (ERC4626), the contract mistakenly deposits the tokens under its own address instead of the user's position, so when it later tries to deposit again, there is nothing left and the whole transaction fails. This means users can never increase leverage on such positions.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.