Skip to content
Business logic Audit finding Intermediate

`SafeERC20.safeApprove` reverts for changing existing approvals

The `CrosschainDistributor._setTotal` function uses `SafeERC20.safeApprove` to change an existing non-zero approval to another non-zero value, which causes a revert. This prevents the owner from updating the total allocation, breaking a core feature of the airdrop protocol.

AkshaySrivastav Follow with Juntao, Musaka and 6 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-06-tokensoft-judging/issues/141

Found by

AkshaySrivastav, Juntao, Musaka, auditsea, blackhole, circlelooper, jah, kutugu, ni8mare

Summary

SafeERC20.safeApprove reverts when a non-zero approval is changed to a non-zero approval. The CrosschainDistributor._setTotal function tries to change an existing approval to a non-zero value which will revert.

Vulnerability Detail

The safeApprove function has explicit warning:

Solidity
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'

But still the _setTotal use it to change approval amount:

Solidity
  function _allowConnext(uint256 amount) internal {
    token.safeApprove(address(connext), amount);
  }

  /** Reset Connext allowance when total is updated */
  function _setTotal(uint256 _total) internal virtual override onlyOwner {
    super._setTotal(_total);
    _allowConnext(total - claimed);
  }

Impact

Due to this bug all calls to setTotal function of CrosschainContinuousVestingMerkle and CrosschainTrancheVestingMerkle will get reverted.

Tokensoft airdrop protocol is meant to be used by other protocols and the ability to change total parameter is an intended offering. This feature will be important for those external protocols due to the different nature & requirement of every airdrop. But this feature will not be usable by airdrop owners due to the incorrect code implementation.

Code Snippet

https://github.com/sherlock-audit/2023-06-tokensoft/blob/main/contracts/contracts/claim/abstract/CrosschainDistributor.sol#L35-L45

Tool used

Manual Review

Recommendation

Consider using 'safeIncreaseAllowance' and 'safeDecreaseAllowance' instead of safeApprove in _setTotal.

Discussion

cr-walker

Good catch, updating the code to simply set approval to zero first and then reset approval. I don't think any of the reentrancy attacks that safeApprove() is worried about are relevant here (neither the owner nor the connect protocol are going to use this to rug the contract, they both have much more direct ways to take tokens if malicious!)

cr-walker

Fixed by https://github.com/SoftDAO/contracts/pull/12

maarcweiss

Fixed by approving to 0 before approving again by implementing the following line: token.safeApprove(address(connext), 0);

The original report as published on Sherlock, by AkshaySrivastav. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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 code calls `safeApprove` to change an existing non-zero allowance to another non-zero value, which the SafeERC20 library explicitly disallows.

Impact

All calls to `setTotal` on the affected contracts will revert, making the intended feature unusable for airdrop owners.

What the attacker needed

Owner calls setTotal; existing non-zero approval

The fix

The code was fixed by setting the approval to zero before setting the new approval amount.

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 Ethereum tokens, an approval lets someone else spend your tokens. The `safeApprove` function is meant only for setting an initial approval or resetting to zero; changing directly from one non-zero amount to another is blocked because it can be unsafe. Here, the code tries to update an existing approval, so the transaction always fails, and the owner cannot change the total amount.

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 AkshaySrivastav

View all

16 more disclosed reports, best first.

More from Tokensoft

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.