Member-only story

Zero-Knowledge Proof of SHA256 Hash using zkSNARK

This article provides you sufficient commands to run zkSNARK algorithm with circom circuits on a Ubuntu Docker image to prove SHA256 hash.

Binod Karunanayake
2 min readApr 30, 2024

If you are just testing for educational purposes, I recommend to use Docker for cleaner setup. However, if you wish to run the zkSNARK program on your machine, you can start from Install Prerequisites section.

Setup Ubuntu Instance on Docker

  1. docker run -it ubuntu:jammy
  2. apt update
  3. apt install curl
  4. apt install nano

Install Prerequisites

  1. apt install build-essential
  2. curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh (proceed with standard installation)
  3. . "$HOME/.cargo/env"
  4. curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
  5. nvm install 20
  6. export NVM_DIR="$HOME/.nvm"
  7. [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
  8. apt install git-all
  9. git clone https://github.com/iden3/circom.git
  10. cd circom
  11. cargo build --release
  12. cargo install --path circom
  13. npm install -g snarkjs

Develop and Run the zkSNARK Program

  1. Create program.circom file by running nano program.circom
pragma circom 2.0.0;
include "./circomlib/circuits/sha256/sha256.circom";

template program() {
signal input in[2];
signal output out[256];

component SHA = Sha256(2);
SHA.in <== in;
out <== SHA.out;
}

component main = program();

2. Get sha256 library by simply running git clone https://github.com/iden3/circomlib.git in project directory.

Pro tip: Similarly you can use other given libraries to write any custom program for your scenario

3. Compile the .circom file using circom program.circom --r1cs --wasm --sym --c.

--

--

Binod Karunanayake
Binod Karunanayake

Written by Binod Karunanayake

PhD Candidate @RMIT University | Former Software Engineer @WSO2 | BSc Engineering (Hons) University of Moratuwa

No responses yet

Write a response