BalancerRouter is implemented incorrectly and will cause loss of funds when depositing to predeposits
The BalancerRouter contract hard-codes a single Balancer pool token address, so when a user joins any other pool the router measures a zero balance change and deposits nothing into the preDeposit contract. The newly minted pool tokens are left stranded in the router, causing a permanent loss of the user's funds.
Source: https://github.com/sherlock-audit/2024-12-plaza-finance-judging/issues/455
This issue has been acknowledged by the team but won't be fixed at this time.
Found by
0x52, wellbyt3
Summary
The balancerRouter is intended to work with multiple balancers pools but it is implemented incorrect and can only works correctly with a single pool. This is because the balancerPoolToken is hard coded to a single pool token. This makes the balanceOf check highly dangerous when depositing to preDeposit contracts. Only the hardcoded token balance is checked, causing all of the desired BPT to become stuck. This will result in user funds becoming permanently lost.
IVault public immutable balancerVault;
@> IERC20 public immutable balancerPoolToken;
constructor(address _balancerVault, address _balancerPoolToken) {
balancerVault = IVault(_balancerVault);
@> balancerPoolToken = IERC20(_balancerPoolToken);
}
We see above that balancerPoolToken is an immutable variable set during construction.
function joinBalancerPool(
bytes32 poolId,
IAsset[] memory assets,
uint256[] memory maxAmountsIn,
bytes memory userData
) internal returns (uint256) {
... SNIP
// Join Balancer pool
@> uint256 balancerPoolTokenBalanceBefore = balancerPoolToken.balanceOf(address(this));
balancerVault.joinPool(poolId, address(this), address(this), request);
@> uint256 balancerPoolTokenBalanceAfter = balancerPoolToken.balanceOf(address(this));
return balancerPoolTokenBalanceAfter - balancerPoolTokenBalanceBefore;
}
We see that when depositing it will always check the hardcoded address rather than the proper token. This means that it will return 0 when trying to deposit to other pools.
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);
// Step 3: Deposit to PreDeposit
@> PreDeposit(_predeposit).deposit(balancerPoolTokenReceived, msg.sender);
return balancerPoolTokenReceived;
}
As a result of this balancerPoolTokenReceived will be 0. This will cause the tokens to be permanently stuck in the router causing complete loss of funds to the user.
Root Cause
balancerPoolToken is hardcoded
Internal preconditions
None
External preconditions
None
Attack Path
N/A
Impact
Complete loss of user funds
POC
N/A
Mitigation
balancerPoolToken should be retrieved dynamically from the vault.
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
Impact
Complete loss of user funds, because the received pool tokens are never deposited and remain stuck in the router.
What the attacker needed
Deposit into a pool other than the hardcoded one
The fix
The pool token should be looked up dynamically from the vault for the pool being joined rather than fixed at construction.
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.
A router is a helper contract that moves a user's tokens into a pool and then into a deposit contract. Here it always looks at one fixed pool token to see how much it received, so for any other pool it sees zero and sends nothing onward. The user's tokens stay trapped in the helper contract with no way to get them back.
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.