Skip to content

Prove you own a Cardano account

View Markdown

Picture a wallet hack in which attackers obtain users’ address-level signing keys and drain the funds. An operator such as an exchange or wallet provider wants to refund the victims. Now it has a hard problem. The attacker can show up and claim too, and a signature from the leaked keys proves nothing. The genuine owner still has their 24-word recovery phrase, but handing that to anyone would be a disaster. And a refund submitted on-chain can be copied from the mempool and redirected.

This page explains why zero knowledge is the tool that resolves this, and what ZeroJ’s largest circuit proves.

Account recovery · step 1 / 4
Operatorexchange or wallet
hacked address pkhPUBLIC0xe661…265c
refundAmountPUBLIC2 ADA

Knows which accounts were hit and what they're owed. It doesn't choose who gets paid.

CardanoPlutus V3
Voucher UTxO · datum
pkhPUBLIC0xe661…265c
refundAmountPUBLIC2 ADA
OwnershipProofValidatorproof verifies over pkh + recipientan output pays the recipient ≥ 2 ADApkh comes from this voucher's datumno proof, and a signature isn't acceptedpayee swapped: the proof failspayee kept but paid less: the payout check fails
voucher spent: it paid out oncea second claim finds no vouchervoucher still locked for the ownerrelayed unchanged: the owner still gets 2 ADA
Owner's machineKey thiefCopier
Who's claiming?
root keySECRETHIDDENfrom the recovery phraseunknown████████
1852' · 1815' · 0'hardened, one-wayone-way wall: can't climb
account keySECRETLEAKEDHIDDENm/1852'/1815'/0'worked out from the leakunknown████████
0 · 0soft, reversible with the xpubreversed with the xpub ↑
address keySECRETLEAKEDHIDDENm/1852'/1815'/0'/0/0leaked in the hackunknown████████
Blake2b-224
pkhPUBLIC0xe661…265c
recipientPUBLIC0x827f…160e
recipient, swappedPUBLIC0xc9d8…f57e
πGroth16 proof2 public inputs
πowner's proofcopied from the mempool
can sign with the leaked keys, can't prove: the root key is unknown

If the recovery phrase had leaked too, nothing could tell thief and owner apart.

1. Vouchers

The operator locks one refund voucher for each affected account. Its datum holds the hacked address's payment key hash and the refund amount, 2 ADA in the demo. The operator doesn't choose who gets paid. Pick who's claiming to compare the owner with a thief and a copier.

2. Prove

The owner enters the recovery phrase at a hidden prompt and picks a recipient. The prover replays the whole CIP-1852 derivation from the root key inside the proof and binds the recipient. The seed stays in memory and is never sent anywhere.

The thief has a leaked address key and the account xpub, so the soft steps run backwards to the account key, and they can sign with any key in the account. The root key sits above hardened steps, so they can't build the proof.

The copier proves nothing. They watch the mempool, lift the owner's proof from a pending claim and put their own address in as the payee.

3. Verify

Anyone can check the proof off-chain in under a second. On-chain, the claim spends the voucher. The validator verifies the proof over pkh and recipient, taking pkh from the voucher's datum, and requires an output that pays the recipient at least the refund.

A signature from a leaked key proves nothing here, and the validator doesn't accept one. Without a proof the voucher stays locked.

The recipient is bound into the proof, so with a new payee it no longer verifies. Keeping the owner as payee but paying less than 2 ADA fails the payout check.

4. One claim

A UTxO can only be spent once, so each voucher pays out once. Anyone, such as a fee sponsor, may submit the claim, and the funds still go to the bound recipient.

The voucher is still there for the real owner to claim.

Submitting the owner's claim unchanged is allowed, and the refund still goes to the owner.

SECRET never leaves the owner's machinePUBLIC visible on-chainHash values are illustrative.

Cardano wallets derive keys along the CIP-1852 path m / 1852' / 1815' / account' / role / index. The first three steps are hardened, the last two are soft, and the two kinds behave very differently:

  • Soft derivation can be run backwards. A child private key is the parent key plus an offset anyone can compute from the parent’s extended public key (xpub). One leaked address key plus the account xpub, which some wallets keep on their servers, gives up the account private key, and with it every address in the account.
  • So everything from the address up to the account is potentially compromised. A signature under any of those keys can be produced by the attacker too.
  • Hardened derivation is a one-way wall. It feeds the parent private key into the derivation, so the attack can’t climb from the account to the root key. Only the real owner has that.

