createPeriod
initialize Period.totalDuration
to duration
, while it should be initialized to zero, as totalDuration
represents the total duration of accumulated values.
This mistake causes an inflated totalDuration
Let's see what happen to totalDuration
when we create a period and then update it, and if it seems correct.
Let's fix block.timestamp = 0
for simplicity purpose.
First, if we create a period with startTime = 0
and a duration of 3600
seconds, we get:
period.totalDuration = 3600
and lastUpdateTime = 0
Now, let's move to block.timestamp = 1800
and call updateValue()
(whatever the new value):
duration = 1800 - 0 = 1800
which is correct, 1800 second has elapsed since last update of the period
totalDuration += duration
which is totalDuration = 3600 + 1800
But only 1800 seconds have elapsed yet.
totalDuration
will not represent a correct value, which will cause issues in future integration of the library.
Initialize period.totalDuration
to 0
on creation.
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.