sherlock-audit / 2024-08-flayer-judging

0 stars 0 forks source link

Polite Macaroon Parakeet - Malicious users could force swap nft owned by other users in locker #713

Open sherlock-admin2 opened 4 days ago

sherlock-admin2 commented 4 days ago

Polite Macaroon Parakeet

High

Malicious users could force swap nft owned by other users in locker

Summary

In Locker::swap() , there is missing a check if targeted nft is already owned by someone else. In the case when users reserve nfts and obtain them through unlocking, but not yet withdraw, these nfts will be still in the locker . In this scenario, we should not allow swapping to happen.

Root Cause

Consider this scenario:

  1. User A really like an nft X, which is priced at 2 ETH worth of collection token, so he reserve it; he pays 1ETH worth of collection token and creates a protected listing to pay the rest (floor price) later.
  2. After fully paying, now User A can unlock it but decides to keep the nft in the locker.
  3. Attacker B sees this opportunity; they will try to take the nft owned by user A by swapping it with a floor nft and profit.

Internal pre-conditions

  1. Users use reserve() to create a protected listing for their desired nfts.
  2. Users unlock protected listing without withdrawing these nfts.

External pre-conditions

N/A

Attack Path

  1. Malicious users call Locker::swap() contract to swap the nfts owned by other users but not yet being withdrawn from the locker

Impact

Malicious users could steal valuable nfts by swapping them with floor nfts.

Code snippet

https://github.com/sherlock-audit/2024-08-flayer/blob/main/flayer/src/contracts/ProtectedListings.sol#L314-L322

https://github.com/sherlock-audit/2024-08-flayer/blob/main/flayer/src/contracts/Locker.sol#L246

PoC

No response

Mitigation

An easy way is to remove the option to keep the nft in the locker after unlocking it.