Skip to content
Business logic Audit finding Intermediate

Only one GroupBuy can ever use USDT or similar tokens with front-running approval protections

The SeaportLister contract sets an ERC20 approval to the maximum without first resetting it to zero, which reverts for tokens like USDT that require zero before a non-zero approval. As a result, only the first listing using such a token can succeed; subsequent listings or re-listings revert.

IllIllI Follow

Originally disclosed on Code4rena

Submitted by IllIllI

Calling approve() without first calling approve(0) if the current approval is non-zero will revert with some tokens, such as Tether (USDT). While Tether is known to do this, it applies to other tokens as well, which are trying to protect against this attack vector.

Impact

Only the first listing will start with the conduit’s approval at zero and will be able to change it to the maximum. Thereafter, every attempt to approve that same token will revert, causing any order using this lister to revert, including a re-listing at a lower price, which the protocol allows for.

Proof of Concept

The seaport conduit address is set in the constructor as an immutable variable, so it’s not possible to change it once the issue is hit:

// File: src/seaport/targets/SeaportLister.sol : SeaportLister.constructor()   #1

19        constructor(address _conduit) {
20 @>         conduit = _conduit;
21:       }

https://github.com/code-423n4/2022-12-tessera/blob/f37a11407da2af844bbfe868e1422e3665a5f8e4/src/seaport/targets/SeaportLister.sol#L19-L21

The approval is set to the maximum without checking whether it’s already the maximum:

// File: src/seaport/targets/SeaportLister.sol : SeaportLister.validateListing()   #2

29                for (uint256 i; i < ordersLength; ++i) {
30                    uint256 offerLength = _orders[i].parameters.offer.length;
31                    for (uint256 j; j < offerLength; ++j) {
32                        OfferItem memory offer = _orders[i].parameters.offer[j];
33                        address token = offer.token;
34                        ItemType itemType = offer.itemType;
35                        if (itemType == ItemType.ERC721)
36                            IERC721(token).setApprovalForAll(conduit, true);
37                        if (itemType == ItemType.ERC1155)
38                            IERC1155(token).setApprovalForAll(conduit, true);
39                        if (itemType == ItemType.ERC20)
40 @>                         IERC20(token).approve(conduit, type(uint256).max);
41                    }
42                }
43            }
44            // Validates the order on-chain so no signature is required to fill it
45            assert(ConsiderationInterface(_consideration).validate(_orders));
46:       }

https://github.com/code-423n4/2022-12-tessera/blob/f37a11407da2af844bbfe868e1422e3665a5f8e4/src/seaport/targets/SeaportLister.sol#L29-L46

The README states: The Tessera Protocol is designed around the concept of Hyperstructures, which are crypto protocols that can run for free and forever, without maintenance, interruption or intermediaries, and having to deploy a new SeaportLister in order to have a fresh conduit that also needs to be deployed, is not without maintenance or interruption.

Recommended Mitigation Steps

Always reset the approval to zero before changing it to the maximum.

mehtaculous (Tessera) disputed and commented:

Disagree with approval issue since the conduit will not be able to front-run the approvals.

However, the issue regarding the conduit as an immutable variable is valid and it seems that a solution would be to pass the conduit in as a parameter for every validateListing call.

HickupHH3 (judge) commented:

The issue here isn’t about the frontrunning attack vector, but about not being able to reset the approval back to the maximum because some token implementations require the allowance can only be set to non-zero from zero, ie. non-zero -> non-zero is disallowed.

Meaning, once the allowance is partially used, subsequent attempts to approve back to type(uint256).max will fail.

stevennevins (Tessera) commented:

I think this title is mislabeled and they meant SeaportOL. The Vault delegate calls to the Seaport Lister so these approvals would be scoped to the Vault so multiple listing are possible through the target contract. But a vault that relists wouldn’t be able to relist an ERC20 with front running protection.


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 contract calls approve() to set the allowance to the maximum without first resetting it to zero, which reverts for tokens that enforce the zero-first rule.

Impact

Only the first listing with a token like USDT can succeed; later listings or re-listings of that token revert, and the conduit address is immutable so it cannot be changed without redeploying.

What the attacker needed

Token enforces zero-first approval rule; conduit address is immutable

The fix

The approval should be reset to zero before setting it to the maximum.

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 allowance from one non-zero number directly to another; you must first set it to zero. The contract here tries to set the allowance to the maximum without resetting it, so after the first time, the token rejects the change and the listing fails.

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 Tessera - Versus 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.