Tadle

Tadle
DeFi
30,000 USDC
View results
Submission Details
Severity: low
Invalid

Use of magic numbers for contract types reduces code clarity in `RelatedContractLibraries`

Summary

The implementation of the RelatedContractLibraries library uses magic numbers to represent related contract types (e.g., SYSTEM_CONFIG, PRE_MARKETS, etc.). These numbers are hardcoded and lack descriptive context.

Vulnerability Details

Using magic numbers can lead to confusion and errors during development and maintenance. It reduces code readability and increases the risk of misinterpretation, especially for new developers or when revisiting the code after some time.

The constants defined in the library:

uint8 internal constant SYSTEM_CONFIG = 1;
uint8 internal constant PRE_MARKETS = 2;
uint8 internal constant DELIVERY_PLACE = 3;
uint8 internal constant CAPITAL_POOL = 4;
uint8 internal constant TOKEN_MANAGER = 5;

These values are used directly in function calls without any context, making it unclear what each number represents for example in the TadleFactory::deployUpgradeableProxy function:

function deployUpgradeableProxy(
uint8 _relatedContractIndex, // @audit - Index? Magic number
address _logic,
bytes memory _data
) external onlyGuardian returns (address) {
// ...
@> relatedContracts[_relatedContractIndex] = address(_proxy);
// ...
}

Impact

Using magic numbers can lead to confusion and errors during development and maintenance.

It reduces code readability and increases the risk of misinterpretation, especially for new developers or when revisiting the code after some time.

Tools Used

Manual Review

Recommendations

Replace magic numbers with enums, as it's done elsewhere in the code, to improve code clarity and maintainability. For example:

enum ContractType { SYSTEM_CONFIG, PRE_MARKETS, DELIVERY_PLACE, CAPITAL_POOL, TOKEN_MANAGER }

This change would enhance readability and reduce the likelihood of errors related to misinterpretation of the numbers.

Updates

Lead Judging Commences

0xnevi Lead Judge
10 months ago
0xnevi Lead Judge 10 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.