Skip to content
Business logic Audit finding Intermediate

Overpayment of native ETH is not refunded to buyer

The InfinityExchange contract accepts native ETH payments but does not refund any amount sent above the final calculated price. An attacker (or ordinary user) could accidentally overpay, and the excess ETH becomes permanently locked in the contract because a separate bug prevents the owner from withdrawing it.

horsefacts Follow

Originally disclosed on Code4rena

Submitted by horsefacts, also found by 0x29A, antonttc, berndartmueller, byterocket, cccz, codexploder, dipp, GimelSec, GreyArt, Lambda, oyc109, Ruhum, and unforgiven_

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

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

Vulnerability Details

InfinityExchange accepts payments in native ETH, but does not return overpayments to the buyer. Overpayments are likely in the case of auction orders priced in native ETH.

In the case of a Dutch or reverse Dutch auction priced in native ETH, the end user is likely to send more ETH than the final calculated price in order to ensure their transaction succeeds, since price is a function of block.timestamp, and the user cannot predict the timestamp at which their transaction will be included.

In a Dutch auction, final price may decrease below the calculated price at the time the transaction is sent. In a reverse Dutch auction, the price may increase above the calculated price by the time a transaction is included, so the buyer is incentivized to provide additional ETH in case the price rises while their transaction is waiting for inclusion.

The takeOrders and takeMultipleOneOrders functions both check that the buyer has provided an ETH amount greater than or equal to the total price at the time of execution:

InfinityExchange#takeOrders

    // check to ensure that for ETH orders, enough ETH is sent
    // for non ETH orders, IERC20 safeTransferFrom will throw error if insufficient amount is sent
    if (isMakerSeller && currency == address(0)) {
      require(msg.value >= totalPrice, 'invalid total price');
    }

InfinityExchange#takeMultipleOneOrders

    // check to ensure that for ETH orders, enough ETH is sent
    // for non ETH orders, IERC20 safeTransferFrom will throw error if insufficient amount is sent
    if (isMakerSeller && currency == address(0)) {
      require(msg.value >= totalPrice, 'invalid total price');
    }

However, neither of these functions refunds the user in the case of overpayment. Instead, overpayment amounts will accrue in the contract balance.

Moreover, since there is a bug in rescueETH that prevents ether withdrawals from InfinityExchange, these overpayments will be locked permanently: the owner cannot withdraw and refund overpayments manually.

Scenario:

  • Alice creates a sell order for her token with constraints that set up a reverse Dutch auction: start price 500, end price 2000, start time 1, end time 5.
  • Bob fills the order at time 2. The calculated price is 875. Bob is unsure when his transaction will be included, so provides a full 2000 wei payment.
  • Bob’s transaction is included at time 3. The calculated price is 1250.
  • Bob’s additional 750 wei are locked in the contract and not refunded.

Suggestion: Calculate and refund overpayment amounts to callers.

nneverlander (Infinity) confirmed and resolved:

Agree with the assessment, fixed in https://github.com/infinitydotxyz/exchange-contracts-v2/commit/a605b72e44256aee76d80ae1652e5c98c855ffd3

HardlyDifficult (judge) commented:

In the case of a Dutch auction, precise pricing is unknown at the time a tx is broadcasted. This leads to users overpaying and the surplus is taken as exchange fees instead of being refunded.

Accepting as a High risk submission.


The original report as published on Code4rena, by horsefacts. 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 contract checks that the sent ETH is at least the total price but never calculates or returns the difference.

Impact

Overpayments are permanently locked in the contract because a separate bug prevents the owner from withdrawing ETH, so users lose funds.

What the attacker needed

User sends more ETH than the final price; Auction order priced in native ETH

The fix

The contract was fixed to calculate and refund overpayment amounts to callers.

How it was found

  1. Alice creates a sell order set up as a reverse Dutch auction with start price 500, end price 2000, start time 1, end time 5.
  2. Bob fills the order at time 2 when the calculated price is 875, but sends 2000 wei to cover possible price changes.
  3. Bob's transaction is included at time 3 when the calculated price is 1250.
  4. The extra 750 wei is not refunded and remains locked in the contract.

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 pay with ETH, you sometimes send more than needed to make sure the transaction goes through. This contract keeps the extra money instead of giving it back. Because another bug stops the owner from taking ETH out, that extra money is stuck forever.

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 horsefacts

View all

8 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.