20,000 USDC
View results
Submission Details
Severity: gas
Valid

Using magic numbers can lead to code that is hard to maintain, difficult to understand, and potentially error-prone.

Summary

Using magic numbers can lead to code that is hard to maintain, difficult to understand, and potentially error-prone.

Vulnerability Details

Impact

Security: Magic numbers might be used in multiple places, and changing such a number requires synchronizing changes across all instances. This increases the likelihood of errors. Using constants ensures that changes are synchronized.

Ease of Error Handling: Using meaningful constants or enumeration values makes error handling easier, as you can assign specific values for different error states.

Scalability: If your smart contract needs to adjust certain values based on specific conditions, using constants or enumerations makes management and adjustments easier.

Code Consistency: Using constants or enumerations ensures that the same values are consistently used throughout the codebase, reducing issues stemming from using different values in different places.

In conclusion, using meaningful constants or enumeration values instead of magic numbers in Solidity is a good practice. It improves the readability, maintainability, and security of your code. This helps developers and reviewers better understand your code and reduces potential errors and issues.

Tools Used

Recommendations

uint256 public constant FEE_PRECISION = 10000;
uint256 public constant RATIO_PRECISION = 10 ** 18;
uint256 public constant ONE_YEAR = 365 days;

Support

FAQs

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