Skip to content
DoS Audit finding Intermediate

Possible DOS in lendToProject() and toggleLendingNeeded() function because unbounded loop can run out of gas

The projectCost() function loops over all tasks without a bound, so if many tasks are added, calling lendToProject() or toggleLendingNeeded() may run out of gas and revert. This could prevent the project from being funded.

minhquanym Follow

Originally disclosed on Code4rena

Submitted by minhquanym, also found by berndartmueller, Chom, and scaraven

Project.sol#L710

In Project contract, the lendToProject() function might not be available to be called if there are a lot of Task in tasks[] list of project. It means that the project cannot be funded by either builder or community owner.

This can happen because lendToProject() used projectCost() function. And the loop in projectCost() did not have a mechanism to stop, it’s only based on the length taskCount, and may take all the gas limit. If the gas limit is reached, this transaction will fail or revert.

Same issue with toggleLendingNeeded() function which also call projectCost() function.

Proof of Concept

Function projectCost() did not have a mechanism to stop, only based on the taskCount.

function projectCost() public view override returns (uint256 _cost) {
    // Local instance of taskCount. To save gas.
    uint256 _length = taskCount;

    // Iterate over all tasks to sum their cost
    for (uint256 _taskID = 1; _taskID <= _length; _taskID++) {
        _cost += tasks[_taskID].cost;
    }
}

There is no limit for builder when add task.

And function lendToProject() used projectCost() to check the new total lent value

require(
    projectCost() >= uint256(_newTotalLent),
    "Project::value>required"
);

Recommended Mitigation Steps

Consider keeping value of projectCost() in a storage variable and update it when a task is added or updated accordingly.

parv3213 (Rigor) confirmed

Jack the Pug (judge) decreased severity to Medium


The original report as published on Code4rena, by minhquanym. 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 projectCost() function iterates over an unbounded array of tasks without a limit, causing gas exhaustion when the array grows large.

Impact

If the number of tasks becomes large, lendToProject() and toggleLendingNeeded() may become uncallable due to gas limits, preventing the project from being funded.

What the attacker needed

Many tasks added to the project

The fix

The projectCost() value should be stored in a variable and updated whenever a task is added or changed, avoiding the loop.

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 adds up costs by looping over every task can become too expensive to run if there are many tasks. When a transaction uses more gas than allowed, it fails, so users cannot call functions that depend on it.

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 minhquanym

View all

28 more disclosed reports, best first.

More from Rigor Protocol 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.