Skip to content
Business logic Audit finding Intermediate

Must approve 0 first

The claimGovFees function approves the maximum allowance for each asset without first resetting it to zero, which can cause tokens like USDT to revert when changing a non-zero allowance. An attacker could not directly exploit this, but it could block the function from working with certain tokens.

0x4non Follow with kwhuo68, eierina and 6 others

Originally disclosed on Code4rena

Submitted by 0x4non, also found by kwhuo68, eierina, Deivitto, 0xNazgul, 141345, imare, cccz, and rvierdiiev

Some tokens (like USDT) do not work when changing the allowance from an existing non-zero allowance value. They must first be approved by zero and then the actual allowance must be approved.

Proof of Concept

https://github.com/code-423n4/2022-12-tigris/blob/main/contracts/Lock.sol#L117

    function claimGovFees() public {
        address[] memory assets = bondNFT.getAssets();

        for (uint i=0; i < assets.length; i++) {
            uint balanceBefore = IERC20(assets[i]).balanceOf(address(this));
            IGovNFT(govNFT).claim(assets[i]);
            uint balanceAfter = IERC20(assets[i]).balanceOf(address(this));
            IERC20(assets[i]).approve(address(bondNFT), type(uint256).max);// @audit this could fail always with some tokens,
            bondNFT.distribute(assets[i], balanceAfter - balanceBefore);
        }
    }

Recommended Mitigation Steps

Add an approve(0) before approving;

    function claimGovFees() public {
        address[] memory assets = bondNFT.getAssets();

        for (uint i=0; i < assets.length; i++) {
            uint balanceBefore = IERC20(assets[i]).balanceOf(address(this));
            IGovNFT(govNFT).claim(assets[i]);
            uint balanceAfter = IERC20(assets[i]).balanceOf(address(this));
            IERC20(assets[i]).approve(address(bondNFT), 0);
            IERC20(assets[i]).approve(address(bondNFT), type(uint256).max);
            bondNFT.distribute(assets[i], balanceAfter - balanceBefore);
        }
  }

Alex the Entreprenerd (judge) commented:

The Warden has shown how, due to the function approving max multiple times, certain tokens, that only allow a non-zero allowance to be set starting from zero, could revert.

Because this depends on the token implementation, but there’s a reasonable chance to believe that USDT will be used, I agree with Medium Severity.

GainsGoblin (Tigris Trade) confirmed:

Since the purpose of the bonds is to lock tigAsset liquidity, only tigAsset tokens will be allowed to be locked, which don’t have this issue.

GainsGoblin (Tigris Trade) resolved:

Mitigation: https://github.com/code-423n4/2022-12-tigris/pull/2#issuecomment-1419177578


The original report as published on Code4rena, by 0x4non. 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 contract calls approve with a non-zero value without first resetting the allowance to zero, which is incompatible with tokens that require a zero allowance before setting a new one.

Impact

The function claimGovFees could revert for tokens like USDT, preventing the distribution of fees; however, the protocol later stated that only tigAsset tokens will be used, which do not have this issue.

What the attacker needed

Token requires zero allowance before change; function claimGovFees is called

The fix

The fix is to add an approve(0) call before approving the maximum allowance, as shown in the recommended mitigation.

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.

Some digital tokens, like USDT, have a rule that you cannot change an existing permission (allowance) directly to a new number unless you first set it to zero. The smart contract tries to set a maximum permission without resetting it first, so the transaction fails for those tokens. This means the function that distributes fees would not work if such a token is used.

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 0x4non

View all

6 more disclosed reports, best first.

More from Tigris Trade contest

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.