Lack of differentiation between rental types leads to loss of funds #7
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
H-04
primary issue
Highest quality submission among a set of duplicates
🤖_04_group
AI based duplicate group recommendation
selected for report
This submission will be included/highlighted in the audit report
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Lines of code
https://github.com/code-423n4/2024-10-coded-estate/blob/main/contracts/codedestate/src/execute.rs#L1413
https://github.com/code-423n4/2024-10-coded-estate/blob/main/contracts/codedestate/src/execute.rs#L870
Vulnerability details
Impact
This vulnerability allows an attacker to exploit the lack of distinction between short-term and long-term rental types to withdraw funds in a different, more valuable token than the one initially used for payment, effectively steal other users' funds deposited in the contract.
Description
In the CodedEstate system, a property (token) can be listed for both short-term and long-term rentals, with each rental type having separate configurations, including the denomination (
denom
) of the token used for payments. The rental information for both types of rentals is stored in the same vector,rentals
, and arental_type
flag is used within theRental
struct to differentiate between short-term (false
) and long-term (true
) rentals.However, the contract does not make use of the
rental_type
flag in any function that handles rental operations. As a result, functions designated for short-term rentals can be used for long-term rentals, and vice versa, without proper validation of the rental type. This becomes problematic, especially since short-term and long-term rentals may use differentdenom
tokens.An attacker can exploit this by performing the following steps:
Supposed there are two legitimate tokens in on Nibiru chain (deployment chain), TokenX ~ $0.01 and USDC ~ $1
setreservationforshortterm
).cancelreservationbeforeapprovalforlongterm
), which refunds in USDC.This results in the attacker receiving a refund in the higher-value token, effectively stealing funds from other users who deposited USDC.
Proof-of-Concept
The following test demonstrate the described attacker scenario.
Boilerplate for PoC: https://gist.github.com/nnez/c76b1a867dd8dc441dbe552e048b796e
Steps
contracts/codedestate/src/multi_tests.rs
with boilerplate from above secret gist.cargo test h8_shorterm_longterm_denom -- --nocapture
Recommended Mitigations
rental_type
flag to differentiate between short-term and long-term rental and enforce usage of functions according to its type.Assessed type
Invalid Validation
The text was updated successfully, but these errors were encountered: