Skip to content
Business logic Audit finding Intermediate

Poor detection of disputed trees allows claiming tokens from a disputed tree

The contract's getMerkleRoot function returns the current Merkle root if the dispute period has ended, even if the tree is still disputed (disputer address set). A malicious trusted EOA could add a fraudulent tree and claim the entire contract balance if the dispute is not resolved quickly.

Jeiwan Follow with auditor0517

Originally disclosed on Code4rena

Submitted by Jeiwan, also found by auditor0517

https://github.com/AngleProtocol/merkl-contracts/blob/1825925daef8b22d9d6c0a2bc7aab3309342e786/contracts/Distributor.sol#L200

Users can claim rewards from a Merkle tree that’s being disputed. This can potentially lead to loss of funds since a malicious trusted EOA can claim funds from a malicious tree while it’s being disputed.

Proof of Concept

The Distribution.getMerkleRoot function is used to get the current Merkle root during claiming. The function is aware of the dispute period of the current root and returns the previous root if the current tree is still in the dispute period.

However, the function doesn’t take into account the situation when:

  1. a tree was disputed (i.e. the disputer address is set);
  2. and the dispute period has finished (i.e. when block.timestamp >= endOfDisputePeriod).

Such situations can happen realistically when a tree is disputed closer to the end of its dispute period and/or when the governor/guardian takes longer time to resolve the dispute. In such situations, the dispute period checks in the above functions will pass, however the disputer address will be set, which means that the tree is being disputed and shouldn’t be used in claims.

As an example exploit scenario, a malicious trusted EOA can add a Merkle tree root that lets them claim the entire balance of the contract. Even if the tree gets disputed quickly, the success of the attack boils down to how quickly the governor/guardian will resolve the dispute. To increase the chance, the attack can be deliberately executed when the governor/guardian are not active or available immediately.

Recommended Mitigation Steps

When the disputer address is set (after a call to disputeTree), consider treating the current tree as disputed, no matter whether the dispute period has passed or not. E.g. consider these changes:

diff --git a/contracts/Distributor.sol b/contracts/Distributor.sol
index bc4e49f..8fb6a4c 100644
--- a/contracts/Distributor.sol
+++ b/contracts/Distributor.sol
@@ -197,7 +197,7 @@ contract Distributor is UUPSHelper {

     /// @notice Returns the MerkleRoot that is currently live for the contract
     function getMerkleRoot() public view returns (bytes32) {
-        if (block.timestamp >= endOfDisputePeriod) return tree.merkleRoot;
+        if (block.timestamp >= endOfDisputePeriod && disputer == address(0)) return tree.merkleRoot;
         else return lastTree.merkleRoot;
     }

Picodes (Angle) confirmed

Angle mitigated:

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

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


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

Impact

A malicious trusted EOA could claim the entire contract balance if the dispute is not resolved before the dispute period ends.

What the attacker needed

Malicious trusted EOA; dispute not resolved before period ends

The fix

The fix was to also check that the disputer address is zero before returning the current Merkle root.

How it was found

  1. A malicious trusted EOA adds a Merkle tree root that lets them claim the entire contract balance.
  2. The tree is disputed, setting the disputer address.
  3. The dispute period ends before the governor/guardian resolves the dispute.
  4. The malicious EOA claims funds from the disputed tree because getMerkleRoot returns the current root.

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 Merkle tree is a way to store many claims efficiently; users prove their reward by providing a path. The contract has a dispute period during which a new tree can be challenged. The bug is that after the dispute period ends, the contract ignores that the tree was disputed and still allows claims, so a bad actor could create a fake tree and take all the funds if nobody resolves the dispute in time.

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 Jeiwan

View all

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