Noir-CKB: the private tally is live on CKB testnet, try it yourself

GM,
This is a new chapter of noir-ckb, so a quick catch-up first. In my direction check (Direction check: should noir-ckb generate CKB Type Scripts from Noir circuits?) I asked whether noir-ckb should generate CKB Type Scripts from Noir circuits. In the follow-up (Noir-CKB update: what I decided after the direction check, what you can try today, and where this is going) I shared what I decided, and since then I’ve posted updates there as the private tally took shape and its setup ceremony ran to the end.

The private tally is now deployed on testnet, and anyone can create their own. A three-minute recording of the full run:

What the private tally is

A CKB Cell that holds a hidden number. Only the holder of a secret key can add to it, and every addition is authorized by a zero-knowledge proof made on their own computer.

- The Cell stores only a commitment: a fingerprint of the number, made with fresh randomness each time, so it reveals nothing about the value.

- You can add any amount, including 0. A “cover update” looks exactly like a real one, so even “did anything change?” stays private.

- There is no signature lock on the tally. The proof is the only authority.

How it works: the proof is bound to one exact transition

A valid proof on its own is not enough. If the Type Script accepted any valid proof, someone could copy one from the mempool and use it on a different Cell. So the Type Script doesn’t trust the proof’s public values. It rebuilds them from the actual transaction:

- the network,

- the exact Cell being consumed,

- the old and the new commitment,

- the lock and capacity of the new Cell,

and it hashes all of that into the proof’s public input. A proof is therefore valid for exactly one transition of exactly one Cell. Used anywhere else, it fails.

Before anything went on testnet, this was tested in CKB-VM with 49 attack cases (all rejected as expected): replaying a proof on another Cell or another network, swapping commitments, wrong or altered verification keys, malformed witnesses and more. 4 mutation tests then removed one safety check at a time to confirm the tests notice when it is missing.

Why there was a ceremony

Groth16 needs a proving key made with secret randomness, and whoever kept that randomness could forge proofs. Because the proof is the only authority here, a key made by me alone would have meant trusting me completely.

So I ran a public phase 2 setup ceremony. Four people contributed, every key was verified, and the result was sealed with the hash of CKB mainnet block 20,870,000. Nobody can forge proofs as long as at least one contributor threw their randomness away. Thank you, truthixify, alienate, and Cecilia. The transcript is public and can be re-checked with one command: [ceremony folder](noir-ckb-verifier/ceremony/private-tally-v2 at main · wamimi/noir-ckb-verifier · GitHub).

The deployed verification key is that ceremony’s key, and the join tool checks this on your own machine before you use it.

What it looks like on testnet

I created a tally, added 7, then added 0.

One of these updates added 7, the other added nothing. On chain they have the same size and shape: one 33-byte commitment replaced by another, plus a proof. The ~117 million cycles are the Groth16 verification running in CKB-VM. The value 7 exists only in my private folder.

Step Transaction
Deploy (Type Script, ceremony verification key, guard lock) 0x39ef90b8…47b1f9
Create at 0 0x58d64623…6eca67
Add a hidden amount (7) 0xa93b9ed5…1c4a73
Cover update (0) 0xbc062ecc…66046c

A second account then joined the same deployment with its own key and added a hidden amount, the same way you would.

What it does not hide

Anyone can see that a tally exists, when and how often it was updated, and which account paid the fee, and one tally’s updates are linkable to each other. What stays private is the value and every amount added.

Try it

If you’re a developer, you can create your own hidden tally on this deployment and watch it happen on testnet. It costs about 262 testnet CKB (free from the faucet), there is nothing to deploy, and every proof is made on your machine.

After installing git, Python, Node.js and rustup, it is two commands from inside the cloned repository:

```bash

python3 -B scripts/try-private-tally.py install

python3 -B scripts/try-private-tally.py run

```

`install` lists everything it will set up and asks once. `run` rebuilds the proving setup from the ceremony key, checks the deployment, makes a testnet-only account, waits for your faucet payment, then creates your tally and lets you add hidden amounts. It shows every transaction and asks before signing and sending it; your password only ever goes to `ckb-cli`.

Guide: noir-ckb-verifier/docs/try-the-private-tally.md at main · wamimi/noir-ckb-verifier · GitHub

Supported: macOS on Apple silicon and Linux (x86_64, ARM64). The first run takes about 20–30 minutes, most of it downloading and compiling.

