Use of u64
for price_per_day
and price_per_month
limits handling tokens with 18 decimals
#29
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
M-03
primary issue
Highest quality submission among a set of duplicates
🤖_primary
AI based primary recommendation
🤖_27_group
AI based duplicate group recommendation
selected for report
This submission will be included/highlighted in the audit report
sponsor acknowledged
Technically the issue is correct, but we're not going to resolve it for XYZ reasons
Lines of code
https://github.com/code-423n4/2024-10-coded-estate/blob/main/contracts/codedestate/src/msg.rs#L168
https://github.com/code-423n4/2024-10-coded-estate/blob/main/contracts/codedestate/src/msg.rs#L111
Vulnerability details
Impact
The use of
u64
forprice_per_day
andprice_per_month
prevents setting rental prices higher than approximately 18 tokens when using tokens with 18 decimals, potentially restricting landlords from setting appropriate rental prices in tokens with 18 decimals.Proof-of-Concept
The
SetListForShortTermRental
andSetListForLongTermRental
enums in the contract useu64
forprice_per_day
andprice_per_month
respectively, while the corresponding functions,setlistforshorttermrental
andsetlistforlongtermrental
, also define these prices asu64
.This poses a problem when dealing with tokens with 18 decimals, as the maximum value
u64
can store is approximately1.8446744e+19
. In contrast,u128
, which is used elsewhere in the contract for handling token amounts (e.g.,info.funds[0].amount
), can accommodate much larger values, fully supporting tokens with 18 decimals.This mismatch can create issues when landlords attempt to specify rental prices. For example, when a token is worth
$1
(with 18 decimals), the maximum price that can be set per day or month is capped at approximately 18 tokens ~$18
, potentially preventing landlords from setting appropriate rental prices for their properties.Additionally, since Nibiru chain, the deployment chain for Coded Estate, supports custom denominated tokens, landlords may select tokens with 18 decimals as their payment token.
See: https://github.com/NibiruChain/nibiru/blob/main/x/tokenfactory/keeper/msg_server.go#L18-L41
Example Scenario:
u64
limit (2e19 > 1.8446744e+19), the landlord cannot list the property at the desired price.Recommended Mitigations
u64
tou128
instead.Assessed type
Context
The text was updated successfully, but these errors were encountered: