contracts

agreements that enforce themselves

  • 5: Steps, from write to settle
  • 1: STARK proof for every step, made on a party’s device
  • 8: Audited standard contracts, ready to use
  • 3 of 5: Key holders seal a ballot until it closes

The chain sees only the proof. Nobody sees who agreed to what.

how a contract works

  1. Write: a small, deterministic WebAssembly program, usually in Rust with the khensu-contract crate from khensu-core.
  2. Publish: sign it with ML-DSA-87 and publish it like a site. Its address is its hash, so everyone audits the same code.
  3. Open: the parties agree on terms in a private MLS group, each with a fresh key that is never linked to their account.
  4. Step: a party runs the next step on their phone or Mac. The khėnsu zkVM proves it ran correctly, and the update goes to the chain through the mixnet.
  5. Settle: payments come out as shielded notes; key releases, posts, credentials and group invitations go where the terms say.

contracts for any work

A contract can commission any work whose result can be checked.
The reward can be money, or something else entirely.

Accepted byExample
The requesterA logo, a translation or a field report, approved by the person who asked
A reviewer both sides choseA code review or an article, judged by an editor named in the terms
A test in the contractA bug proof, a solved puzzle or data that matches a schema
A node’s work receiptA year of archive storage for a site, or public renditions of a film (network work)
Another app on the networkA vote closes and the contract triggers the co-op’s booking app to order the roof (invoke)
A gateway’s transcript proofA call to a legacy internet API or webhook, with proof the answer came from that server (fetch)
A project’s validatorSpare node time for Einstein@Home’s gravitational-wave search, paid when the project validates each work unit (order)

Rewards: shielded notes, an anonymous credential, a reputation point, admission to a group, or nothing at all.

example: an anonymous ballot

A co-op votes on a proposal.
Each member casts exactly one ballot, and nobody, including the organiser, learns who voted or how.

use khensu_contract::prelude::*;

#[contract]
pub struct Ballot {
    roll: MemberRoot,          // members, each holding one blind-issued credential
    options: u8,
    tally: Vec<u32>,
    seen: NullifierSet,        // one ballot per member
    closes: Epoch,
}

#[contract]
impl Ballot {
    #[action]
    pub fn cast(&mut self, ctx: &Ctx, vote: Sealed<u8>, member: MembershipProof) -> Result<()> {
        ensure!(ctx.epoch() < self.closes, "closed");
        let nullifier = member.verify(&self.roll, ctx.contract_id())?;
        ensure!(self.seen.insert(nullifier), "already voted");
        ctx.hold(vote)                       // sealed to the 3-of-5 holders until close
    }

    #[action(timeout)]
    pub fn close(&mut self, ctx: &Ctx) -> Result<()> {
        ensure!(ctx.epoch() >= self.closes, "still open");
        for vote in ctx.open_held()? {       // opened inside the proof, never revealed
            ensure!(vote < self.options, "bad ballot");
            self.tally[vote as usize] += 1;
        }
        ctx.publish(Feed::terms(), &self.tally)?;
        ctx.close()
    }
}

Only the tally leaves the contract. Ranked choice, weighting and quorums are a few more lines.

standard contracts

Audited and ready to use, at contracts.khensu.nu:

ContractWhat it does
ballotAnonymous votes and polls
work-orderCommission work from people or nodes
escrowMilestones released by both sides or a chosen arbiter
pledgePays only if enough hidden pledges arrive by a deadline
splitPays collaborators their shares from every payment a work earns
ticketAnonymous, unlinkable tickets and memberships
bountyPays the first submission that passes the check
timelockOpens a file, key or message on a date, or when you stop checking in

build and test

cargo add khensu-contract
cargo build --target wasm32-unknown-unknown --release
khensu contract test ./target/wasm32-unknown-unknown/release/ballot.wasm   # runs every action and proves it locally
khensu contract publish ballot.wasm --name ballot.your-name.khensu.nu

khensu-devnet runs the chain, aggregators and beacon on one machine, so a full contract round trip takes seconds.

rules every contract keeps

Full specification: webË, section 14.