Skip to content
Tutorials Center
My learning

Topics

Lesson 31 of 41 ยท Using Blockchains in Practice

Privacy and Zero-Knowledge Proofs

Why public blockchains are pseudonymous, not anonymous: chain analysis, mixers, hash commitments and a toy zero-knowledge proof you can run in Python.

Public blockchains are often called "anonymous", but that is wrong. Every transaction on Bitcoin or Ethereum is visible to the whole world, forever. What you get is pseudonymity: you act under an address instead of a name. As soon as one address is linked to a real person, their whole history can be linked to them too.

This lesson explains how that linking works, what mixers and privacy coins try to do about it, and then introduces one of the most interesting ideas in modern cryptography: a zero-knowledge proof, a way to convince someone that a statement is true without revealing why it is true. You will build a hash commitment and a tiny, working proof of knowledge in Python. The numbers are toy-sized so that you can read every step, so nothing here is safe to use for real secrets.

Pseudonymity is not anonymity

An address like 1A1zP1... does not contain your name, but the ledger around it tells a story: when funds arrived, from where, how much, and where they went next. Anyone can download the full ledger and analyze it. The weak points are usually at the edges of the system:

  • Exchanges. Most people buy coins on a platform that checks their identity. The withdrawal address is now tied to a name in the exchange's database.
  • Reuse. Using one address for everything makes all your activity trivially linkable.
  • Public statements. A donation address posted on a website or a social account links itself to that identity.
  • Network metadata. The IP address that first broadcasts a transaction can leak who sent it, if you are not careful.

Linking addresses is called chain analysis. Companies and researchers build graphs of the ledger and group addresses that probably belong to the same person.

flowchart LR
  A["Address A<br/>(known: exchange account)"] -->|"pays"| B["Address B"]
  B -->|"pays"| C["Address C"]
  B -->|"pays"| D["Address D<br/>(shop)"]
  C -->|"pays"| D
  A -.->|"inferred same owner"| C

Once one address is identified, links between addresses extend the identification to the others.

A classic heuristic: common input ownership

In Bitcoin, one transaction can spend several coins at once. To do that, the sender must sign for every input, which normally means one person controls all of the input addresses. So a rule of thumb emerges: addresses that appear together as inputs of one transaction probably belong to the same owner. Chain analysts apply this rule over and over and merge groups ("clusters").

Python Clustering addresses with common input ownership

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice that the outputs shop and cafe are not merged. Paying the same shop does not make two people the same person. The heuristic only merges inputs, and even that can be wrong when several people deliberately build one transaction together (which is exactly the idea behind mixing).

Mixers and privacy coins

A mixer (also called a tumbler or a CoinJoin) tries to break the links. In a CoinJoin, many users build one shared transaction. Each puts in a coin of the same size, and each receives a coin of that size at a fresh address. An observer sees ten equal inputs and ten equal outputs and cannot tell which output belongs to which input.

Python Why equal amounts hide the link

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The set of matching possibilities is called the anonymity set. The bigger it is, the better your privacy. That is why equal amounts matter: unique amounts make a transaction stand out.

Mixers have downsides. Services that hold your money for you ("custodial mixers") can steal it, and many authorities treat mixing as suspicious or restrict it. Some blockchains, such as Monero and Zcash, build privacy into the protocol itself using stealth addresses, ring signatures or zero-knowledge proofs. The trade-off is more complex code, larger transactions and in some places, delisting from exchanges.

Commitments: sealing a value

Before we reach zero-knowledge, you need one small building block: a commitment. A commitment lets you lock in a value now and reveal it later. It has two promises:

  • Hiding. The commitment reveals nothing about the value.
  • Binding. You cannot later claim a different value.

A hash with a random salt makes a simple commitment: commit = SHA-256(salt || value).

Python A hash commitment: commit now, reveal later

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Commitments appear all over blockchains. Auctions use them so that nobody can copy a bid. Some privacy systems store only a commitment to a coin's value on the chain, keeping the amount secret while still letting the network check the books. The next step is proving things about a hidden value.

The idea of a zero-knowledge proof

Imagine a cave shaped like a ring with a magic door in the middle that only opens with a secret word. You want to prove to a friend that you know the word without saying it. You walk in, your friend waits outside and shouts which side (left or right) you should come out of. If you know the word, you can always comply. If you do not, you only have a 50 percent chance each round. After 20 rounds, a bluffer succeeds with a chance of about one in a million, yet your friend learned nothing about the word.

A zero-knowledge proof needs three properties:

  1. Completeness. An honest prover who knows the secret always convinces the verifier.
  2. Soundness. A cheating prover who does not know the secret almost never convinces the verifier.
  3. Zero knowledge. The verifier learns nothing beyond the fact that the statement is true.
