IOP _ ThunderNFT 34677 - [Smart Contract - Insight] NFTs can not be canceled since the cancel_order

Submitted on Tue Aug 20 2024 14:58:06 GMT-0400 (Atlantic Standard Time) by @zeroK for IOP | ThunderNFT

Report ID: #34677

Report type: Smart Contract

Report severity: Insight

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

Impacts:

  • Contract fails to deliver promised returns, but doesn't lose value

  • Permanent freezing of NFTs

  • Block stuffing

Description

Brief/Intro

the function cancel_order in the thunder_exchange contract is meant to be used to cancel NFTs order and withdraw the nft back to its owner, this function have storage read attribute #[storage(read)] which mean its a pure function, however this function will call the cancel_order() function in strategy fixed which have write and read storage attribute, this will lead to sway compiler error since pure function can not call impure function and nfts owners can not transfer back their NFTs since they deposit it.

Vulnerability Details

the thunder_exchange#cancel_order() function is implemented as below:

and the cancel_order in fixed strategy is implemented as below:

this wat NFTs can be locked forever in scenario below:

  • Bob listed NFT.

  • time passed and bob want to cancel his order since the bid offer not met his interest and no one bought the NFT directly.

  • the cancel_order will revert since its impossible to call impure function inside pure function.

CHECK fuel docs about the pure and impure function in the link below:

https://docs.fuel.network/docs/sway/blockchain-development/purity/#purity

Impact Details

incorrect set of storage attribute in cancel_order lead to stuck NFTs.

References

change the #[storage(read)] in cancel_order to #[storage(read,write)]

Proof of concept

Proof of Concept

create new project and run the code in the src/main.sw with forc test:

Last updated

Was this helpful?