Skip to content

Canonical interface hashing

The interface hash is the fingerprint of a block's interface, such as xci-sha256:a5cb0b94…. It covers everything a caller relies on: the interface identity and version, and each method's number, name, parameter and result types, errors, delivery, effect and retry declaration, plus the resources and retired numbers. Two interfaces with the same hash are the same contract.

What changes it

The hash follows the contract and ignores how the definition file is laid out. The ledger interface, edited four ways:

Change to billing.xci.json Interface hash Source digest
None xci-sha256:a5cb0b94… sha256:4397cca1…
Whitespace removed xci-sha256:a5cb0b94… sha256:68db7402…
Methods listed in reverse order xci-sha256:a5cb0b94… sha256:3ae29935…
charge_status renamed to charge_state xci-sha256:173ed4e9… sha256:7d6ad8e6…

Renaming a method, renumbering it, changing a type, an effect or a retry declaration, retiring a number, or changing the version gives a new hash. A rename counts because callers see method names in their generated code.

Two fingerprints

Every compilation records two values:

  1. The interface hash (xci-sha256:) identifies the contract. It moves only when the contract does.
  2. The source digest (sha256:) identifies the exact bytes of the XCI source file. Any change to the file moves it, including whitespace.

Bake uses the source digest to confirm it is compiling the same file generation compiled, and the interface hash to confirm the contract is unchanged.

Who computes it and who checks it

The XCI compiler computes the interface hash, and only for an interface it accepts. Bake recomputes it and compares. The kernel recomputes it once more from the compiled interface in the capsule, and refuses the capsule when the values differ:

compiled interface interface_hash is xci-sha256:…; independently projected value is xci-sha256:…

The compiler and the kernel are separate implementations, in Python and in Rust. A shared set of test vectors holds both to the same hash for the same interface, so an interface sealed by one is accepted by the other.