Skip to content
Business logic Audit finding Intermediate

The first disputer might lose funds although his dispute is valid

The disputeTree function allows a new dispute to be created even when one is already active, and resolveDispute refunds only the most recent disputer. A malicious user could front-run the resolution of a valid dispute, causing the original disputer to lose their deposit.

auditor0517 Follow with Udsen and Jeiwan

Originally disclosed on Code4rena

Submitted by auditor0517, also found by Udsen and Jeiwan

Users can dispute the current tree using disputeTree() and the governor refunds the dispute funds if the dispute is valid in resolveDispute().

    function disputeTree(string memory reason) external {
        if (block.timestamp >= endOfDisputePeriod) revert InvalidDispute();
        IERC20(disputeToken).safeTransferFrom(msg.sender, address(this), disputeAmount);
        disputer = msg.sender;
        emit Disputed(reason);
    }

    /// @notice Resolve the ongoing dispute, if any
    /// @param valid Whether the dispute was valid
    function resolveDispute(bool valid) external onlyGovernorOrGuardian {
        if (disputer == address(0)) revert NoDispute();
        if (valid) {
            IERC20(disputeToken).safeTransfer(disputer, disputeAmount);
            // If a dispute is valid, the contract falls back to the last tree that was updated
            _revokeTree();
        } else {
            IERC20(disputeToken).safeTransfer(msg.sender, disputeAmount);
            endOfDisputePeriod = _endOfDisputePeriod(uint48(block.timestamp));
        }
        disputer = address(0);
        emit DisputeResolved(valid);
    }

But disputeTree() can be called again by another disputer although there is an active disputer and resolveDispute() refunds to the last disputer only.

In the worst case, a valid disputer might lose the dispute funds by malicious frontrunners.

  1. A valid disputer creates a dispute using disputeTree().
  2. As it’s valid, the governor calls resolveDispute(valid = true) to accept the dispute and refund the funds.
  3. A malicious user calls disputeTree() by front running.
  4. Then during resolveDispute(true), the dispute funds will be sent to the second disputer and the first disputer will lose the funds although he’s valid.

Recommended Mitigation Steps

disputeTree() shouldn’t allow another dispute when there is an active dispute already.

Picodes (Angle) confirmed, but disagreed with severity and commented:

Valid scenario and issue, although this is only a griefing attack, and the governance could still send back the funds to the first dispute using recoverERC20.

Considering the scenario is very unlikely as it would cost gas to the attacker for nothing, and easily fixable, I think this should be downgraded to Med

hansfriese (Judge) commented:

@Picodes - Will keep as High because honest disputers may lose their funds and it requires the governance’s additional work to recover.

Picodes (Angle) commented:

@hansfriese - indeed but when there is a dispute it requires additional work from the governance anyway. Like the permissions for resolveDispute and recoverERC20, and recoverERC20 is even cheaper. So the trust assumptions of the disputer are exactly the same with and without this issue: he trusts the governance to send him back its deposit at some point.

This whole disputeAmount / period thing is meant to prevent spam and to force disputers to behave correctly as they will lose some funds if they don’t, so someone using this attack vector also exposes himself to the governance deciding to not accept the dispute and seize the funds. Overall we will of course respect your final decision but still think med is more appropriate here

hansfriese (Judge) commented:

@Picodes - I totally understand your point and I’d like to mention two things.

  • The governance should refund one by one outside of the contract.
  • While checking disputeTree(), I see it doesn’t emit the disputer’s address and disputeAmount which would be changed later. So it wouldn’t be that easy to refund in practice.

I agree it’s between High and Medium and will keep as High.

Angle mitigated:

PR: https://github.com/AngleProtocol/merkl-contracts/commit/7402ee6b84789391479c5876b27be23fd579f7b2 Applies the suggested fix.

Status: Mitigation confirmed. Full details in reports from Lambda, auditor0517, and Jeiwan.


The original report as published on Code4rena, by auditor0517. 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

The disputeTree function does not check whether a dispute is already active, allowing the disputer to be overwritten.

Impact

A valid disputer could lose their dispute funds, though the governance could later recover and return the funds using recoverERC20.

What the attacker needed

An active dispute; attacker can front-run the resolution transaction

The fix

The disputeTree function should not allow a new dispute when one is already active; this was fixed by applying the suggested change.

How it was found

  1. A valid disputer creates a dispute using disputeTree().
  2. The governor calls resolveDispute(valid = true) to accept the dispute and refund the funds.
  3. A malicious user calls disputeTree() by front running.
  4. During resolveDispute(true), the dispute funds are sent to the second disputer and the first disputer loses the 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 this smart contract, users can challenge a decision by paying a deposit. If the challenge is valid, the deposit is returned. However, the contract lets someone else start a new challenge while one is already active, and only the latest challenger gets the deposit back. So an attacker can jump in just before the valid challenge is accepted and steal the refund.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by auditor0517

View all

11 more disclosed reports, best first.

More from Angle Protocol - Invitational

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.