What I’d love to hear

1. Did it work on your machine? Where did you get stuck?

2. What would you build with this, and what would you want a proof like this bound to?

The next step for noir-ckb is turning these examples into a toolkit you can install and use for your own Noir circuits, with the CKB binding generated for you. Your answers will shape it.

7 Likes

GM xiaomao, congrats on getting this live, and on running a real ceremony instead of asking us to trust one key. Rebuilding the public inputs from the transaction itself is a neat answer to replay.

On your question 2: I’ve been thinking about on-chain voting on CKB, where encrypted tallies have to stay hidden until disclosure. A proof bound to one ballot cell and one tally transition is the kind of thing that design space needs.

Two loose thoughts, in case they’re useful:

  • Fee payer: you list it as a remaining leak. Since the tally has no signature lock and the proof pins the new Cell’s lock and capacity, a third party could in principle relay the transaction without being able to alter it. CKB Service Runner, a side app for full nodes with a sandboxed service runtime on testnet, is one kind of place where something like that could live.
  • Ceremonies: independent full-node operators with a stake could be a natural pool of contributors for future phase 2 ceremonies.

Just ideas for now. Looking forward to seeing where the toolkit goes.

3 Likes

Thanks for reading it this closely, and for the ideas.

Voting is actually something I’ve spent a lot of time on. Earlier this year I built a ZK voting system for the Buidl Guidl challenge, and I wrote up everything that broke along the way: Anonymous Blockchain Voting is Impossible (I Was Wrong)

The main thing I took from that was that the proof on its own doesn’t give you private voting. You need a commitment tree so people can prove they’re registered without saying which registration is theirs, a nullifier per election so nobody votes twice and you can’t follow the same voter across elections, and something like a paymaster, because the moment the voter’s own account pays the fee, everything you hid with the proof is linked back to them. So the tally today only covers one piece of that. It keeps a value hidden and binds each update to one exact Cell transition, but it doesn’t do the membership or the unlinking yet.

Your version is also a bit different from what I built. In mine, the votes themselves were public, and only the voter was hidden. You want the tally to stay hidden until a disclosure step, which is a harder problem. How are you thinking about that part: threshold decryption, commit-and-reveal, something else?

On the fee payer, yes, that’s how I read it too. The proof covers the consumed Cell, the old and new commitments, and the new Cell’s lock and capacity, but not the fee inputs. So a relayer should be able to add its own CKB to pay without being able to change anything about the tally. Basically the CKB version of the paymaster problem. I want to add a test for exactly that before I claim it publicly, one where a different account pays and one where someone tries to change the tally output. I’ll also look at Service Runner as a place where a relayer like that could live.

The part I think will be hardest on CKB is the shared state. A commitment tree and a nullifier set mean lots of people trying to update the same Cells, and I haven’t seen a good answer for that yet. Would love to hear if you’ve thought about it for voting.

And the node operators idea for ceremonies is a really good one. Contributors with something at stake would be much stronger than whoever happened to see my post. I’ll keep it in mind for the next one.

1 Like

Hi xiaomao,

Thanks for the thoughtful reply, and for the write-up on what broke in your Buidl Guidl system. Your three ingredients (commitment tree, per-election nullifier, paymaster) are exactly the list I keep landing on too.

Some context, so you know where I stand. For about a year and a half I have been working on VoteSecure, a private voting app on CKB (site: votesecure.net, code: GitHub - psawyerberlin/votesecure: VoteSecure is a decentralized application (dApp) for running transparent, tamper evident, and privacy preserving elections and polls. The application is open source and designed so results can be independently audited without trusting a central authority. · GitHub). To be upfront: the prototype in the repo follows an old v1 design, and its script still accepts every transaction. The current spec (v2.3) is a work in progress with several open problems still to solve.

Your question: how the tally stays hidden until disclosure. My first answer was drand. Each event had one tally key, timelock-encrypted to a future drand round, so nobody could read the ballots before release. I dropped it for two reasons. Once the round passed, anyone could decrypt every individual ballot. And whoever generated the key could peek before release.

