A blockchain-based reputation system built on Ethereum using Solidity and Foundry, enabling users to rate each other in a trustless, transparent manner.
This decentralized reputation system allows users to build and maintain reputation scores through peer-to-peer ratings. The system implements anti-gaming mechanisms, dispute resolution, and weighted scoring to ensure fair and reliable reputation tracking.
- Peer-to-Peer Rating: Users can rate each other on a configurable scale
- Weighted Reputation: Ratings from higher-reputation users carry more weight
- Anti-Gaming Protection: Cooldown periods, Sybil resistance, and rating limits
- Dispute Resolution: Built-in mechanism for challenging unfair ratings
- Reputation Decay: Time-based reputation decay to keep scores current
- Profile Management: User profiles with metadata and rating history
- Access Control: Role-based permissions for system administration
src/
βββ core/
β βββ ReputationRegistry.sol # Main reputation storage and calculation
β βββ RatingSystem.sol # Rating submission and validation
β βββ UserProfile.sol # User profile management
βββ governance/
β βββ AccessControl.sol # Role-based permissions
β βββ DisputeResolution.sol # Rating dispute handling
βββ token/
β βββ ReputationToken.sol # Optional tokenized reputation
βββ interfaces/
βββ IReputationRegistry.sol
βββ IRatingSystem.sol
βββ IUserProfile.sol
βββ IDisputeResolution.sol
- User Registration: Users register through
UserProfile.sol - Rating Submission: Ratings submitted via
RatingSystem.sol - Reputation Update:
RatingSystem.solcallsReputationRegistry.solto update scores - Dispute Process: Unfair ratings can be disputed through
DisputeResolution.sol
- Clone the repository:
git clone <repository-url>
cd build- Install Foundry dependencies:
forge install- Install additional dependencies:
forge install OpenZeppelin/openzeppelin-contracts
forge install foundry-rs/forge-stdCreate a .env file in the root directory:
# RPC URLs
ETHEREUM_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/your-key
GOERLI_RPC_URL=https://eth-goerli.g.alchemy.com/v2/your-key
SEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/your-key
# Private keys (for deployment)
PRIVATE_KEY=your-private-key
# Etherscan API (for verification)
ETHERSCAN_API_KEY=your-etherscan-api-key
# System Configuration
INITIAL_REPUTATION_SCORE=100
RATING_SCALE_MAX=5
RATING_COOLDOWN_PERIOD=86400 # 24 hours in seconds
REPUTATION_DECAY_RATE=1 # 1% per monthforge buildRun all tests:
forge testRun tests with gas reporting:
forge test --gas-reportRun specific test file:
forge test --match-path test/ReputationRegistry.t.solDeploy to local network:
anvil # Start local node
forge script script/Deploy.s.sol --rpc-url http://localhost:8545 --private-key $PRIVATE_KEY --broadcastDeploy to testnet:
forge script script/Deploy.s.sol --rpc-url $SEPOLIA_RPC_URL --private-key $PRIVATE_KEY --broadcast --verifyforge verify-contract <CONTRACT_ADDRESS> src/core/ReputationRegistry.sol:ReputationRegistry --etherscan-api-key $ETHERSCAN_API_KEY --chain sepoliaThe core contract managing reputation scores and calculations.
Key Functions:
getReputationScore(address user): Get current reputation scoreupdateReputation(address user, uint256 newRating, address rater): Update reputation (internal)calculateWeightedScore(address user): Calculate weighted reputation scoreapplyDecay(address user): Apply time-based reputation decay
Events:
ReputationUpdated(address indexed user, uint256 newScore, uint256 timestamp)ReputationDecayed(address indexed user, uint256 oldScore, uint256 newScore)
Manages user profiles and metadata.
Key Functions:
registerUser(string memory username, string memory metadata): Register new userupdateProfile(string memory metadata): Update user profilegetUserProfile(address user): Get user profile informationisRegistered(address user): Check if user is registered
Handles disputes over ratings.
Key Functions:
submitDispute(address rater, address ratee, string memory reason): Submit disputevoteOnDispute(uint256 disputeId, bool support): Vote on disputeresolveDispute(uint256 disputeId): Resolve disputegetDispute(uint256 disputeId): Get dispute details
Located in test/ directory:
ReputationRegistry.t.sol: Core reputation logic testsRatingSystem.t.sol: Rating submission and validation testsUserProfile.t.sol: Profile management testsDisputeResolution.t.sol: Dispute mechanism testsIntegration.t.sol: Cross-contract integration tests
- Functionality Tests: Verify core features work as expected
- Security Tests: Test access controls and attack vectors
- Gas Optimization Tests: Ensure efficient gas usage
- Edge Case Tests: Handle boundary conditions and errors
- Integration Tests: Test contract interactions
# Security tests
forge test --match-test testSecurity
# Gas optimization tests
forge test --gas-report --match-test testGas
# Integration tests
forge test --match-path test/Integration.t.sol- Cooldown Periods: Prevent spam ratings
- Rating Limits: Limit number of ratings per user per time period
- Weighted Scoring: Higher reputation users have more influence
- Sybil Resistance: Minimum reputation threshold for meaningful ratings
- Admin Role: Contract deployment and emergency functions
- Moderator Role: Dispute resolution and content moderation
- User Role: Standard user functions
- Sybil Attacks: Mitigated through reputation weighting and minimum thresholds
- Collusion: Monitoring and dispute mechanisms help detect coordinated attacks
- Rating Manipulation: Cooldowns and limits reduce manipulation potential
- Front-running: Consider commit-reveal schemes for sensitive operations
- Packed Structs: Optimize storage layout
- Batch Operations: Process multiple ratings in single transaction
- Event Indexing: Use indexed parameters efficiently
- Storage vs Memory: Optimize variable declarations
| Function | Estimated Gas |
|---|---|
| Register User | ~50,000 |
| Submit Rating | ~80,000 |
| Update Reputation | ~45,000 |
| Submit Dispute | ~120,000 |
- Framework: Next.js with TypeScript
- Web3 Library: Wagmi + Viem
- Wallet Connection: RainbowKit or ConnectKit
- State Management: Zustand or React Context
import { useContractWrite, useContractRead } from 'wagmi'
import { ReputationRegistryABI } from './abis/ReputationRegistry'
// Read reputation score
const { data: reputationScore } = useContractRead({
address: REPUTATION_REGISTRY_ADDRESS,
abi: ReputationRegistryABI,
functionName: 'getReputationScore',
args: [userAddress],
})
// Submit rating
const { write: submitRating } = useContractWrite({
address: RATING_SYSTEM_ADDRESS,
abi: RatingSystemABI,
functionName: 'submitRating',
})- ReputationRegistry:
0x... - RatingSystem:
0x... - UserProfile:
0x... - DisputeResolution:
0x...
- ReputationRegistry:
0x... - RatingSystem:
0x... - UserProfile:
0x... - DisputeResolution:
0x...
Coming soon...
All contracts emit events for off-chain tracking and frontend updates. See individual contract documentation for complete event specifications.
Common error codes across contracts:
UnauthorizedAccess(): Caller lacks required permissionsInvalidRating(): Rating value out of boundsCooldownPeriodActive(): Must wait before rating againUserNotRegistered(): User must register before participatingDisputeNotFound(): Referenced dispute doesn't exist
- Fork the repository
- Create a feature branch
- Write tests for new functionality
- Implement the feature
- Run full test suite
- Submit pull request
- Follow Solidity style guide
- Use NatSpec documentation
- Include comprehensive tests
- Optimize for gas efficiency
Use conventional commits:
feat:New featuresfix:Bug fixesdocs:Documentation changestest:Test additions/modificationsrefactor:Code refactoring
MIT License - see LICENSE file for details.
For questions and support:
- Open an issue on GitHub
- Join our Discord community
- Check the documentation wiki
- β Core reputation system
- β Basic rating functionality
- β User profiles
- π Dispute resolution
- π― Advanced anti-gaming mechanisms
- π― Reputation token integration
- π― Frontend application
- π― Mobile app support
- π― Cross-chain reputation
- π― Integration APIs
- π― Governance features
- π― Analytics dashboard
Built with β€οΈ using Foundry and Solidity