Zero Knowledge Proofs: The Data Protection Method That Even Your Grandma Could Understand

Keith Dumont
4 min readDec 17, 2022

--

(source)

Zero knowledge proofs (ZKPs) are a type of cryptographic technique that allow one party (the prover) to prove to another party (the verifier) that they know a certain piece of information, without revealing what that information is. This may sound counterintuitive at first, but ZKPs have a number of important uses, including enhancing privacy and security in various applications.

At a high level, a zero knowledge proof consists of three main components:

  1. a statement or a theorem that the prover wants to prove
  2. a set of rules or axioms that the prover and verifier both agree upon
  3. a protocol that the prover and verifier follow to interact and exchange information

One of the key features of zero knowledge proofs is that they are “non-interactive,” meaning that the prover and verifier do not need to exchange any additional information beyond the initial proof and verification. This makes them particularly useful for situations where the prover and verifier may not fully trust each other, or where the prover wants to maintain a high level of privacy.

A Concrete Example

Imagine that Alice wants to prove to Bob that she knows the secret password to a certain account, but she doesn’t want to reveal the actual password to Bob. Alice can use a zero knowledge proof to demonstrate that she knows the password without actually revealing it to Bob.

To do this, Alice and Bob can agree on a set of axioms or rules that they both understand, such as the rules of a particular mathematical function. Alice can then use these rules to construct a proof that she knows the password, without revealing the actual password to Bob. Bob can then verify the proof using the agreed-upon axioms, without learning the actual password.

(source)

Applications & Use Cases

Zero knowledge proofs (ZKPs) have a number of interesting and important use cases:

  1. Enhancing privacy and security in online transactions: ZKPs can be used to allow a user to prove their identity or possession of certain information (such as a password or private key) without revealing that information to the other party. This can be useful for protecting against identity fraud and enhancing the security of online transactions.
  2. Verifying the authenticity of documents or data: ZKPs can be used to verify the authenticity of a document or data without revealing the actual content of the document or data. This can be useful for applications such as verifying the authenticity of a certificate or diploma without revealing the actual grades or coursework.
  3. Protecting against voting fraud: ZKPs can be used to allow voters to verify that their vote was counted without revealing their actual vote to anyone else. This can help to protect against voting fraud and ensure the integrity of elections.
  4. Enhancing privacy in decentralized systems: ZKPs can be used to allow users to participate in decentralized systems (such as blockchains) without revealing their identity or other sensitive information. This can help to enhance privacy and protect against malicious actors in decentralized systems.

Let’s Try a Fun Exercise

Great! Now that we have the basics down. Let’s have some fun! Here is an interesting way that you could use zero knowledge proofs in Python and really impress your interviewer while solving a coding interview question.

(source)

Assume that you are asked to write a function that takes in a list of strings and returns a Boolean value indicating whether or not the list contains a palindrome. However, you are not allowed to reveal the actual palindrome to the interviewer.

One way you could solve this problem using zero knowledge proofs is by using a hash function to create a digest of the list of strings. You could then return the digest to the interviewer as a proof that the list contains a palindrome, without revealing the actual palindrome to them. Let’s take a look at the code:

import hashlib

def contains_palindrome(lst):
# Iterate through the list and check if any of the strings are palindromes
for str in lst:
if is_palindrome(str):
# If a palindrome is found, create a digest of the list using a hash function
digest = hashlib.sha256(str(lst).encode()).hexdigest()
# Return the digest as a proof that the list contains a palindrome
return digest
# If no palindromes are found, return False
return False

def is_palindrome(str):
# Implement a function to check if a string is a palindrome
return str == str[::-1]

# Example usage:
print(contains_palindrome(["racecar", "hello", "world"])) # Output: "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"
print(contains_palindrome(["apple", "orange", "banana"])) # Output: False

In this example, the function contains_palindrome takes in a list of strings and returns a digest of the list as a proof that it contains a palindrome, without revealing the actual palindrome to the interviewer. The function is_palindrome is used to check if a given string is a palindrome.

This is just one way that zero knowledge proofs could be used to solve a coding interview question involving the need to prove knowledge of a certain piece of information without revealing it.

Zero knowledge proofs are a powerful and versatile tool for proving knowledge without revealing sensitive information. They have a wide range of applications in various fields and are likely to continue to be an important part of cryptography and computer science for years to come.

I hope you enjoyed this article. If you have any questions, feel free to reach out to me on Twitter.

--

--

Keith Dumont

Head of Developer Relations & Growth @Supra, MS Computer Science @Penn, Decentralization Maxi. Connect with me on X: https://twitter.com/KeithDumont3