xian-contracting
xian-contracting is the contract compiler, source/artifact utility layer,
local test harness, and standard-library bridge for Xian. Network execution is
defined by the chain's Xian VM profile. The fresh-genesis profile is xian_vm_v2.
The published PyPI package is xian-tech-contracting. The import package
remains contracting. Side packages under packages/ (deterministic runtime
types, accounts, fast-path validator, VM crates, zk tooling)
are released independently and consumed by xian-abci, xian-py, and the
node runtime.
Package Shape
flowchart LR
Source["Authored contract source"] --> Compiler["Compiler and linter"]
Compiler --> Artifact["Profile-tagged Xian IR"]
Artifact --> VM["Native VM under the selected chain profile"]
Executor["V2 local harness"] --> VM
VM --> Storage["Deterministic storage"]
VM --> Stdlib["Host bridge"]
VM --> Events["LogEvent output"]
Packages["Side packages"] --> VM
Packages --> ZK["xian-zk"]
Quick Start
From this checkout, install the local compiler, matching runtime types and V2 VM with Python 3.14:
uv sync
The base installation includes the native VM, compiler and runtime types. The
VM links the zk verifier, so every installation verifies zk proofs; add the
zk extra for the xian_zk prover and shielded-note tooling.
Compile artifacts for the fresh-genesis profile:
from contracting.artifacts import build_contract_artifacts
contract_source = "@export\ndef half(amount: decimal):\n return amount / 2"
artifacts = build_contract_artifacts(module_name="con_math", source=contract_source)
Run the same source under the native V2 VM. The local harness compiles
deployments and executes constructors, exported functions and cross-contract
calls. Fractional Python inputs use decimal.Decimal.
from decimal import Decimal
from tempfile import TemporaryDirectory
from contracting.local import ContractingClient
with TemporaryDirectory() as home:
with ContractingClient(storage_home=home) as client:
client.submit(contract_source, name="con_math")
result = client.get_contract_proxy("con_math").half(amount=Decimal("0.25"))
assert result == Decimal("0.125")
submit accepts source text or a Python function containing the contract
definition. ContractingClient supports only xian_vm_v2, the execution
profile selected by fresh-chain validators. It rejects an explicit V1 profile
or a supplied V1 driver with ValueError.
Use a fresh V2 storage directory for local tests.
Local clients use the canonical compiler and do not accept a compiler=
override. Use compile_contract_source or build_contract_artifacts from
contracting.artifacts to compile offline; both delegate to the Rust compiler
core, so tools that only compile can call xian_compiler_core (package
xian-tech-compiler-core) directly. V1 compilation, IR validation and
stored-value encoding remain for migration and archival tooling; current code
does not execute V1 contracts (historical V1 execution uses the pinned older
release). Every contract call runs in the Rust VM; the Python package does not
execute contracts through CPython or expose a Python-bytecode compiler. See the compatibility guide for pinned
historical observations and their capture procedure.
Principles
- Contracts use Python syntax, but are not general Python. Execution rules are consensus-sensitive and intentionally narrower than the host language.
- Consensus parity comes first. Metering, storage encoding, import restrictions, and runtime helpers must stay version-aligned across all validators.
- The Xian VM is the execution target. Validators accept cleartext source and derive canonical Xian VM IR themselves before persisting deployed state.
- Compiler and harness stay distinct. SDKs and CLI deployment flows submit source. Offline artifacts are useful for diagnostics and CI, but are not the public deployment payload.
- Compilation is bounded. The Rust compiler admits at most 128 KiB source,
50,000 syntax nodes, syntax depth 64, 100,000 tokens total, 4,096 tokens on
one logical line, 1 MiB of canonical IR JSON, and 512 contract-handle
inference passes. Its whole-program analyses take work linear in the
program and stop at a counted (not timed) ceiling of 1,000,000 work units.
Every binding returns the same
xian.limit.*diagnostic. A deployment pays 15,000,000 raw chi plus 100 per submitted source byte before its source is compiled, so a source that fails to compile pays for its compilation too. - Stay scoped. Built-in helpers serve the execution model. They do not grow into a general convenience framework.
- No node orchestration here. Operator workflow, genesis distribution, and
container lifecycle belong in
xian-abci,xian-cli, andxian-stack. - Security-sensitive. Favor small, well-tested changes. If a fix changes execution semantics, add regression tests in the same change.
Key Directories
src/contracting/— compiler, artifacts, local harness, storage, and stdlib bridge.artifacts/— public source compiler, artifact builder, and validator.compilation/— parser, compiler, linter, and whitelist logic.compiler/— public compiler import surface.execution/— shared native host context and execution errors.local/— high-levelContractingClientfor local tests and tooling.storage/— drivers, ORM helpers, encoder, and LMDB-backed state.contracts/— package-local contract assets (e.g. the built-in submission contract).stdlib/— contract-side standard-library bridge.
packages/— independently released sibling packages:xian-accounts,xian-compiler-core,xian-runtime-types,xian-vm-core,xian-zk; plus the Rust-only cratesxian-numericandxian-fastpath-core(transaction admission rules) thatxian-vm-corelinks.scripts/— audit and fixture-generation tools used by VM/runtime work.tests/—unit/,integration/,security/,performance/coverage.examples/— notebook walk-throughs and a non-Jupyter validation script.docs/— architecture, backlog, current-state notes, and active design drafts.
What This Runtime Covers
- compilation and linting of contract source
- local harness execution, metering, and import restrictions
- storage drivers and encoding
- contract-side runtime helpers (
stdlibbridge) - native V2 local clients
- native zero-knowledge verifier building blocks
- Xian VM IR generation, validation, native execution and compatibility fixtures
Validation
Default CI runs the Python suite with the required Rust compiler extension:
uv sync --group dev
uv run ruff check .
uv run ruff format --check .
uv run pytest --cov=contracting --cov-report=term-missing --cov-report=xml
The default pytest config deselects the larger corpus marked
optional_native. The native/release path selects that corpus and installs
additional packages needed by checks such as the optional zk integrations.
Native / release CI path:
./scripts/validate-release.sh
validate-release.sh runs the default suite plus compiler-core, zk, and VM
checks, the WASM compiler package build, optional-native parity and fuzz
coverage, and the Rust-side package checks used by release CI. It is the gate
for tagging a release.
The published application corpus pins bounded token, nameservice, staking and DEX workflows over unchanged historical V1 sources against a pinned pre-VM Python capture. Current code no longer executes V1, so its observer runs only with the pinned older release; the current suite keeps the corpus's provenance checks. The compatibility guide also describes the separate language-level corpus and historical capture procedure.
The determinism campaign compares exact metered native observations across fresh-process perturbations and supported platforms. It includes the full reviewed surface corpus, seeded generated stateful programs, semantic oracles, rollback and reopen checks. Run a larger local campaign with:
uv run --no-sync python -m tests.determinism.campaign \
--output .artifacts/determinism-run --seed 20261103 --generated 256 --extended
If you change metering, tracing, storage encoding, or import restrictions,
treat the change as consensus-sensitive and run the relevant tests/security/
and tests/integration/ paths explicitly.
Related Docs
- AGENTS.md — repo-specific guidance for AI agents and contributors
- docs/README.md — index of internal design notes
- docs/ARCHITECTURE.md — major components and dependency direction
- docs/BACKLOG.md — open work and follow-ups
- docs/COMPILER_RELEASE.md — compiler package validation and publish order
- docs/SAFETY_INVARIANTS.md — invariants the runtime must preserve
- docs/COMPILE_TIME_EXTENDS.md — contract import / extends model
- docs/EXECUTION_BACKLOG.md — execution-engine follow-ups
- docs/SHIELDED_STATE_REDESIGN_V2.md — shielded-state model
- docs/ZK_PRIVACY_OPTIMIZATION_PLAN.md — zk privacy roadmap
License
src/contracting, published as xian-tech-contracting, derives from Lamden's
contracting and is licensed under the GNU General Public License, version 3
only (GPL-3.0-only). The repository as a whole is GPL-3.0-only as well; see
LICENSE. Copyright the Lamden authors and Xian Technology.
The packages under packages/ are Xian's own work and
are licensed MIT, each with its own LICENSE file: xian-runtime-types,
xian-accounts, xian-numeric, xian-compiler-core, xian-fastpath-core,
xian-zk and xian-vm-core. xian-vm-core is MIT AND OLDAP-2.8 because it
vendors LMDB under the OpenLDAP Public License. None of these packages depends
on xian-tech-contracting at runtime
(tests/unit/test_mit_packages_independent.py checks this), so the MIT SDKs
built on them, such as xian-py through xian-tech-runtime-types, stay MIT.
Metadata
Release files for xian-tech-contracting 1.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| xian_tech_contracting-1.1.4.tar.gz | 81.5 kB | With provenance | Details for xian_tech_contracting-1.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| xian_tech_contracting-1.1.4-py3-none-any.whl | Python 3 | none | any | Details for xian_tech_contracting-1.1.4-py3-none-any.whl |
Total release size: 170.5 kB
Release files / xian_tech_contracting-1.1.4.tar.gz
| Download URL | xian_tech_contracting-1.1.4.tar.gz |
|---|---|
| Size | 81.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6755c3523d275993163382a6be19dbb943140348ec15a1a2d7be20a22bf4fda8
|
|
BLAKE2b-256 checksum How to use checksums |
d7b3f1a585d99eac05f57d60177165b72b7f02f17031ac33de429d4174c42fad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logRelease files / xian_tech_contracting-1.1.4-py3-none-any.whl
| Download URL | xian_tech_contracting-1.1.4-py3-none-any.whl |
|---|---|
| Size | 88.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b06eb975d323638265f60051ee93c993501f1af1479e0301701596280e0955ae
|
|
BLAKE2b-256 checksum How to use checksums |
47efb37b018bb133debb972fd758e726a25ee1fce506c46179efe7bfd59e0337
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logSecurity for xian-tech-contracting 1.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for xian_tech_contracting-1.1.4.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.