Description:
The _updateWeights function is designed to update the weights for a time-weighted average calculation by either creating a new period or updating an existing one. However, despite checking if weightPeriod.startTime == 0, both branches of the conditional statement execute the same logic, differing only in the initial period start time calculation.
This redundancy results in unnecessary computation, increased gas costs, and confusion regarding the function's intended behavior. Additionally, the function does not differentiate between the initialization of a new period and the update of an existing one, which may lead to incorrect weight calculations.
Impact:
The presence of an ineffective conditional structure makes the function inefficient and misleading:
Unnecessary gas consumption: due to redundant calculations.
Lack of distinction between the initial and subsequent periods: making the conditional check unnecessary.
Potential miscalculations in weight updates: as the same formula is applied regardless of whether it is the first or subsequent update.
Proof of Concept:
The function's logic results in identical operations regardless of whether it's the first or a subsequent update:
Despite the if condition checking whether it is the initial period, both branches of the statement calculate nextPeriodStart in the same manner and pass identical values to createPeriod. This means the conditional structure does not impact the function's behavior, rendering it redundant.
Recommended Mitigation:
The formula used in the else condition should be reevaluated to ensure the function properly differentiates between the initialization of a new period and the update of an existing one. The logic should be adjusted to correctly apply weight updates for subsequent periods while avoiding unnecessary computations.
Tools used:\Manual Review
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.