The one claim an attacker can’t fake is therefore “I know the root key this address descends from”. You can’t reveal the root key. And a verifier can’t check the root-to-address link from public data, because the hardened steps need the private key. That combination is exactly what a zero-knowledge proof handles.

The owner proves “I know a wallet root key that derives, along the real CIP-1852 path, to this address’s payment key hash, and I authorise a payout to this recipient”. Only the key hash and the recipient are revealed.

The circuit takes the root extended private key as a secret witness and replays the whole derivation inside the proof. That means three hardened and two soft BIP32-Ed25519 steps (HMAC-SHA512 plus Ed25519 arithmetic emulated in the BLS12-381 field), the leaf public key and the Blake2b-224 key hash. It then checks that the result equals the public payment key hash.

InputVisibilityWhy
rootKL, rootKR, rootChainCodeSecretThe root extended private key: the wallet’s master secret
account, role, indexSecretThe derivation path is private from chain observers; pkh already pins the address
recipientBytesSecret witnessConstrained to pack exactly to the public recipient
pkhPublicThe address’s payment key hash, already public on-chain
recipientPublicThe payout’s payment key hash, bound so a copied proof can’t be redirected

“Private” here means private from people watching the chain. Anyone who holds the account’s xpub, such as a wallet service or a watch-only wallet, can derive the account’s addresses, find the one whose key hash is pkh, and so learn its role and index.

The proof also publicly links the compromised address to the recipient. Use a fresh recipient address that isn’t tied to your other wallets.

  1. Vouchers. The operator locks a refund voucher UTxO for each affected account. Its datum holds pkh, refundAmount, the funder’s key hash funderPkh and a fee allowance maxFee.
  2. Prove. The owner runs the desktop app or CLI, enters the recovery phrase at a hidden prompt and chooses a recipient address. The seed is used in memory only. It’s never written to disk or sent anywhere.
  3. Verify. Anyone can check the proof off-chain in under a second. On-chain, a claim transaction spends the voucher.
  4. One claim. A UTxO can only be spent once, so each voucher pays out once. Anyone, such as a fee sponsor, may submit the claim. The refund still goes to the bound recipient, and the rest of the voucher, less at most maxFee, goes back to the funder.

This is the demo’s OwnershipProof, unchanged apart from imports and comments:

OwnershipProof.java
import org.zeroj.circuit.annotation.*;
import org.zeroj.circuit.lib.zk.ZkCip1852;
@ZKCircuit(name = "account-ownership-proof", version = 4)
public class OwnershipProof {
@Prove
void prove(ZkContext zk,
@Secret @FixedSize(32) ZkBytes rootKL,
@Secret @FixedSize(32) ZkBytes rootKR,
@Secret @FixedSize(32) ZkBytes rootChainCode,
@Secret @FixedSize(4) ZkBytes account,
@Secret @FixedSize(4) ZkBytes role,
@Secret @FixedSize(4) ZkBytes index,
@Secret @FixedSize(28) ZkBytes recipientBytes,
@Public ZkField pkh,
@Public ZkField recipient) {
// Root key + full CIP-1852 path -> 28-byte payment key hash, pinned to the public pkh
ZkBytes derived = ZkCip1852.paymentKeyHash(zk, rootKL, rootKR, rootChainCode, account, role, index);
pack(zk, derived).assertEqual(pkh);
// Bind the payout: the proof commits to the recipient's packed key hash
pack(zk, recipientBytes).assertEqual(recipient);
}
// Big-endian packing of a 28-byte hash into one field element (Horner's rule)
private static ZkField pack(ZkContext zk, ZkBytes bytes) {
ZkField acc = bytes.get(0).asField();
for (int i = 1; i < bytes.size(); i++) {
acc = acc.mul(zk.constant(256L)).add(bytes.get(i).asField());
}
return acc;
}
}

