Part 2

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

Unused constants


Summary

The code defines several constants (ASSET_SWAP_STRATEGY_LOCATION, COLLATERAL_LOCATION, and CREDIT_DELEGATION_LOCATION) to calculate storage slots for structs like AssetSwapPath.Data, Collateral.Data, and CreditDelegation.Data. However, these constants are not used outside their respective libraries, making them redundant. While this issue does not directly impact functionality, it introduces unnecessary clutter and could confuse developers maintaining or auditing the code.


Vulnerability Details

Code Analysis

Constants Defined

  1. ASSET_SWAP_STRATEGY_LOCATION :

    bytes32 internal constant ASSET_SWAP_STRATEGY_LOCATION =
    keccak256(abi.encode(uint256(keccak256("fi.zaros.market-making.AssetSwapPath")) - 1));
    • Used only in the AssetSwapPath.load() function to calculate the storage slot for AssetSwapPath.Data.

  2. COLLATERAL_LOCATION :

    bytes32 internal constant COLLATERAL_LOCATION =
    keccak256(abi.encode(uint256(keccak256("fi.zaros.market-making.Collateral")) - 1));
    • Used only in the Collateral.load() function to calculate the storage slot for Collateral.Data.

  3. CREDIT_DELEGATION_LOCATION :

    bytes32 internal constant CREDIT_DELEGATION_LOCATION =
    keccak256(abi.encode(uint256(keccak256("fi.zaros.market-making.CreditDelegation")) - 1));
    • Used only in the CreditDelegation.load() function to calculate the storage slot for CreditDelegation.Data.

Key Observations

  • These constants are not referenced outside their respective libraries.

  • Their sole purpose is to derive storage slots for the load() functions.

  • If these constants are removed or renamed, it would not affect the functionality of the system as long as the load() functions are updated accordingly.

Attack Scenario

While this issue does not pose a direct security risk, unused constants can:

  1. Confuse developers who might assume these constants have broader usage.

  2. Increase the cognitive load during audits or maintenance.

  3. Potentially lead to accidental misuse if someone assumes these constants are globally accessible.


Impact

  • Low Functional Impact : The unused constants do not affect the system's behavior or security.

  • Code Clutter : Redundant constants add unnecessary complexity to the codebase.

  • Maintenance Overhead : Developers may waste time investigating the purpose of these constants, assuming they have broader usage.


Tools Used

  1. Manual Code Review : Analyzed the usage of constants across the codebase.

  2. Slither : Static analysis tool used to identify unused variables and constants.

  3. MythX : Security analysis platform used to verify the absence of functional dependencies on these constants.


Recommendations

Short-Term Fix

Remove the unused constants and inline their values directly into the load() functions. For example:

function load(address asset) internal pure returns (Data storage collateral) {
bytes32 slot = keccak256(
abi.encode(
keccak256(abi.encode(uint256(keccak256("fi.zaros.market-making.Collateral")) - 1)),
asset
)
);
assembly {
collateral.slot := slot
}
}

Long-Term Fix

  1. Refactor Storage Slot Derivation :

    • Centralize storage slot derivation logic into a utility library to avoid redundancy.

    • Example:

      library StorageSlot {
      function getSlot(bytes32 namespace, bytes32 key) internal pure returns (bytes32) {
      return keccak256(abi.encode(namespace, key));
      }
      }
  2. Document Constants :

    • If the constants are retained, add clear documentation explaining their purpose and scope.

    • Example:

      /// @notice ERC7201 storage location for AssetSwapPath data.
      /// @dev Used exclusively in the `load()` function to calculate storage slots.
      bytes32 internal constant ASSET_SWAP_STRATEGY_LOCATION =
      keccak256(abi.encode(uint256(keccak256("fi.zaros.market-making.AssetSwapPath")) - 1));
  3. Automated Linting :

    • Use tools like Solhint or custom scripts to detect and flag unused constants during development.

Updates

Lead Judging Commences

inallhonesty Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Lack of quality

Support

FAQs

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

Give us feedback!