Skip to content
Business logic Audit finding Intermediate

Maker order buyer is forced to reimburse the gas cost at any tx.gasprice

Maker buy orders reimburse the transaction gas cost to the executor at whatever gas price the transaction used, so the buyer's total cost is unpredictable. A match executor could execute the order during a busy period at a very high gas price, and the buyer would pay that inflated cost.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug, also found by 0xsanson, and shenwilly

uint256 gasCost = (startGasPerOrder - gasleft() + wethTransferGasUnits) * tx.gasprice;
// if the execution currency is weth, we can send the protocol fee and gas cost in one transfer to save gas
// else we need to send the protocol fee separately in the execution currency
if (buy.execParams[1] == weth) {
  IERC20(weth).safeTransferFrom(buy.signer, address(this), protocolFee + gasCost);
} else {
  IERC20(buy.execParams[1]).safeTransferFrom(buy.signer, address(this), protocolFee);
  IERC20(weth).safeTransferFrom(buy.signer, address(this), gasCost);
}

In the current design/implementation, while the order is executed by the MATCH_EXECUTOR, the gas cost will always be paid by the maker order’s buyer.

While the buyer did agreed to pay a certain price for certain NFTs, the actual cost for that maker buy order is unpredictable: because the MATCH_EXECUTOR can choose to execute the order while the network is extremly busy and the gas price is skyhigh.

As the gas cost at whatever gas price will be reimbursed by the buyer, the executor has no incentive to optimize and choose to execute the order at a lower gas cost.

The result is the buyer can sometimes end up paying much higher total price (incl. gas cost) for the items they bought.

Impact

While this is more of a design issue than a wrong implementation, the impact can be very severe for some users, and can cause defacto fund loss to the users who have they maker buy orders matched at a high gas price transactions.

Recommendation

Consider adding a new paramer to maker buy orders, maxGasCost to allow the buyer to limit the max gas they agreed to pay.

nneverlander (Infinity) acknowledged, but disagreed with severity and commented:

We have considered this issue and decided to handle it offchain. The offchain matching engine does not send txns if gas costs are high by default. While this involves some trust, we wanted to simplify the UX for users.

In any case, it is trivial for us to add the max gas preference setting offchain on the UI and the matching engine will respect that.

We can consider adding this preference to the orderType itself in a future implementation.

As such, the bug can be classified as low risk but I leave it up to more experienced judges.

HardlyDifficult (judge) decreased severity to Medium and commented:

Thank you for the detailed response here @nneverlander!

Due to the gas refund logic highlighted by the warden here, users could end up spending their entire balance (or amount approved) unexpectedly. I understand that this could be handled with off chain logic but a bug in that system could have significant impact on users. Since it is just a single trusted actor that could cause damage here - I believe this is a Medium risk issue due to the “external requirements” such as a bug in the off chain matcher.


The original report as published on Code4rena, by WatchPug. 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 gas reimbursement is computed from the live tx.gasprice with no cap set by the buyer, so the executor controls the cost the buyer pays.

Impact

A buyer whose maker order is matched during a high gas price transaction could pay much more than expected, effectively losing funds; the project says its offchain matching engine avoids high gas by default, but that relies on trust.

What the attacker needed

A maker buy order is placed; a match executor executes it; gas price is high at execution

The fix

The report recommends adding a maxGasCost parameter to maker buy orders so the buyer can cap the gas they will reimburse; the project said it would handle this offchain and consider adding it to the order type later.

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 someone places an order to buy an item, they agree to a price. Here the buyer also pays back the gas fee (the cost of running the transaction on the blockchain) to whoever executes the order. Because that fee is calculated from the live gas price, the buyer cannot know in advance how much extra they will be charged, and the executor has no reason to keep it low.

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 WatchPug

View all

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