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.
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.
The following instances of repeated literal values were identified in the Helpers.sol
file:
decimals == 18
Condition:
Line 55: if (decimals == 18)
Line 67: if (decimals == 18)
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.
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.
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:
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:
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.