-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect use of u64
for arg amount
in withdrawtolandlord
can cause withdrawal failure
#27
Comments
Does not seem to be a significant problem to me at first sight, if such a scenario would ever happen, withdrawal should be possible with multiple calls |
OpenCoreCH marked the issue as primary issue |
Unlike #29, this does not impact the functionality of the protocol significantly. While a larger data type could still be a good idea here, the owner can still withdraw funds by splitting up the withdrawals into multiple calls |
OpenCoreCH changed the severity to QA (Quality Assurance) |
Hi @OpenCoreCH I might have overstate the impact in the report (unable to withdraw funds). This bug does impact the protocol's functionality. Consider the scenario wherein the required deposit is 5_000e18 tokens. That’s a lot of transactions and this is just for one long-term rental. An individual token owner’s can have more than one property and they can have more than one active long-term rental with deposit to withdraw. Instead of paying gas for one transaction, users unnecessarily have to pay 200x+ more of gas in order to withdraw the full amount. Additionally, 5_000e18 is just an arbitrary reasonable number for a 18 decimals token worth $1, the problem could get worse with a larger amount of tokens. For example, 50_000e18 of $0.1 would take 2711 transactions to withdraw the full amount. |
That's true, 5,000$ is a reasonable amount for such a protocol to handle. Potentially even low, with business apartments in cites like Zurich that often cost 5,000$ per month, so you could easily have 30,000$ for a longer rental. 18 decimal stable coins are also very common. So it is not that unlikely that a landlord would have to perform ~1,632 calls for one withdrawal. On the one hand, this would be of course very cumbersome (especially if the UI did not support this), but it can also become pretty expensive (if one call were roughly $1, this would be an almost 5% fee on top). So based on that, Medium is indeed more appropriate. |
This previously downgraded issue has been upgraded by OpenCoreCH |
OpenCoreCH marked the issue as selected for report |
we update u64 to u128 to address this issue |
Lines of code
https://github.com/code-423n4/2024-10-coded-estate/blob/main/contracts/codedestate/src/execute.rs#L1786-L1796
https://github.com/code-423n4/2024-10-coded-estate/blob/main/contracts/codedestate/src/msg.rs#L156-L162
Vulnerability details
Impact
The use of
u64
for token amount in thewithdrawtolandlord
function can lead to failed withdrawals when handling tokens with 18 decimals, limiting the landlord’s ability to withdraw their entitled funds if the amount exceeds the maximum value ofu64
.Proof-of-Concept
In the
withdrawtolandlord
function, the token amount is defined as au64
value. However, this can cause issues when handling tokens with 18 decimals, as theu64
data type can only store values up to approximately1.8446744e+19
~18
token of token with 18 decimals. This limit is significantly lower than what is supported byu128
, which is used in other parts of the contract to handle token amount, such asinfo.funds[0].amount
is aU128
type.This discrepancy between the data types can create an issue. If the token amount owed to the landlord exceeds the maximum value supported by
u64
, the landlord will not be able to withdraw their entitled funds through thewithdrawtolandlord
function.This is problematic as the Nibiru chain, the chain on which Coded Estate is deployed, supports custom denominated tokens, and users can specify tokens with 18 decimals as their payment currency. For example, if a large payment is made in such a token, the landlord would be unable to withdraw the full amount due to the limitations of the
u64
type.See: https://github.com/NibiruChain/nibiru/blob/main/x/tokenfactory/keeper/msg_server.go#L18-L41
Example Scenario:
u64
(~18 tokens for 18-decimal tokens).withdrawtolandlord
function, the function fails because theu64
type cannot accommodate the large token amount.Recommended Mitigations
amount
tou128
for consistency with other parts in the system.Assessed type
Context
The text was updated successfully, but these errors were encountered: