"0 Divergences" Is a Statement About the Corpus
A Go-Rust differential test said 0 divergences while real splits existed. What it missed, what the freeze gate can't see, and why both now run in CI.
The SwornMail docs said “0 divergences” between the Go and the Rust verifier, and it was true. Earlier this week I wrote about CBOR type bugs that were in both verifiers the whole time. This post is about why the number didn’t show them, and what changed so it means a bit more.
Two checks, two different questions
SwornMail has two mechanical checks that I lean on.
The freeze gate asks: does the Go reference still produce exactly the published test vectors? The -01 wire format is frozen. The Go repo generates v1.json, and it must be byte-identical to the copy in the spec repo. Today that is 123 vectors: 74 token, 39 record and 10 policy-authorization cases.
The differential test (difftest) asks: do Go and Rust agree? It builds a corpus, runs every case through both, and compares the result, plus operator and unit on a pass. The default run is 3,155 cases: 155 structured ones and 3,000 byte-level fuzz cases. A second harness, recorddiff, does the same for DNS records between Go and the Lua module, 266 cases.
Both answered “yes” before the review, and both were right about what they checked.
What the corpus didn’t have
The 3,000 fuzz cases are byte-level mutations of one valid token: flip a few bytes, truncate, append junk. A mutated token almost never makes a validly signed token with null in the unit field, or a bignum where the operator key should be. A signature check rejects them long before the interesting code runs. So the fuzz part looks big and tests mostly the envelope and the signature check.
The structured part has only the shapes somebody thought of. And nobody thought of nulls, simple values, self-described tags or bignum keys. After the review I added 76 shapes, and the old code split on 17 of them.
The review found one more split outside the corpus, in the key record parser. Go checked pk the moment it saw it. Rust reads k (the algorithm) first. So for a record of a future algorithm:
v=SWORN1; k=future; pk=<future key> Go: none Rust: none
v=SWORN1; pk=<future key>; k=future Go: permerror Rust: none
Same record, tags in a different order, a different verdict in Go. The draft wants none for an algorithm you don’t implement, so an operator who publishes a new selector early isn’t punished by older verifiers. The Go parser now holds pk back until every tag is read (swornmail-go#19), and a test checks both orders.
What the freeze gate can’t see
That tag order fix changed a result: permerror became none for one record shape. And the freeze gate stayed green, byte-identical.
The reason is boring. The record vectors store only ok or error, 13 and 26 of them. “Malformed record” and “unsupported algorithm” are both error. So the gate can tell you a record is rejected, but not which way, and the way decides between permerror and none in the header.
The change is deliberate, and the PR says so. But the gate would have said nothing if it wasn’t.
Under the freeze I keep the record vectors as ok/error. In the next spec revision I want the vectors to store the exact result, so the gate catches this kind of change by itself.
Running them in CI
Until November both checks ran by hand. The freeze gate was easy to skip. The Rust repo had no test workflow at all, only the boundary and secret-scan checks.
Now:
- swornmail-go CI has a
freeze-gatejob (generate the vectors,cmpagainst the spec repo) and adifftestjob that builds the Rust binary from the Rust repo’s main and runs Go against it (swornmail-go#19). - The Rust repo runs rustfmt, clippy and the tests on stable, and the tests on the declared minimum Rust version, against the vectors from the spec repo (swornmail#19).
The minimum version job already caught something. The crate said rust-version = "1.81", and 1.81 could not even build the dependency tree any more (signature 3.0.0 needs edition 2024). Nobody noticed, because nothing in CI built it with 1.81. 0.2.5 says 1.85 now.
The harness got stricter too. It used to let a duplicate case name or a repeated Rust answer slip through, and a read error ended in a normal report. Now each of these stops the run. I will write about this kind of checks separately.
The numbers on the sites
While we are on numbers: swornmail.com said 85 vectors and swornmail.dev said 111. The real number was 123. Each was correct at some point and nobody updated it. Both sites now say 123, and the corpus sizes (3,155 and 266) are counted from the generators (swornmail.com#7, swornmail.dev#18).
What is still open
The splits I listed in that post are still outside the corpus: header labels beyond int64, indefinite-length items outside the payload, non-minimal envelope heads, nesting deeper than 32, an unassigned simple value under an unknown key, and go-cose’s own validation of registered headers. And the fuzz part still mutates one valid token, so it still tests mostly the envelope. “0 divergences” today means 0 on these 3,155 cases. Not more.
Next I want the fuzzer to build tokens from the draft’s types instead of flipping bytes in one valid token. That should reach the payload and the headers, where these bugs were.
My decision card
- What I’d do today: publish the corpus size next to every “0 divergences”, and run the differential in CI against the other implementation’s main, not a pinned copy.
- What would change my mind: a structure-aware fuzzer that makes signed, well-formed tokens with odd types. Then the fuzz count would mean something on its own.
- Who should choose differently: with one implementation and no second one coming, spend the time on conformance vectors instead.
If you run a differential test somewhere, I’d like to know how you decide what goes in the corpus. Thanks!
Disclosure: I designed SwornMail. The protocol and its reference code are free and open source (Apache-2.0).