DeFiLayer 1Layer 2
14,723 OP
View results
Submission Details
Severity: medium
Invalid

Precision Loss in `_obtain_price_params` Function

Summary

Precision Loss in Period Calculation

The function _obtain_price_params suffers from potential precision loss due to integer division when calculating the number of elapsed periods. This issue can result in delayed updates to price parameters, affecting accuracy in reward distribution.

Description

Affected Function:

@view
def _obtain_price_params(parameters_ts: uint256) -> PriceParams:

The issue arises in this section:

number_of_periods: uint256 = min(
(parameters_ts - params.last_profit_update) // period,
self.max_v2_duration,
)
  • Since Solidity/Vyper uses integer division, if parameters_ts - params.last_profit_update is slightly less than period, the division results in 0.

  • Example:

    Realistic Scenario:

    • Assume params.last_profit_update = 1,000,000

    • Assume parameters_ts = 1,000,599

    • Assume period = 7 * 86400 = 604800 (one week)

    (1,000,599 - 1,000,000) // 604800 = 599 // 604800 = 0
    • Even though nearly a full week has passed, it is ignored, causing a delay in updating parameters.

This means almost a full period may pass before an update occurs, leading to lag in updating parameters.

Impact

  • Delayed Unlocking of Profits: The vault’s profit distribution could be postponed unnecessarily, reducing yield efficiency.

  • Inconsistent Parameter Updates: The contract assumes regular updates, but this issue creates gaps in update intervals.

  • Potential Underestimation of Rewards: Fewer periods counted means less asset growth, impacting user returns.

Recommendation

Modify the calculation to ensure fractional periods contribute appropriately:
Use Ceiling Division.

Instead of integer division, use a ceiling function to account for partial periods

Updates

Lead Judging Commences

0xnevi Lead Judge 3 months ago
Submission Judgement Published
Invalidated
Reason: Lack of quality
Assigned finding tags:

[invalid] finding-precision-loss

All values will be scaled to a combined of 36 decimals before division (be it price-related values or totalSupply). Considering the 18 decimals of all values, no realistic values were presented in any duplicates to proof a substantial impact on precision loss.

Support

FAQs

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