-
Notifications
You must be signed in to change notification settings - Fork 0
rewrite it to solana rust pinocchio program (Run ID: openSVM_tornado-svm_issue_1_eb373c59) #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
cfd3cb1
37e7a5d
e84b699
06a72bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| 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 |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,124 @@ | ||||||||||||||||||||||||||||||||||||
| # Tornado Cash Privacy Solution [](https://github.com/tornadocash/tornado-core/actions/workflows/build.yml) [](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. | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| [](https://opensource.org/licenses/MIT) | ||||||||||||||||||||||||||||||||||||
| [](https://github.com/your-username/tornado-svm/actions) | ||||||||||||||||||||||||||||||||||||
| [](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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: |
||||||||||||||||||||||||||||||||||||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ## 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. | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
|
|
@@ -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 | ||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||
This file was deleted.
This file was deleted.
| 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" | ||
| } |
There was a problem hiding this comment.
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: