IOP _ ThunderNFT 34934 - [Smart Contract - Critical] thunder_exchangeupdate_order can be abused to s

Submitted on Sun Sep 01 2024 15:04:49 GMT-0400 (Atlantic Standard Time) by @jasonxiale for IOP | ThunderNFT

Report ID: #34934

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 funds, whether at-rest or in-motion, other than unclaimed yield

Description

Brief/Intro

According to discord chat history, ERC1155 tokens are also in scope.

In current implementation, there is an issue that when ERC1155 token is used, malicious can steal erc1155 token that has the same assetId by abusing thunder_exchange.update_order

Vulnerability Details

In thunder_exchange. place_order, while the order.side is Side::Sell, the function will check if the tx's assetId matches order's tokenId, and also check if tx's token amount equals order_input.amount in thunder_exchange#L96-L101

But in thunder_exchange.update_order, while order.side is Side::Sell, the function doesn't check the assetId and amount mathces with the order in thunder_exchange#L124

Impact Details

Because thunder_exchange.update_order does nothing when the order.side is Side::Sell in thunder_exchange#L124

  1. malicious user can abusing this issue to steal ERC1155 token.

  2. when a honest user wants to reduce order_input.amount, the remaining ERC1155 token won't be returned to the user.

References

Add any relevant links to documentation or code

Proof of concept

Proof of Concept

  1. To mock the ERC1155, I make some changes in erc721 folder, and re-use erc721 as ERC1155

  1. Then generate a Rust test template under thunder_exchange folder, and puts the following code in thunder_exchange/tests/harness.rs and run cargo test -- --nocapture

As the test case shows, by abusing thunder_exchange.update_order and thunder_exchange.cancel_order, the malicious user(wallet_1) get more erc1155 token than expected.

Last updated

Was this helpful?