Skip to content

A beginner-friendly Rust project demonstrating basic Zero-Knowledge Proof concepts with simple examples.

Notifications You must be signed in to change notification settings

younesbram/rust-zkp-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zero Knowledge Proof (ZKP) Demonstration in Rust

This project is a Rust-based demonstration of a simple Zero-Knowledge Proof (ZKP) system. It illustrates how a prover can convince a verifier that they know a secret without revealing the secret itself.

Introduction to ZKP

Zero-Knowledge Proofs are a category of cryptographic protocols that allow one party (the prover) to prove to another party (the verifier) that a certain statement is true, without revealing any information beyond the validity of the statement itself.

The concept can be compared to a color-blind person who wants to know if two balls are of the same color or not without knowing the actual color. The prover, who can see colors, can demonstrate that they are indeed the same or different without revealing the specific color to the color-blind verifier.

Project Overview

The project is structured as follows:

  • src/lib.rs: Contains the core ZKP logic with a simple arithmetic circuit as an example.
  • tests/lib_test.rs: Includes tests to ensure the correctness of the ZKP implementation.
  • Cargo.toml: The manifest file for Rust's package manager, which includes metadata and dependencies for the project.

How to Build and Run

Ensure you have Rust installed on your system. You can install Rust using rustup.

To run the project, navigate to the project directory in your terminal and run:

cargo run

Implementation Details

The project implements a trivial ZKP system where the 'circuit' is a simple square operation. The prover generates a proof by squaring the secret, and the verifier checks if the square of the secret (which is public) matches the commitment in the proof.

Behind the Curtains of Our Secret Club

In our club, we're using a basic math operation (like squaring a number) to create a proof. The Prover whispers a hashed version of the secret to the Verifier, who then checks if the hash matches the expected value.

Prover

Think of the Prover as the keeper of an ancient math riddle. They hold a secret number and use it to create a proof that only someone with the secret could conjure.

Verifier

The Verifier is like the guardian who checks if you're worthy to join the club. They take the proof and ensure it matches the known information, without ever seeing the secret itself.

From Classroom to the Real World

While our example is ideal for learning purposes, real-world applications of ZKPs involve more sophisticated and robust protocols:

  • zk-SNARKs (Zero-Knowledge Succinct Non-Interactive Argument of Knowledge): These are proofs that are succinct (short and easy to verify) and non-interactive, which means the prover can send just one message to the verifier. zk-SNARKs can handle complex statements efficiently, but they require a setup phase that relies on a common reference string shared between the prover and verifier.

  • zk-STARKs (Zero-Knowledge Scalable Transparent Arguments of Knowledge): Similar to zk-SNARKs in their efficiency, zk-STARKs boast greater scalability and do not require a trusted setup, making them more secure against certain types of cryptographic attacks. They are also post-quantum secure, meaning they are resistant to attacks from quantum computers.

  • Bulletproofs: These are a newer type of non-interactive ZKP that don't require a trusted setup and are more concise than zk-SNARKs, although they typically result in longer proofs. Bulletproofs are especially useful for blockchain applications because they help in reducing transaction sizes.

In production-grade systems, the randomness that is often needed for generating proofs is derived from cryptographically secure pseudo-random number generators (CSPRNGs). CSPRNGs are designed to produce output that is indistinguishable from true randomness, which is vital for maintaining security in cryptographic systems.

Moreover, it is common practice to utilize well-established cryptographic libraries when implementing ZKPs in production. These libraries have been thoroughly reviewed and tested by the cryptographic community, reducing the risk of vulnerabilities that could arise from implementing one's own cryptographic protocols.

Lastly, ZKP protocols can be categorized into interactive and non-interactive types:

  • Interactive ZKPs require multiple rounds of communication between the prover and verifier, where the verifier sends a series of challenges, and the prover responds with corresponding answers.
  • Non-Interactive ZKPs allow the prover to send a single proof that the verifier can check without any further interaction. This is often achieved through the use of a common reference string or through transformations that convert interactive proofs into non-interactive ones (such as the Fiat-Shamir heuristic).

About

A beginner-friendly Rust project demonstrating basic Zero-Knowledge Proof concepts with simple examples.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published