It should never be possible to change the status of a completed task #230
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
duplicate
This issue or pull request already exists
edited-by-warden
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
valid
Lines of code
https://github.com/code-423n4/2022-08-rigor/blob/main/contracts/Project.sol#L330-L359
https://github.com/code-423n4/2022-08-rigor/blob/main/contracts/Project.sol#L705-L713
https://github.com/code-423n4/2022-08-rigor/blob/main/contracts/Project.sol#L386-L490
https://github.com/code-423n4/2022-08-rigor/blob/main/test/utils/projectTests.ts#L1110
Vulnerability details
High Risk Finding
Impact
In Project.sol, once a task is set as completed (by calling function setComplete), the contract pays the subcontractor. Once in this state, in should not be possible to change the task state back to ACTIVE/INACTIVE, because then the same task could be set as completed again and payed out multiple times. Furthermore, function projectCost would not return the real cost, because it loops through all tasks of a project adding up the cost of each task, but the real cost of a completed task payed out multiple times would be the cost of the task times the number of times it has been set as completed.
A call to function changeOrder can unapprove a completed task just by passing a _newCost greater than _taskCost and provided that (totalLent - _totalAllocated < _newCost - _taskCost) holds. It can also be unapproved by passing in a new subcontractor to changeOrder.
It could be possible for a malicious contractor and subcontractor to (almost) drain the total lent to the project by setting as complete, changing order to unnaprove task, then setting again as complete, multiple times.
Proof of Concept
I added a new test in file projectTests.ts, substituting test 'should be able to complete a task' with the following test:
It first sets as complete a task, and then it call changeOrder with a greater cost and same subcontractor.
The test fails, because it expects the task state to be 3 (COMPLETE), but it is 1 (INACTIVE) instead.
Tools Used
Hardhat
Recommended Mitigation Steps
There are various things that can be done to mitigate this issue, but I would:
The text was updated successfully, but these errors were encountered: