Skip to content
Business logic Audit finding Beginner

SpeedBumpPriceGate: Excess ether did not return to the user

The passThruGate function in the SpeedBumpPriceGate contract did not return excess ether sent by users when purchasing an NFT. An attacker could exploit this by sending more ether than the current price, causing the user to lose the excess funds.

cccz Follow

Originally disclosed on Code4rena

Submitted by cccz, also found by 0x52, 0xYamiDancho, csanuragjain, GimelSec, gzeon, hickuphh3, horsefacts, hyh, IllIllI, kenzo, leastwood, PPrieditis, reassor, unforgiven, WatchPug, and danb

The passThruGate function of the SpeedBumpPriceGate contract is used to charge NFT purchase fees. Since the price of NFT will change due to the previous purchase, users are likely to send more ether than the actual purchase price in order to ensure that they can purchase NFT. However, the passThruGate function did not return the excess ether, which would cause asset loss to the user. Consider the following scenario:

  1. An NFT is sold for 0.15 eth
  2. User A believes that the value of the NFT is acceptable within 0.3 eth, considering that someone may buy the NFT before him, so user A transfers 0.3 eth to buy the NFT
  3. When user A’s transaction is executed, the price of the NFT is 0.15 eth, but since the contract does not return excess eth, user A actually spends 0.3 eth.

Proof of Concept

https://github.com/code-423n4/2022-05-factorydao/blob/e22a562c01c533b8765229387894cc0cb9bed116/contracts/SpeedBumpPriceGate.sol#L65-L82

Recommended Mitigation Steps

-   function passThruGate(uint index, address) override external payable {
+  function passThruGate(uint index, address payer) override external payable {
        uint price = getCost(index);
        require(msg.value >= price, 'Please send more ETH');

        // bump up the price
        Gate storage gate = gates[index];
        // multiply by the price increase factor
        gate.lastPrice = (price * gate.priceIncreaseFactor) / gate.priceIncreaseDenominator;
        // move up the reference
        gate.lastPurchaseBlock = block.number;

        // pass thru the ether
        if (msg.value > 0) {
            // use .call so we can send to contracts, for example gnosis safe, re-entrance is not a threat here
-           (bool sent, bytes memory data) = gate.beneficiary.call{value: msg.value}("");
+          (bool sent, bytes memory data) = gate.beneficiary.call{value: price}("");
            require(sent, 'ETH transfer failed');
        }
+      if (msg.value - price > 0){
+         (bool sent, bytes memory data) = payer.call{value: msg.value - price}("");
+          require(sent, 'ETH transfer failed');}
    }

illuzen (FactoryDAO) confirmed, but disagreed with severity

illuzen (FactoryDAO) resolved:

https://github.com/code-423n4/2022-05-factorydao/pull/4

Justin Goro (judge) commented:

Maintaining severity as user funds are lost.


The original report as published on Code4rena, by cccz. 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 forwards the entire msg.value to the beneficiary instead of only the required price, and does not refund any excess to the payer.

Impact

Users could lose excess ether when purchasing NFTs, as the contract does not refund overpayment.

What the attacker needed

User sends more ether than the current price

The fix

The contract was fixed to send only the required price to the beneficiary and refund any excess to the payer.

How it was found

  1. An NFT is sold for 0.15 eth
  2. User A transfers 0.3 eth to buy the NFT, expecting a refund of excess
  3. When the transaction executes, the price is 0.15 eth, but the contract does not return excess eth, so user A spends 0.3 eth

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 buying an NFT, a user might send extra ether to ensure the purchase goes through if the price changes. The contract kept all the ether sent, even if the actual price was lower, so the user lost money. This is a bug because the contract should return the extra ether to the buyer.

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 cccz

View all

104 more disclosed reports, best first.

More from FactoryDAO 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.