A demonstration project for interacting with Tornado Cash smart contracts on the Sepolia testnet, implementing deposit and zero-knowledge proof-based withdrawal functionality.
This project is intended solely for educational and research purposes. Users assume all risks and responsibilities associated with using this code. The authors are not responsible for any misuse or legal consequences resulting from the use of this software.
This project demonstrates:
- ETH deposits to Tornado Cash contracts on Sepolia testnet
- Anonymous withdrawals using Zero-Knowledge Proofs
- Merkle tree construction and verification
- ZK-SNARK proof generation and verification
- Node.js
- ethers.js
- circomlib (Pedersen hash implementation)
- websnark (ZK-SNARK proof generation)
- fixed-merkle-tree (Merkle tree implementation)
- Node.js
- Git
- Basic understanding of Ethereum and Zero-Knowledge Proofs
- Clone the repository
git clone https://github.com/Chenxinjie65/Tornado_Sepolia.git
cd Tornado_Sepolia
- Install dependencies
npm install
- Create a
.env
file in the root directory with the following parameters:
Network Configuration
--------------------
RPC_URL=https://sepolia.infura.io/v3/YOUR-PROJECT-ID
NETWORK_ID=11155111
TORNADO_ADDRESS=0x8C4A04d872a6C1BE37964A21ba3a138525dFF50b
Account Configuration
--------------------
PRIVATE_KEY=your_private_key
Depoist Configuration
------------------------
DEPOSIT_AMOUNT=0.1
Withdraw Configuration
------------------------
NOTE=
RECIPIENT_ADDRESS=
RELAYER_ADDRESS=
FEE=0
Execute the deposit script:
node depoist.js
The script will:
- Generate random nullifier and secret
- Create a commitment
- Submit the deposit transaction
- Output a note (IMPORTANT: Save this note securely)
Before withdrawal, fetch the latest deposit events:
node getOnchainEvents.js
This script fetches all deposit events from the blockchain and caches them locally. This cached data will be used later to construct the Merkle tree during the withdrawal process.
To withdraw your deposited ETH:
- Set your note in the
.env
file:
NOTE=your_saved_note
- Execute the withdrawal script:
node withdraw.js
The script will:
- Parse your note
- Generate a zero-knowledge proof
- Submit the withdrawal transaction
- Transfer ETH to your recipient address
depoist.js
: Handles deposit functionalitywithdraw.js
: Implements withdrawal logic with ZK-proof generationgetOnchainEvents.js
: Fetches and caches depoist events from blockchainbuild/
: Contains compiled circuits and proving keyscache/
: Stores deposit events
- Never share your note or private key
- Ensure secure storage of deposit notes
- Use different addresses for deposit and withdrawal
- Wait for sufficient block confirmations