Skip to content
Access control Audit finding Intermediate

Malicious governance can use updateWethTranferGas to steal WETH from buyers

The contract's owner can set the WETH transfer gas units to an arbitrarily high value, which inflates the gas cost charged to buyers when their orders are filled. A malicious or compromised governance could use this to take the buyer's approved WETH as gas fees.

shenwilly Follow

Originally disclosed on Code4rena

Submitted by shenwilly, also found by 0x29A, berndartmueller, BowTiedWardens, peritoflores, and VAD37

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

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

Vulnerability Details

A malicious or compromised governance can set the transfer gas cost to an unreasonable amount and steal approved WETH from buyers.

There are two ways for governance to exploit this:

  • When an order is being executed, governance can frontrun the transactions by setting WETH_TRANSFER_GAS_UNITS to a very high amount.
  • Set WETH_TRANSFER_GAS_UNITS to a very high amount, and execute trades against active buy orders. As long as the value of WETH to steal is higher than the cost to prepare the NFTs to sell, it is profitable to do so.

Proof of Concept

  • WETH_TRANSFER_GAS_UNITS is set to 50000.
  • Alice has 100 WETH and 100 USDC. She approved infinite allowance to InfinityExchange.
  • Alice signs a buy order to buy a FakePunk NFT with 100 USDC price.
  • Malicious governance sets WETH_TRANSFER_GAS_UNITS to a very high amount such that the gasCost calculation equals 100 WETH.
  • Governance then bought a FakePunk in open market, and fills Alice’s order.
  • Alice received the NFT but paid 100 WETH as gas cost.

Recommended Mitigation Steps

Set a sanity check in updateWethTranferGas so governance can’t set it to unreasonable value. Consider using timelock for setting governance settings.

function updateWethTranferGas(uint32 _wethTransferGasUnits) external onlyOwner {
    require(_wethTransferGasUnits <= 100000, "gas unit must not be higher than 100000");
    WETH_TRANSFER_GAS_UNITS = _wethTransferGasUnits;
    emit NewWethTransferGasUnits(_wethTransferGasUnits);
}

nneverlander (Infinity) acknowledged, but disagreed with severity

HardlyDifficult (judge) commented:

When a transaction is sent by the matching engine, the user pays for the gas costs of their portion of that call. There’s overhead in actually getting the money from the user in WETH, which is estimated with WETHTRANSFERGAS_UNITS. That value is currently uncapped so the admin could increase it significantly, impacting users who signed orders back when that value was more reasonably assigned.

Agree with Medium risk here.


The original report as published on Code4rena, by shenwilly. 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 function that updates the WETH transfer gas units lacks an upper bound, allowing governance to set an arbitrarily high value that directly increases the gas cost charged to buyers.

Impact

A malicious or compromised governance could steal buyers' approved WETH by inflating the gas cost, potentially up to the full approved amount.

What the attacker needed

Malicious or compromised governance; buyer has approved WETH allowance; buyer has signed a buy order

The fix

The updateWethTranferGas function should include a sanity check to cap the gas units at a reasonable maximum, and consider using a timelock for governance settings.

How it was found

  1. Governance sets WETH_TRANSFER_GAS_UNITS to a very high value.
  2. A buyer has approved WETH allowance to the exchange and signed a buy order.
  3. Governance acquires the NFT and fills the buyer's order.
  4. The buyer receives the NFT but is charged an excessive gas cost in WETH.

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.

This is a smart contract bug where the person in charge (governance) can change a setting that controls how much extra fee a buyer pays when their order is completed. If they set it very high, the buyer ends up paying a huge fee in WETH, which goes to the governance. The buyer still gets the item they ordered but loses a lot of money.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More by shenwilly

View all

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

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.