
Zero Knowledge Proofs (ZKPs) sound like magic — proving something without ever revealing the underlying secret. But beneath the hype, their security rests on three core pillars: completeness, soundness, and zero knowledge. These are known as three core properties of ZKP. Miss one, and your protocol is wide open for attackers. In this article, we’ll break down each property with simplified examples from CryptoHack, a fun platform where anyone can explore, hack, and deeply learn modern cryptography
If the statement is true and the prover follows the protocol honestly, the verifier accepts. Most practical ZK constructions are built from Sigma protocols — simple 3-move interactions:
Prover → Verifier: Commitment (a)
Prover ← Verifier: Challenge (e)
Prover → Verifier: Response (z)Let's break this down with a concrete example.
Suppose Alice wants to prove she knows the value of secret w such that y = g^w mod p, without revealing w.
Here's how the sigma protocol works:
Step 1: Commitment
r = randint(0, q) # Random nonce
a = pow(g, r, p) # Commitment: g^r mod p
# Alice sends 'a' to BobStep 2: Challenge
e = randint(0, 2**511) # Bob picks random challenge
# Bob sends 'e' to AliceStep 3: Response
z = (r + e * w) % q # Alice computes response
# Alice sends 'z' to BobVerification
# Bob checks: g^z = a * y^e mod p
# This works because:
# g^z = g^(r + e*w) = g^r * g^(e*w) = a * (g^w)^e = a * y^e
assert pow(g, z, p) == (a * pow(y, e, p)) % pIf a prover does not know the witness w, they cannot produce an accepted proof. Soundness is the property that protects verifiers from being fooled.
Without knowing the secret, the prover’s chance of convincing the verifier is negligible
Recall the verification equation:
g^z ≡ a * y^e (mod p)A prover who knows w can always satisfy this. But suppose a malicious prover wants to cheat without w. They can try to choose a maliciously so the verification equation holds anyway.
Strategy:
Guess the e value being sent by verifier if verifier doesnt uses random generation for value e.
Compute the fake response z without value using value w
Set the commitment backwards:
a = g^z * (y^e)^(-1) mod pNow the transcript (a, e, z) will always pass verification, even though the prover never used w!
g^z ≡ a * y^e (mod p)
g^z ≡ g^z * (y^e)^(-1) * (y^e) mod p
g^z ≡ g^zThis trick only works if the prover already knows the challenge e before sending a.
But in a properly designed Sigma protocol:
The prover must commit to a first (before seeing e).
The verifier then chooses e at random.
So the malicious prover can’t “adapt” a to the challenge — they’re forced to send a blindly, and their chance of guessing a valid (a, z) pair without w is negligible.
It’s crucial that the prover commits to a before seeing e, and that the verifier chooses e randomly, so the prover can’t predict it in advance
The zero knowledge property ensures that verifiers learn nothing beyond the verifying the proof sent by prover. This means verifier should not be able to extract value of w from the proofs sent by prover.
Imagine a malicious verifier who can somehow get the prover to accept two different responses to two different challenges for the same commitment.
Here's the attack in action:
# Attacker gets verifier to challenge the same commitment twice
e1 = randint(0, 2**511) # First challenge
z1 = z1 = r + e1*w # First response
e2 = randint(0, 2**511) # Second challenge
z2 = z2 = r + e2*w # Second response
# Now attacker can extract the secret!
# Since: z1 = r + e1*w and z2 = r + e2*w
# Therefore: z2 - z1 = (e2 - e1)*w
secret = (z2 - z1) * pow(e2 - e1, -1, q) % qThe mathematical relationship reveals the secret:
From z1 = r + e1*w and z2 = r + e2*w (Vulnerability here is same r value is used multiple times)
Subtracting: z2 - z1 = (e2 - e1)*w
Solving: w = (z2 - z1) / (e2 - e1)
This is why secure ZK protocols must ensure each commitment e is only used once.
Interactive protocols require back-and-forth communication, which is problematic for blockchain applications.
The solution is to replace the random challenge (second step) with a hash of the commitment done by prover itself. this reduces the interaction with Verifier(Step 1 & Step 2 above)
# Interactive version:
a = pow(g, r, p) # Interactive! Prover has to send value a to Verifier
e = randint(0, q) # Interactive! Prover has to wait for e from Verifier
z = (r + e * w) % q
# Non-interactive version (Fiat-Shamir):
a = pow(g, r, p)
e = hash(a) % 2**511 # Challenge is deterministic hash
z = (r + e * w) % qThe hash function acts as a "random value" - it produces unpredictable challenges that the prover can't manipulate. The hash is needed because we should not allow prover to choose any random a value. Because this will motivate Provider to act maliciously and compute the value of z without knowing w at all. Since the prover must commit to a before computing e = hash(a), they can't bias the challenge.
from hashlib import sha512
from Crypto.Util.number import bytes_to_long
# Generate proof
r = random.randint(0, q) # select random value between 0 to q
a = pow(g, r, p) # g ^ r mod p
e = bytes_to_long(sha512(str(a).encode()).digest()) % 2**511 # Converts bytes into integer
z = (w * e + r) % q
# Verification
assert pow(g, z, p) == (a * pow(y, e, p)) % p
assert e == bytes_to_long(sha512(str(a).encode()).digest()) % 2**511We have now understood the three fundamental properties of Zero Knowledge Proofs and their behavior's. Completeness ensures honest provers with valid secrets can always generate accepted proofs. Soundness prevents dishonest provers from faking proofs without knowing the secret. Zero knowledge guarantees that verifiers learn nothing about the secret beyond its validity. These three properties work together to make ZK protocols both secure and private. Understanding how each property can break helps us build stronger cryptographic systems
Author: Ashish Lachuria
Security Researcher at TECHFUND