Submitted by cmichel
The MovingAverage.sol contract defines several variables that in the end make the samples array act as a ring buffer:
The _getFirstSample function computes the first sample as (counter + 1) % sampleMemory which returns the correct index only if the ring buffer is full, i.e., it wraps around. (in the counter + 1 >= sampleMemory).
If the samples array does not wrap around yet, the zero index should be returned instead.
Returning counter + 1 if counter + 1 < sampleMemory returns a zero initialized samples observation index.
This then leads to a wrong computation of the TWAP.
Add an additional check for if (counter + 1 < sampleMemory) return 0 in _getFirstSample.
0xScotch (sponsor) confirmed and disagreed with severity:
Alex the Entreprenerd (judge) commented:
