Zero-Knowledge Proofs: Prove Your Bank Balance Without Revealing It

February 20, 2025

What is a ZK Proof?

A ZK Proof is a mathematical proof that a certain statement is true, without revealing any additional information.

How zk-SNARKs Work

Let's break down zk-SNARKs using an analogy. The Where's Waldo Analogy (Zero-Knowledge Proofs)

Imagine you have a Where's Waldo book, and you want to prove to your friend that you found Waldo without revealing where he is. How do you do that?

  • Take a large piece of cardboard and cut a small hole in it.
  • Place the cardboard over the book so that only Waldo is visible.
  • Show your friend that Waldo is inside the hole but without revealing anything else about the page.

Where's Waldo

This proves to your friend that you know where Waldo is without giving them any clue about his actual location.

This is the core idea of Zero-Knowledge Proofs

Scenario applying for a mortgage

You want to buy a house that costs €500.000 EUR, and you need to prove that you have at least €100.000 EUR in your bank account (Bank A) so the mortgage provider (Bank B) can give you a loan.

The Traditional Way

There is no way for Bank B to know the actual balance of your account without you revealing it.

Possible traditional solutions:

  • You screenshot or export to PDF, your bank account statements and send it to the mortgage provider most of the time even through a third party like a mortgage advisor.

Disadvantages:

  • You need to trust the mortgage advisor not to leak your information.
  • You need to trust the mortgage provider (Bank B) not to leak your information.
  • You need to trust the mortgage provider not to use your information for other purposes.
  • You could fraud the bank statements to prove that you have more money than you actually do.

Traditional way

How to proof your balance without revealing it?

You can use a ZK Proof to prove that you have at least €100.000 EUR in your bank account without revealing the actual balance.

Secure Threshold Verification Using ZoKrates

Now, let's implement this threshold-based balance proof using ZoKrates, a high-level zk-SNARK framework for generating real-world Zero-Knowledge Proofs.

What We Will Do

  1. The bank sets a threshold (e.g., €100.000) and signs it.
  2. The user generates a ZoKrates zk-SNARK proof that their balance is at least the threshold based on the bank's signed threshold.
  3. The bank verifies both the zk-SNARK proof and the threshold signature.

Ensures the threshold is fixed.
Prevents user from modifying the threshold.
Keeps the actual balance private.
zk-SNARK proof is fast and efficient.

Step 1: Writing the ZoKrates Program

We'll write a ZoKrates program that:

  • Takes the actual balance (as a private input) from the user.
  • Computes a proof that balance ≥ threshold (100.000).
  • Ensures that the proof is valid only for the bank's signed threshold.

The Bank creates a file called balance_proof.zok:

def main(private field balance) -> bool {
    assert(balance >= 100000);
    return true;
}

Step 2: The Bank Compiles the ZoKrates Program

Run the following commands in your terminal:

# Compile the ZoKrates program
zokrates compile -i balance_proof.zok

This generates:

  • abi.json
  • out
  • out.r1cs

This step compiles the Zero-Knowledge proof circuit.
It converts the balance check into mathematical constraints.

Step 3: The Bank Generates a Trusted Setup

Now, the Bank needs to create zk-SNARK keys.

Run the following command:

# Generate a trusted setup
zokrates setup

This generates:

  • proving.key (used by the user to create proofs).
  • verification.key (used by the bank to check proofs).

Step 4: User Generates a zk-SNARK Proof

Now, the user runs the program with their private balance

Example where the user's balance is €101.432:

zokrates compute-witness -a 101432

This generates:

  • witness
  • out.wtns

Now, the user generates the Zero-Knowledge Proof:

zokrates generate-proof

This generates:

  • proof.json

A zk-SNARK proof is now generated!

Step 5: The Bank Verifies the Proof

The bank receives the proof and verifies it.

Verification Command:

zokrates verify
...
Performing verification...
PASSED

✅ If the verification passes, the user's balance is above the threshold without revealing the exact amount.

❌ If the verification fails, the user is lying and doesn't have enough balance.

Visual representation of the process

Visual representation of the process

Extra: Exporting a Verifier as a Smart Contract

This process is optional, but if we want the bank to verify proofs on-chain, we can deploy a smart contract. Will be the next blog post.

Generate a Solidity Verifier:

zokrates export-verifier

This creates a Solidity contract that can be deployed to Ethereum or any EVM compatible blockchain supporting zk-SNARKs.

The bank can now verify proofs automatically on the blockchain!