Skip to content
DoS Audit finding Intermediate

PermissionlessBasicPoolFactory’s withdraw can become frozen on zero reward token transfers

The withdraw function in PermissionlessBasicPoolFactory attempts to transfer reward tokens even when the reward amount is zero. If a reward token rejects zero-value transfers, the entire withdrawal reverts, preventing users from exiting the pool and freezing their funds.

hyh Follow

Originally disclosed on Code4rena

Submitted by hyh

Reward tokens that do not allow for zero amount transfers can prevent user pool exit.

Now it is required that all reward amounts be successfully transferred to a receipt owner and the reward token amount isn’t checked in the process.

If withdraw was called at the moment when some reward amount is zero (because either zero time passed or zero slope is set), the withdraw() will revert.

Say once such reward token is there (say with no malicious intent, as it’s just a specifics of some valid tokens), user cannot withdraw immediately after deposit as no rewards accrued yet and this token transfer will revert the whole call even if it is one of the many.

As withdraw() the only way for a user to exit pool, her funds will be frozen within.

If slope is set to zero for such a token, either maliciously or mistakenly, the withdrawals are impossible for all the users.

As this is user fund freeze case with external assumptions, setting the severity to medium.

Proof of Concept

Some ERC20 tokens do not allow for zero amount transfers:

https://github.com/d-xo/weird-erc20#revert-on-zero-value-transfers

withdraw() iterates across the set of reward tokens, and requires all transfers to go through:

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/PermissionlessBasicPoolFactory.sol#L230-L230

success = success && IERC20(pool.rewardTokens[i]).transfer(receipt.owner, transferAmount);

Once some is not ok, the whole call reverts. As it’s the only way for a user to exit the pool, her funds are frozen until non-zero reward is obtained.

It might never happen as rewardsWeiPerSecondPerToken is allowed to be zero:

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/PermissionlessBasicPoolFactory.sol#L92-L112

    function addPool (
        uint startTime,
        uint maxDeposit,
        uint[] memory rewardsWeiPerSecondPerToken,
        uint programLengthDays,
        address depositTokenAddress,
        address excessBeneficiary,
        address[] memory rewardTokenAddresses,
        bytes32 ipfsHash,
        bytes32 name
    ) external {
        Pool storage pool = pools[++numPools];
        pool.id = numPools;
        pool.rewardsWeiPerSecondPerToken = rewardsWeiPerSecondPerToken;
        pool.startTime = startTime > block.timestamp ? startTime : block.timestamp;
        pool.endTime = pool.startTime + (programLengthDays * 1 days);
        pool.depositToken = depositTokenAddress;
        pool.excessBeneficiary = excessBeneficiary;
        pool.taxPerCapita = globalTaxPerCapita;

        require(rewardsWeiPerSecondPerToken.length == rewardTokenAddresses.length, 'Rewards and reward token arrays must be same length');

This way, when one of the reward tokens doesn’t allow for zero transfers:

  1. immediate withdraw after deposit is impossible
  2. factory allows for creation of malicious or misconfigured pools by adding such a reward token with zero rewardsWeiPerSecondPerToken, making withdraw impossible for all users

Recommended Mitigation Steps

Consider controlling for zero amounts in reward transfer cycle:

        for (uint i = 0; i < rewards.length; i++) {
+	        if (rewards[i] > 0) {
	            pool.rewardsWeiClaimed[i] += rewards[i];
	            pool.rewardFunding[i] -= rewards[i];
	            uint tax = (pool.taxPerCapita * rewards[i]) / 1000;
	            uint transferAmount = rewards[i] - tax;
	            taxes[poolId][i] += tax;
	            success = success && IERC20(pool.rewardTokens[i]).transfer(receipt.owner, transferAmount);
+	        }
        }

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/PermissionlessBasicPoolFactory.sol#L224-L231

illuzen (FactoryDAO) marked as duplicate and commented:

Duplicate of #108 (M-13)

Justin Goro (judge) commented:

Unmarking duplicate as FOT and revert-on-zero tokens are different. Consider this issue implicitly acknowledged as sponsor has communicated that badly implemented ERC20 tokens are allowed so long as they respect pool isolation. However, this bug is still a useful boundary condition to consider and so it will not be marked as invalid.


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

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 withdrawal loop does not skip zero-amount reward transfers, so a token that reverts on zero-value transfers causes the entire withdrawal to fail.

Impact

Users may be unable to withdraw their funds from the pool, and if a reward token's slope is set to zero, withdrawals could be impossible for all users.

What the attacker needed

Pool uses a reward token that reverts on zero transfers; user has deposited into the pool

The fix

The withdrawal loop should check that the reward amount is greater than zero before attempting the token transfer.

How it was found

  1. A pool is created with a reward token that does not allow zero-amount transfers.
  2. A user deposits into the pool.
  3. The user immediately calls withdraw, but no rewards have accrued yet, so the reward amount is zero.
  4. The withdraw function attempts to transfer zero reward tokens, which reverts, and the whole withdrawal fails.

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.

Some digital tokens refuse to process a transfer of zero tokens. The pool's withdrawal function tries to send every reward token, even when the amount is zero, and if any transfer fails the whole withdrawal is cancelled. This means a user's deposit can get stuck in the pool because they cannot complete the exit step.

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.

More by hyh

View all

137 more disclosed reports, best first.

More from FactoryDAO contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.