Skip to content
Business logic Audit finding Intermediate

Not calling approve(0) before setting a new approval causes the call to revert when used with Tether (USDT)

The contract calls approve() on tokens without first resetting the existing allowance to zero. With tokens like USDT that revert on a non-zero approval, these calls fail, preventing the protocol from using such tokens in Uniswap pools.

IllIllI Follow

Originally disclosed on Code4rena

Submitted by IllIllI, also found by cccz and hyh

Some tokens do not implement the ERC20 standard properly but are still accepted by most code that accepts ERC20 tokens. For example Tether (USDT)‘s approve() function will revert if the current approval is not zero, to protect against front-running changes of approvals.

Impact

The code as currently implemented does not handle these sorts of tokens properly when they’re a Uniswap pool asset, which would prevent USDT, the sixth largest pool, from being used by this project. This project relies heavily on Uniswap, so this would hamper future growth and availability of the protocol.

Proof of Concept

  1. File: contracts/vaultandoracles/FlashLoan.sol (line 48)
IERC20(assets[0]).approve(address(LP_VAULT), amounts[0]);
  1. File: contracts/vaultandoracles/FlashLoan.sol (line 58)
IERC20(assets[0]).approve(address(LENDING_POOL), amountOwing);
  1. File: contracts/vaultandoracles/UniV3LpVault.sol (line 418)
IERC20Detailed(params.asset).approve(msg.sender, owedBack);

There are other calls to approve(), but they correctly set the approval to zero after the transfer is done, so that the next approval can go through.

Recommended Mitigation Steps

Use OpenZeppelin’s SafeERC20’s safeTransfer() instead.

0xdramaone (Duality Focus) confirmed and commented:

Agree that we should set approve 0 before all approvals to avoid approval protection reverting and to support assets such as USDT.

0xdramaone (Duality Focus) resolved


The original report as published on Code4rena, by IllIllI. 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 code calls approve() without first setting the allowance to zero, which is required by non-standard ERC20 tokens like USDT.

Impact

The protocol cannot use USDT as a Uniswap pool asset, which would hamper future growth and availability.

What the attacker needed

Token like USDT that reverts on non-zero approval; existing non-zero allowance

The fix

The code should set the approval to zero before setting a new approval, or use OpenZeppelin's SafeERC20 safeTransfer().

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 tokens, like USDT, have a safety rule: you cannot change an existing approval directly; you must first set it to zero. The code here tries to change approvals without that reset, so the transaction fails. This means the project cannot work with USDT in its Uniswap pools.

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 IllIllI

View all

119 more disclosed reports, best first.

More from Duality Focus 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.