Skip to content
Business logic Audit finding Intermediate

ArcadeTreasury.sol allowance may be overriden

The ArcadeTreasury contract uses ERC20 approve directly, so multiple approval functions overwrite each other's allowances for the same spender. A malicious GSC_CORE_VOTING_ROLE could reset a large allowance to a tiny amount, disrupting intended spending.

bin2chen Follow with ladboy233, caventa and 1 other

Originally disclosed on Code4rena

Submitted by bin2chen, also found by ladboy233, caventa, and 0xWaitress

Direct use of IERC20(token).approve(spender, amount); causes the same spender allowances to be overridden by each other.

Proof of Concept

In the gscApprove() method, it is possible to give spender a certain allowance.

The code is as follows:

    function gscApprove(
        address token,
        address spender,
        uint256 amount
    ) external onlyRole(GSC_CORE_VOTING_ROLE) nonReentrant {
        if (spender == address(0)) revert T_ZeroAddress("spender");
        if (amount == 0) revert T_ZeroAmount();

        // Will underflow if amount is greater than remaining allowance
@>      gscAllowance[token] -= amount;

        _approve(token, spender, amount, spendThresholds[token].small);
    }

    function _approve(address token, address spender, uint256 amount, uint256 limit) internal {
        // check that after processing this we will not have spent more than the block limit
        uint256 spentThisBlock = blockExpenditure[block.number];
        if (amount + spentThisBlock > limit) revert T_BlockSpendLimit();
        blockExpenditure[block.number] = amount + spentThisBlock;

        // approve tokens
@>      IERC20(token).approve(spender, amount);

        emit TreasuryApproval(token, spender, amount);
    }

From the above code, we can see that when executed, gscApprove consumes gscAllowance[] and ultimately uses IERC20(token).approve(); to give the spender allowance. Since the direct use is IERC20.approve(spender, amount), the amount of the allowance is overwritten, whichever comes last.

In the other method,s approveSmallSpend, approveMediumSpend and approveLargeSpend also use IERC20(token).approve();, which causes them to override each other if targeting the same spender.

Even if there is a malicious GSC_CORE_VOTING_ROLE, it is possible to execute gscApprove(amount=1 wei) after approveLargeSpend() to reset to an allowance of only 1 wei.

The recommendation is to use accumulation to avoid, intentionally or unintentionally, overwriting each other.

Recommended Mitigation Steps

    function _approve(address token, address spender, uint256 amount, uint256 limit) internal {
        // check that after processing this we will not have spent more than the block limit
        uint256 spentThisBlock = blockExpenditure[block.number];
        if (amount + spentThisBlock > limit) revert T_BlockSpendLimit();
        blockExpenditure[block.number] = amount + spentThisBlock;

        // approve tokens
-      IERC20(token).approve(spender, amount);
+      uint256 old = IERC20(token).allowance(address(this),spender);
+      IERC20(token).approve(spender,  old + amount);

        emit TreasuryApproval(token, spender, amount);
    }

Assessed type

Context

141345 (lookout) commented:

https://github.com/code-423n4/2023-07-arcade-findings/issues/58 talks about the issue with internal accounting of gscAllowance. Another aspect of the issue.

This report shows some unexpected results due to the external erc20 allowance overwrite.

PowVT (Arcade.xyz) confirmed

0xepley (warden) commented:

Doesn’t it fall under the admin mistake? The admin would be aware and can change these to desired values anytime.

0xean (judge) commented:

Doesn’t it fall under the admin mistake? The admin would be aware and can change these to desired values anytime.

I don’t believe this should be viewed as input sanitization, as the core functionality is written in a way that has unexpected consequences that could affect the functionality of the protocol. I can see arguing for QA, I welcome more comments from other wardens or sponsors.

0xnev (warden) commented:

@0xean - correct me if I’m wrong, but I think it is intended for allowance to be overwritten for the spender when it is decreased, given the changing of approval needs to go through a GSC proposal.

But since this report also highlights the potential inability to reduce allowance due to underflow in the gscAllowance mapping, it should be duplicated with #58.

Again correct me if I’m wrong, If the above reasoning is correct, #55, #146, and #535 should be invalidated since they do not mention the possible DoS when decreasing allowance.


The original report as published on Code4rena, by bin2chen. 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 calls IERC20.approve with a new amount instead of adding to the existing allowance, so approvals overwrite each other.

Impact

A malicious GSC_CORE_VOTING_ROLE could reset a spender's allowance to a tiny amount, potentially disrupting protocol operations that rely on that allowance.

What the attacker needed

Malicious GSC_CORE_VOTING_ROLE

The fix

The approval should add the new amount to the existing allowance instead of overwriting it.

How it was found

  1. A user with GSC_CORE_VOTING_ROLE calls approveLargeSpend to grant a large allowance to a spender.
  2. The same user calls gscApprove with amount=1 wei for the same spender.
  3. The spender's allowance is reset to 1 wei, overriding the previous large allowance.

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 many tokens, an approval sets the amount a spender can use, replacing any previous approval. Here, different functions each set the approval without adding to it, so a later small approval can wipe out a larger one. This could let someone with special permissions reduce an allowance unexpectedly.

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 bin2chen

View all

139 more disclosed reports, best first.

More from Arcade.xyz

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.