# Lack of validation in setlistforsell allows changing denom while there is active bid, leading to stealing of other users' funds

setlistforsell lets seller change payment denom during an active bid; canceling refunds the bid in the new higher-value denom, draining contract funds.

- Payout: Audit contest
- Severity: high
- Program: Coded Estate
- Found by: nnez
- Disclosed: 2024-12-04
- Write-up quality: 7/10
- Original: https://github.com/code-423n4/2024-10-coded-estate-findings/issues/5
- Library page: https://bugbountylibrary.com/r/c4%3A2024-10-coded-estate%3AH-06
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:solidity technique:source-review vuln:access-control vuln:accounting-error vuln:business-logic

**Target:** CosmWasm NFT marketplace contract (setlistforsell/setbidtobuy)
**Root cause:** setlistforsell overwrites token.sell.denom without checking for active bids, while setbidtobuy refunds using the current token.sell.denom rather than the denom originally escrowed.
**Steps:**
1. Mint a token as attacker.
2. Call `SetListForSell{islisted:true, denom:"useless-coin", price:1000}`.
3. Call `SetBidToBuy{token_id}` sending `1000 useless-coin`; contract now holds useless-coin.
4. Call `SetListForSell{islisted:true, denom:"USDC", price:1000}` to overwrite denom.
5. Call `SetBidToBuy{token_id}` again to cancel; contract refunds `1000 USDC` from pooled funds.
**How found:** Code review of setlistforsell noting no active-bid check, then tracing setbidtobuy's refund path which reads token.sell.denom at cancel time instead of the escrowed denom.
**Exploitation:** Attacker self-bids with a worthless denom, then flips the listing denom to a valuable token and cancels the bid, receiving a refund in the valuable denom drawn from other users' deposits held by the contract.
**Escalation:** Repeat across tokens/denoms to drain the contract's entire balance of valuable tokens.
**Insight:** When a refund path reads a mutable config field (denom/price) at cancel time instead of the value recorded at deposit time, look for any setter that can mutate that field while funds are escrowed.

