Skip to content
Smart contracts Audit finding Intermediate

USDT is not supported because of approval mechanism

kenzo Follow

Originally disclosed on Code4rena

Submitted by kenzo, also found by MaratCerby, 0x1f8b, berndartmueller, Dravee, 0xsomeone, cryptphi, IllIllI, and xiaoming90

https://github.com/code-423n4/2022-05-rubicon/blob/main/contracts/rubiconPools/BathHouse.sol#L180

https://github.com/code-423n4/2022-05-rubicon/blob/main/contracts/RubiconRouter.sol#L157

https://github.com/code-423n4/2022-05-rubicon/blob/main/contracts/rubiconPools/BathToken.sol#L256

Vulnerability details

When using the approval mechanism in USDT, the approval must be set to 0 before it is updated. In Rubicon, when creating a pair, the paired asset’s approval is not set to 0 before it is updated.

Impact

Can’t create pairs with USDT, the most popular stablecoin, as the approval will revert.

Proof of Concept

USDT reverts on approval if previous allowance is not 0:

require(!((_value != 0) && (allowed[msg.sender][_spender] != 0)));

When creating a pair, Rubicon approves the paired asset without first setting it to 0:

desiredPairedAsset.approve(pairedPool, initialLiquidityExistingBathToken);

Therefore, if desiredPairedAsset is USDT, the function will revert, and pairs with USDT can not be created.

This problem will also manifest in RubiconMarket’s approval function and BathToken’s approval function,

Recommended Mitigation Steps

Set the allowance to 0 before setting it to the new value.

bghughes (Rubicon) disputed and commented:

This doesn’t sound right to me because it implies that USDT is non-compliant with the infinite approval pattern. I believe USDT can be infinitely approved, asking for an extra pair of eyes to verify.

Just tested this on Rubicon trading and there is no need to re-approve USDT before using it so I believe this is a bad issue.

KenzoAgada (warden) commented:

@bghughes This is not related to infinite approval (which USDT allows); you’re approving a specific amount. USDT on mainnet does not allow changing from a non-zero allowance to another non-zero allowance.

Did you test it on Optimism? USDT on optimism seems to use an updated version of USDT, unlike the one in mainnet. In Optimism you can change the approval from non-zero to another non-zero. But if you look at USDT on Ethereum mainnet, the code does not allow this (look at the second clause):

        require(!((_value != 0) && (allowed[msg.sender][_spender] != 0)));

HickupHH3 (judge) commented:

The issue is valid on approveAssetOnMarket() and approveMarket(), but not on the other lines. Even that, it’s likely for these functions to be called just once. Nevertheless, I will let the issue stand.

The reason is because the allowance will be entirely consumed when the deposit function is called, so it will be set to zero always.

desiredPairedAsset.approve(
    pairedPool,
    initialLiquidityExistingBathToken
);

// Deposit assets and send Bath Token shares to msg.sender
// This will use up the entire allowance given

IBathToken(pairedPool).deposit(
    initialLiquidityExistingBathToken,
    msg.sender
);

Hence, any issue that does not reference the approveAssetOnMarket() and approveMarket() functions will be marked as invalid.

bghughes (Rubicon) confirmed and commented:

Thank you for the explanation and thank you @HickupHH3.


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

What is known

A medium-severity smart contracts bug in Rubicon v2. Code4rena made it public on 1 August 2022. Found in the 2022-05-rubicon audit contest (finding M-08).

About Smart contracts

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by kenzo

View all

53 more disclosed reports, best first.

More from Rubicon v2

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.