sequenceDiagram
  participant P as Prover (knows x)
  participant V as Verifier
  P->>V: commitment t (hides a random number)
  V->>P: random challenge c
  P->>V: response s (mixes x, the random number and c)
  V->>V: check the equation, accept or reject

The three-move shape of a classic proof of knowledge: commit, challenge, respond.

A toy proof you can run: Schnorr

The Schnorr protocol proves that you know a number x (a discrete logarithm) without revealing x. Everything happens in a small group of numbers modulo a prime p. Take p = 2039, the group order q = 1019 (note p = 2q + 1) and generator g = 4. The public value is y = g^x mod p. The secret x is the thing you know.

  1. The prover picks a random r and sends t = g^r mod p.
  2. The verifier sends a random challenge c.
  3. The prover answers with s = (r + c * x) mod q.
  4. The verifier checks that g^s mod p == t * y^c mod p.

Why does the check hold? Because g^s = g^(r + c*x) = g^r * (g^x)^c = t * y^c. And why is the proof zero-knowledge? Because r is random, s looks random on its own and tells nothing about x.

Python Schnorr proof of knowledge with tiny numbers

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The honest prover passes every round. The cheater, who used a wrong secret, fails (the chance of a lucky pass is about 1 in 1019 per round here, and with 256-bit groups it would be negligible). The verifier never saw x: only t, c and s.

Making it non-interactive: Fiat-Shamir

On a blockchain, nobody can wait for a live verifier. The Fiat-Shamir transform removes the interaction: the prover computes the challenge by hashing the commitment (and any message to be bound to the proof), so that no one can pick the challenge after seeing the response.

Python A non-interactive proof with Fiat-Shamir

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

This is the same trick behind many real signature schemes: a signature is a non-interactive proof that you know the private key, bound to a message. The proof cannot be reused for a different message, because the challenge depends on the message.

The numbers here are tiny on purpose. A prime of 11 bits can be broken in a fraction of a second by trying every x. Real systems use groups of 256 bits or more, vetted libraries and careful handling of randomness. Never write your own cryptography for real value.

Where zero-knowledge is used

Modern systems prove far more than "I know a discrete logarithm". With general-purpose proof systems (zk-SNARKs and zk-STARKs), you can prove that an entire program ran correctly and get a tiny proof that anyone can check quickly. Applications include:

  • Private payments. Prove that a transaction balances and the sender owns the coins without revealing amounts or participants (Zcash).
  • Rollups. Prove thousands of transactions were executed correctly off-chain, so the base chain only checks one short proof (Scaling: Layer 2, Rollups and Sharding).
  • Identity. Prove that you are over 18, or a resident of a country, without handing over your birth date or passport.

Zero-knowledge is not magic. Proving can be expensive, some systems need a trusted setup ceremony, and bugs in circuits are a real source of vulnerabilities. Privacy also comes with tension with regulation: transparency helps auditors, while secrecy protects users.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Why is a public blockchain like Bitcoin called pseudonymous rather than anonymous?

    Everything is public. Addresses are only labels, so once one label is tied to a person (for example via an exchange), the links around it expose the rest.
  2. 2. What does the common-input-ownership heuristic assume?

    Signing every input normally requires all the keys, so inputs are likely owned together. The assumption can fail when users build a joint transaction on purpose.
  3. 3. Why do CoinJoin transactions use equal amounts?

    Unique amounts let an observer match an input to an output. Equal amounts leave many possible matchings.
  4. 4. In a hash commitment, what is the purpose of the random salt?

    Without a salt, a small set of possible values (yes/no, a bid in whole dollars) can be tested by hashing each. A long random salt makes this infeasible, so the commitment stays hiding.
  5. 5. Which statement describes the soundness property of a zero-knowledge proof?

    Soundness protects the verifier against cheaters. Zero knowledge is the separate promise that nothing beyond the truth of the statement is revealed.

Summary

  • Public blockchains are pseudonymous: addresses are labels, and chain analysis links them using heuristics such as common input ownership.
  • Mixers and CoinJoins enlarge the anonymity set; privacy-focused chains build hiding into the protocol.
  • A salted hash commitment hides a value now and binds you to it later.
  • A zero-knowledge proof is complete, sound and reveals nothing but the truth of the statement. The Schnorr protocol is the classic example.
  • Fiat-Shamir turns an interactive proof into a non-interactive one by hashing the commitment into the challenge.
  • zk proofs power private payments, rollups and identity, but they are complex and need expert implementations.

Next: DeFi, DAOs and Governance, where smart contracts become markets and voting systems.