The current idea is threshold decryption plus homomorphic tallying:

  • Each ballot is one exponential-ElGamal ciphertext per option, under a key generated jointly by t-of-n trustees. Nobody ever holds the whole key. Staked operators from CKB Service Runner (GitHub - ckb-service-runner/ckb-service-runner: Side application for CKB full nodes: dashboard, node ranking, and a sandboxed service runtime · GitHub) are my main candidate pool for the trustees.
  • Each ballot carries a validity proof (each value is 0 or 1, and the sum is allowed), bound to the voter’s pseudonym so it cannot be copied.
  • After the deadline, a SEAL transaction adds up the ciphertexts on chain. At release, the trustees publish partial decryptions with DLEQ proofs, and the script accepts only the tally those proofs allow. No individual ballot is ever decrypted.
  • No live option totals: two decryptions of a running sum would reveal the votes cast in between.

The trade-off: I replaced trust in a time source with trust in the trustees. If t of them collude, they can read ballots. If too few show up, there is no result.

Shared state. My answer so far is unglamorous: a relay serializes and batches ballots into one Ballot Box cell per shard (sharded by pseudonym prefix), and a voter with funds can bypass a censoring relay. For nullifiers, the box would keep an SMT root, with the non-membership proof in the witness. One cell per ballot plus a final dedup proof avoids contention, but needs a heavy final proof. Not solved at scale.

Where our work overlaps

noir-ckb already has pieces VoteSecure is missing:

  • A working Groth16 verifier on CKB-VM with a measured cost (~117M cycles). Whether my own proof checks fit on chain is still unmeasured.
  • Public inputs rebuilt from the transaction, plus 49 attack cases and mutation tests. That is the test culture a voting script needs.
  • Anonymous membership + nullifier is my biggest privacy gap. With per-voter keys, whoever issues the keys can tell who voted. A Noir membership/nullifier circuit is the leading candidate fix.

In the other direction, some of my work may be useful to you:

  • CKB Service Runner, which I am building partly for VoteSecure: a possible home for a relayer, and a pool of staked operators for future ceremonies.
  • A relay/paymaster design: fee sponsorship from an escrow cell with capacity conservation, receipts, and a self-pay fallback. I’d be glad to compare it with your relayer test once you have it.

The v2.3 spec is here if you want to dig in: votesecure/docs/architecture.md at main · psawyerberlin/votesecure · GitHub

My view: within ten years, public blockchains will be the most trusted settlement layer in finance. People will then ask why their elections are less verifiable than their money, and I think CKB is the right chain to host the answer. For a voting app to earn that trust and get adopted, it has to be the work of many people, not of a single developer. So I would be very happy to keep exchanging ideas on how to make voting on CKB transparent, secure and private.

Cheers from Berlin,
Patrick (psawyerberlin)

3 Likes

Hi Patrick,

I didn’t know VoteSecure existed, and it’s really cool to find someone who’s been working on private voting on CKB this long. I’m going to read the v2.3 spec properly this week.

Dropping drand for threshold decryption is the right call, I think. I hadn’t thought about the problem where the person generating the key could just look before the release round, and once you see it, you can’t really unsee it. Same with the live totals. Decrypting a running sum twice and getting the votes in between is the kind of leak I would have walked straight into.

I did notice something about the batching that might bite you though. One Groth16 verification costs about 117M cycles in my tests, and a CKB block can only use 3.5B cycles in total, so you can fit fewer than 30 proof verifications in a block. If the relay puts lots of ballots into one Ballot Box transaction and each ballot has its own proof, you’ll hit that limit pretty quickly. On the other hand, Groth16 verification doesn’t really get more expensive as the circuit gets bigger, so a membership proof over a deep Merkle tree would cost about the same to verify as my tally proof does.

I was also wondering where you want the 0-or-1 validity proofs to live. If they’re inside a SNARK, the circuit has to do elliptic curve operations over the ElGamal ciphertexts, and that gets expensive fast. Are you planning to do them in Noir, or as sigma proofs that the script checks directly? I feel like that one choice decides a lot of your cycle budget.

The anonymous membership and nullifier part is where I think we could actually build something together. A Noir circuit that proves you’re in the voter tree and gives a nullifier per election, taken through noir-ckb so the proof is bound to the Ballot Box transition, with real cycle numbers. It’s small enough to actually finish, it would close your biggest privacy gap, and it would be the first time noir-ckb gets used for something that isn’t my own example.

I’m also writing the relayer test this week, where a different account pays the fee and any change to the tally gets rejected. Once it works I’d love to compare it with your escrow design.

2 Likes

gm!

