getRoundPhase is designed to calculate the current round, phase, and time remaining for a contract. It does so by iterating through a list of market parameters, marketParams, each associated with a specific timestamp. The issue with the iterating is that it assumes there is no discontinuity between consecutive market parameters, which may not be the case always. Any overlap or gap may lead to incorrect round, which may affect critical functions like purchase()
getRoundPhase is defined as:
As it can be seen from the loop in the function, rounds are calculated using the difference in timestamps between consecutive market parameters in _computePhase() . _computePhase returns the round based on the integer division of elapsedTime / cycleTime. Since each phase calculation relies on elapsedTime, any discontinuity in marketParams[idx].timestamp values may result in incorrect round calculation.
Consider the following Cases:
Case 1: Suppose two market parameters have overlapping intervals, like so:
Here, the second marketParams entry starts at 1200, which falls within the timeframe of the first entry (1000 + cycleTime up to 1600). This causes ambiguity: should the function use the first or second parameter for phases within the overlapping time? This overlapping could result in skipped or repeated phases.
Case2: Assume the following timestamps with a gap between consecutive parameters:
In this case, the first marketParams entry ends at 1600, but the next one starts at 2000. This gap between 1600 and 2000 means there is no defined phase during this period. getRoundPhase could misinterpret the contract state if block.timestamp falls within this undefined gap. A potential
gap or overlap is highly likely to happen, because the market Params are set manually in the following function:
As it can be seen block.timestamp is used as timestamp and it is set manually by the owner. If there is a delay between consecutive markets, then unintended gaps will exist.
Considering the round variable used in many place in the code, it may lead to undesired outcomes. For instance in purchase() function:
an incorrect round can lead to incorrect taskId, which may lead to revert and preventing the purchase.
Incorrect calculation of phase and round, potentially disrupting behavior of critical functions
Manual Review, Vs Code
Implement a logic that dynamically adjusts intervals to prevent gaps and overlaps.
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.