本文へ移動
Contact

TECHFUND
Media

Hi AUDIT
2025/8/4

Tornado Cash Demystified: Why Privacy Matters and How the Protocol Makes It Work

Table Of Contents:

Introduction

Tornado Cash is a decentralized protocol on Ethereum that breaks the on-chain link between sender and receiver. Instead of sending funds directly from Alice to Bob (where everyone can trace the flow), Tornado Cash lets Alice deposit into a smart contract and Bob withdraw from a separate address, making it cryptographically not feasible to tell who paid whom. Under the hood, it uses zero-knowledge proofs (zkSNARKs), one-way commitments, Merkle trees, and “nullifiers” to make sure deposits and withdrawals can’t be linked, can’t be double spent, and can’t be front-run. And all of this happens without need of any trusted party in between.

Core idea: Alice locks her ETH into a “pool” (e.g. 1 ETH, 5 ETH). Bob later proves he knows a secret commitment (but reveals nothing) and withdraws the deposited amount from a fresh address. On-chain observers see only “5 ETH went in” and “5 ETH went out” but can never connect the sender and receiver.

Now, why is privacy important?

When every transaction on the blockchain is public, anyone can trace your moves from daily spends to big transfers. This reveals habits, business plans, even your net worth. It opens up opportunities for hackers, MEV bots, or even extortion, something we’ve already seen happen in the past.

That’s why it’s crucial to secure financial activity and give control back to the user and Privacy isn’t about hiding, it’s about protecting.

Problem currently: Everyone knows sender Alice sent 100 ether to Bob. There is a link created between Alice and Bob. Everyone knows Bob received 100 ether from Alice.

Now let’s break down how protocol actually solves these problems step by step. Make sure to take time to read till the end for a complete understanding

First strategy: Fixed Denomination

The main problem is that if the full 100 ETH is deposited and later full 100 ETH is withdrawn, then it becomes easier to link the receiver to the original depositor

So the first strategy is to divide the 100 ETH amount into smaller fixed denominations: 1 ETH, 5 ETH, etc.

Alice deposits 5 ETH multiple times (5 * 20 = 100 ETH) and during deposit it gives addresses of Bob the right to withdraw by providing his address. Bob addresses can call withdraw().

What this solves: Tracking where full 100 ETH went becomes less easy. Some privacy is maintained, however full unlinkability is not achieved here


New Problem: Anyone can query the chain and still see how much Bob has withdrawn. Even if Bob uses multiple addresses, total inflows to each address are visible and can be aggregated.

Root cause: We should avoid providing Bob addresses during deposit itself


Second Strategy: Hide the Recipient and use Commitments

Don’t keep recipient address during deposit - introduce a commitment.

A commitment is a hash of some secret values known only to the depositor. Since hashes are one-way, no one can reverse them to reveal the original values.

Only the person who knows the original inputs used to create the commitment can later prove ownership and withdraw the ETH.

Here is how commitment is generated:

commitment = H(secret)

No one can reverse the final commitment value and find the original value - secret.

The secret value is sent to Bob off-chain. Bob will pass these values to the withdraw() function. The withdraw() function checks these values match with the commitment hash and transfers the 5 ETH.

What this solves: Since the receiver’s address isn’t included during the deposit, it becomes much harder to link the depositor and receiver.


New Problem: Bob’s withdrawal transaction can be front-run. When he sends a transaction with the secret, anyone can see it in the mempool, verify it's valid, and front-run it by submitting the same data with higher gas fees. The attacker then receives the 5 ETH before Bob does.

Root cause: The secret pair acts like a private key to the deposited funds. If it’s exposed in the mempool before inclusion, the funds are at risk. These values must remain private. But how can Bob reveal he knows the secret without revealing these values itself? That’s exactly where zero-knowledge proofs come in — and how they solve this is explained below.


Third strategy: Integrate with Zero-Knowledge Proofs

ZKPs are helpful to prove that you know the secret to the public without revealing the secret itself.

Steps:

  1. Bob passes the secret along with commitment to the ZK circuit and generates a zkSNARK proof. This proof is short and can be verifiable on-chain. The generation of proof can be done entirely off-chain so there is no risk of revealing it to the public.

  2. ZK Circuit will check whether commitment = hash(secret) and will give the proof results to Bob.

  3. Bob submits this proof along with the commitment in the withdraw() function.

  4. Suppose the deposit() function stores all commitments in commitments[]. Withdraw function checks whether the commitment is present in the commitments[] and proceeds.

  5. The contract then verifies the proof on-chain by passing the commitment hash and the zero-knowledge proof to the verifier contract. Note: The secret is never revealed — only the proof is submitted. And from this proof, it's impossible to get to the original values with the current technology we have as of now.

  6. Once the on-chain verification succeeds, the smart contract transfers 5 ETH to Bob successfully.

What this solves: The secret is never revealed and the smart contract can verify that Bob knows it. This is the core power of zero-knowledge proofs — proving knowledge without revealing the underlying data.


New problem:

If the commitment is passed to the withdraw() function, it creates a link back to the depositor — because the same commitment was submitted during deposit. But our main goal was to break this linkage and we’re back at the same problem - the linkage still exists 🙂

Root cause: To remove the linkage, the commitment should not be passed to the withdraw() function. How can withdraw() function make sure the withdrawal is called only after funds were deposited? Users can call this function by passing any valid commitment which was not deposited. Let’s try using Merkle Trees.


Fourth strategy: Use Merkle trees

