# Lack of differentiation between rental types leads to loss of funds

Short-term and long-term rentals share one rentals vector without rental_type checks, so a short-term reservation can be cancelled via the long-term cancel function and refunded in the long-term (more valuable) denom.

- 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/7
- Library page: https://bugbountylibrary.com/r/c4%3A2024-10-coded-estate%3AH-04
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:solidity technique:source-review vuln:access-control vuln:business-logic

**Target:** CosmWasm NFT rental contract (execute.rs rental functions)
**Root cause:** Rental structs store a rental_type flag but no rental-handling function validates it; cancelreservationbeforeapprovalforlongterm matches any rental by address and period, then refunds using token.longterm_rental.denom regardless of the rental's actual denom.
**Steps:**
1. Mint a token and call `SetListForShortTermRental` with denom `useless-coin`, price_per_day 1000, auto_approve true.
2. Call `SetListForLongTermRental` on same token with denom `USDC`, price_per_month 1000, auto_approve true.
3. Call `SetReservationForShortTerm` with renting_period [tmr, tmr+1d] sending 1000 `useless-coin`.
4. Call `RejectReservationForLongterm` with same token_id, tenant, and renting_period.
5. Contract matches the short-term rental in `rentals`, removes it, and sends `amount` in `token.longterm_rental.denom` (USDC) to attacker.
**How found:** Code review noticed the `rental_type` flag in the Rental struct is never read by any rental function, and that cancellation functions look up rentals by address+period only while refunding using the long-term denom field.
**Exploitation:** Attacker lists the same token for both rental types with different denoms, reserves the cheap-denom short-term rental, then invokes the long-term cancellation/rejection path which refunds the recorded deposit_amount in the long-term denom, draining USDC held by the contract for other users.
**Insight:** When a struct carries a discriminator flag, grep for every read of that field; if a shared collection stores heterogeneous records, any lookup-by-attributes function that then uses type-specific config (denom, price) is a cross-type confusion candidate.

## Proof of concept (copied exactly from the original report)

**Cancel longterm refunds in longterm denom**

```
pub fn cancelreservationbeforeapprovalforlongterm(
// function arguments
) -> Result<Response<C>, ContractError> {
    let mut token = self.tokens.load(deps.storage, &token_id)?;
    let mut position: i32 = -1;
    let mut amount = Uint128::from(0u64);
    let tenant_address = info.sender.to_string();
    // @c4-contest: rental is loaded from rentals vector
    for (i, item) in token.rentals.iter().enumerate() {
        if item.address == Some(info.sender.clone()) && item.renting_period[0].to_string() == renting_period[0]
        && item.renting_period[1].to_string() == renting_period[1]
            {
            if item.approved_date.is_some() {
                return Err(ContractError::ApprovedAlready {});
            } else {
                position = i as i32;
                amount = item.deposit_amount;
            }
        }
    }

    if position == -1 {
        return Err(ContractError::NotReserved {});
    }
    else {
        token.rentals.remove(position as usize);
        self.tokens.save(deps.storage, &token_id, &token)?;
    }

    if amount > Uint128::new(0) {
        Ok(Response::new()
        .add_attribute("action", "cancelreservationbeforeapprovalforlongterm")
        .add_attribute("sender", info.sender)
        .add_attribute("token_id", token_id)
        .add_message(BankMsg::Send {
            to_address: tenant_address,
            amount: vec![Coin {
                denom: token.longterm_rental.denom, // @c4-contest: Funds are sent back in long-term denom according to long-term rental agreement
```

