EVM patterns
OpenZeppelin Checkpoints: Historical Lookup and Zero Results
Historical values depend on which record the application intends to select. OpenZeppelin Checkpoints uses different predecessor and successor rules: they returned different values in 104 of our 216 local queries. Zero results, key insertion and voting clock checks need separate acceptance criteria.

Key facts
- Executed query population
- 216 rows across 4 trace types, 6 histories and 9 query keys
- Lookup direction
- 104 of 216 queries returned different lower and upper values
- Recent lookup
- 216 of 216 recent upper results matched ordinary upper lookup
- Zero result classification
- 136 upper zeros: 92 absent predecessors and 44 stored zeros
- Write transitions
- 24 attempts: 16 completed and 8 reverted
- Scope
- Pinned OpenZeppelin v5.5.0 local trace wrappers, no executed voting application
Choose the record before choosing the method
In our constructed query set, changing from upperLookup to lowerLookup changed the returned value in 104 of 216 rows.
Both methods behaved as their source describes.
The discrepancy came from asking different questions of the same history, which makes function selection an application requirement rather than a naming preference.
OpenZeppelin Checkpoints stores ordered key and value pairs in a trace. A key can represent a block number or another ordered quantity chosen by the application. The library does not infer that meaning from the number. Before accepting an integration, write down whether a query needs the value established by an earlier checkpoint or a value belonging to the next qualifying checkpoint. Those are different contracts with the caller.
| Method | Selected record | No qualifying record |
|---|---|---|
upperLookup | Last key less than or equal to the query | Returns 0 |
lowerLookup | First key greater than or equal to the query | Returns 0 |
upperLookupRecent | Same predecessor rule as upperLookup | Returns 0 |
Consider an illustrative history with keys 10, 20 and 30 storing values 100, 0 and 300. A query at key 25 returns 0 through the predecessor rule and 300 through the successor rule. The first result represents a stored zero. Treating it as missing data would discard a real state transition. Treating the successor as the past value would select a record after the requested key.
These names can be misleading when read as everyday language. Match the inequality, not an intuition about the word upper. The OpenZeppelin utilities reference documents the predicates, while the release-pinned source establishes the implementation used in this experiment.
A second illustrative query shows why a successful function call can still answer the wrong question. At key 70, after the last key 60 of our six-entry history, the predecessor value is 600 while the successor result is 0. That zero says there is no later qualifying entry. It does not mean the earlier value was erased. The caller should choose the predicate before it sees the output, otherwise a fallback that selects whichever number looks plausible can quietly change the meaning of the query.
The trace types also encode a choice. Our pinned source provides Trace256 with a uint256 key and value, Trace224 with a uint32 key and uint224 value, Trace208 with a uint48 key and uint208 value, plus Trace160 with a uint96 key and uint160 value. Record the actual type before comparing results from an explorer, test harness or indexer. A shared method name does not make every key domain interchangeable.
216 local queries and 24 write attempts
Method
We executed the retained library rather than a rewritten binary search. The fixture exposes its methods through typed wrappers and creates a fresh history for each combination. It deliberately permits caller-selected keys to make insertion behavior observable. That exposure is a test arrangement, not a proposed production interface.
- Retrieved and executed
- Library and toolchain
- OpenZeppelin Contracts
v5.5.0, Solidity0.8.36, Cancun target, optimizer and IR pipeline enabled - Query population
- 4 trace types multiplied by 6 histories and 9 query keys: 216 rows, each calling 3 lookup methods
- History lengths
0,1,1,3,5and6. The singleton histories distinguish a nonzero value from a stored zero- Query keys
0,9,10,15,20,25,30,55and70- Write population
- 4 trace types multiplied by 6 sequential insertion attempts: 24 transitions, including repeated, decreasing and maximum keys
- Exclusions
- No row excluded from either completed grid
The repository retains seo/research/openzeppelin-checkpoints-security-2026-12-02/measurement.py, CheckpointMatrix.t.sol and measurement.json. These are repository artifacts, not public download endpoints. The runner records source hashes, compiler settings and encoded observations. An independent script checks every row with linear predecessor and successor predicates, then models each write transition. A separate execution reproduced the full ledger exactly.
Results
| History | Entries | Different lower and upper values | Zero upper results |
|---|---|---|---|
| Empty | 0 | 0 | 36 |
| Single nonzero value | 1 | 32 | 16 |
| Single stored zero | 1 | 0 | 36 |
| Sparse history | 3 | 24 | 16 |
| Five entries | 5 | 24 | 16 |
| Six entries | 6 | 24 | 16 |
Across all 216 rows, upperLookupRecent equaled upperLookup. The pinned implementation enters its recent-key partitioning branch when the history length exceeds 5, using a split based on the square root of its length. Our five-entry and six-entry histories cross that branch boundary. The observation supports result equivalence for these inputs. It does not quantify an execution-cost advantage.
There were 136 zero-valued upper results. Classification against the known input histories assigned 92 to a missing predecessor and 44 to an existing predecessor whose stored value was zero. The returned number alone could not distinguish the groups. Our classification used the complete history, which a production caller must not assume it can recover from that number.
Limits
- This is a complete constructed local grid, not a sample of deployed protocols or a vulnerability prevalence estimate.
- The histories cover selected lengths and keys. They do not establish correctness for every possible trace, numeric conversion or malformed surrounding application.
- Votes, Governor and token transfers were source reviewed separately. They were not executed by the checkpoint fixture.
- No public-chain fork, gas benchmark, live attack or loss measurement was performed. The independent model is not a second EVM implementation.
Repeated keys and the maximum-key boundary
The source requires non-decreasing insertion keys. An insertion below the last key reverts with CheckpointUnorderedInsertion. An equal last key updates the existing value. A larger key appends a record. Consequently, successful calls are not interchangeable with new historical entries. A transaction log or application event count can exceed the number of retained checkpoints.
Our write sequence began by storing value 100 at key 10, then replacing it with 200 at the same key. The trace still contained one entry. A subsequent attempt at key 9 reverted and left the stored state unchanged. Successful insertion returned the previous latest value and the new value, which the independent checker also reconciled.
| Step | Attempt | Completed | Reverted | Length afterward |
|---|---|---|---|---|
| 1 | Insert key 10 | 4 | 0 | 1 |
| 2 | Replace key 10 | 4 | 0 | 1 |
| 3 | Try smaller key 9 | 0 | 4 | 1 |
| 4 | Insert that type's maximum key | 4 | 0 | 2 |
| 5 | Try key 11 after the maximum | 0 | 4 | 2 |
| 6 | Replace the maximum-key value | 4 | 0 | 2 |
Of 24 attempts, 16 completed and 8 reverted. The 8 same-key replacements comprise both step 2 and step 6. All ordering failures returned the named custom error, and the state checks confirmed that the rejected calls did not change the latest checkpoint or length.
Do not expose arbitrary checkpoint keys to an untrusted caller. The source explicitly warns that inserting a type's maximum key can disable normal progression. Our four post-ceiling attempts at key 11 all reverted. However, replacing the maximum-key value remained possible. Describe the obstruction precisely: subsequent smaller keys cannot be appended, while an equal last key remains an update route. Calling every write impossible would overstate the result.
There is another distinction in the return tuple. After inserting a larger key, the old value refers to the previous latest checkpoint, not to a preexisting record at the new key. In step 4, that value was 200 and the inserted maximum-key value was 300. A consumer computing a delta from the tuple must interpret it as an ordered-state transition. It should not present the old value as proof that a record already existed at the requested key. Our state model checked the tuple alongside the array length and final key for every completed write.
Who chooses the key is therefore part of the security boundary. A clock-derived internal key and a freely supplied external key have different trust models even when both call the same library function. Before treating the warning as an exploitable project finding, establish that an attacker can reach the insertion path, choose the relevant key and affect a history the application relies on.
A trace is not the voting timepoint gate
The pinned Votes implementation uses Trace208 for delegated voting histories and derives inserted keys from clock(). Its default clock returns the block number. The accompanying CLOCK_MODE() identifies that interpretation, while ERC6372 contract clocks defines the interface and requires a non-decreasing clock. A timestamp-based override needs a matching mode description.
Historical voting reads add another condition. In the inspected source, getPastVotes validates the requested timepoint before calling upperLookupRecent. The validation rejects a timepoint greater than or equal to the current clock through ERC5805FutureLookup. Past total-supply lookup uses the same gate. That is source inspection of Votes, distinct from the bare-library queries we executed.
The distinction changes a test expectation. Calling a trace directly with a key after its last record can return that last value under the predecessor rule. It does not mean a voting interface should accept a current or future timepoint. Conversely, a current-timepoint rejection from Votes need not indicate corrupted checkpoint history. It can be the intended temporal guard.
Use the clock's unit throughout the integration. A timestamp and a block number can both fit the declared integer type while referring to different moments. Neither a successful cast nor a plausible-looking result establishes that the query uses the token's intended clock. Retain the token address, chain context, mode and exact queried timepoint with the result.
Repeated keys also explain why a checkpoint trace is not automatically an event archive. Several updates with the same latest key can leave one retained record containing the final value. The inspected Votes comments describe block-number snapshots as the value at the end of the corresponding block. A review that needs the order of intermediate actions must obtain execution or event evidence separately. Reading the final checkpoint can establish the retained value for that key, but it cannot reconstruct every write that produced it.
This page addresses that lookup boundary. The DAO security audit guide follows voting power through proposal rules and execution authority, while governance timelock security examines delayed execution. A correct historical lookup does not establish that the counted units, quorum or eventual action are appropriate for a proposal.
Keep absence separate from a stored zero
A zero-return policy must come from the application. For some histories, zero is the intended value throughout an interval. For others, the caller needs evidence that a qualifying record exists before using the result. Those requirements cannot be reconciled by replacing every returned zero with an error or a default balance.
- Absent predecessor
- The query comes before the first key or the trace is empty. No qualifying record supplies the returned zero.
- Stored zero
- A qualifying earlier record exists and its value is zero. Preserve that state rather than silently substituting another record.
The library's latestCheckpoint tuple includes an existence flag, key and value for the latest record. It can distinguish an empty trace from an existing latest zero. That tuple is not an existence proof for every arbitrary historical query. A nonempty trace can still have no predecessor for a query before its first key.
Nor does an equal result prove equal selection. In the single-zero history, lower and upper lookups returned the same number in all 36 rows, including positions where their qualifying-record conditions differed. Numeric agreement is useful as one check, but it cannot establish which record the application intended to select. Our 104 differences count disagreements in returned values, not every difference in record selection.
Write the acceptance condition at that level. If the consumer needs a predecessor, compare against an independently enumerated key history during testing. If it also needs record existence, capture that evidence separately.
Do not infer a complete history from one value read.
Build a reproducible historical-value review
Start a discrepancy investigation with the exact artifact and input. An indexer reporting a latest value, an explorer exposing a positional checkpoint and a contract answering a historical query can disagree without any of them performing the same operation. The pinned at method reads by array position. length counts records. Neither turns a key into an index.
- Pin the deployed implementation and library source. Record the trace type and source hash so that a current reference page cannot silently substitute for the release being reviewed.
- Capture the queried key, lookup method and relevant checkpoint pairs. Identify the expected predecessor or successor explicitly.
- Exercise an empty history, an exact key and a gap. Include a stored zero and a query outside the recorded range. Retain both returned values and expected record selection.
- Test insertion separately: equal keys, decreasing keys and an attempted maximum key where the exposed interface makes that possible. Check state after rejection rather than accepting a revert label alone.
- For a voting integration, record the clock mode and test its temporal guard through the public voting route. The local checkpoint fixture does not supply that execution evidence.
When two tools disagree, first ask for their query semantics. Preserve the same source pin and history, then compare the exact key and record position each tool used. If those match and the values still differ, retain the complete observations before changing the implementation. That packet gives an independent reviewer a falsifiable question instead of a screenshot showing an unexplained zero. A result without the input history remains incomplete evidence even when the returned number falls inside an expected range.
Keep the result packet small enough to inspect. It should contain the intended predicate, concrete pairs, observed output and any application gate that changes acceptance. The protocol invariants catalog helps turn those expectations into maintained tests. An external review can assess the same evidence through a scoped engagement, such as the Pharos Production member profile. The security tools hub is a starting point for comparing supporting tooling.
The valid use of our result is to select controls, not estimate how often protocols are broken. Re-run the fixture when the pinned implementation changes, then add application tests for the actual clock, access path and consumer. Acceptance requires the intended historical record and the intended temporal policy to agree.
Frequently asked questions
Can a positional checkpoint read safely use a timepoint as its index?
The inspected at method indexes the checkpoint array. A timepoint is a key, which can differ greatly from its record position. An out-of-range position follows the array access failure path. Check length and the intended position rather than silently treating it as a historical lookup. The local matrix did not execute out-of-range at calls.
Can a token and governor use different clock units?
The integration must interpret a proposal snapshot in the token clock domain. ERC6372 exposes clock and CLOCK_MODE so callers can identify that domain. A block number should not be substituted for a timestamp simply because both fit an integer. Verify the deployed token and governor together. No governor execution or clock mismatch experiment was included in this grid.
What evidence should accompany a checkpoint storage upgrade?
Record the existing trace type, storage layout and representative historical key and value pairs before the change. Recheck those reads afterward, including stored zeros and repeated-key behavior. A matching library method name does not establish storage compatibility between different structures. This is an acceptance recommendation. No proxy upgrade or trace migration was executed in the experiment.