sherlock-audit / 2023-09-perennial-judging

0 stars 0 forks source link

0xVinylDavyl - The code essential Risk Parameter lacks proper documentation in the form of inline comments and explanations #23

Closed sherlock-admin2 closed 11 months ago

sherlock-admin2 commented 11 months ago

0xVinylDavyl

medium

The code essential Risk Parameter lacks proper documentation in the form of inline comments and explanations

Summary

The code essential Risk Parameter lacks proper documentation in the form of inline comments and explanations, making it difficult for developers and auditors to understand the code's functionality and purpose.

Vulnerability Detail

The code provided is missing essential inline comments and explanations that would help readers, including developers and auditors, understand the code's logic and purpose. Clear and comprehensive documentation is crucial for maintaining code quality, ensuring transparency, and facilitating the auditing process.

Impact

The absence of proper documentation can have several adverse effects:

Code Snippet

example of code without proper documentation, particularly lacking inline comments:

function validate(RiskParameter memory self, ProtocolParameter memory protocolParameter) public pure {
    if (
        self.takerFee.max(self.takerSkewFee).max(self.takerImpactFee).max(self.makerFee).max(self.makerImpactFee)
        .gt(protocolParameter.maxFee)
    ) revert RiskParameterStorageInvalidError();

    if (
        self.minLiquidationFee.max(self.maxLiquidationFee).max(self.minMargin).max(self.minMaintenance)
        .gt(protocolParameter.maxFeeAbsolute)
    ) revert RiskParameterStorageInvalidError();

    if (self.liquidationFee.gt(protocolParameter.maxCut)) revert RiskParameterStorageInvalidError();

    if (
        self.utilizationCurve.minRate.max(self.utilizationCurve.maxRate).max(self.utilizationCurve.targetRate).max(self.pController.max)
        .gt(protocolParameter.maxRate)
    ) revert RiskParameterStorageInvalidError();

    // ... (other validation checks)
}

https://github.com/sherlock-audit/2023-09-perennial/blob/main/perennial-v2/packages/perennial/contracts/types/RiskParameter.sol#L142

Tool used

Manual Review

Recommendation

To improve code readability and facilitate understanding, it is recommended to add detailed inline comments and explanations to clarify the purpose and functionality of each part of the code. Here is an example of how the code can be documented:

/**
 * @dev Validate risk parameters against protocol parameters.
 *
 * This function checks if the provided risk parameters are within acceptable ranges based on the protocol parameters.
 *
 * @param self The risk parameters to validate.
 * @param protocolParameter The protocol parameters used for validation.
 */
function validate(RiskParameter memory self, ProtocolParameter memory protocolParameter) public pure {
    // Check if taker fees are within acceptable limits
    if (
        self.takerFee.max(self.takerSkewFee).max(self.takerImpactFee).max(self.makerFee).max(self.makerImpactFee)
        .gt(protocolParameter.maxFee)
    ) revert RiskParameterStorageInvalidError();

    // Check if fee-related parameters are within acceptable limits
    if (
        self.minLiquidationFee.max(self.maxLiquidationFee).max(self.minMargin).max(self.minMaintenance)
        .gt(protocolParameter.maxFeeAbsolute)
    ) revert RiskParameterStorageInvalidError();

    // Check if liquidation fee is within acceptable limits
    if (self.liquidationFee.gt(protocolParameter.maxCut)) revert RiskParameterStorageInvalidError();

    // Check if utilization curve and P controller parameters are within acceptable limits
    if (
        self.utilizationCurve.minRate.max(self.utilizationCurve.maxRate).max(self.utilizationCurve.targetRate).max(self.pController.max)
        .gt(protocolParameter.maxRate)
    ) revert RiskParameterStorageInvalidError();

    // ... (other validation checks)
}

By adding such inline comments and explanations, the code becomes more understandable, reducing the risk of misunderstandings and errors during development and auditing.

sherlock-admin commented 11 months ago

4 comment(s) were left on this issue during the judging contest.

panprog commented:

invalid because lack of documentation is not a valid issue by sherlock rules

n33k commented:

invalid, ai generated groundless report

darkart commented:

The same as 14

polarzero commented:

Invalid. This is true, as the lack of documentation and comments make it very difficult to understand the code. However, this does not qualify as a medium/high severity issue.