Deterministic results: canonical JSON and the result hash
Two honest nodes must hash the same bytes. How gaussia-search and gaussia-match each turn a result into bytes, why their formats differ today, and what still breaks equality.
Agreement is a byte comparison
In Gaussia’s design, two nodes run the same job without seeing each other’s work and commit to a hash of their result. The job is verified only when the two hashes are equal. A hash does not care that 3.2860001 and 3.28600009999 mean the same period, or that two JSON files list their keys in a different order. If honest nodes produce different bytes, honest work gets sent to a tiebreak.
So both open-source pieces define a canonical JSON: one exact byte form for any result, hashed with sha256. They do it in two different ways today, and this post shows both, with real output.
gaussia-search: %.7e floats
The search tool’s canonical form [1]:
- Object keys sorted by Unicode code point, no whitespace anywhere.
- Non-ASCII characters escaped as
\uXXXX. - Integers stay integers. Every float is written as C
printf("%.7e"): 8 significant digits, round half to even on the exact binary value.1.0becomes1.0000000e+00. - NaN and infinities become
null;-0.0becomes0.0000000e+00.
result_hash = "sha256:" + hex(sha256(ascii(canonical_json(result without "result_hash"))))The hashed object includes each input file’s sha256, every pipeline parameter and the versions of gaussia_search, Python, numpy and astropy. A different library version is a different result on purpose. It contains no timestamps, paths or host names, and the thread count is never hashed, which is why 1 thread and 20 threads give the same hash on the L 98-59 run [2].
gaussia-match: canonical JSON v0
The matching library defines its own form for any JSON result it hashes [3]:
- Keys sorted by UTF-16 code units, the default JavaScript sort, as in RFC 8785. No whitespace.
- Strings escaped as ECMAScript’s JSON.stringify does, other characters left as UTF-8.
- Every number rounded to 6 decimal places, half to even on the exact binary value, then written with the fewest digits:
2.50→2.5,0.1 + 0.2→0.3,4e-7→0. - Duplicate keys are refused, since parsers disagree on which one wins (v0.9.2 added the strict parser to every command that reads JSON).
result_hash = sha256(utf8(canonical))as 64 hex characters;sha256:<hex>is accepted as input.
The rounding is there because two nodes on different GPUs can differ in the last bits of a float. Rounding lets those runs hash equal in the common case.
The same values in both formats
We ran both canonicalisers on the grid block and on peak 3 (L 98-59 d) of the real L 98-59 result file [2]:
gaussia-search canonical_json
{"log_step":1.0050828e-04,"n_periods":36703,"period_max_days":1.9999509e+01,"period_min_days":5.0000000e-01}{"depth_ppm":8.8291154e+02,"duration_days":4.0000000e-02,"period_days":7.4507475e+00,"t0":2.9646501e+03}gaussia-match canonical JSON v0
{"log_step":0.000101,"n_periods":36703,"period_max_days":19.999509,"period_min_days":0.5}{"depth_ppm":882.91154,"duration_days":0.04,"period_days":7.450748,"t0":2964.6501}Fixed decimal places treat small numbers badly, which is why the spec tells producers to pick units where 6 decimals keep the precision that matters, such as depth in ppm rather than as a fraction [3]. Significant digits suit values of any size but need an exponent in the text.
Hashing the whole file gives two different hashes: the search tool checks its stored sha256:905cb980…c08acc384, while gaussia-match canonicalises the same file its own way:
$ gaussia-search hash examples/l98-59-s61-65.jsonok: matches result_hash in file$ gaussia-match result-hash examples/l98-59-s61-65.jsonresult_hash d9933af60f3b156eb6ea0564ccd85cf9a6cc7fb25faafd7935a7f71f5530e04dHow the two fit together today
That is the note in the docs, word for word [4]. So a node running gaussia-search can commit the search tool’s own result_hash directly, and the two formats never have to meet. Still, two implementations of one idea is a cost, and settling on a single format is open work, not a decision we have made.
What still breaks equality
- Rounding edges. Rounding hides last-bit noise except when a value sits right on a boundary; then two honest runs round apart and the hashes differ like any other mismatch [1] [3].
- Versions. Any library version difference changes the search hash, so both nodes must run the same pinned release. The Docker image pins its base images by digest [1].
- Inputs. MAST may reprocess a sector. The input file’s sha256 in the result shows which file was searched.
- Platforms. Byte equality is tested on x86-64 Linux. Tests on other CPUs and platforms are in progress.
What's in progress
- One shared canonical format for search results and matching. Today there are two, as above.
- Byte-equality tests beyond x86-64 Linux, and on GPUs: GPU BLS is in progress.
- The node software that would run gaussia-search and commit its hash with gaussia-match, and the coordinator that would compare them.
- Both specs are drafts and may change before v1.