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.

Layer 1: Entry Layer - User Interactions
PoolController
Deposits, withdrawals, ZK verification
MockWETH
Test token (faucet)
Layer 2: Strategy Layer - Fund Management
StrategyRouter
Multi-protocol routing
AaveAdapter
Lending strategy
LidoAdapter
Staking strategy
CompoundAdapter
Lending strategy
Layer 3: Verification Layer - Proofs and Commitments
Groth16Verifier
ZK proof verification
Groth16VerifierAdapter
Interface bridge
AIRecommendationCommitment
AI audit trail
Layer 4: Governance Layer - Policies and Constraints
DAOConstraintManager
Policy enforcement
AutoRebalancer
Automated execution

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

📥Receive

commitment + amount

Validate

Check uniqueness

💾Store

Mark commitment

🔀Route

Deploy to strategies

Withdrawal Flow

📝Receive

nullifier + proof

🔍Check

Nullifier unused

Verify

ZK proof valid

💸Transfer

Send to recipient

StrategyRouter

Manages the distribution of pool funds across multiple yield strategies. Maintains allocation weights and handles rebalancing.

Weight
aaveWeight
Basis Points
4000
Percentage
40%
Example ($100k pool)
$40,000 to Aave
Weight
lidoWeight
Basis Points
3500
Percentage
35%
Example ($100k pool)
$35,000 to Lido
Weight
compoundWeight
Basis Points
2500
Percentage
25%
Example ($100k pool)
$25,000 to Compound

Groth16Verifier

The on-chain verifier for Groth16 ZK-SNARK proofs. Generated by snarkjs from the trusted setup ceremony.

Precompile
ecAdd
Address
0x06
Operation
Point addition
Gas Cost
~500
Precompile
ecMul
Address
0x07
Operation
Scalar multiplication
Gas Cost
~6,000
Precompile
ecPairing
Address
0x08
Operation
Pairing check
Gas Cost
~45,000 + 34,000/pair
ℹ️
Verification Cost
Total verification costs approximately 200,000 gas. On L2s like Arbitrum or Base, this translates to ~$0.05-0.50 depending on network conditions.

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
PoolController
Modifier
onlyOwner
Who Can Call
DAO multisig
Functions
updateAllocationWeights, setVerifier
Contract
PoolController
Modifier
onlyAIService
Who Can Call
AI service address
Functions
updateAllocationWeightsWithAI
Contract
StrategyRouter
Modifier
onlyController
Who Can Call
PoolController
Functions
allocate, rebalance
Contract
AICommitment
Modifier
onlyAIService
Who Can Call
AI service address
Functions
commitRecommendation
Contract
DAOConstraintManager
Modifier
onlyGovernance
Who Can Call
Governance contract
Functions
setPolicy
⚠️
Upgrade Path
The current contracts are not upgradeable. For mainnet, consider using proxy patterns (UUPS or Transparent) to allow bug fixes without migration.