Skip to content
Business logic Audit finding Intermediate

Allo#_fundPool

The fee calculation in the _fundPool function rounds down to zero for small deposit amounts when the token has low decimals, allowing any user to avoid paying protocol fees by making many small deposits. The protocol therefore collects no fees from pools that use such tokens.

0xkaden Follow with AsenXDeth, HChang26 and 9 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/198

Found by

0xkaden, AsenXDeth, HChang26, Martians, RadCet, SBSecurity, Shubham, alexxander, imare, sashik_eth, trachev, vangrim

Vulnerability Detail

Let's see the code of the _fundPool function:

Solidity
function _fundPool(uint256 _amount, uint256 _poolId, IStrategy _strategy) internal {
        uint256 feeAmount;
        uint256 amountAfterFee = _amount;

        Pool storage pool = pools[_poolId];
        address _token = pool.token;

        if (percentFee > 0) {
            feeAmount = (_amount * percentFee) / getFeeDenominator();
            amountAfterFee -= feeAmount;

            _transferAmountFrom(_token, TransferData({from: msg.sender, to: treasury, amount: feeAmount}));
        }

        _transferAmountFrom(_token, TransferData({from: msg.sender, to: address(_strategy), amount: amountAfterFee}));
        _strategy.increasePoolAmount(amountAfterFee);

        emit PoolFunded(_poolId, amountAfterFee, feeAmount);
    }

The feeAmount is calculated as follows:

Solidity
feeAmount = (_amount * percentFee) / getFeeDenominator();

where getFeeDenominator returns 1e18 and percentFee is represented like that: 1e18 = 100%, 1e17 = 10%, 1e16 = 1%, 1e15 = 0.1% (from the comments when declaring the variable).

Let's say the pool uses a token like GeminiUSD which is a token with 300M+ market cap, so it's widely used, and percentFee == 1e15 (0.1%)

A user could circumvent the fee by depositing a relatively small amount. In our example, he can deposit 9 GeminiUSD. In that case, the calculation will be: feeAmount = (_amount * percentFee) / getFeeDenominator() = (9e2 * 1e15) / 1e18 = 9e17/1e18 = 9/10 = 0;

So the user ends up paying no fee. There is nothing stopping the user from funding his pool by invoking the fundPool with such a small amount as many times as he needs to fund the pool with whatever amount he chooses, circumventing the fee.

Especially with the low gas fees on L2s on which the protocol will be deployed, this will be a viable method to fund a pool without paying any fee to the protocol.

Impact

The protocol doesn't collect fees from pools with low decimal tokens.

Code Snippet

https://github.com/allo-protocol/allo-v2/blob/main/contracts/core/Allo.sol#L502

Tool used

Manual Review

Recommendation

Add a minFundAmount variable and check for it when funding a pool.

Discussion

sherlock-admin

1 comment(s) were left on this issue during the judging contest.

n33k commented:

bypassing of fee is an acceptable risk

nevillehuang

Escalate

In the contest README here:

Fee skirting where pool manager directly fund the pool without paying the fees

Fee bypass is only acceptable for pool managers funding pools, NOT just anybody. Some form of check needs to be implemented to check if msg.sender is a pool manager to allow fee skirting (if it even is intentional).

Sidenote: #248, #253, #533, #571, #602, #628, #636, #706 ,#764, #812, #818, #825, #911, #947 are valid duplicates of this issue

sherlock-admin2

Escalate

In the contest README here:

Fee skirting where pool manager directly fund the pool without paying the fees

Fee bypass is only acceptable for pool managers funding pools, NOT just anybody. Some form of check needs to be implemented to check if msg.sender is a pool manager to allow fee skirting (if it even is intentional).

Sidenote: #248, #253, #533, #571, #602, #628, #636, #706 ,#764, #812, #818, #825, #911, #947 are valid duplicates of this issue

You've created a valid escalation!

To remove the escalation from consideration: Delete your comment.

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

neeksec

Suggest to keep the original judging.

Fee skirting where pool manager directly fund the pool without paying the fees

Fee bypass is only acceptable for pool managers funding pools, NOT just anybody.

It's acceptable for anybody. If it's not, pool managers can use another EOA to do the fee skirting which easily voids this contest rule.

nevillehuang

While i respect your point, based on contest READ.ME, only pool managers can bypass fees. Unless it is intended protocol functionality to allow anyone other than pool manager to bypass fees, some sort of check is required. (I.e. minimum fee amount check)

Evert0x

Planning to accept escalation make issue medium together with listed duplicates.

It's acceptable for anybody

It's clear that it is NOT an acceptable risk for anybody. It's only an acceptable risk for the pool manager role.

Please list any known issues/acceptable risks that should not result in a valid finding. Fee skirting where pool manager directly fund the pool without paying the fees

Says pool manager, not anybody.

Evert0x

Result: Medium Has Duplicates

sherlock-admin2

Escalations have been resolved successfully!

Escalation status:

The original report as published on Sherlock, by 0xkaden. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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 integer division truncation in the fee calculation causes the fee to round down to zero for small deposit amounts when the token has low decimals.

Impact

The protocol does not collect fees from pools that use low-decimal tokens, and the low gas fees on L2s make this a viable method to avoid fees.

What the attacker needed

Pool uses a token with low decimals; percentFee is non-zero; attacker can call fundPool repeatedly

The fix

Add a minimum fund amount check to prevent fee rounding to zero.

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 tokens into a pool, the protocol takes a small percentage as a fee. The code calculates this fee by multiplying the deposit amount by a fee rate and then dividing by a large number. If the deposit is small and the token has few decimal places, the result rounds down to zero, so no fee is charged. An attacker can split a large deposit into many tiny deposits, each paying zero fee, and fund the pool without ever paying the protocol.

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.

More by 0xkaden

View all

11 more disclosed reports, best first.

More from Allo V2

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.