Expand description
The deterministic contract behind FeltDB’s semantic state diff.
This is the second specimen of the pattern established by
crate::trigger_contract: a decision FeltDB already makes, drawn behind a
runtime-independent boundary so that more than one implementation can be
held to it.
canonical state A + canonical state B
│
┌──────────────┴──────────────┐
│ │
native evaluation WASM evaluation
│ │
└──────────────┬──────────────┘
│
canonical diff bytes§This module adds no diff semantics
SemanticDiff::compute is untouched and remains authoritative. Everything
here is envelope: identity, version, canonical encoding, and the decision to
report an unusable input rather than fail. If this module and
SemanticDiff::compute ever disagree, SemanticDiff::compute is right.
§Determinism budget
Evaluation reads nothing but its two states. No clock, filesystem, network, random source, process identity, authentication context, authority metadata or process-global mutable state participates, and the audit that produced this contract found none in the implementation either.
§What the audit established about the semantics
These are properties of the existing implementation, recorded here because the contract is defined against them rather than against an idea of what a diff should do:
- Arrays are positional. A reorder is not detected;
[1,2] -> [2,1]reportsChangedat index 0 and at index 1. Elements past the shorter length becomeAddedorRemovedat their index. - Absence and null are different, in both directions.
missing -> valueisAdded,null -> valueisChanged,value -> missingisRemoved,value -> nullisChanged. old_valueandnew_valueareOption, encoded asnullwhen absent. That is ambiguous with a JSON null on its own, andkindis what disambiguates:missing -> nullisAddedwithnew_value: null.- Numbers compare by
serde_jsonvariant.42and42.0differ, so they reportChanged;-0is a float and so differs from the integer0;-0.0and0.0are equal under IEEE equality and report nothing. - A type transition is one
Changed, carrying both whole values, at the path where it happens — including at the empty path, for the states themselves. - Ordering is total. Changes sort by path, then by kind. Paths are unique within one diff, so the ordering does not depend on sort stability.
Structs§
- Contract
Error Body - The error body of a contract output.
- State
Diff Input - The complete deterministic input: two states, and the contract’s identity.
- State
Diff Output - The complete deterministic output.
Enums§
- Contract
Error Code - Why an input could not be evaluated.
- Contract
Runtime - The runtime that executed a contract, recorded in evidence.
Constants§
- STATE_
DIFF_ CONTRACT_ ID - Stable identity of this contract.
- STATE_
DIFF_ CONTRACT_ VERSION - Version of this contract’s input shape, output shape and semantics.
Functions§
- canonical_
input_ bytes - The canonical byte encoding of a contract input.
- canonical_
output_ bytes - The canonical byte encoding of a contract output.
- diff_
states - The deterministic contract, natively implemented.
- evaluate_
canonical - The runtime-independent entry point: canonical bytes in, canonical bytes out.
- evaluate_
canonical_ output evaluate_canonicalbefore encoding, for callers that want the value.- input_
digest - Content identity of a contract input, for provenance.