Overview This project demonstrates how to use Zero-Knowledge Proofs (ZKPs) to prove that a computation was performed correctly without revealing the actual inputs. Specifically, we are using a ZKP technique called zk-SNARKs (Zero-Knowledge Succinct Non-Interactive Argument of Knowledge).
Key Components Circuits: These are mathematical representations of the computation we want to prove. In our case, we created a simple circuit that multiplies two numbers.
Trusted Setup: This is a one-time setup that generates some cryptographic keys required for creating and verifying proofs. It ensures the system is secure and that proofs cannot be forged.
Proof Generation and Verification: Using JavaScript, we wrote scripts to generate proofs of computation and verify them. We used snarkjs, a JavaScript library for zk-SNARKs.
Steps Involved Define the Circuit:
We defined a circuit that multiplies two numbers (a and b) and outputs the result (c). Compile the Circuit:
We compiled the circuit using Circom to generate files needed for the trusted setup and proof generation. Perform the Trusted Setup:
We performed a series of steps to generate cryptographic keys. This step is crucial to ensure the security of the ZKP system. Generate and Verify Proofs:
We created a script to generate proofs that the multiplication was done correctly. We created another script to verify these proofs without knowing the actual numbers being multiplied. How It Works Frontend:
A simple HTML form allows users to input two numbers. When the form is submitted, it sends the numbers to our backend server. Backend:
The server takes the input numbers, generates a proof that they were multiplied correctly, and returns this proof. The server can also verify the proof to check if the multiplication was done correctly without knowing the numbers. Proof Generation:
The server uses the input numbers to generate a proof. This proof shows that the multiplication was performed correctly. Proof Verification:
The server verifies the proof to ensure it's valid. If valid, it confirms the multiplication was done correctly without revealing the actual numbers. Simplified Example Imagine you want to prove to someone that you know the product of two secret numbers without revealing those numbers. You can use a ZKP system to create a proof that convinces the other person that the multiplication was done correctly. They can verify this proof without knowing your secret numbers.
In this project, we automated this process using cryptographic techniques and JavaScript, allowing a user to input numbers and receive proof of their multiplication, which can be verified by others.
Real-World Application Such systems can be used in various scenarios where privacy and correctness need to be ensured, such as:
Financial transactions: Proving a transaction is valid without revealing the details. Identity verification: Proving identity without revealing personal information. Secure computations: Ensuring computations are done correctly without exposing the inputs.