Awesome
Tornado Cash [Re-built]
Tornado Cash is a non-custodial Ethereum and ERC20 privacy solution based on zkSNARKs.
This repository re-builds Tornado Cash for educational purposes as a Foundry project, and uses the latest versions of Circom (circomlib and circomlibjs) and snarkJS to generate proofs.
The original-repository is built with older versions of tools, and it is difficult to use it as educational reference material to understand the latest Solidity <-> Circom workflow for writing smart contracts with ZK-SNARK capabilities.
Installation
Clone this repository
git clone https://github.com/nkrishang/tornado-cash-rebuilt.git
Install dependencies:
forge install
yarn
Usage
Compiling circom circuits
The main workflow of this repo is:
- Compile circuits to generate circuit artifacts
- Perform a powers of tau ceremony
- Generate zkey and verifier Solidity smart contract
These three steps are written as bash commands in the makefile. Run the following to perform these steps:
make all
This will create a /circuit_artifacts
folder that contains everything needed to run tests.
Running tests
There is a single forge test file /test/ETHTornado.t.sol
and scripts used in this test /forge-ffi-scripts
. The test and script files are annotated.
Run the following command to run tests (after you have generated circuit artifacts):
forge test
Credits
For a comprehensive understanding of ZK-SNARKs, see the Rareskills ZK Book and their article on how Tornado Cash works.