How tornadocash/tornado-core works
Main Components
• Smart Contracts & Blockchain Layer: Represented by the “contracts” folder (with multiple contract types, including mock contracts and contracts for ETH/erc20 tornado applications) along with “migrations” and “truffle-config.js” that manage deployment.
• Zero-Knowledge Circuits: Found in the “circuits” directory (e.g., merkleTree.circom and withdraw.circom), along with related build and trusted setup scripts in the “scripts” folder and even commands in the README to emulate an MPC trusted setup ceremony.
• Application/CLI and Frontend: The “src” folder contains CLI functionality (cli.js and minimal-demo.js) and the “index.html” file indicates a browser interface. These components allow users to interact with the Tornado Cash solution either via command line or via a web-based interface.
• Supporting Scripts and Configuration: This includes various build, compile, and utility scripts in “scripts” (like compileHasher.js, ganacheHelper.js) plus configuration files (.env.example, .nvmrc, prettier, eslint, etc.) which set up the development and build environments.
• Testing and Development Environment: Notably, the “test” folder houses tests for ERC20, ETH, and Merkle trees. A local blockchain simulation (via ganache-cli) is used as indicated by instructions in the README.
• External Services & Deployment Tools: The README also walks through using Infura RPC endpoints, relayer services, and external block explorers (Etherscan) for transaction verification. There is also integration with GitHub Actions (via .github/workflows) for CI/CD.
Relationships and Interactions
• zkSNARK Circuit Interaction: From the CLI or a dedicated module, illustrate how data flows to the zkSNARK proving system. The circuits (in the “circuits” folder) take inputs (e.g., user secrets and deposit commitments) and produce a proof which is then submitted.
• Deployment and Testing: Show how the “migrations” and “scripts” interact with the blockchain environment (local Ganache or public networks such as Kovan/Mainnet) using Truffle. Indicate directions of deployment commands launching from the developer machine to the network.
• External Trusted Setup & Relayer Service: In a sidebar or additional component, include elements for the trusted setup ceremony (using zkutil and circom commands) and the relayer service used during withdrawal (as described in the README example).
Architectural Patterns and Design Principles
• Layer Separation: Clearly separate blockchain (smart contracts), off-chain computation (zkSNARK generation and trusted setup), and user interaction layers (CLI/browser).
• Modular Design: Note how circuits, smart contracts, and the application logic are encapsulated in separate directories, following a modular approach.
• CI/CD Integration: Include an element for automated testing/build (via GitHub workflows) – even if it’s not core to the runtime, it’s essential for maintenance and quality assurance.
Relevant Technologies and Frameworks
• Ethereum Smart Contracts (Solidity)
• zkSNARK circuits using circom and websnark library
• Truffle for deployments and migrations
• Node.js for scripting and CLI functions
• Testing frameworks (likely using Mocha/Chai or similar via yarn/npm test)
• Optionally, external services like Infura for RPC endpoints and Etherscan for transaction verification