We need to ensure that the withdraw() function is only called for a commitment that was used in a valid deposit — without revealing the commitment in withdraw() function. Let’s see how we can achieve this

If we store commitments[] in an array on-chain, a withdrawal must say:

My commitment exists at index i in the array

Now privacy is broken — the index reveals linkability.

Also, verifying this for a large array is even more expensive.

Solution:

  • Store commitments in a Merkle tree instead of a plain array.

  • Maintain a history of Merkle roots on-chain because the root value will change for every new leaf addition. The smart contract should know all roots.

  • To generate proof, Bob passes the below inputs to the ZK circuits: Secret - private input Merkle proof - private input Merkle root - public input

  • ZK circuit verifies: The commitment equals hash(secret). The user provides a valid Merkle proof for the commitment such that: When the commitment is combined with the provided Merkle proof and all intermediate hashes are computed up to the root, the resulting Merkle root must exactly match the Merkle root passed as a public input.

  • Bob will pass the proof and the same public inputs to the withdraw() function.

  • withdraw() function verifies the proof is valid and also checks if the root is present in the root history.

  • Once checks are passed, 5 ETH will be transferred to Bob.

What this solves: Linkage is broken between depositor and receiver as the receiver doesn’t need to pass commitment.


New Problem:

This is vulnerable to replay attack. After Bob successfully withdraws the 5 ETH, someone could reuse the same proof to withdraw again. This opens the door to a replay attack, since the smart contract zk verifier only checks whether the proof is valid but it doesn't check if the proof has already been used.

Possible solution: Since zkSNARK proofs are short, one approach is to store them on-chain and check if a new proof was already used before to prevent replays. But the problem with this is zkSNARKs can generate a different valid proof for the same inputs every time due to built-in randomness. So what will be good solution, lets understand it in next step


Fifth strategy: Use Nullifiers to avoid Withdraw replays

We can’t store the commitment, and we can’t rely on storing zkSNARK proofs either — both are either private or random. So how do we prevent replay attacks?

Use an additional parameter called nullifiers along with the secret value when generating commitments during deposits.

commitment = H(secret, nullifier)

  • Nullifier hash will be passed in the withdraw() function.

  • withdraw() function checks if this nullifier is already present, if not, proceeds with all other checks.

  • Only when all checks pass, 5 ETH will be transferred.

But how can we be sure that the nullifier passed to withdraw() is the same one used in the original commitment?

  1. The nullifier is part of the input when generating the commitment — typically, commitment = hash(nullifier, secret).

    So if the nullifier is different, the resulting commitment will be different and won’t match the one in the Merkle tree.

  2. All the important checks are present inside the ZK circuit so the nullifier cannot be given differently than what was used when generating commitment:

    The nullifier hash equals hash(nullifier). The commitment equals hash(secret + nullifier) and exists in Merkle root.

What this solves: Replay attacks are reduced as nullifier hash checks are in place which will make sure the same deposit commitment proof is not used multiple times. The replay attack vector is now fixed, but it is still vulnerable to front-running attacks.


New Problem:

The proof and nullifier hash can be front-run — if someone sees Bob’s transaction in the mempool, they can copy it and submit it first.


Sixth strategy: Hardcode the recipient in the proof to avoid Front Running behaviour

We need to make sure that only the person who generated the ZK proof can actually receive the funds.

Right now, Bob creates the proof, but anyone who sees the proof and nullifier hash in the mempool can front-run the transaction.

They just take the proof and nullifier hash values, submit the transaction with higher gas, and grab the funds before Bob does.

Solution:

  • ZK Proof should include the recipient address.

  • While generating the proof, Bob passes the recipient address as a public input.

  • This address is hardcoded in the proof. This is achieved by including a dummy constraint like recipientSquare <== recipient * recipient at the end of the ZK circuit

  • During withdraw(), the contract checks: The proof is valid for the given recipient. The ETH is sent only to that address.

Now even if someone front-runs the transaction, they cannot change the recipient. The ETH will go only to the original address used in proof generation.

Front-running is prevented by binding the recipient address inside the ZK proof.


Seventh Strategy: Add a Time Gap Between Deposit and Withdraw

There should be some gap between deposit and withdraw; otherwise, a link can be created easily through on-chain timing analysis.

Take an example — Suppose Alice wanted to transfer 100 ether so she deposited 5 ETH (20 times) into a smart contract, and Bob withdraws all 20 deposits within 30 mins. Now even with the gap, it's still possible to link them through the amount, exact match, and transaction timing.

However, if the deposit and withdraw traffic is high, it becomes difficult to create linkage. Privacy is weak unless many people deposit and withdraw around the same time.

Conclusion & Final Thoughts

We’ve now walked through each major component of this protocol — fixed denominations, one-way commitments, zkSNARK proofs, Merkle trees, nullifiers, and recipient binding in the proof. At its core, this protocol shows what’s possible when cryptography, smart contract engineering, and zero-knowledge proofs come together to restore financial privacy on transparent blockchains.

This protocol is being used by both black-hat users (to hide funds) and genuine users (to maintain privacy). But this protocol’s purpose is not to promote it. It is to give people privacy and control over their own financial transaction. Also It’s important we use and promote such protocols for ethical purposes only. Abusing it for illegal purposes would be an insult to the vision and effort of those builders who have built this powerful technology with integrity

Thank you for reading! Feel free to share your thoughts in the DM

Author: Ashish Lachuria

Security Researcher Intern at TECHFUND

Hi AUDIT

Hi AUDIT is a high speed, high quality, best price security audit service, providing automated audit SaaS and consulting for web3 startups.
View More