contracts
agreements that enforce themselves
- 5: Steps, from write to settle55
- 1: STARK proof for every step, made on a party’s device11
- 8: Audited standard contracts, ready to use88
- 3 of 5: Key holders seal a ballot until it closes33of 5
The chain sees only the proof. Nobody sees who agreed to what.
how a contract works
- Write: a small, deterministic WebAssembly program, usually in Rust with the
khensu-contractcrate fromkhensu-core. - Publish: sign it with ML-DSA-87 and publish it like a site. Its address is its hash, so everyone audits the same code.
- Open: the parties agree on terms in a private MLS group, each with a fresh key that is never linked to their account.
- 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.
- 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 by | Example |
|---|---|
| The requester | A logo, a translation or a field report, approved by the person who asked |
| A reviewer both sides chose | A code review or an article, judged by an editor named in the terms |
| A test in the contract | A bug proof, a solved puzzle or data that matches a schema |
| A node’s work receipt | A year of archive storage for a site, or public renditions of a film (network work) |
| Another app on the network | A vote closes and the contract triggers the co-op’s booking app to order the roof (invoke) |
| A gateway’s transcript proof | A call to a legacy internet API or webhook, with proof the answer came from that server (fetch) |
| A project’s validator | Spare 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:
| Contract | What it does |
|---|---|
ballot | Anonymous votes and polls |
work-order | Commission work from people or nodes |
escrow | Milestones released by both sides or a chosen arbiter |
pledge | Pays only if enough hidden pledges arrive by a deadline |
split | Pays collaborators their shares from every payment a work earns |
ticket | Anonymous, unlinkable tickets and memberships |
bounty | Pays the first submission that passes the check |
timelock | Opens 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.nukhensu-devnet runs the chain, aggregators and beacon on one machine, so a full contract round trip takes seconds.
rules every contract keeps
- Code is public, signed and addressed by its hash; wallets show its author and audit labels before anyone signs.
- Inputs and state stay private to the parties. A contract that needs public state says so and uses a feed or forum.
- The only outside input is the epoch, so deadlines are deterministic. If a party disappears, the deadline lets anyone else time it out.
- State expires with the shielded pool’s eras. Nothing sits on the chain forever.
Full specification: webË, section 14.