IOP _ ThunderNFT 34980 - [Smart Contract - Critical] Order side manipulation can lead to theft of NF

Submitted on Mon Sep 02 2024 07:14:37 GMT-0400 (Atlantic Standard Time) by @Solosync6 for IOP | ThunderNFT

Report ID: #34980

Report type: Smart Contract

Report severity: Critical

Target: https://github.com/ThunderFuel/smart-contracts/tree/main/contracts-v1/thunder_exchange

Impacts:

  • Direct theft of any user NFTs, whether at-rest or in-motion, other than unclaimed royalties

Description

Brief/Intro

The ThunderExchange contract contains a critical vulnerability that could allow an attacker to manipulate buy/sell order and potentially gain unauthorized ownership of NFTs.

This vulnerability stems from insufficient checks during order updates and cancellations, particularly when changing an order from buy to sell.

Vulnerability Details

The vulnerability exists in the interaction between the update_order and cancel_order functions. Here's a step-by-step breakdown:

  1. An attacker can place a buy order at a very low price for an NFT they don't own. All they need to do is to make sure they have pool balance greater than order price:

  1. Attacker can then update this buy order to a sell order:

Note that changing sides is allowed in _validate_maker_order_input. Also, crucially, there is no check if the attacker indeed owns the NFT if order side is changed.

  1. The attacker can then cancel this "sell" order:

Note that on cancellation, the NFT asset is transferred back to the maker, only this time, the maker was never the original owner of the NFT.

The vulnerability arises because:

  • There's no check to prevent changing order sides during updates.

  • There's no verification of NFT ownership when updating to a sell order.

  • The cancellation process trusts the strategy contract to return the correct order information without additional verification.

Impact Details

In the worst-case scenario, an attacker could:

  • Create buy orders for valuable NFTs they don't own.

  • Update these to sell orders without owning the NFTs.

  • Cancel these "sell" orders, potentially receiving NFTs they never owned.

This could lead to unauthorized transfer of high-value NFTs, significant financial losses for legitimate NFT owners, and a complete breakdown of trust in the marketplace.

References

https://github.com/ThunderFuel/smart-contracts/blob/260c9859e2cd28c188e8f6283469bcf57c9347de/contracts-v1/thunder_exchange/src/main.sw#L114

https://github.com/ThunderFuel/smart-contracts/blob/260c9859e2cd28c188e8f6283469bcf57c9347de/contracts-v1/thunder_exchange/src/main.sw#L157

Proof of concept

Proof of Concept

Note: the commented test code in ThunderSDK contains old contracts that are no longer in use. All tests are commented as the function signatures in the tests don't match with the code in scope

New ABIs need to be generated for all contracts. I have created this setup using latest contracts.

Last updated

Was this helpful?