Overview
The TornadoPool contract is the main contract that enables private transactions on Layer 2. It allows deposits of arbitrary amounts, shielded transfers between registered users, and withdrawals. The contract uses a UTXO (Unspent Transaction Output) model to manage user funds privately. Contract Location:contracts/TornadoPool.sol
Constants
Maximum external amount value:
2^248Maximum fee value:
2^248Minimum external amount limit:
0.5 etherState Variables
Immutable address of the SNARK verifier for 2 inputs
Immutable address of the SNARK verifier for 16 inputs
Immutable address of the ERC20 token used by this pool
Immutable address of the OmniBridge contract for cross-chain functionality
Immutable address of the L1Unwrapper contract
Immutable address of the multisig governance contract
Last recorded token balance of the contract
Maximum amount that can be deposited in a single transaction
Mapping to track spent nullifiers to prevent double-spending
Constructor
The address of SNARK verifier for 2 inputs
The address of SNARK verifier for 16 inputs
Height of the commitments merkle tree
Hasher address for the merkle tree (Poseidon hash)
Token address for the pool
OmniBridge address for the specified token
Address of the L1Helper contract
Owner address for governance
Chain ID of L1
Multisig address on L2
Public Functions
initialize
Maximum amount that can be deposited per transaction
contracts/TornadoPool.sol:112
transact
Proof structure containing ZK proof and transaction data
External data structure containing recipient, amounts, fees, and encrypted outputs
- For deposits (extAmount > 0): Amount must be transferred from sender and not exceed maximumDepositAmount
- Valid merkle root
- Nullifiers not already spent
- Valid external data hash
- Valid public amount calculation
- Valid ZK proof
contracts/TornadoPool.sol:119
register
Account structure containing owner address and public key
- Account owner must be msg.sender
contracts/TornadoPool.sol:129
registerAndTransact
Account structure containing owner address and public key
Proof structure containing ZK proof and transaction data
External data structure containing recipient, amounts, fees, and encrypted outputs
contracts/TornadoPool.sol:134
onTokenBridged
Token contract address (must match pool token)
Amount of tokens bridged
Encoded Proof and ExtData for the transaction
- Only callable by omniBridge
- Token must match pool token
- Amount must match extData.extAmount
- Bridge must send sufficient tokens
- Amount must not exceed maximumDepositAmount
contracts/TornadoPool.sol:143
onTransact
Proof structure containing ZK proof and transaction data
External data structure
contracts/TornadoPool.sol:163
rescueTokens
Token contract to rescue (address(0) for ETH)
Recipient address
Amount to rescue (0 for full balance)
- Only callable by multisig
- Cannot rescue pool token
- Cannot send to zero address
contracts/TornadoPool.sol:169
configureLimits
New maximum deposit amount
contracts/TornadoPool.sol:191
calculatePublicAmount
External amount (positive for deposits, negative for withdrawals)
Relayer fee
- Fee must be less than MAX_FEE
- extAmount must be within valid range
contracts/TornadoPool.sol:195
isSpent
Nullifier hash to check
true if the nullifier has been spent, false otherwise
Source: contracts/TornadoPool.sol:203
verifyProof
Proof structure to verify
true if the proof is valid, false otherwise
Requirements:
- Input nullifiers length must be 2 or 16
contracts/TornadoPool.sol:207
Inherited Functions
TornadoPool inherits from:MerkleTreeWithHistory- Provides merkle tree functionalityIERC20Receiver- Token bridge receiver interfaceReentrancyGuard- Protection against reentrancy attacksCrossChainGuard- Cross-chain message verification
isKnownRoot() from MerkleTreeWithHistory.