Skip to content
Business logic Audit finding Beginner

Did not Approve to zero first

The contract calls ERC20 approve directly on tokens such as USDT that revert when the existing allowance is not zero, so the approval step can fail. An attacker cannot exploit this directly, but legitimate transfers through the bridge could be blocked.

HonorLt Follow with Ruhum, Saeedalipoor01988 and 6 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-01-derby-judging/issues/36

Found by

HonorLt, Ruhum, Saeedalipoor01988, SunSec, chainNue, hyh, koxuan, martin, tsvetanovv

Summary

Vulnerability Detail

Some ERC20 tokens like USDT require resetting the approval to 0 first before being able to reset it to another value. The ohm.approve, pairToken.approve, pool.approve function does not do this - unlike OpenZeppelin's safeApprove implementation.

Impact

unsafe ERC20 approve that do not handle non-standard erc20 behavior. 1.Some token contracts do not return any value. 2.Some token contracts revert the transaction when the allowance is not zero.

Code Snippet

https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/XProvider.sol#L150

Solidity
    // This contract approves transfer to Connext
    IERC20(_token).approve(address(connext), _amount);

Tool used

Manual Review

Recommendation

It is recommended to set the allowance to zero before increasing the allowance and use safeApprove/safeIncreaseAllowance.

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

Likely the code calls the raw ERC20 approve function instead of a safe helper that first zeroes the allowance and checks the return value.

Impact

Approvals for non-standard tokens such as USDT could revert, blocking the intended transfer; the text does not claim any theft or direct attacker gain.

What the attacker needed

Token behaves like USDT on approve; existing non-zero allowance

The fix

The allowance should be set to zero before it is increased, using safeApprove or safeIncreaseAllowance.

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, such as USDT, refuse to change an existing spending permission unless it is first set back to zero. This contract skips that reset step, so the approval call can fail and the transfer cannot go ahead. It is a reliability bug rather than a way for someone to steal funds.

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 HonorLt

View all

13 more disclosed reports, best first.

More from Derby

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.