Submitted by hyh, also found by CertoraInc, d3e4, and rbserver
Now the precision is lost in moving average calculations as the difference is calculated separately and added each time, while it typically can be small enough to lose precision in the division involved.
For example, 10000 moves of 990 size, numObservations = 1000. This will yield 0 on each update, while must yield 9900 increase in the moving average.
Moving average is calculated with the addition of the difference:
https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/modules/PRICE.sol#L134-L139
/ numObs can lose precision as currentPrice - earliestPrice is usually small.
It is returned on request as is:
https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/modules/PRICE.sol#L189-L193
Consider storing the cumulative sum, while returning sum / numObs on request:
https://github.com/code-423n4/2022-08-olympus/blob/2a0b515012b4a40076f6eac487f7816aafb8724a/src/modules/PRICE.sol#L189-L193
Oighty (Olympus) disagreed with severity and commented:
hyh (warden) commented:
Oighty (Olympus) confirmed
0xean (judge) commented:
