Uniswap / v3-core-optimism

Optimism fork of the V3 core contracts
Other
32 stars 41 forks source link

first mul, then div. Is this a bug? #8

Closed zgfzgf closed 3 years ago

zgfzgf commented 3 years ago

(atOrAfter.tickCumulative - beforeOrAt.tickCumulative) * targetDelta / observationTimeDelta

corresponding L283

https://github.com/Uniswap/uniswap-v3-core-optimism/blob/da89f9b88a1616be1ef075ad4313e8aeb3532906/contracts/libraries/Oracle.sol#L276-L284

moodysalem commented 3 years ago

it is correct. (atOrAfter.tickCumulative - beforeOrAt.tickCumulative) % observationTimeDelta == 0 is an invariant tested in the echidna tests, so division before multiplication is safe.

zgfzgf commented 3 years ago

I see. tick == (atOrAfter.tickCumulative - beforeOrAt.tickCumulative) / observationTimeDelta I think. may should test it. @moodysalem