Overview
The ZKScore Score Calculator is a sophisticated smart contract that computes on-chain reputation scores based on eight distinct categories: DeFi, NFT, Social, Trading, Governance, Gaming, Identity, and Trust. The contract aggregates data from various on-chain sources and applies weighted algorithms to generate comprehensive ZKScores.Contract Architecture
Core Components
The Score Calculator consists of several key components:- Category Calculators: Specialized modules for each of the 8 scoring categories
- Weight Management: Dynamic weighting system for category importance
- Data Aggregation: On-chain data collection and validation
- Score Computation: Algorithm for combining category scores
- Cache System: Efficient score storage and retrieval
Scoring Categories
1. DeFi Score (Weight: 20%)
Evaluates decentralized finance activity:- Liquidity provision
- Lending/borrowing history
- Protocol participation
- Transaction volume
- Portfolio diversity
2. NFT Score (Weight: 15%)
Measures NFT ecosystem engagement:- Collection ownership
- Trading frequency
- Rarity score
- Creator support
- Community participation
3. Social Score (Weight: 10%)
Assesses social platform activity:- Profile completeness
- Content creation
- Community engagement
- Follower quality
- Reputation signals
4. Trading Score (Weight: 20%)
Evaluates trading performance:- Trade volume
- Success rate
- Risk management
- Protocol diversity
- Market timing
5. Governance Score (Weight: 10%)
Measures governance participation:- Proposal voting
- Delegation activity
- Forum participation
- Proposal creation
- Voting power
6. Gaming Score (Weight: 10%)
Tracks gaming achievements:- Games played
- Achievements earned
- Leaderboard rankings
- Tournament participation
- In-game assets
7. Identity Score (Weight: 10%)
Validates identity strength:- Verification level
- Account age
- Cross-platform links
- ENS/ZKS ID ownership
- Attestations received
8. Trust Score (Weight: 5%)
Evaluates trustworthiness:- Attestations given/received
- Reputation signals
- Dispute history
- Community feedback
- Trust modules passed
Contract Addresses
Mainnet Deployments
Testnet Deployments
Scoring Algorithm
Overall Score Calculation
The total ZKScore is calculated using a weighted average of all category scores:Score Normalization
All category scores are normalized to a 0-1000 scale:Score Components
Each category score is composed of multiple sub-metrics:Contract Interface
Core Functions
Events
Data Sources
On-Chain Data Collection
The Score Calculator collects data from multiple on-chain sources:Score Updates
Automatic Updates
Scores are automatically updated when:- User performs qualifying on-chain action
- Scheduled batch update runs (every 24 hours)
- User requests manual refresh
- Category weight changes occur
Manual Updates
Users can manually trigger score updates:Update Costs
| Update Type | Gas Cost | Frequency |
|---|---|---|
| Automatic Update | ~200,000 | Per qualifying action |
| Manual Refresh | ~250,000 | User-initiated |
| Batch Update | ~150,000/user | Every 24 hours |
| Category Update | ~50,000 | Per category change |
Gas Optimization
Caching Strategy
The contract implements efficient caching to minimize gas costs:Batch Operations
For efficiency, the contract supports batch score calculations:Access Control
Roles
Permission Matrix
| Operation | CALCULATOR_ROLE | UPDATER_ROLE | ADMIN_ROLE | Public |
|---|---|---|---|---|
| Calculate Score | ✅ | ✅ | ✅ | ✅ |
| Update Category Score | ✅ | ❌ | ✅ | ❌ |
| Update Weights | ❌ | ❌ | ✅ | ❌ |
| Refresh Score | ❌ | ✅ | ✅ | ✅ (own) |
| View Score | ✅ | ✅ | ✅ | ✅ |
Integration Examples
Basic Score Query
Score Update
Security Considerations
Data Validation
All input data is validated before processing:Reentrancy Protection
All external calls are protected against reentrancy:Best Practices
For Developers
- Cache Scores: Cache scores locally to minimize gas costs
- Batch Queries: Use batch functions when querying multiple users
- Monitor Events: Listen for score update events
- Validate Input: Always validate user addresses before queries
- Handle Errors: Implement comprehensive error handling
For Users
- Update Regularly: Keep scores updated for accuracy
- Understand Categories: Know how each category contributes
- Monitor Changes: Track score changes over time
- Optimize Activity: Focus on high-weight categories
- Verify Data: Cross-check scores with on-chain data
Related Documentation
- Functions Reference - Complete function documentation
- Events Reference - Event documentation
- Integration Guide - Integration examples
- Identity SBT - Identity contract documentation