Vault set to the zero-address will break swaps and flash loans in all deployed pools
The vault address in the AlgebraFactory could be set to the zero address, causing all swaps and flash loans in deployed pools to either revert or burn community fees, depending on the ERC-20 token implementation.
Originally disclosed on Code4rena
Submitted by berndartmueller, also found by 0xbepresent, 8olidity, and tonisives
Collected community fees from each swap and flash loan are immediately sent to the defined AlgebraFactor.vaultAddress address. Contrary to the used pull pattern in Uniswap V3.
Having fees (ERC-20 tokens) immediately sent to the vault within each swap and flash loan, opens up potential issues if the vault address is set to the zero address.
The following AlgebraPool functions are affected:
swap,swapSupportingFeeOnInputTokens, andflash
Impact
If the AlgebraFactor.vaultAddress address is set to address(0), all Algebra pools deployed by this factory contract will have their swap and flash loan functionality affected in a either completely broken way (transactions will revert due to ERC-20 token transfers to the zero address) or fees are sent (effectively burned) to the zero address. In the end, it will depend on the ERC-20 token implementation if it reverts or simply burns the fees.
Proof of Concept
AlgebraFactory.setVaultAddress
AlgebraFactory.setVaultAddress is used by the owner of the AlgebraFactory to set the vault address.
function setVaultAddress(address _vaultAddress) external override onlyOwner {
require(vaultAddress != _vaultAddress);
emit VaultAddress(_vaultAddress);
vaultAddress = _vaultAddress;
}
function flash(
address recipient,
uint256 amount0,
uint256 amount1,
bytes calldata data
) external override lock {
[...]
address vault = IAlgebraFactory(factory).vaultAddress();
uint256 paid0 = balanceToken0();
require(balance0Before.add(fee0) <= paid0, 'F0');
paid0 -= balance0Before;
if (paid0 > 0) {
uint8 _communityFeeToken0 = globalState.communityFeeToken0;
uint256 fees0;
if (_communityFeeToken0 > 0) {
fees0 = (paid0 * _communityFeeToken0) / Constants.COMMUNITY_FEE_DENOMINATOR;
TransferHelper.safeTransfer(token0, vault, fees0); // @audit-info `vault` is used as the recipient of community fees
}
totalFeeGrowth0Token += FullMath.mulDiv(paid0 - fees0, Constants.Q128, _liquidity);
}
uint256 paid1 = balanceToken1();
require(balance1Before.add(fee1) <= paid1, 'F1');
paid1 -= balance1Before;
if (paid1 > 0) {
uint8 _communityFeeToken1 = globalState.communityFeeToken1;
uint256 fees1;
if (_communityFeeToken1 > 0) {
fees1 = (paid1 * _communityFeeToken1) / Constants.COMMUNITY_FEE_DENOMINATOR;
TransferHelper.safeTransfer(token1, vault, fees1); // @audit-info `vault` is used as the recipient of community fees
}
totalFeeGrowth1Token += FullMath.mulDiv(paid1 - fees1, Constants.Q128, _liquidity);
}
emit Flash(msg.sender, recipient, amount0, amount1, paid0, paid1);
}
This function is called from within the AlgebraPool.swap and AlgebraPool.swapSupportingFeeOnInputTokens functions.
function _payCommunityFee(address token, uint256 amount) private {
address vault = IAlgebraFactory(factory).vaultAddress();
TransferHelper.safeTransfer(token, vault, amount);
}
Recommended mitigation steps
Either
- consider adding a check if
vault == address(0)inAlgebraPool._payCommunityFeeand inAlgebraPool.flash, - prevent setting
vaulttoaddress(0)inAlgebraFactory.setVaultAddress, or - use a pull pattern to collect community (protocol) fees
vladyan18 (QuickSwap & StellaSwap) confirmed
IliaAzhel (QuickSwap & StellaSwap) disagreed with severity
0xean (judge) decreased severity to Medium and commented:
Downgrading to Medium, requires an admin to set the failure state.
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 contract does not check that the vault address is not the zero address before using it as a recipient for token transfers.
Impact
If the vault is set to the zero address, all swaps and flash loans in every pool from that factory will either revert or burn the community fees, depending on the token.
What the attacker needed
Admin sets vault to zero address
The fix
The fix should either prevent setting the vault to the zero address in the factory, add a zero-address check in the pool functions, or use a pull pattern for fee collection.
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 vault is a special address where a small fee from each trade is sent. If that address is set to the zero address (a placeholder that cannot receive tokens), then every trade that tries to send a fee will either fail or the fee will be lost forever. This only happens if the contract owner makes a mistake and sets the vault to zero.
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.