Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .solhint.json

This file was deleted.

49 changes: 49 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[package]
name = "tornado-svm"
version = "0.1.0"
edition = "2021"
description = "Solana Tornado Cash Privacy Solution"
license = "MIT"

[lib]
crate-type = ["cdylib", "lib"]
name = "tornado_svm"

[features]
no-entrypoint = []
no-idl = []
no-log-ix-name = []
cpi = ["no-entrypoint"]
default = []

[dependencies]
solana-program = "1.16.0"
thiserror = "1.0.40"
borsh = "0.10.3"
borsh-derive = "0.10.3"
num-derive = "0.3.3"
num-traits = "0.2.15"
spl-token = { version = "4.0.0", features = ["no-entrypoint"] }
spl-associated-token-account = { version = "2.0.0", features = ["no-entrypoint"] }
arrayref = "0.3.7"
bytemuck = { version = "1.13.1", features = ["derive"] }
sha3 = "0.10.8"
ark-ff = "0.4.2"
ark-bn254 = "0.4.0"
ark-ec = "0.4.2"
ark-groth16 = "0.4.0"
ark-serialize = "0.4.2"
ark-relations = "0.4.0"
ark-crypto-primitives = "0.4.0"
ark-std = "0.4.0"

[dev-dependencies]
solana-program-test = "1.16.0"
solana-sdk = "1.16.0"
rand = "0.8.5"

[profile.release]
overflow-checks = true
lto = "fat"
codegen-units = 1
opt-level = 3
124 changes: 122 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,124 @@
# Tornado Cash Privacy Solution [![build status](https://github.com/tornadocash/tornado-core/actions/workflows/build.yml/badge.svg)](https://github.com/tornadocash/tornado-core/actions/workflows/build.yml) [![Coverage Status](https://coveralls.io/repos/github/tornadocash/tornado-core/badge.svg?branch=master)](https://coveralls.io/github/tornadocash/tornado-core?branch=master)
# Tornado Cash Privacy Solution for Solana

A privacy solution for Solana based on zkSNARKs. It improves transaction privacy by breaking the on-chain link between the sender and recipient addresses. It uses a Solana program that accepts SOL deposits that can be withdrawn by a different address. Whenever SOL is withdrawn by the new address, there is no way to link the withdrawal to the deposit, ensuring complete privacy.
Comment on lines +1 to +3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (typo): Consistently capitalize "zkSNARKs" throughout the documentation.

Suggested implementation:

Later, the user decides to make a withdrawal. To do that, the user provides a zkSNARKs proof that they possess a secret to an unspent commitment from the program's Merkle tree.

The zkSNARKs technology allows this to happen without revealing which exact deposit corresponds to this secret.