I’m one of the ceremony contributors, and I came back to this as a reader working through the step-by-step guide on Ubuntu 24.04. Taking your first question first, because I did get stuck.

The two-command path works. The step-by-step guide does not, if you have no nargo of your own:

$ python3 -B scripts/start-counter.py doctor
OK: Nargo beta.18 and compiler pin
Prerequisite checks passed.

$ python3 -B scripts/setup-private-tally.py --out target/my-tally-setup \
    --backend ../Noir-Groth16 --ptau target/ppot_0080_12.ptau \
    --ceremony ceremony/private-tally-v2
RuntimeError: Nargo 1.0.0-beta.18 (99bb8b5c) required

The doctor probes nargo through tool_environment(), which puts the pinned tools first on PATH. setup-private-tally.py defaults --nargo to the bare string, so it gets whatever PATH already had. try-private-tally.py goes through tool_environment() as well, which is why the two commands in your post are fine and only the guide’s longer path breaks.

What made it slow to find: the troubleshooting table sends an R1CS mismatch to “run the doctor again”, and the doctor passes. So the suggested remedy can’t diagnose it. With no nargo at all it’s a bare FileNotFoundError.

Fix on my side, in case someone else lands here:

export PATH="$PWD/target/counter-tools/linux-x86_64:$PATH"

Then your second question, what I’d build with it.

A commitment scheme has two halves, committing and opening, and the Cell has the committing half. Right now the only way to open it is to hand over (value, r, key), which gives away the exact number. So: a circuit that proves a bound on the hidden value instead, checked against the commitment that is already on chain.

One circuit covers a range, at-least, at-most and exact-value. It reuses the private-tally-v2 commitment unchanged, so a proof opens exactly what the deployed Type Script stores, and at 1,749 constraints against v2’s 3,338 it still fits under the power-12 ceiling, so ppot_0080_12.ptau is reusable. It authorizes nothing, to be clear: there is no transaction binding, so a proof is a reusable bearer attestation and never permission to update a Cell.

If that PATH default is worth fixing in the scripts rather than in my shell, say so and I will send it separately.

2 Likes

GM xiaomao, Cecilia,

I ran the private tally today on Ubuntu 24.04 under WSL2 (x86_64), repo at commit b481cfc.

Your question 1: did it work? Yes, first time. Install took under 3 minutes, the first run about 17 (10 of those were me typing passwords). One creation and five hidden additions, all committed on testnet:

The amounts were 112, 1112, 10112, the maximum 4294967295, and then 0 as a cover update. The final total, 4294978631, was correct and went past 2^32, so the 32-bit limit is per addition, as the guide says. The cover update left the value unchanged, and on chain it has the same size and shape as the others. Typing 4294967296 was refused at the prompt, with nothing sent.

Local test suite on x86_64: start-counter.py tally-local passed all 10 stages, including the 49-case CKB-VM matrix and the 4 mutation tests. The doctor still notes that the matrix has not run on x86_64, so this may be the first run there. The unit tests pass too (74/74 with the pinned nargo).

The guide’s longer path: Cecilia, I can confirm your report on x86_64, in the “no nargo at all” form: the doctor passes, then setup-private-tally.py stops with FileNotFoundError: 'nargo'. Your PATH workaround fixes it. One more thing to know: the failed run leaves target/my-tally-setup/ behind, so rerunning the same command fails with FileExistsError until you delete that folder. After that, the setup passed, and its verification key hash matched the ceremony’s. I’ll send xiaomao the details separately.

On your voting points, xiaomao: the 0-or-1 validity proofs are planned as sigma proofs (disjunctive Chaum-Pedersen) checked directly by the script, not inside a SNARK. So the Noir circuit would only carry membership and the nullifier, at a fixed ~117M cycles, and the ElGamal curve can stay secp256k1. Your cycle point is taken: under 30 Groth16 checks per block caps the relay batch size, and I’ll put that into the spec.

And yes to building the membership + nullifier circuit together. As a first step, within the next two weeks I’ll write down VoteSecure’s requirements for that circuit: what the proof must show, exactly what it has to be bound to on a Ballot Box transition, and what it must leave open, such as the fee inputs, so that any relayer can pay without being able to change the ballot. That gives you a fixed target to build against in noir-ckb. The requirements will live at `docs/specs/ballot-membership-binding.md’ in the VoteSecure repo, with a GitHub issue for comments.

PSBerlin

3 Likes