The file is short, but the circuit behind it is large. ZkCip1852.paymentKeyHash composes ZeroJ’s in-circuit Blake2b, SHA-512, HMAC-SHA512, Ed25519 and BIP32 gadgets. The composed derivation is validated byte-for-byte against Cardano Client Lib’s HD-wallet derivation. Packing each 28-byte hash into one field element keeps the proof at two public inputs, which is what makes the on-chain check affordable.

MetricMeasured
Circuit sizeAbout 19 million constraints (19,075,097 in the measured runs)
Local dev setupAbout 6 min on a 12-core, 128 GB machine; about 9.6 GB key bundle on disk
ProveAbout 1.5 min on that machine; about 2.6 min on an ordinary 16 GB machine
Verify off-chainUnder 1 s
Verify on-chainAbout 2.3×10⁹ CPU steps, under the 10×10⁹ per-transaction limit

These figures come from the demo’s CLI documentation and ZeroJ’s prover-memory work, and they depend on hardware. Proving a circuit this size in commodity memory relies on the memory-mapped proving key and the streaming setup; see Performance.

The demo’s OwnershipProofValidator is a JuLC spending validator parameterized with the verification key. On a claim it checks all of the following:

  1. The proof verifies over [pkh, recipient], where pkh comes from the voucher’s datum.
  2. It’s the right voucher. The datum’s pkh equals the proof’s pkh.
  3. The voucher pays exactly what it owes. Only outputs whose inline datum is exactly the spent voucher’s TxOutRef count as its payments. Tagged outputs to recipient must sum to at least refundAmount, and tagged outputs to the funder to at least the remainder, voucher − refundAmount − maxFee. The voucher must hold only ADA.

Why the tags? An earlier version only checked that some output paid the recipient at least refundAmount. The demo locks 10 ADA and refunds 2 ADA, so anyone who saw a pending claim could resubmit its redeemer, pay the recipient 2 ADA and keep the rest (less fees). One output could also satisfy two vouchers in one transaction. A tag is unique to one voucher, so neither works now.

Whoever submits the claim can still keep maxFee minus the actual fee (the demo uses a 2 ADA maxFee), so a funder should set maxFee close to the expected fee. In the demo the funder is the admin account whose mnemonic you give the CLI or app (AOR_ADMIN_MNEMONIC or a hidden prompt): a low-value funding wallet, auto-funded on a devnet. The tag guarantee holds only between validators that enforce tags, so don’t spend a voucher in the same transaction as a script that counts any paying output.

This is a good example of “a valid proof is not authorization”. The pairing check alone would let anyone with a copied proof spend the voucher to any address. The recipient and amount checks bind the proof to the transaction. See Application security.

  • The whole argument assumes the root seed didn’t leak. If the attacker has the recovery phrase, owner and attacker are cryptographically identical, and no scheme can tell them apart.
  • Trusted setup is critical here. Whoever knows the setup randomness can forge ownership proofs. A locally generated key bundle is single-party and for testing only. A refund program needs a multi-party phase-2 ceremony (run externally with snarkjs and imported); see the ceremony guide.
  • Confirm the recipient. A production refund program should also confirm the payout address through its own authenticated channel.
  • Use a fresh recipient. The proof links the compromised address to the recipient on-chain.
  • The path is hidden only from observers. An xpub holder for the account can find which role and index the proven address has.
  • Protect the seed on the proving machine. The tools read it at a hidden prompt and keep it in memory only, but the machine itself must be trusted.
  • Review status. The derivation gadgets are validated against an independent implementation but haven’t been externally audited.

The demo lives in account-ownership. It doesn’t use demo.sh. Instead it ships a desktop app and a CLI (installers and a Java zip on the repo’s releases page). From source:

Terminal window
cd account-ownership
./gradlew :ui:run

The CLI flow is setup (a local, development-only key bundle, which needs --i-understand-insecure), then prove --recipient <bech32-address>, then verify, or verify --onchain against a local Yaci DevKit. Allow about 10 GB of free disk and use a machine with at least 16 GB of RAM. Test with the public BIP-39 test mnemonic or a throwaway wallet, never a real recovery phrase.