User may lose funds if they call `BalancerRouter::joinBalancerAndPredeposit`
The BalancerRouter contract calls PreDeposit.deposit, which caps the deposited amount at the reserve cap and leaves any excess tokens with the router instead of refunding the user. An attacker could cause a user to lose funds when the deposit exceeds the remaining cap.
056Security Follow with 0x23r0, 0xDemon and 22 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-12-plaza-finance-judging/issues/278
This issue has been acknowledged by the team but won't be fixed at this time.
Found by
056Security, 0x23r0, 0xDemon, 0xShahilHussain, 0xc0ffEE, Adotsam, JohnTPark24, Kenn.eth, Kirkeelee, MysteryAuditor, Pablo, X0sauce, Xcrypt, ZeroTrust, ZoA, bladeee, dobrevaleri, farismaulana, future, hrmneffdii, makeWeb3safe, phoenixv110, super_jack, tutiSec, y4y
Summary
BalancerRouter::joinBalancerAndPredeposit calls Predeposit::deposit to deposit balancerPoolTokens into the Predeposit contract. In the Predeposit::deposit if reserveAmount + amount > reserveCap, the difference is deposited and the rest remains with msg.sender, which in this case is the BalancerRouter.
The user will have less than expected amount deposited in Predeposit without getting refund for the rest of the funds.
function _deposit(uint256 amount, address onBehalfOf) private checkDepositStarted checkDepositNotEnded {
if (reserveAmount >= reserveCap) revert DepositCapReached();
address recipient = onBehalfOf == address(0) ? msg.sender : onBehalfOf;
// if user would like to put more than available in cap, fill the rest up to cap and add that to reserves
@> if (reserveAmount + amount >= reserveCap) {
@> amount = reserveCap - reserveAmount;
}
balances[recipient] += amount;
reserveAmount += amount;
IERC20(params.reserveToken).safeTransferFrom(msg.sender, address(this), amount);
emit Deposited(recipient, amount);
}
Root Cause
No response
Internal Pre-conditions
No response
External Pre-conditions
No response
Attack Path
Assume reserveCap is 1,000 BPT and reserveAmount is 900BPT
User calls BalancerRouter::joinBalancerAndPredeposit and deposits assets worth 500 BPT
Only 100 BPT is deposited and users loses 400 BPT which is trapped inside the contract.
Impact
Loss of funds
PoC
No response
Mitigation
function joinBalancerAndPredeposit(
bytes32 balancerPoolId,
address _predeposit,
IAsset[] memory assets,
uint256[] memory maxAmountsIn,
bytes memory userData
) external nonReentrant returns (uint256) {
// Step 1: Join Balancer Pool
uint256 balancerPoolTokenReceived = joinBalancerPool(balancerPoolId, assets, maxAmountsIn, userData);
// Step 2: Approve balancerPoolToken for PreDeposit
balancerPoolToken.safeIncreaseAllowance(_predeposit, balancerPoolTokenReceived);
+ uint256 BPTBalanceBefore = balancerPoolToken.balanceOf(address(this));
// Step 3: Deposit to PreDeposit
PreDeposit(_predeposit).deposit(balancerPoolTokenReceived, msg.sender);
+ uint256 BPTBalanceAfter = balancerPoolToken.balanceOf(address(this));
+ if (BPTBalanceAfter - BPTBalanceBefore > 0) {
+ revert ( 'ReserveCap Reached` ); }
return balancerPoolTokenReceived;
}
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 router does not check whether the deposit was capped and does not refund the excess tokens to the user.
Impact
Users could lose funds because excess tokens remain stuck in the router contract.
What the attacker needed
ReserveAmount close to reserveCap; user deposits more than remaining cap
The fix
The router should check whether the deposit was capped and revert if any tokens remain, as suggested in the mitigation.
How it was found
- Assume reserveCap is 1,000 BPT and reserveAmount is 900 BPT.
- User calls BalancerRouter::joinBalancerAndPredeposit and deposits assets worth 500 BPT.
- Only 100 BPT is deposited and the user loses 400 BPT which is trapped inside the contract.
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 deposit money into a savings pot that has a maximum limit, the system should only take what fits and return the rest. Here, the system takes only what fits but keeps the extra money stuck in a middleman contract, so the user loses it.
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.