Skip to content

Where the XCI compiler runs

The XCI compiler ships with the Xratu SDK. It runs where you run the Xratu CLI, on your machine or in CI, at two points in a block's life: when the block pipeline generates the block, and when bake builds the package. The kernel runs no compiler. It receives the block's capsule from the published package and checks the compiled interface's hash.

flowchart TB
  B["billing.py<br/>your block"]
  B --> G["xratu capability generate<br/>compile, write everything the block needs"]
  G --> K["xratu bake<br/>compile again, compare, build the package"]
  K --> C["Xratu package<br/>with the block's capsule"]
  C --> R["Kernel<br/>recompute the hash, then run"]

At generation

xratu capability generate runs the compiler on the block's interface definition and writes everything the later stages need:

billing.xci.json                                     the interface definition
python/acme/billing/ledger_guest.py                  Python binding
rust/acme/billing/ledger.rs                          Rust binding
capsule/acme/billing/ledger_adapter_dispatch.py      dispatch module
.xratu/generated/acme.billing_reusable_capability_block_manifest.json
.xratu/generated/acme.billing_reusable_capability_block_adapter_manifest.json
.xratu/generated/acme.billing_reusable_capability_block_env_intent.json
.xratu/generated/acme.billing_reusable_capability_block_interface_seed.json

The interface seed records the compiled interface, its hash, the method numbers, and the path and digest of each file the compiler produced.

ledger.rs is a typed Rust representation of the block's XCI contract: its records, method numbers and declarations as Rust types. It is not a translation of your Python code and not what runs it. The Rust kernel works from the sealed compiled interface, and your Python runs in the CPython provider.

At bake

xratu bake runs the compiler again and compares its result with the interface seed: the same interface file, the same identity, version and hash, the same method numbers, and generated files identical byte for byte. What generation recorded is checked, so a change after generation is caught before anything is sealed. It then builds the Xratu package, with the block's capsule:

{
  "status": "baked",
  "capsule_count": 1,
  "capsules": ["sha256:40e4f7107cd51aaf3f71dfa261b1db2a8c4f7f2c50f5c92965f4dce90124d537"],
  "provider_requirement": {"kind": "cpython", "abi": "cp311", "min_version": "3.11.12"}
}

See Interface conformance for what each check refuses, and Bake pipeline for everything bake produces.

In the kernel

The kernel receives only what was baked and published. It reads the compiled interface from the capsule, recomputes its hash, and refuses the capsule when the hash disagrees. It works from the compiled interface alone, so every decision about an interface is made before the block runs. See Canonical interface hashing.