Token owner can burn their token with active rental leading to renters’ funds being stuck
The burn function deletes all token data, including active rental records and deposits, without checking for active rentals. A property owner can burn their token while rentals are active, causing renters' deposited funds to become stuck in the contract.
Submitted by nnez, also found by Ch_301
If the property owner calls the burn function while active rentals exist, the rental information, including deposits, is deleted. This prevents renters from retrieving their funds through the cancellation process, leading to funds of renters being stuck in the contract.
Description
The burn function in the contract deletes all data associated with a token, including any active rental information. In Coded Estate, renters must deposit funds in advance for short-term rentals, and this information is stored in a vector, rentals, linked to the token.
The issue arises because the burn function only checks whether the caller is the owner or has approval to burn the token. It does not validate whether there are any active rentals associated with the token. As a result, if the property owner calls the burn function while rentals are still active, all rental data, including the deposit amounts, is deleted from storage.
Without the rental information, renters can no longer use the cancellation function to retrieve their deposits, as the contract does not retain any record of the rental. This leads to irreversible loss of funds for the renters.
Relevant code snippets
File: contracts/codedestate/src/state.rs
pub struct TokenInfo<T> {
/// The owner of the newly minted NFT
pub owner: Addr,
pub approvals: Vec<Approval>,
pub longterm_rental: LongTermRental,
pub shortterm_rental: ShortTermRental,
pub rentals: Vec<Rental>, // <-- rental information is stored here
pub bids: Vec<Bid>,
pub sell: Sell,
pub token_uri: Option<String>,
pub extension: T,
}
File: contracts/codedestate/src/execute.rs
pub fn setlistforshorttermrental(
//...
//... function arguments
//...
) -> Result<Response<C>, ContractError> {
...
... snipped
...
let traveler = Rental {
denom:token.shortterm_rental.denom.clone(),
rental_type:false,
approved_date:None,
deposit_amount: Uint128::from(rent_amount),
renting_period: vec![new_checkin_timestamp, new_checkout_timestamp],
address: Some(info.sender.clone()),
approved: token.shortterm_rental.auto_approve,
cancelled:false,
guests:guests,
};
// token.shortterm_rental.deposit_amount += sent_amount;
token
.rentals
.insert(placetoreserve as usize, traveler); // deposited amount is stored in rentals vector
...
... snipped
...
}
fn burn(
&self,
deps: DepsMut,
env: Env,
info: MessageInfo,
token_id: String,
) -> Result<Response<C>, ContractError> {
let token = self.tokens.load(deps.storage, &token_id)?;
self.check_can_send(deps.as_ref(), &env, &info, &token)?; // <-- Only checks ownership or approval
self.tokens.remove(deps.storage, &token_id)?; // <-- Deletes all token data including saved rentals vector
self.decrement_tokens(deps.storage)?;
Ok(Response::new()
.add_attribute("action", "burn")
.add_attribute("sender", info.sender)
.add_attribute("token_id", token_id))
}
Example Scenario
- A property owner lists a property for short-term rental, and several renters reserve it by depositing funds in advance.
- The property owner calls the
burnfunction to burn the token while rentals are still active. - All rental information, including the deposit amounts, is erased.
- When renters attempt to cancel their reservations expecting a refund, the transaction will revert as the rental information is deleted with the token.
Proof-of-Concept
The following test demonstrates that the token owner can burn their token while there is active rental leading to renter’s funds getting stuck in the contract:
Boilerplate for PoC here.
- Replace everything in
contracts/codedestate/src/multi_tests.rswith boilerplate from above secret gist. - Insert below test:
#[test]
fn h1_burn_active_rental() {
let (mut app, contract_addr) = mock_app_init_contract();
// Minter mints a new token
execute_mint(&mut app, &contract_addr, MINTER, TOKEN_ID);
// Asserts that token is minted
assert_eq!(query_token_count(&app, &contract_addr.to_string()), 1);
// Minter set list for short term rental
let list_short_term_rental_msg: ExecuteMsg<Option<Empty>, Empty> = ExecuteMsg::SetListForShortTermRental {
token_id: TOKEN_ID.to_string(),
denom: USDC.to_string(),
price_per_day: 10,
auto_approve: true,
available_period: vec![],
minimum_stay: 1,
cancellation: vec![]
};
let res = app.execute_contract(
Addr::unchecked(MINTER),
contract_addr.clone(),
&list_short_term_rental_msg,
&[],
);
assert!(res.is_ok()); // Everyting is ok
// Traveler makes reservation on minter's property (token)
init_usdc_balance(&mut app, TRAVELER, 10);
let tmr = app.block_info().time.plus_days(1);
let list_short_term_rental_msg: ExecuteMsg<Option<Empty>, Empty> = ExecuteMsg::SetReservationForShortTerm {
token_id: TOKEN_ID.to_string(),
renting_period: vec![tmr.seconds().to_string(), tmr.plus_days(1).seconds().to_string()],
guests: 1
};
let res = app.execute_contract(
Addr::unchecked(TRAVELER),
contract_addr.clone(),
&list_short_term_rental_msg,
&vec![Coin {
denom: USDC.to_string(),
amount: Uint128::new(10),
}],
);
assert!(res.is_ok()); // Everything is ok
// 10 USDC is deposited into the contract from Traveler
assert_eq!(query_usdc_balance(&app, &contract_addr.to_string()), 10);
// Minter burns the token while there is active rental from traveler
let burn_msg: ExecuteMsg<Option<Empty>, Empty> = ExecuteMsg::Burn {
token_id: TOKEN_ID.to_string()
};
let res = app.execute_contract(
Addr::unchecked(MINTER),
contract_addr.clone(),
&burn_msg,
&[],
);
assert!(res.is_ok()); // Minter successfully burns the token whiel there is active rental
// Funds are stuck in contract
assert_eq!(query_usdc_balance(&app, &contract_addr.to_string()), 10);
assert_eq!(query_usdc_balance(&app, &TRAVELER.to_string()), 0);
assert_eq!(query_usdc_balance(&app, &MINTER.to_string()), 0);
// Token is burnt
assert_eq!(query_token_count(&app, &contract_addr.to_string()), 0);
// Funds are also not collected as fees
assert_eq!(query_fee_balance(&app, &contract_addr.to_string()), 0);
}
- Run
cargo test h1_burn_active_rental -- --nocapture. - Observe that the test passes.
Recommended Mitigation
Add a validation in burn function that there is no active rental.
Assessed type
Invalid Validation
blockchainstar12 (Coded Estate) confirmed
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The burn function only checks ownership or approval and does not verify that there are no active rentals before deleting the token and its associated rental data.
Impact
Renters' deposited funds become permanently stuck in the contract, as they cannot cancel or retrieve their deposits.
What the attacker needed
Owner has a token with active rentals; renters have deposited funds
The fix
The burn function should be modified to check that there are no active rentals before allowing the token to be burned.
How it was found
- A property owner lists a property for short-term rental.
- Renters reserve the property by depositing funds in advance.
- The property owner calls the burn function while rentals are still active.
- All rental information, including deposit amounts, is erased.
- Renters attempt to cancel their reservations expecting a refund, but the transaction reverts because the rental information is deleted.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When someone rents a property, they pay a deposit that is stored in the contract. The owner can delete the property token, which also erases the rental record, so the renter cannot get their deposit back.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.