[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Build Status](https://img.shields.io/github/workflow/status/your-username/tornado-svm/CI)](https://github.com/your-username/tornado-svm/actions)
[![Documentation](https://img.shields.io/badge/docs-GitHub%20Pages-blue)](https://your-username.github.io/tornado-svm/)

## Overview

To make a deposit, a user generates a secret and sends its hash (called a commitment) along with the deposit amount to the Tornado program. The program accepts the deposit and adds the commitment to its Merkle tree of deposits.

Later, the user decides to make a withdrawal. To do that, the user provides a zkSNARK proof that they possess a secret to an unspent commitment from the program's Merkle tree. The zkSNARK technology allows this to happen without revealing which exact deposit corresponds to this secret. The program checks the proof and transfers the deposited funds to the address specified for withdrawal. An external observer will be unable to determine which deposit this withdrawal came from.

## Features

- **Privacy**: Breaks the on-chain link between sender and recipient addresses
- **Non-custodial**: Users maintain control of their funds at all times
- **Optimized for Solana**: Designed to be efficient with Solana's compute units
- **Relayer support**: Allows third-party relayers to pay for gas fees
- **Multiple denominations**: Supports different deposit amounts

## Architecture

The system consists of the following main components:

```mermaid
graph TD
A[Client] -->|Interact| B[Solana Program]
B -->|Store| C[Merkle Tree]
B -->|Verify| D[zkSNARK Verifier]
E[User] -->|Use| A
```

For more details, see the [Architecture Overview](https://your-username.github.io/tornado-svm/architecture.html).

## Installation

### Prerequisites

- Rust 1.60+
- Solana CLI 1.16.0+
- Node.js 14+

### Build

```bash
# Clone the repository
git clone https://github.com/your-username/tornado-svm.git
Comment on lines +48 to +49
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question (typo): Please double-check the repository URL. "svm" might be extraneous.

Suggested implementation:

git clone https://github.com/your-username/tornado.git

cd tornado

[![Build Status](https://img.shields.io/github/workflow/status/your-username/tornado/CI)](https://github.com/your-username/tornado/actions)

[![Documentation](https://img.shields.io/badge/docs-GitHub%20Pages-blue)](https://your-username.github.io/tornado/)

cd tornado-svm

# Build the Solana program
cargo build-bpf

# Install the CLI tool
cd client
npm install
```

## Usage

### Initialize a Tornado Instance

```bash
# Create a new Tornado instance with a denomination of 1 SOL and a Merkle tree height of 20
npx tornado-cli initialize --denomination 1000000000 --height 20
```

### Deposit

```bash
# Generate a commitment
npx tornado-cli generate-commitment

# Deposit 1 SOL
npx tornado-cli deposit --instance <INSTANCE_ADDRESS> --commitment <COMMITMENT> --amount 1
```

### Withdraw

```bash
# Generate a proof
npx tornado-cli generate-proof --note <NOTE_PATH> --root <MERKLE_ROOT> --recipient <RECIPIENT_ADDRESS>

# Withdraw to a recipient address
npx tornado-cli withdraw --instance <INSTANCE_ADDRESS> --proof <PROOF> --root <MERKLE_ROOT> --nullifier-hash <NULLIFIER_HASH> --recipient <RECIPIENT_ADDRESS>
```

For more detailed usage instructions, see the [Quick Start Guide](https://your-username.github.io/tornado-svm/usage/quick-start.html).

## Documentation

Comprehensive documentation is available at [https://your-username.github.io/tornado-svm/](https://your-username.github.io/tornado-svm/).

The documentation includes:

- [Architecture Overview](https://your-username.github.io/tornado-svm/architecture.html)
- [Algorithms](https://your-username.github.io/tornado-svm/algorithms/)
- [Data Structures](https://your-username.github.io/tornado-svm/data-structures/)
- [Usage Guide](https://your-username.github.io/tornado-svm/usage/)
- [API Reference](https://your-username.github.io/tornado-svm/api/)
- [Development Guide](https://your-username.github.io/tornado-svm/development/)

## Security

The security of this program relies on the security of the zkSNARK implementation and the Merkle tree. The zkSNARK proofs ensure that only the owner of a commitment can withdraw the corresponding deposit, and the Merkle tree ensures that each commitment can only be spent once.
Comment on lines +104 to +106
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 suggestion (security): Consider expanding the security considerations to discuss potential vulnerabilities and mitigation strategies.

Suggested change
## Security
The security of this program relies on the security of the zkSNARK implementation and the Merkle tree. The zkSNARK proofs ensure that only the owner of a commitment can withdraw the corresponding deposit, and the Merkle tree ensures that each commitment can only be spent once.
## Security
The security of this program relies on the security of the zkSNARK implementation and the Merkle tree. The zkSNARK proofs ensure that only the owner of a commitment can withdraw the corresponding deposit, and the Merkle tree ensures that each commitment can only be spent once.
### Potential Vulnerabilities and Mitigation Strategies
While the current security measures provide a strong foundation, several potential vulnerabilities should be considered:
- Cryptographic weaknesses: Regularly audit and update the underlying cryptographic libraries to address any emerging vulnerabilities.
- Side-channel attacks: Implement constant-time algorithms for critical cryptographic operations to avoid leaking sensitive information.
- Replay and man-in-the-middle attacks: Use session tokens, timestamps, or nonce-based approaches to prevent replay attacks and secure communication channels.
- Smart contract vulnerabilities: Regularly test the implementation for issues such as reentrancy, and enforce proper access controls.
Implementing these strategies can help further secure the system against evolving threats.


## Performance

The program is optimized for Solana's compute units:

- Deposit gas cost: ~200,000 CUs
- Withdraw gas cost: ~300,000 CUs

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

Tornado Cash is a non-custodial Ethereum and ERC20 privacy solution based on zkSNARKs. It improves transaction privacy by breaking the on-chain link between the recipient and destination addresses. It uses a smart contract that accepts ETH deposits that can be withdrawn by a different address. Whenever ETH is withdrawn by the new address, there is no way to link the withdrawal to the deposit, ensuring complete privacy.

Expand Down Expand Up @@ -176,4 +296,4 @@ zkutil setup -c build/circuits/withdraw.json -p build/circuits/withdraw.params
zkutil export-keys -c build/circuits/withdraw.json -p build/circuits/withdraw.params -r build/circuits/withdraw_proving_key.json -v build/circuits/withdraw_verification_key.json
zkutil generate-verifier -p build/circuits/withdraw.params -v build/circuits/Verifier.sol
sed -i -e 's/pragma solidity \^0.6.0/pragma solidity 0.5.17/g' ./build/circuits/Verifier.sol
```
```
51 changes: 0 additions & 51 deletions circuits/merkleTree.circom

This file was deleted.

67 changes: 0 additions & 67 deletions circuits/withdraw.circom

This file was deleted.

22 changes: 22 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "tornado-svm-cli",
"version": "0.1.0",
"description": "CLI for Tornado Cash Privacy Solution on Solana",
"main": "tornado-cli.js",
"bin": {
"tornado-cli": "./tornado-cli.js"
},
"scripts": {
"start": "node tornado-cli.js"
},
"dependencies": {
"@solana/web3.js": "^1.73.0",
"bn.js": "^5.2.1",
"bs58": "^5.0.0",
"commander": "^9.4.1"
},
"engines": {
"node": ">=14.0.0"
},
"license": "MIT"
}
Loading