Approval overflow causes DoS in `BalancerRouter`'s `exitPlazaAndBalancer`
The BalancerRouter contract attempts to increase its allowance to the Balancer vault for pool tokens, but these tokens already have an infinite allowance, causing an arithmetic overflow. This prevents any withdrawal via exitPlazaAndBalancer, effectively breaking a core function.
Source: https://github.com/sherlock-audit/2024-12-plaza-finance-judging/issues/835
Found by
0xadrii
Summary
In _exitBalancerPool, the BalancerRouter contract will invoke balancerPoolToken.safeIncreaseAllowance in order to increase the allowance to the balancerVault by the desired balancerPoolTokenIn. This is incorrect, given that Balancer Pool Tokens by default have an inifinite allowance to the Balancer vault. This will lead to an overflow always being triggered when trying to approve the vault, effectively Dos’ing exitPlazaAndBalancer.
Root Cause
In BalancerRouter's _exitBalancerPool function, the router tries to approve the BPT tokens to the balancerVault in order to exit the pool:
// File: BalancerRouter.sol
function _exitBalancerPool(
bytes32 poolId,
IAsset[] memory assets,
uint256 balancerPoolTokenIn,
uint256[] memory minAmountsOut,
bytes memory userData,
address to
) internal {
IVault.ExitPoolRequest memory request = IVault.ExitPoolRequest({
assets: assets,
minAmountsOut: minAmountsOut,
userData: userData,
toInternalBalance: false
});
balancerPoolToken.safeIncreaseAllowance(address(balancerVault), balancerPoolTokenIn);
balancerVault.exitPool(poolId, address(this), payable(to), request);
}
The problem is that BPT tokens always have an inifinite allowance to the Balancer’s vault in order to save gas and avoid approvals. This can be seen in Balancers official BalancerPoolToken.sol implementation, where allowance always returns uint256(-1) if the spender is the vault, and is also mentioned explicitly in natspec: “Override to grant the Vault infinite allowance, causing for Pool Tokens to not require approval.”:
// File: BalancerPoolToken.sol
/**
* @dev Override to grant the Vault infinite allowance, causing for Pool Tokens to not require approval.
*
* This is sound as the Vault already provides authorization mechanisms when initiation token transfers, which this
* contract inherits.
*/
function allowance(address owner, address spender) public view override returns (uint256) {
if (spender == address(getVault())) {
return uint256(-1);
} else {
return super.allowance(owner, spender);
}
}
When the router tries to approve the vault, it uses safeIncreaseAllowance from OpenZeppelin’s SafeERC20 library, which is implemented in the following way:
// File: SafeERC20.sol
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
Because oldAllowance will be type(uint256).max when spender is the Balancer vault, the following oldAllowance + value addition will overflow, effectively preventing any withdrawal to be performed via the BalancerRouter contract.
Internal Pre-conditions
No response
External Pre-conditions
No response
Attack Path
- User calls
exitPlazaAndBalancer - The router tries to approve the
balancerVaultas a spender for thebalancerPoolToken. ThesafeIncreaseAllowancefunction is called, and an overflow is triggered, DoS’ing any exit via the router.
Impact
Medium. The exitPlazaAndBalancer will never work. Because this effectively breaks core contract functionality and effectively renders the contract useless (the main purpose of the router is to allow pool deposits/withdrawals and wrap/unwrap BPT tokens while doing it, and it has been demonstrated that withdrawals will never work, a core mechanism of the router), this issue should be deemed medium severity.
PoC
The following proof of concept illustrates the overflow. To run it, just create a foundry project and paste the following test contract:
contract ContractTest is Test {
string BASE_RPC_URL = vm.envString("BASE_RPC_URL");
// -- CREATE CONSTANTS HERE --
using SafeERC20 for IERC20;
// -- CREATE STORAGE VARIABLES HERE --
IERC20 public pool = IERC20(0xC771c1a5905420DAEc317b154EB13e4198BA97D0); // BPT token
address public vault = 0xBA12222222228d8Ba445958a75a0704d566BF2C8; // Balancer vault
function setUp() public {
vm.createSelectFork(BASE_RPC_URL);
}
function testBalancer_approvalOverflow() public {
pool.safeIncreaseAllowance(vault, 1e18); // reverts with arithmetic error
}
}
library SafeERC20 {
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
// ...
}
}
interface IERC20 {
function allowance(address user, address operator) external view returns (uint256);
}
Then, create a .env with and set BASE_RPC_URL to an RPC, and run the poc with forge test --mt testBalancer_approvalOverflow. It will revert with “panic: arithmetic underflow or overflow (0x11)” reason.
Mitigation
Don’t approve the Balancer vault when withdrawing.
// File: BalancerRouter.sol
function _exitBalancerPool(
bytes32 poolId,
IAsset[] memory assets,
uint256 balancerPoolTokenIn,
uint256[] memory minAmountsOut,
bytes memory userData,
address to
) internal {
IVault.ExitPoolRequest memory request = IVault.ExitPoolRequest({
assets: assets,
minAmountsOut: minAmountsOut,
userData: userData,
toInternalBalance: false
});
- balancerPoolToken.safeIncreaseAllowance(address(balancerVault), balancerPoolTokenIn);
balancerVault.exitPool(poolId, address(this), payable(to), request);
}
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/Convexity-Research/plaza-evm/pull/146
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
The router incorrectly assumes it needs to approve the Balancer vault for pool tokens, but these tokens already grant infinite allowance to the vault, so increasing the allowance overflows.
Impact
The exitPlazaAndBalancer function will never work, breaking a core mechanism of the router and rendering it useless for withdrawals.
What the attacker needed
None
The fix
The approval step should be removed so that the router does not attempt to increase allowance to the Balancer vault.
How it was found
- User calls exitPlazaAndBalancer
- The router tries to approve the balancerVault as a spender for the balancerPoolToken
- The safeIncreaseAllowance function is called, and an overflow is triggered, DoS’ing any exit via the router
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.
The router tried to give the vault permission to spend its pool tokens, but the vault already had unlimited permission. Adding to an unlimited number caused a math error, so the withdrawal always failed.
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.