Verification checklist
- Separate the two lengths. After cardinalityNext is raised to 4, cardinality is still 1. Slots 1, 2 and 3 hold timestamp 1, and initialized is still false.
- The write at time 1100, tick 100, liquidity 1000000 before the change, raises cardinality to 4. The tick cumulative is 10000. The seconds-per-liquidity increment is 34028236692093846346337460743176821. A second liquidity change in that block leaves the index at 1.
- The write at time 1200 uses index 2 and a tick cumulative of 20000. Slot 3 is still timestamp 1.
- At time 1200, 200 seconds targets 1000. 201 seconds targets 999 and reverts OLD. 400 seconds reverts as well.
1. Prepaid slots and recorded history are two numbers
Oracle.sol v1.0.0 stores observations in a ring. A pool starts with array length 1. Anyone can pay the storage cost to raise the maximum. New slots become part of the ring on the next write that lands when the index is at the end of the current length. Once the ring is full, a new observation overwrites the oldest slot. The newest observation can be read by itself: pass 0 as secondsAgo. That read does not require a longer array.
initialize fills only slot 0. blockTimestamp is the time passed in, tickCumulative is 0, secondsPerLiquidityCumulativeX128 is 0, and initialized is true. The returned cardinality and cardinalityNext are both 1. Initialization does not multiply the current tick into the cumulative. The tick starts accruing at that instant, and it enters the cumulative on the next transform.
grow requires current to be greater than 0, or it reverts with I. If next is not greater than current, it returns current unchanged, so asking to shrink a ring from 4 back to 1 does not shorten it. When next is larger, the function writes slots from current through next minus 1 and sets only blockTimestamp to 1. The comment says this data will not be used, because initialized is still false. The boolean defaults to false, and grow never sets it to true.
UniswapV3Pool v1.0.0 keeps three values in slot0. observationIndex is the index of the most recently written observation. The comment on observationCardinality calls it the current maximum number of observations being stored. The comment on observationCardinalityNext calls it the next maximum, triggered inside observations.write. increaseObservationCardinalityNext calls grow and stores the return value in next. It does not call write, and it does not change the index. After next is raised to 4, a reader can observe next equal to 4 and cardinality still equal to 1. Treating those two fields as one history length stretches the window.
2. From time 1000 to 1200, three of the four slots are observations
The teaching pool is initialized at time 1000. The current tick is 100 and liquidity is 1000000. Slot 0 has timestamp 1000 and a tick cumulative of 0. Next is then raised to 4. Cardinality stays 1. Slots 1, 2 and 3 have timestamp 1, a cumulative of 0, and initialized false. Timestamp 1 does not mean the pool had a price at time 1. It is the placeholder grow writes so the cold storage is paid up front.
At time 1100 a position change on ticks 60 and 180 triggers a write. Tick 100 lies inside that range, so _modifyPosition writes an observation before it changes liquidity, using the tick and the liquidity from before the change. write sees that the previous timestamp is 1000, not 1100, and continues. next is greater than cardinality, and the index equals cardinality minus 1. Cardinality therefore becomes 4 in one step, not 2. The new index is (0 + 1) modulo 4, which is 1.
The transform delta is 100. The tick cumulative is 0 plus 100 times 100, which is 10000. The seconds-per-liquidity increment is (100 shifted left by 128) divided by 1000000, rounded down, which is 34028236692093846346337460743176821. The remainder 145600 is dropped. The whole 100 seconds is charged at tick 100. The write records the tick from before the liquidity change, not a tick the position change was meant to reach. A mint or a burn does not move the current tick.
In the same block the liquidity just added is removed. The second write sees a previous timestamp of 1100 and returns the old index and cardinality at the top of the function. Liquidity can return to 1000000. The array does not gain a second observation with timestamp 1100. History is at most one observation per block, and only when execution actually enters write. A swap writes only when the tick after the swap differs from the tick before it, and the value it writes is still the pre-swap tick. A swap that never crosses a tick does not add an observation just because a trade occurred.
| index | blockTimestamp | tickCumulative | initialized |
|---|---|---|---|
| 0 | 1000 | 0 | true |
| 1 | 1100 | 10000 | true |
| 2 | 1200 | 20000 | true |
| 3 | 1 | 0 | false |
At time 1200, with liquidity back at 1000000 and the tick still 100, another write runs. The index is 1 and cardinality is already 4, so the index is not 3 and the ring length stays put. The new index is 2. The delta is again 100. The tick cumulative is 10000 plus 10000, which is 20000. Seconds per liquidity increases by the same 34028236692093846346337460743176821. The two steps sum to 68056473384187692692674921486353642. That equals the single floor of a 200-second division, because twice the one-step remainder 145600 is still below 1000000. If a remainder were at least 500000, two separate floors would be 1 short of the combined floor. Equality here is a property of this denominator, not a reason to ignore the floor.
3. 200 seconds lands on 1000. 201 seconds reverts OLD
observe requires cardinality to be greater than 0, or it reverts with I. When secondsAgo is 0 and the newest timestamp is not the current time, the function transforms that slot forward with the current tick and the current liquidity. That is an extrapolation to the present. It does not consume a new slot, and it does not read next.
When secondsAgo is greater than 0, the target is the current time minus the seconds. getSurroundingObservations looks at the newest slot first. If the target is not older than that timestamp, the function either returns the slot, when the target equals it, or transforms forward to the target. A successful extrapolation does not mean a stored observation exists at that exact time.
If the target is older than the newest observation, the candidate for the oldest slot is self[(index + 1) modulo cardinality]. At time 1200, with index 2 and cardinality 4, that index is 3. Slot 3 is not initialized, so the code uses slot 0 instead: time 1000 and cumulative 0. It then requires the target to be no older than that timestamp, or it reverts OLD. The left edge of a lookback is the oldest initialized observation. It is not next, and it is not cardinality times an imagined block interval.
At time 1200, looking back 200 seconds targets 1000, the oldest observation, and the call can succeed. Looking back 201 seconds targets 999, which is older than 1000, and the call reverts OLD. Looking back 400 seconds targets 800 and reverts the same way. Cardinality is already 4. The timestamp 1 in slot 3 is not used as a price from time 1 to fill those 400 seconds. An uninitialized slot only sends the search back to slot 0. It does not extend the window.
4. Until the ring is full, the left edge stays at initialization
At time 1200 the newest index is 2. The next write in a different block lands on index 3. The ring length stays 4, and that slot becomes initialized for the first time. The write after that returns to index 0 and overwrites the observation from time 1000. If those writes fall at 1300 and 1400, and the tick is still 100, the cumulative at 1300 is 30000 and the cumulative at 1400 is 40000, stored at index 0. The newest index is then 0. (0 + 1) modulo 4 is 1. Slot 1 is initialized and its timestamp is 1100, so the code no longer falls back to slot 0. The oldest usable time moves from 1000 to 1100. At time 1400, 300 seconds targets 1100 and can succeed. 301 seconds targets 1099 and reverts OLD.
Raising next to 4 buys a slower overwrite of those four slots. It does not immediately create four spans of history. Before the ring is full, the left edge stays at the initialization time 1000, and the usable lookback is now minus 1000. After slot 0 is overwritten, the left edge jumps to whichever initialized slot is oldest on the ring. The seconds between slots come from the blocks that actually wrote. A second call in the same block does not insert a slot. A swap that does not change the tick does not insert one either. The contract does not promise a 100-second gap. Multiplying cardinality by an imagined interval turns a storage cap into a duration.
After slot 0 is overwritten, timestamp 1 remains only on a slot write has not visited yet. At time 1200 that slot is index 3. Once index 3 has been written, all four slots are initialized and the search no longer falls back because of a false flag. From then on, the left edge is always the slot at (index + 1) modulo cardinality, until someone raises next again and a write at the end of the ring lifts cardinality once more.
5. At time 1250, with no new write, the current reading still exists
Time moves to 1250 and no new write occurs. The newest observation is still index 2, timestamp 1200, tick cumulative 20000. With secondsAgo equal to 0, the transform delta is 50. The tick cumulative is 20000 plus 100 times 50, which is 25000. If current liquidity is still 1000000, seconds per liquidity increases by (50 shifted left by 128) divided by 1000000, rounded down, which is 17014118346046923173168730371588410. Cardinality is unchanged, and the reading exists. Array length blocks queries older than the oldest initialized observation. It does not require a fresh stored slot before the present can be read.
Looking back 150 seconds at that same moment targets 1100, which is index 1 and a tick cumulative of 10000. The difference divided by the seconds is (25000 − 10000) / 150 = 100. The quotient is a tick, not a price. Converting 100 and another endpoint tick into powers of 1.0001, then taking an arithmetic mean, produces a different number. That gap is the subject of TWAP Check: The Time-Weighted Tick Is Not the Average of the Prices. This note fixes whether the window exists. If the target were 999, the call would revert OLD before the division. It would not pad the missing history with 0 and return an average that looks complete.
When the target falls between two observations, observeSingle divides the cumulative gap by the time gap with integer division, then multiplies by the seconds from the left observation to the target. In this teaching the tick stays at 100, so the cumulative gap divides evenly and the interpolation has no remainder. When a remainder is dropped, the interpolated cumulative is smaller than the real-number proportion. That is rounding. The window does not get longer because of it. Extrapolation uses the current tick passed into the call, not the path the tick actually took between the stored points. A tick that came and went without an observation is not reconstructed.
6. Read three fields, then the timestamp of the oldest slot
Reading only observationCardinalityNext treats reserved length as seconds of history. Read cardinality and observationIndex as well, then the newest observation and the slot at (index + 1) modulo cardinality. If that slot is not initialized, the oldest usable time is slot 0, and only while the ring has not yet overwritten slot 0. If that slot is initialized, its own blockTimestamp is the left edge. Now minus that timestamp is the longest lookback that does not trigger OLD. One second further, and the target falls before the left edge.
This is a different set of fields from Feed Check: Time Inside the Heartbeat Is Not a Slice of the Deviation. A heartbeat and a deviation threshold describe how soon another kind of feed must update, and how far the price must move before it must update. The Uniswap array stores neither a heartbeat nor a deviation threshold. It stores a cumulative at each real write. Between writes, the tick is treated as a constant multiplied by the time delta. Seconds without a write do not grow a new observation just because next is already 4.
This is an analytical frame. Ring initialization, grow writing only timestamp 1, the same-block early return in write, cardinality jumping to next at the end of the ring, and the OLD revert when the target is older than the oldest initialized observation come from Oracle.sol v1.0.0. The three slot0 fields, increaseObservationCardinalityNext calling only grow, the in-range position write using the pre-change tick and liquidity, and the swap write using the pre-swap tick only when the tick changes come from UniswapV3Pool.sol v1.0.0. 10000, 20000, 25000, 34028236692093846346337460743176821 and 68056473384187692692674921486353642 are teaching results of those integer operations, not a pool reading from 9 November 2026, and they are not investment advice.
7. Misreadings that keep coming back
Does cardinalityNext of 4 mean the pool can look back across four spans of history?
No. Growing to 4 writes blockTimestamp 1 into slots 1, 2 and 3, leaves initialized false, and leaves cardinality at 1. The first write, at time 1100, raises cardinality to 4 and fills only index 1. At time 1200 slot 3 is still timestamp 1. The left edge of a successful lookback is the oldest initialized observation, time 1000, not four spans.
At time 1200, why does 201 seconds revert while 200 seconds succeeds?
Looking back 200 seconds targets time 1000, the slot initialize wrote. Looking back 201 seconds targets 999, which is older than that blockTimestamp. getSurroundingObservations reverts OLD when the comparison fails. Cardinality is already 4, and that does not change the comparison.
If time reaches 1250 with no new write, does secondsAgo of 0 have no reading?
It has one. When secondsAgo is 0 and the newest observation timestamp is not the current time, observeSingle transforms that observation forward with the current tick. The cumulative goes from 20000 plus 100 times 50, which is 25000. Array length limits queries older than the oldest initialized observation, not the current time.