Part 2

Zaros
PerpetualsDEXFoundrySolidity
70,000 USDC
View results
Submission Details
Severity: low
Invalid

Unsafe ABI Encodings: Risk of Error in Low-Level Calls

Summary

The codebase employs abi.encodeWithSelector for generating calldata for low-level calls. While widely used, this approach is both type-unsafe and typo-unsafe, making it prone to errors. It is recommended to replace these usages with abi.encodeCall, which provides type safety and helps prevent errors caused by typos.

Vulnerability Details

Description

The following instances of abi.encodeWithSelector have been identified across the codebase:

  1. ChainlinkAutomationUtils.sol: Multiple occurrences.

  2. DexAdapterUtils.sol: Multiple occurrences.

  3. Markets.sol: Single occurrence.

  4. PriceAdapterUtils.sol: Single occurrence.

  5. ReferralUtils.sol: Single occurrence.

  6. TreeProxyUtils.sol: Single occurrence.

  7. Vaults.sol: Multiple occurrences.

    Using abi.encodeWithSelector lacks type validation, which can result in:

    • Mismatched parameter types going unnoticed during compilation.

    • Errors arising from typos in function signatures or selectors.

    Replacing abi.encodeWithSelector with abi.encodeCall ensures that both the function signature and the parameter types are validated during compilation, reducing the likelihood of runtime errors.

Impact

** Type Safety**: Lack of type validation can lead to runtime failures, causing critical functionality to break.

  • Error-Prone: Typos in function signatures or selectors may go undetected, resulting in unintended behavior.

  • Security Risk: Improper encoding can potentially introduce vulnerabilities, especially when interacting with external contracts.

Tools Used

  1. Remix IDE: To identify occurrences of abi.encodeWithSelector.

  2. Slither: For static analysis to detect unsafe ABI encodings.

  3. MythX: To analyze potential vulnerabilities associated with unsafe ABI encoding.

Recommendations

Replace abi.encodeWithSelector with abi.encodeCall:
Use abi.encodeCall for generating calldata, which ensures type safety and prevents errors caused by typos. For example:

// Current Usage
abi.encodeWithSelector(contract.functionName.selector, arg1, arg2);
// Recommended Replacement
abi.encodeCall(contract.functionName, (arg1, arg2));
  1. Refactor All Identified Occurrences:
    Refactor the following files to replace abi.encodeWithSelector with abi.encodeCall:

    • ChainlinkAutomationUtils.sol

    • DexAdapterUtils.sol

    • Markets.sol

    • PriceAdapterUtils.sol

    • ReferralUtils.sol

    • TreeProxyUtils.sol

    • Vaults.sol

  2. Conduct Comprehensive Testing:
    Write tests to validate that refactored calldata generation matches expected behavior and interacts correctly with target contracts.

  3. Static Analysis and Linting:
    Use static analysis tools to scan for unsafe ABI encoding methods and enforce best practices in future development.

  4. Code Review and Documentation:
    Perform a thorough code review and update documentation to reflect the refactored approach, ensuring team members understand the rationale behind the changes.

Updates

Lead Judging Commences

inallhonesty Lead Judge 4 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.