NFTBridge
60,000 USDC
View results
Submission Details
Severity: low
Invalid

Use of Struct for Function Arguments to Improve Code Maintainability

Description:

The current implementation of certain functions, such as Bridge.cairo::deposit_tokens, involves passing multiple arguments individually. As the number of arguments increases, this approach can lead to decreased readability and a higher risk of passing incorrect parameters. Using a struct to group these arguments enhances code clarity and maintainability.

Impact:

Without using a struct, the code may become harder to understand and maintain, especially as more arguments are added to functions. The likelihood of errors, such as passing arguments in the wrong order or missing arguments, increases. This can lead to subtle bugs and make future modifications more error-prone.

Recommended Mitigation:

Refactor functions to accept a struct containing the related arguments. This not only simplifies the function signature but also makes the code more modular and easier to extend or modify in the future. An example of this approach is shown below:

struct DepositParams {
salt: felt252,
collection_l2: ContractAddress,
owner_l1: EthAddress,
token_ids: Span<u256>,
use_withdraw_auto: bool,
use_deposit_burn_auto: bool,
}
fn deposit_tokens(ref self: ContractState, params: DepositParams) {
// function body
}

This structure enhances code readability and reduces the potential for parameter-related errors, thereby improving overall code quality.

Updates

Lead Judging Commences

n0kto Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational / Gas

Please, do not suppose impacts, think about the real impact of the bug and check the CodeHawks documentation to confirm: https://docs.codehawks.com/hawks-auditors/how-to-determine-a-finding-validity A PoC always helps to understand the real impact possible.

Support

FAQs

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