If FFactory::buyTax and / or FFactory::sellTax is set to 0, buy / sell would revert
YouCrossTheLineAlfie Follow with NHristov
Originally disclosed on Code4rena
Submitted by YouCrossTheLineAlfie, also found by NHristov
Finding description
The FFactory::setTaxParams can be called by the admin to change the buyTax and sellTax.
// FFactory.sol
function setTaxParams(address newVault_, uint256 buyTax_, uint256 sellTax_) public onlyRole(ADMIN_ROLE) {
require(newVault_ != address(0), "Zero addresses are not allowed.");
taxVault = newVault_;
buyTax = buyTax_;
sellTax = sellTax_;
}
This is used inside the FRouter::buy and FRouter::sell to levy fees.
// FRouter.sol
function buy(
uint256 amountIn,
address tokenAddress,
address to
) public onlyRole(EXECUTOR_ROLE) nonReentrant returns (uint256, uint256) {
// . . . Rest of the code . . .
uint fee = factory.buyTax();
uint256 txFee = (fee * amountIn) / 100;
address feeTo = factory.taxVault();
uint256 amount = amountIn - txFee;
IERC20(assetToken).safeTransferFrom(to, pair, amount);
IERC20(assetToken).safeTransferFrom(to, feeTo, txFee); <<@ -- // Fee sent to taxManager
uint256 amountOut = getAmountsOut(tokenAddress, assetToken, amount);
IFPair(pair).transferTo(to, amountOut);
IFPair(pair).swap(0, amountOut, amount, 0);
if (feeTo == taxManager) {
IBondingTax(taxManager).swapForAsset(); <<@ -- // Swap for Asset call
}
return (amount, amountOut);
}
// FRouter.sol
function sell(
uint256 amountIn,
address tokenAddress,
address to
) public nonReentrant onlyRole(EXECUTOR_ROLE) returns (uint256, uint256) {
// . . . Rest of the code . . .
uint fee = factory.sellTax();
uint256 txFee = (fee * amountOut) / 100;
uint256 amount = amountOut - txFee;
address feeTo = factory.taxVault();
pair.transferAsset(to, amount);
pair.transferAsset(feeTo, txFee); <<@ -- // Fee sent to taxManager
pair.swap(amountIn, 0, 0, amountOut);
if (feeTo == taxManager) {
IBondingTax(taxManager).swapForAsset(); <<@ -- // Swap for Asset call
}
return (amountIn, amountOut);
}
However, when we have a closer look at the BondingTax::swapForAsset function, we can observe that it reverts if the balance of the contract is 0:
// BondingTax.sol
function swapForAsset() public onlyBondingRouter returns (bool, uint256) {
uint256 amount = IERC20(taxToken).balanceOf(address(this));
require(amount > 0, "Nothing to be swapped"); <<@ -- // Reverts if balance is 0
if (amount < minSwapThreshold) {
return (false, 0);
}
if (amount > maxSwapThreshold) {
amount = maxSwapThreshold;
}
Hence, if buy and/or sell tax is set to 0 via FFactory::setTaxParams, there can be a case where the balance of taxManager becomes 0.
Also this is not unlikely, and can be very easily manipulated by an attacker by simply donating exactly to match maxSwapThreshold funds. Setting fees to 0 is a very valid and intuitive value to set.
Impact
Failed buy and sell swaps will lead to DoS.
Recommended mitigation steps
It is recommended to simply return with (false, 0) instead of reverting:
// BondingTax.sol
function swapForAsset() public onlyBondingRouter returns (bool, uint256) {
uint256 amount = IERC20(taxToken).balanceOf(address(this));
- require(amount > 0, "Nothing to be swapped");
- if (amount < minSwapThreshold) {
+ if (amount < minSwapThreshold || amount == 0) {
return (false, 0);
}
if (amount > maxSwapThreshold) {
amount = maxSwapThreshold;
}
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A medium-severity doS bug in Virtuals Protocol. Code4rena made it public on 4 August 2025. Found in the 2025-04-virtuals-protocol audit contest (finding M-15), also found by 1 other warden.
About DoS
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
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.