Flow

Sablier
FoundryDeFi
20,000 USDC
View results
Submission Details
Severity: low
Invalid

[L-3] Potential for Inconsistency and Errors Due to Repeated Literal Values Without constant Variable Definition

Summary:

The contract uses the same literal values repeatedly without defining them as constant variables. Using literal values in multiple places increases the risk of inconsistencies and can make the code harder to understand and maintain. Defining these values as constant variables ensures consistency, improves readability, and potentially reduces gas costs, as constant variables are stored directly in the contract’s bytecode.

Vulnerability Details:

The contract currently uses the same literal values multiple times without defining them as constant variables. This repetition can lead to inconsistencies, particularly if a developer modifies one instance of a literal but fails to update it in other locations, potentially introducing logic errors or unintended behavior.

Instances:

The following instances of repeated literal values were identified in the Helpers.sol file:

  1. decimals == 18 Condition:

    • Line 55: if (decimals == 18)

    • Line 67: if (decimals == 18)

  2. scaleFactor Calculation:

    • Line 60: uint256 scaleFactor = 10 ** (18 - decimals);

    • Line 72: uint256 scaleFactor = 10 ** (18 - decimals);

An attacker may exploit inconsistencies in literal values to influence calculations or logic. In a scenario where developers modify only some instances of a literal value (e.g., updating a scaling factor for a token with different decimal places), the contract may perform incorrect calculations.

Impact:

Calculation Errors:

  • Repeated literals without centralization can lead to inconsistent updates if values are modified in only some locations. For instance, if one occurrence of decimals == 18 is updated but others are overlooked, any calculations relying on this value may produce incorrect results. This could impact financial computations, potentially leading to erroneous token balances or incorrect amounts in transfers.

  • Incorrect Scaling Factors:

    • The example scaleFactor = 10 ** (18 - decimals) relies on the hardcoded 18 as the scaling base. If the value 18 is changed in one part of the contract and not in others, scaling calculations might be mismatched, leading to incorrect results. This inconsistency could result in improperly scaled token values, enabling attackers to manipulate balances or extract more tokens than intended, particularly in contracts with financial logic.

  • Increased Gas Consumption:

    • Defining repeated literals as constant variables reduces gas costs, as constant variables are stored directly in bytecode rather than memory. Repeated literals can increase gas costs unnecessarily, affecting the efficiency of each transaction and the overall user experience.

Tools Used: Slither and Aderyn.

Recommendations:

Define Commonly Used Literals as constant Variables:

  • Identify all frequently used literal values, such as 18 in the scaling and decimal logic, and define them as constant variables at the top of the contract or in a dedicated constants file. This ensures consistency and reduces maintenance risks. For example:

uint8 constant DECIMALS_STANDARD = 18;

Reference the constant Variables Throughout the Contract:

  • Replace all instances of repeated literal values with the newly defined constant variables. This centralized approach makes the codebase easier to read, modify, and audit:

if (decimals == DECIMALS_STANDARD) {
uint256 scaleFactor = 10 ** (DECIMALS_STANDARD - decimals);
}
Updates

Lead Judging Commences

inallhonesty Lead Judge 8 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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