This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
# Build the main CLI (without prover)
cargo build --profile=test
# Build with prover feature (requires GPU/CUDA support)
cargo build --profile=test --features prover
# Install CLI locally
cargo install --profile=test --path . --locked
# Install CLI locally with prover feature. Do this and run `charms` rather than `cargo run`.
cargo install --profile=test --path . --locked --features prover
# Run tests
cargo test
# Run a single test
cargo test <test_name>
# Build an app to WASM
charms app buildCharms is a Rust framework for programmable assets on Bitcoin and Cardano using zero-knowledge proofs. Users create "spells" (transaction metadata) that define creation/transformation of "charms" (bundles of tokens, NFTs, and app state) attached to UTXOs.
The project is organized as a Cargo workspace with these crates:
-
charms (root) - Main CLI binary and REST API server. Entry point for spell proving, transaction building, and app management.
-
charms-data - Core data types:
UtxoId,Charms,Transaction,App,Data. Uses CBOR serialization via ciborium. -
charms-client - Client library for multi-chain transaction handling (Bitcoin/Cardano) and spell verification. Contains verification keys for all protocol versions. Depends on
pallas-*andcml-*crates for Cardano,bitcoincrate for Bitcoin. -
charms-sdk - Minimal SDK for app developers. Provides
main!macro and re-exportscharms_data. -
charms-app-runner - WASM execution environment using wasmi. Runs apps compiled to
wasm32-wasip1with WASI syscalls. -
charms-spell-checker (excluded from workspace) - RISC-V binary for SP1 zkVM that recursively validates spells. Has its own workspace declaration.
-
charms-proof-wrapper - SNARK wrapper for spell proofs using SP1.
-
charms-lib - Library (
cdylib+rlib) with optional WASM bindings for JavaScript integration viawasm-bindgen.
Spell: YAML/JSON structure defining inputs, outputs, apps, and charm transformations for a transaction. Located in src/spell.rs.
App: WebAssembly program implementing app_contract(app: &App, tx: &Transaction, x: &Data, w: &Data) -> bool. An App is identified by three fields: tag (char: 't' for token, 'n' for NFT), identity (32-byte hash), and vk (32-byte verification key, SHA256 of WASM binary). String format: tag/identity_hex/vk_hex.
Charms: BTreeMap<App, Data> — a bundle of app states attached to a UTXO.
Data: CBOR-based dynamic value wrapping ciborium::Value.
Proof Pipeline: Spells are validated via SP1 zkVM execution, then wrapped in Groth16 SNARKs. Current protocol version is V10.
Transaction Protocol:
- Bitcoin: Two-transaction protocol — a commit transaction (funds the spell output) followed by a spell transaction (spends commit and includes proof in witness data).
- Cardano: Single transaction — spell and proof are embedded in one Cardano transaction (Plutus data/redeemer). Requires a
--collateral-utxoargument.
Main commands in src/cli/:
server- REST API server (POST /spells/prove,GET /ready; default port 17784)spell check- Check spell correctness (--spell,--app-bins,--prev-txs,--mock)spell prove- Prove spell correctness (adds--change-address,--fee-rate,--chain <bitcoin|cardano>,--collateral-utxo)spell vk- Print protocol version and spell verification keyapp new <NAME>- Create new app from template (usescargo-generate)app build- Build app towasm32-wasip1app vk [PATH]- Show verification key (SHA256 of WASM binary)tx show-spell- Extract and display spell from a transaction (--chain,--tx,--json,--mock)wallet list- List UTXOs with charms (callsbitcoin-cli listunspent)completions <SHELL>- Generate shell completion scripts
The prover mode is controlled by feature flags and environment variables:
--features proverenables real proving (CPU/CUDA/Network)- Without
proverfeature, uses mock prover APP_SP1_PROVER- Selects prover type for app proving (cuda,cpu,network)SPELL_SP1_PROVER- Selects prover type for spell proving (app= same as app prover,network)SP1_GPU_SERVICE_URL- GPU service URL (default:http://localhost:3000/twirp/)CHARMS_PROVE_API_URL- Override remote proving API URLCHARMS_FEE_SETTINGS- Path to YAML fee configuration fileREDIS_URL- Redis-based proof caching/deduplication (prover feature only)MOCK=1or--mockflag - Mock proving mode (skips proof generation)
Tests use property-based testing with proptest. Mock mode (--mock flag or MOCK=1 env var) skips expensive proof generation for faster testing.
Uses Rust 1.91 (Edition 2024). See rust-toolchain.toml.