# SQLite WAL checksums and value fidelity
## Finding
Two captured SQLite 3.45.1 fixtures show a designed three-byte change inside a
128-byte BLOB while original WAL checksums, headers and the later frame stay
unchanged. Native cold reads return the altered value and later marker;
integrity_check returns ok. A one-byte control returns the old base state,
also structurally ok. This is not an observed disk fault or a new vulnerability.

| Case | Valid WAL frame prefix | Read BLOB | Later marker | integrity_check |
| --- | ---: | --- | ---: | --- |
| main_only | none | base Q x 128 | 0 | ok |
| intact | 2 of 2 | intended A x 128 | 2 | ok |
| neutral | 2 of 2 | altered, 3 bytes differ | 2 | ok |
| single_word | 0 of 2 | base Q x 128 | 0 | ok |

Each row occurred in both captures. These are four designed cases, not sampled
faults. results.json is generated from verified observations. Both captures
retain exact inputs, full payloads, original runtime IDs and compilation options.

## Mechanism and method
For word pair x,y the checksum updates unsigned 32-bit accumulators:
a = a + x + b; b = b + y + a, modulo 2^32.
Our derivation changes four pair-aligned words by (d,-d,-d,0). The accumulator
difference becomes (d,0) after one pair and (0,0) after two. Every unchanged
suffix has the original checksum. The mutation is inside covered payload,
not an unchecked region. This fixture uses d=1.

Tests independently evaluate the four-word closed form across 4096 seeded
vectors, both byte orders, overflow and unchanged suffixes. Native observations
use little-endian checksum words only; big-endian coverage is algebraic.

The probe creates a private three-page database, checkpoints the base and then
commits a BLOB update followed by a marker update in separate transactions.
It freezes the unchanged main file and two-frame WAL before closing the writer.
Mutations affect detached synthetic bytes only. Each read uses a new directory,
no copied SHM, mode=ro and query_only=ON. The engine supplies data and integrity
results; a parser separately checks headers and the checksum chain.

The captured runtime is Ubuntu libsqlite3-0 3.45.1-1ubuntu2.9 via Python 3.12.3.
The pinned upstream source explains the mechanism but is not asserted identical
to that patched binary. replay.py prints active and captured identities separately.
A later marker alone does not certify the earlier BLOB value.

## Reproduce offline
Extract the ZIP to disposable storage. Python with SQLite WAL support is needed;
no third-party package or network is required.

    python3 -B replay.py
    python3 -B -m unittest -v test_probe.py
    python3 -B -O -m unittest -v test_probe.py

A replay on another build is a new observation, not automatically part of the
captured result. Optional fresh capture, with a nonexistent output directory:

    python3 -B probe.py --capture /tmp/new-wal-capture

Never substitute a live database. The probe removes temporary recovery copies.
manifest.json identifies every payload by SHA-256; this checks consistency
relative to that manifest, not authentication of an untrusted download.
sources.json records source URLs, locators, downloaded hashes and rights.
Source documents and runtime binaries are not redistributed in this bundle.

## Interpretation and limits
A recovery review needs evidence for identity, generation and application
content in addition to structure. Compare intended values or a trusted external
reference. A digest beside equally mutable data is not authentication.

One host build, page size and small schema were tested. No power-loss, writable
recovery, encrypted/overflow-page, random-fault or performance claim is made.
Do not infer a 2^-64 miss probability from two checksum words. Two captures are
not independent-person replication. This is unrelated to the WAL-reset race.

See [WAL synthesis](https://hesela.com/analyses/wal-checkpoints-torn-pages/#sqlite-wal-value-fidelity)
and [Checksum](https://hesela.dev/terms/checksum/).

## Primary sources and rights
- [SQLite file format, sections 4.1-4.2](https://www.sqlite.org/fileformat2.html#walformat).
- [Pinned SQLite 3.45.1 wal.c](https://github.com/sqlite/sqlite/blob/189e44dfecdc7868bb860dfb5d98eab371318c37/src/wal.c).
- [integrity_check](https://www.sqlite.org/pragma.html#pragma_integrity_check).
- [WAL and read-only access](https://www.sqlite.org/wal.html).

SQLite upstream source is public domain. Original Hesela code/data retain
the repository's existing rights; this bundle grants no additional license.
