Skip to content
Business logic Audit finding Intermediate

Incorrect refund amount is sent to the tenant if long term reservation is cancelled after approval

The long-term rental cancellation function marks a reservation as cancelled but never refunds the tenant, and the cancellation percentage set by the token owner is ignored. Instead, the protocol fee is deducted later, so the tenant receives a different amount than the landlord intended.

adeolu Follow with adeolu

Originally disclosed on Code4rena

Submitted by adeolu, also found by adeolu

token.longterm_rental.cancellation.percentage is not deducted from the token.longterm_rental.deposit_amount and refunded back to the user as expected after a cancelreservationafterapprovalforlongterm() call to cancel a reservation that has been approved.

Proof Of Concept

https://github.com/code-423n4/2024-10-coded-estate/blob/97efb35fd3734676f33598e6dff70119e41c7032/contracts/codedestate/src/execute.rs#L1647-L1683

    pub fn cancelreservationafterapprovalforlongterm(
        &self,
        deps: DepsMut,
        info: MessageInfo,
        token_id: String,
        renting_period: Vec<String>
    ) -> 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();
        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_none() {
                    return Err(ContractError::NotApproved {});
                } else {
                    position = i as i32;
                    // amount = item.deposit_amount;
                }
            }
        }

        if position != -1 {
            // token.rentals.remove(position as usize);
            token.rentals[position as usize].cancelled = true;
            self.tokens.save(deps.storage, &token_id, &token)?;
            Ok(Response::new()
            .add_attribute("action", "cancelreservationafterapprovalforlongterm")
            .add_attribute("sender", info.sender)
            .add_attribute("token_id", token_id))
        } else {
            return Err(ContractError::NotReserved {});
        }
    }

In cancelreservationafterapprovalforlongterm() we can see how no money is refunded to the tenant after cancellation is made after approval. The function does not calculate the refundable amount incase of a cancellation by tenant after approval like it is done in cancelreservationafterapprovalforshortterm(). See here.

A landlord can set that cancellations after approval will happen with a 90% refund via setlistforlongtermrental(), where the token.longterm_rental.cancellation.percentage will be set to 90. But this will never be enforced in the cancelreservationafterapprovalforlongterm() code. The function will never refund but instead cancel the reservation with no refund processed to the tenant. This is against the intention of the landlord/token owner because token owner set the token.longterm_rental.cancellation.percentage to be 90% and so 90% of the deposit amount should be refunded to the tenant that cancelled.

In finalizelongtermrental(), since item.cancelled has been set to true, the iteration logic there tries to deduct a fee percentage from the amount, but this amount is not the token.longterm_rental.cancellation.percentage set by the token owner. Instead it is the fee_percentage for the protocol which only the contract owner can set via set_fee_value().

https://github.com/code-423n4/2024-10-coded-estate/blob/97efb35fd3734676f33598e6dff70119e41c7032/contracts/codedestate/src/execute.rs#L1727-L1731

                if item.cancelled {

                    ....

                    let fee_percentage = self.get_fee(deps.storage)?;
                    self.increase_balance(deps.storage, token.longterm_rental.denom.clone(), Uint128::new((u128::from(amount) * u128::from(fee_percentage)) / 10000))?;
                    //@audit  why increase it again here? money isn't sent in

                    amount -= Uint128::new((u128::from(amount) * u128::from(fee_percentage)) / 10000);

The use of self.get_fee(deps.storage) instead of token.longterm_rental.cancellation.percentage means that the cancellation penalty specified by the token owner to be enforced on cancellations after approvals will not happen.

Recommended Mitigation

Use token.longterm_rental.cancellation.percentage to calculate amount to be returned to tenant instead of self.get_fee(deps.storage) if the deduction will be enforced in finalizelongtermrental().

OR

Add extra logic like below into cancelreservationafterapprovalforlongterm() to check that refundable amount is calculated as directed by the landlord/token owner.

            let mut cancellation = token.longterm_rental.cancellation.clone();

            .....

            let diff_days = (check_in_time_timestamp - current_time)/86400;
            for (_i, item) in cancellation.iter().enumerate() {
                if item.deadline < diff_days {
                    refundable_amount =  Uint128::new((amount.u128() * u128::from(item.percentage)) / 100);
                    break;
                }
            }

           .....

                     if refundable_amount > Uint128::new(0) {
                    Ok(Response::new()
                    .add_attribute("action", "cancelreservationafterapprovalforlongterm")
                    .add_attribute("sender", info.sender)
                    .add_attribute("token_id", token_id)
                    .add_message(BankMsg::Send {
                        to_address: traveler_address,
                        amount: vec![Coin {
                            denom: token.longterm_rental.denom,
                            amount: refundable_amount,
                        }],
                    }))
                }

Assessed type

Context

blockchainstar12 (Coded Estate) acknowledged and commented:

This is intended logic.

Lambda (judge) decreased severity to Medium and commented:

I agree that it seems weird that the cancellation vector for long term rentals is completely ignored. While this seems to be intended according to the sponsor, I have not found any documentation indicating this and an owner may therefore, have different expectations. Because of this, I am judging it as impact on the function of the protocol / value leak with external requirements (assumptions about the long-term cancellation process).


The original report as published on Code4rena, by adeolu. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

Likely the cancellation function only sets a cancelled flag and omits the refund logic, while the finalisation step uses the protocol fee rather than the landlord's cancellation percentage.

Impact

The tenant may receive no refund or the wrong refund amount, contrary to the landlord's configured cancellation terms; the sponsor says this is intended logic, but the judge rated it Medium as a value leak.

What the attacker needed

An approved long-term reservation; tenant cancels after approval; landlord set a cancellation percentage

The fix

The cancellation percentage should be used to calculate the refund in the cancellation function, or in finalisation instead of the protocol fee.

How it was found

  1. A landlord sets a long-term rental with a cancellation percentage.
  2. A tenant reserves and the reservation is approved.
  3. The tenant calls the cancel-after-approval function for long-term rentals.
  4. The reservation is marked cancelled but no refund is sent.
  5. At finalisation, the protocol fee is deducted instead of the landlord's cancellation percentage.

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.

A smart contract holds a tenant's deposit for a long-term rental. The landlord can set a rule saying how much of the deposit is returned if the tenant cancels after approval, but the cancellation code never applies that rule and never sends money back. Later, a different fee is taken instead, so the tenant gets the wrong amount.

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.

More by adeolu

View all

16 more disclosed reports, best first.

More from Coded Estate Invitational

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.