Tadle

Tadle
DeFiFoundry
27,750 USDC
View results
Submission Details
Severity: low
Invalid

Underflow issue in `_updateReferralBonus`

Github

Summary

There is an underflow issue in _updateReferralBonus function within the PreMarkets contract. This issue arises when calculating the remainingPlatformFee, where the sum of referrerReferralBonus and authorityReferralBonus could exceed the platformFee, leading to an underflow. This results in the remainingPlatformFee wrapping around to a very large number, potentially causing unexpected behavior and significant financial discrepancies in the contract.

Vulnerability Details

The issue is located in the following portion of the _updateReferralBonus function:

remainingPlatformFee = platformFee - referrerReferralBonus - authorityReferralBonus;

If the sum of referrerReferralBonus and authorityReferralBonus exceeds platformFee, the subtraction operation causes an underflow. In Solidity, underflowing an unsigned integer wraps around to the maximum possible value, which can lead to incorrect and highly inflated values for remainingPlatformFee.

Consider the following scenario to illustrate the underflow issue:

  • platformFee is set to 1000 units.

  • referrerReferralBonus is calculated as 600 units (e.g., 60% of platformFee).

  • authorityReferralBonus is calculated as 500 units (e.g., 50% of platformFee).

In this case, the sum of referrerReferralBonus and authorityReferralBonus is 1100 units, which is greater than the platformFee of 1000 units. The subtraction operation would therefore result in:

remainingPlatformFee = 1000 - 600 - 500; // which underflows

This calculation results in an underflow, and remainingPlatformFee would incorrectly be set to a large value due to the wrapping behavior of unsigned integers in Solidity.

Impact

The remainingPlatformFee could be erroneously set to a large value, leading to incorrect token balances and potential overpayment to the platform or other involved parties. The referral bonus distribution logic could be compromised, leading to unfair or unintended distribution of funds. Attackers could exploit this underflow by manipulating the referral rates to trigger the underflow, potentially draining the platform's funds or causing other financial damage.

Tools Used

Manual Review

Recommendations

Add a check to ensure that the sum of referrerReferralBonus and authorityReferralBonus does not exceed platformFee before performing the subtraction.

Updates

Lead Judging Commences

0xnevi Lead Judge 12 months ago
Submission Judgement Published
Invalidated
Reason: Known issue
Assigned finding tags:

[invalid] finding-Admin-Errors-Malicious

The following issues and its duplicates are invalid as admin errors/input validation/malicious intents are1 generally considered invalid based on [codehawks guidelines](https://docs.codehawks.com/hawks-auditors/how-to-determine-a-finding-validity#findings-that-may-be-invalid). If they deploy/set inputs of the contracts appropriately, there will be no issue. Additionally admins are trusted as noted in READ.ME they can break certain assumption of the code based on their actions, and

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.