# setbidtobuy
allows token purchase even when sale is no longer listed
#23
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
H-02
primary issue
Highest quality submission among a set of duplicates
🤖_primary
AI based primary recommendation
🤖_11_group
AI based duplicate group recommendation
selected for report
This submission will be included/highlighted in the audit report
sponsor acknowledged
Technically the issue is correct, but we're not going to resolve it for XYZ reasons
upgraded by judge
Original issue severity upgraded from QA/Gas by judge
Lines of code
https://github.com/code-423n4/2024-10-coded-estate/blob/main/contracts/codedestate/src/execute.rs#L646-L720
Vulnerability details
Impact
The bug allows buyers to purchase tokens that have been delisted by the seller, bypassing the seller’s intent to halt the sale. This can result in tokens being sold against the seller's wishes.
Description
The
setbidtobuy
function is responsible for allowing buyers to submit bids to purchase a token listed for sale. A seller can invokesetlistforsell
to list a token, specifying the price, payment token (denom), and whether the sale is auto-approved. If auto-approve is set totrue
, any buyer who callssetbidtobuy
can acquire the token without further input from the seller, while a manual approval is required when auto-approve is set tofalse
.However, there is a flaw in the logic of
setbidtobuy
—it does not check thesell.islisted
flag, which is supposed to indicate whether a token is still available for sale. Even if the seller later decides to delist the token by settingsell.islisted
tofalse
, buyers can still invokesetbidtobuy
and proceed with the purchase if auto-approve is enabled. This creates a scenario where sellers lose control over the sale, allowing unintended buyers to purchase delisted tokens.Example Scenario:
setlistforsell
, specifying the sale details including price, payment token, and settingauto-approve
totrue
.sell.islisted
tofalse
while leaving other parameters unchanged.setbidtobuy
, and because the function does not respect theislisted
flag and auto-approve istrue
, the token is sold despite the seller’s intent to delist it. This results in an unintended sale, leading to potential loss or misuse of assets by the seller.Additional note
An action of delisting the token on sale in this manner is justified because there is no other functions serving this purpose as in short-term rental and long-term rental where there is a specific function to unlist the token from rental service.
Code Snippet
The following snippet shows that the
islisted
flag is not verified insetbidtobuy
, which allows unintended purchases:This lack of validation enables buyers to acquire delisted tokens without the seller's consent.
Proof-of-Concept
The following test demonstrates that a buyer can still buy delisted token (token with islisted set to false).
Boilerplate for PoC: https://gist.github.com/nnez/c76b1a867dd8dc441dbe552e048b796e
Steps
contracts/codedestate/src/multi_tests.rs
with boilerplate from above secret gist.cargo test m3_buyer_can_buy_delisted_token -- --nocapture
Recommended Mitigations
sell.islisted
flag set to false/NoneAssessed type
Context
The text was updated successfully, but these errors were encountered: