Skip to content
Smart contracts Audit finding Advanced

Project funds can be drained by reusing signatures, in some cases

The smart contract functions changeOrder() and setComplete() did not prevent signature reuse, and the Tasks.unApprove() library function lacked a required modifier. An attacker could reuse signatures to repeatedly call setComplete() and drain project funds, or external users could change task costs or subcontractors.

0xA5DF Follow

Originally disclosed on Code4rena

Submitted by 0xA5DF, also found by Bahurum, bin2chen, byndooa, cryptphi, hansfriese, horsefacts, kaden, Lambda, neumo, panprog, rokinot, scaraven, and sseefried

Project.sol#L386-L490 Project.sol#L330-L359 Tasks.sol#L153-L164

This attack path is the results of signatures reusing in 2 functions - changeOrder() and setComplete(), and a missing modifier at Tasks.unApprove() library function.

Impact

Draining the project from funds

Current or previous subcontractor of a task can drain the project out of its funds by running setComplete() multiple times.

This can be exploited in 3 scenarios:

  • The price of a task was changed to a price higher than available funds (i.e. totalLent - _totalAllocated, and therefore gets unapproved), and than changed back to the original price (or any price that’s not higher than available funds)

  • The subcontractor for a task was changed via changeOrder and then changed back to the original subcontractor

    • e.g. - Bob was the original SC, it was changed to Alice, and then back to Bob
  • Similar to the case above, but even if the current SC is different from the original SC - it can still work if the current and previous SCs are teaming up to run the attack

    • e.g. Bob was the original SC, it was changed to Alice, and changed again to Eve. And now Alice and Eve are teaming up to drain funds from the project

After setComplete() ran once by the legitimate users (i.e. signed by contractor, SC and builder), the attackers can now run it multiple times:

  • Reuse signatures to run changeOrder() - changing SC or setting the price to higher than available funds

    • The only signer that might change is the subcontractor, he’s either teaming up with the attacker (scenario #3) or he was the SC when it was first called (scenario #2)
  • In case of price change:

    • change it back to the original price via changeOrder(), reusing signatures
    • Run allocateFunds() to mark it as funded again
  • SC runs acceptInvite() to mark task as active

  • Run setComplete() reusing signatures

    • If SC has changed - replace his signature with the current one (current SC should be one of the attackers)
  • Repeat till the project runs out of funds

Changing tasks costs/subcontractor by external users

This can also be used by external users (you don’t need to be builder/GC/SC in order to run changeOrder()) to troll the system (This still requires the task to be changed at least twice, otherwise re-running changeOrder() with the same data would have no effect).

  • Changing the task cost up or down, getting the SC paid a different amount than intended (if it goes unnoticed, or front-run the setComplete() function)

  • Unapproving a task by setting a different SC or a price higher than available funds

    • The legitimate users can change it back, but the attacker can change it again, both sides playing around till someone gets tired :)

Proof of Concept

Since the tests depend on each other, the PoC tests were created by adding them to the file test/utils/projectTests.ts, after the function it('should be able to complete a task' (Line 1143).

In the first test - a subcontractor is changed and then changed back. In the second scenario a price is changed to the new price (that is higher than the total available funds, and therefore is unapproved) and then back to its original price (it can actually be any price that is not higher than the available funds). In both cases I’m demonstrating how the project can be drained out of fund.

Note: see warden’s original submission for full proof of concept.

Tools Used

Hardhat

Recommended Mitigation Steps

  • Use nonce to protect setComplete() and changeOrder() from signatures reuse
  • Add the onlyActive() modifier to Tasks.unApprove()
  • Consider limiting allocateFunds() for builder only (this is not necessary to resolve the bug, just for hardening security)

zgorizzo69 (Rigor) confirmed and commented:

Very nice wrap up.


The original report as published on Code4rena, by 0xA5DF. 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 contract functions changeOrder() and setComplete() did not include a nonce or other replay protection, allowing the same signatures to be reused, and Tasks.unApprove() was missing the onlyActive() modifier.

Impact

A current or previous subcontractor could drain the project's funds by repeatedly calling setComplete(), and external users could change task costs or subcontractors to troll the system.

What the attacker needed

Be a current or previous subcontractor; or be an external user to troll; task must have been changed at least twice

How it was found

  1. Legitimate users run setComplete() once, signing the transaction.
  2. Attacker reuses signatures to run changeOrder(), changing the subcontractor or setting the price higher than available funds.
  3. If price was changed, attacker changes it back to the original price via changeOrder() reusing signatures, then runs allocateFunds() to mark it as funded again.
  4. Subcontractor runs acceptInvite() to mark the task as active.
  5. Attacker runs setComplete() reusing signatures, replacing the subcontractor's signature with the current one if needed.
  6. Repeat until the project runs out of funds.

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.

In blockchain applications, a signature is like a digital permission slip that proves someone approved an action. If the same permission slip can be used more than once, an attacker can repeat an action that should only happen once, such as marking a task as complete and releasing funds. Here, the contract did not check that each signature was used only once, so a subcontractor could repeatedly claim payment.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by 0xA5DF

View all

35 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.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.