PositionAction4626.sol#_onWithdraw should withdraw from position CDPVault position instead of address(this)
The _onWithdraw function in PositionAction4626.sol withdraws collateral from the contract's own address instead of the specified position, meaning withdrawals are taken from the wrong CDPVault position. An attacker could potentially withdraw funds from an unintended position, though the exact impact is not detailed.
Submitted by pkqs90
Note: This is based on the 2024-07 Loopfi audit M-35 issue. This protocol team applied a fix, but the fix is incomplete.
Only the bug in the _onDeposit() was fixed, but not the one in _onWithdraw(). PositionAction4626.sol#_onWithdraw does not withdraw from the correct position, it should withdraw from position instead of address(this).
function _onDeposit(address vault, address position, address src, uint256 amount) internal override returns (uint256) {
address collateral = address(ICDPVault(vault).token());
// if the src is not the collateralToken, we need to deposit the underlying into the ERC4626 vault
if (src != collateral) {
address underlying = IERC4626(collateral).asset();
IERC20(underlying).forceApprove(collateral, amount);
amount = IERC4626(collateral).deposit(amount, address(this));
}
IERC20(collateral).forceApprove(vault, amount);
// @audit-note: This was fixed.
return ICDPVault(vault).deposit(position, amount);
}
function _onWithdraw(
address vault,
address /*position*/,
address dst,
uint256 amount
) internal override returns (uint256) {
// @audit-note: This is still a bug.
@> uint256 collateralWithdrawn = ICDPVault(vault).withdraw(address(this), amount);
// if collateral is not the dst token, we need to withdraw the underlying from the ERC4626 vault
address collateral = address(ICDPVault(vault).token());
if (dst != collateral) {
collateralWithdrawn = IERC4626(collateral).redeem(collateralWithdrawn, address(this), address(this));
}
return collateralWithdrawn;
}
Recommended Mitigation Steps
- uint256 collateralWithdrawn = ICDPVault(vault).withdraw(address(this), amount);
+ uint256 collateralWithdrawn = ICDPVault(vault).withdraw(position, amount);
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 _onWithdraw function passes address(this) as the position argument to ICDPVault.withdraw instead of the intended position parameter.
Impact
Could allow withdrawal from an incorrect position, potentially affecting other users' funds or causing accounting errors.
What the attacker needed
Access to withdraw function
The fix
The fix is to change the withdraw call to use the position parameter instead of address(this).
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.
This is a smart contract bug where a function that handles withdrawals uses the wrong account. Instead of taking funds from the user's specific position, it takes them from the contract's own address, which could mix up funds between users.
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.