Smart Contract Architecture
Deep dive into the contract structure, state management, and interaction patterns.
System Overview
The smart contract system is organized into four layers, each with specific responsibilities.
PoolController
The main entry point for user interactions. Manages the privacy pool commitments and nullifiers, and coordinates with the verifier for proof validation.
Deposit Flow
commitment + amount
Check uniqueness
Mark commitment
Deploy to strategies
commitment + amount
Check uniqueness
Mark commitment
Deploy to strategies
Withdrawal Flow
nullifier + proof
Nullifier unused
ZK proof valid
Send to recipient
nullifier + proof
Nullifier unused
ZK proof valid
Send to recipient
StrategyRouter
Manages the distribution of pool funds across multiple yield strategies. Maintains allocation weights and handles rebalancing.
| Weight | Basis Points | Percentage | Example ($100k pool) |
|---|---|---|---|
| aaveWeight | 4000 | 40% | $40,000 to Aave |
| lidoWeight | 3500 | 35% | $35,000 to Lido |
| compoundWeight | 2500 | 25% | $25,000 to Compound |
Groth16Verifier
The on-chain verifier for Groth16 ZK-SNARK proofs. Generated by snarkjs from the trusted setup ceremony.
| Precompile | Address | Operation | Gas Cost |
|---|---|---|---|
| ecAdd | 0x06 | Point addition | ~500 |
| ecMul | 0x07 | Scalar multiplication | ~6,000 |
| ecPairing | 0x08 | Pairing check | ~45,000 + 34,000/pair |
AIRecommendationCommitment
Implements the commit-reveal pattern for verifiable AI. Stores commitments before execution and verifies them during allocation updates.
The commitment hash is computed as: keccak256(aaveAlloc, lidoAlloc, compoundAlloc, reason, timestamp)
Access Control
Each contract has specific access controls to prevent unauthorized operations:
| Contract | Modifier | Who Can Call | Functions |
|---|---|---|---|
| PoolController | onlyOwner | DAO multisig | updateAllocationWeights, setVerifier |
| PoolController | onlyAIService | AI service address | updateAllocationWeightsWithAI |
| StrategyRouter | onlyController | PoolController | allocate, rebalance |
| AICommitment | onlyAIService | AI service address | commitRecommendation |
| DAOConstraintManager | onlyGovernance | Governance contract | setPolicy |