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.
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
docker run -it ubuntu:jammy
apt update
apt install curl
apt install nano
Install Prerequisites
apt install build-essential
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
(proceed with standard installation). "$HOME/.cargo/env"
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
nvm install 20
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
apt install git-all
git clone https://github.com/iden3/circom.git
cd circom
cargo build --release
cargo install --path circom
npm install -g snarkjs
Develop and Run the zkSNARK Program
- Create
program.circom
file by runningnano 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
.