---
# System prepended metadata

title: Core smart contracts

---

# Core smart contracts

The core of Tornado Cash logic is implemented in a set of smart contracts that are shown on below diagram.


```mermaid
classDiagram
    MerkleTreeWithHistory <|-- Tornado
    MerkleTreeWithHistory o-- Hasher
    ReentrancyGuard <|-- Tornado
    Tornado <|-- ETHTornado
    Tornado <|-- ERC20Tornado
    Tornado o-- Verifier

    class Hasher{
        +MiMCSponge()
    }
    class MerkleTreeWithHistory{
        +IHasher hasher
        +mapping filledSubtrees
        +mapping roots
        +hashLeftRight() bytes32
        +isKnownRoot() bool
        +getLastRoot() bytes32
        +zeros() bytes32
        ~_insert() uint32
    }
    class ReentrancyGuard{
        ~int sizeInFeet
        ~canEat()
    }
    class Verifier{
        +verifyProof() bool
    }
    class Tornado{
        +IVerifier verifier
        +uint256 denomination
        +mapping nullifierHashes
        +mapping commitments
        +deposit()
        +withdraw()
        +isSpent() bool
        +isSpentArray() bool[]
    }
    class ETHTornado{
        +IVerifier verifier
        +uint256 denomination
        +mapping nullifierHashes
        +mapping commitments
        +deposit()
        +withdraw()
        +isSpent() bool
        +isSpentArray() bool[]
    }
    class ERC20Tornado{
        +IVerifier verifier
        +uint256 denomination
        +mapping nullifierHashes
        +mapping commitments
        +IERC20 token
        +deposit()
        +withdraw()
        +isSpent() bool
        +isSpentArray() bool[]
    }

```

### MerkleTreeWithHistory contract
This is the contract that implements the Merkle tree functionality to be used in the basic Tornado Cash contract. The contract takes 2 parameters in its constructor:
- **levels**: the number of tree levels (should be less than 32)
- **hasher**: the reference to the Hasher contract defined by the IHasher interface

This contract provides several service functions that are used in Tornado contract:
- **hashLeftRight**: hashes 2 tree leaves (using hasher contract) and returns MiMC hash
- **isKnownRoot**: determines hether the root is present in the root history
- **getLastRoot**: returns the last root of the tree
- **zeros**: provides empty elements for a MiMC Merkle Tree up to 32 levels
- **_insert**: inserts the leaf element in the MErkle tree and returns its index


### ReentrancyGuard contract


### Verifier contract


### Tornado contract


### ETHTornado contract


### ERC20Tornado contract

sss


