Unbounded loop in withdraw() may cause rewards to be locked in the contract
The withdraw function contains an unbounded loop that makes external token transfer calls, so if gas costs change or the number of rewards grows, the function may revert due to exceeding the block gas limit, locking rewards in the contract.
Submitted by IllIllI
The withdraw() has an unbounded loop with external calls. If the gas costs of functions change between when deposits are made and when rewards are withdrawn, or if the gas cost of the deposit (transferFrom()) is less than the gas cost of the withdrawal (transfer()), then the withdraw() function may revert due to exceeding the block size gas limit.
Proof of Concept
transfer() is an external call, and rewards.length has no maximum size:
File: contracts/PermissionlessBasicPoolFactory.sol #1
224 for (uint i = 0; i < rewards.length; i++) {
225 pool.rewardsWeiClaimed[i] += rewards[i];
226 pool.rewardFunding[i] -= rewards[i];
227 uint tax = (pool.taxPerCapita * rewards[i]) / 1000;
228 uint transferAmount = rewards[i] - tax;
229 taxes[poolId][i] += tax;
230 success = success && IERC20(pool.rewardTokens[i]).transfer(receipt.owner, transferAmount);
231 }
Recommended Mitigation Steps
Allow the specification of an offset and length to the withdraw() function, so that withdrawals can be broken up into smaller batches if required
illuzen (FactoryDAO) confirmed
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 withdraw function iterates over an array with no maximum length and performs an external call in each iteration, so the total gas required can exceed the block gas limit.
Impact
Rewards may become locked in the contract because withdraw could revert due to exceeding the block gas limit, especially if gas costs change or the number of rewards is large.
What the attacker needed
Multiple rewards in the pool; gas costs increase or many rewards
The fix
The withdraw function should be modified to allow specifying an offset and length so that withdrawals can be processed in smaller batches.
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 smart contract function that pays out rewards uses a loop that can run for an unlimited number of times. Each iteration makes an external call to transfer tokens, which costs gas. If there are too many rewards or gas costs increase, the transaction may run out of gas and fail, leaving the rewards stuck.
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.