Skip to content
Business logic Audit finding Intermediate

Malicious tokens can be used to grief buyers and cause loss of their WETH balance

The exchange contract charges buyers a dynamically calculated fee based on gas consumed during order matching, and a malicious seller token can deliberately waste gas to inflate this fee, draining the buyer's approved WETH. An attacker could cause the buyer to lose all WETH they have approved to the exchange.

0xalpharush Follow

Originally disclosed on Code4rena

Submitted by 0xalpharush

https://github.com/code-423n4/2022-06-infinity/blob/765376fa238bbccd8b1e2e12897c91098c7e5ac6/contracts/core/InfinityExchange.sol#L739-L746

https://github.com/code-423n4/2022-06-infinity/blob/765376fa238bbccd8b1e2e12897c91098c7e5ac6/contracts/core/InfinityExchange.sol#L727

https://github.com/code-423n4/2022-06-infinity/blob/765376fa238bbccd8b1e2e12897c91098c7e5ac6/contracts/core/InfinityExchange.sol#L1087

Impact

The function matchOneToOneOrders transfers an arbitrary amount of WETH from the user, buy.signer , in its inner call to _execMatchOneToOneOrders. The amount charged to the user is calculated dynamically based off of the gas consumption consumed during the trace. Notably, this amount is controlled by the seller since the seller’s token can be malicious and purposefully consume a large amount of gas to grief the buyer. For example, when a user purchases an ERC721 token, the _transferNFTs will result in a call to an ERC721.safeTransferFrom that can exhibit any behavior such as wasting gas. This scenario is unlikely given that a buyer would have to purchase a malicious token, but the impact would be devastating as any WETH that the buyer has approved to the exchange can be lost.

This vulnerability is potentially possible in these functions as well: https://github.com/code-423n4/2022-06-infinity/blob/765376fa238bbccd8b1e2e12897c91098c7e5ac6/contracts/core/InfinityExchange.sol#L236-L242 https://github.com/code-423n4/2022-06-infinity/blob/765376fa238bbccd8b1e2e12897c91098c7e5ac6/contracts/core/InfinityExchange.sol#L787-L796

Proof of Concept

A buyer gives infinite WETH approval to the exchange contract and unknowingly purchases a malicious token from an attacker. The attacker’s token wastes gas in the transfer call and causes all of the buyer’s WETH to be sent to the protocol when matchOneToOneOrders is performed by the match executor.

Recommended Mitigation Steps

Allow users to input a maximum fee/ gas cost they are willing to spend on each order. Pulling an arbitrary amount from a user’s wallet without any restriction is a dangerous practice given that many users give large/ infinite approval to contracts.

In addition, manual gas accounting is error prone and it would make more sense to allow users to match orders themselves instead of extracting fees to compensate the matcher.

nneverlander (Infinity) acknowledged and commented:

Thanks, we are adding a max price variable

HardlyDifficult (judge) commented:

This is a clever way to leverage safeTransferFrom to grief users. Accepting as Medium risk.


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

Likely the fee is calculated from actual gas used during the transfer, which the seller's token can manipulate by consuming extra gas.

Impact

A buyer could lose all WETH they have approved to the exchange, though the scenario is unlikely because the buyer must purchase a malicious token.

What the attacker needed

Buyer approves WETH to the exchange; buyer purchases a malicious token; match executor processes the order

The fix

The project acknowledged the issue and said they are adding a maximum price variable to limit the fee.

How it was found

  1. Buyer gives infinite WETH approval to the exchange contract.
  2. Buyer unknowingly purchases a malicious token from an attacker.
  3. The attacker's token wastes gas in the transfer call.
  4. The match executor performs matchOneToOneOrders, causing all of the buyer's WETH to be sent to the protocol.

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.

When you buy something on this exchange, the contract charges you a fee that depends on how much computing power (gas) the transaction used. A malicious seller can make their token use up a lot of gas on purpose, so the fee becomes huge and the contract takes all the WETH (a cryptocurrency token) you've approved. This is like a shop charging you based on how long the cashier takes, and the seller bribing the cashier to be very slow.

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

View all

4 more disclosed reports, best first.

More from Infinity NFT Marketplace 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.