Block usage of addCuratedPool
The function curatedPoolCount() loops over an array that can be arbitrarily extended by creating and removing pools, causing it to run out of gas and revert. This prevents addCuratedPool() from being executed, blocking the addition of new curated pools.
Submitted by gpersoon, also found by hickuphh3, and cmichel
The function curatedPoolCount() contains a for loop over the array arrayPools. If arrayPools would be too big then the loop would run out of gas and curatedPoolCount() would revert. This would mean that addCuratedPool() cannot be executed anymore (because it calls curatedPoolCount() )
The array arrayPools can be increased in size arbitrarily by repeatedly doing the following:
- create a pool with
createPoolADD()(which requires 10,000 SPARTA) - empty the pool with
remove()of Pool.sol, which gives back the SPARTA tokens These actions will use gas to perform.
function createPoolADD(uint256 inputBase, uint256 inputToken, address token) external payable returns(address pool){
require(getPool(token) == address(0)); // Must be a valid token
require((inputToken > 0 && inputBase >= (10000*10**18)), "!min"); // User must add at least 10,000 SPARTA liquidity & ratio must be finite
Pool newPool; address _token = token;
if(token == address(0)){_token = WBNB;} // Handle BNB -> WBNB
require(_token != BASE && iBEP20(_token).decimals() == 18); // Token must not be SPARTA & it's decimals must be 18
newPool = new Pool(BASE, _token); // Deploy new pool
pool = address(newPool); // Get address of new pool
mapToken_Pool[_token] = pool; // Record the new pool address in PoolFactory
_handleTransferIn(BASE, inputBase, pool); // Transfer SPARTA liquidity to new pool
_handleTransferIn(token, inputToken, pool); // Transfer TOKEN liquidity to new pool
arrayPools.push(pool); // Add pool address to the pool array
..
function curatedPoolCount() internal view returns (uint){
uint cPoolCount;
for(uint i = 0; i< arrayPools.length; i++){
if(isCuratedPool[arrayPools[i]] == true){
cPoolCount += 1;
}
}
return cPoolCount;
}
function addCuratedPool(address token) external onlyDAO {
...
require(curatedPoolCount() < curatedPoolSize, "maxCurated"); // Must be room in the Curated list
function remove() external returns (uint outputBase, uint outputToken) {
return removeForMember(msg.sender);
}
// Contract removes liquidity for the user
function removeForMember(address member) public returns (uint outputBase, uint outputToken) {
uint256 _actualInputUnits = balanceOf(address(this)); // Get the received LP units amount
outputBase = iUTILS(_DAO().UTILS()).calcLiquidityHoldings(_actualInputUnits, BASE, address(this)); // Get the SPARTA value of LP units
outputToken = iUTILS(_DAO().UTILS()).calcLiquidityHoldings(_actualInputUnits, TOKEN, address(this)); // Get the TOKEN value of LP units
_decrementPoolBalances(outputBase, outputToken); // Update recorded BASE and TOKEN amounts
_burn(address(this), _actualInputUnits); // Burn the LP tokens
iBEP20(BASE).transfer(member, outputBase); // Transfer the SPARTA to user
iBEP20(TOKEN).transfer(member, outputToken); // Transfer the TOKENs to user
emit RemoveLiquidity(member, outputBase, outputToken, _actualInputUnits);
return (outputBase, outputToken);
}
Recommend creating a variable curatedPoolCount and increase it in addCuratedPool and decrease it in removeCuratedPool.
verifyfirst (Spartan) confirmed and disagreed with severity:
We agree with the issue, this could be more efficient.
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 recalculates the curated pool count by iterating over an unbounded array instead of maintaining a separate counter.
Impact
The addCuratedPool() function cannot be executed, preventing the DAO from adding new curated pools.
What the attacker needed
10,000 SPARTA tokens; ability to create and remove pools
The fix
The contract should maintain a separate counter variable for curated pools, incrementing it in addCuratedPool and decrementing it in removeCuratedPool, instead of looping over the array.
How it was found
- Create a pool with createPoolADD() by providing at least 10,000 SPARTA and some tokens.
- Remove liquidity from the pool using remove() in Pool.sol, which returns the SPARTA tokens.
- Repeat these actions to arbitrarily increase the size of arrayPools.
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 counts curated pools by looping over a list. An attacker can make that list very long by repeatedly creating and removing pools, so the loop uses too much gas and fails. Then the function that adds new curated pools cannot work.
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.