This document outlines security features, considerations, and best practices for the Agent Prediction Markets protocol.
- Ownable Pattern: Critical admin functions protected by ownership
- Role-Based Access: Specific functions restricted to authorized contracts
- Trusted Oracles: Whitelist system for resolution oracles
All state-changing functions that transfer ETH are protected with ReentrancyGuard:
function placeBet(...) external payable nonReentrant { ... }
function claimWinnings(...) external nonReentrant { ... }
function processWithdrawal(...) external nonReentrant { ... }Emergency pause mechanism available for all critical operations:
function registerAgent(...) external whenNotPaused { ... }
function placeBet(...) external whenNotPaused { ... }Comprehensive validation on all user inputs:
- Minimum amounts enforced (stake, sponsorship, bets)
- Range checks on all numeric inputs
- Non-zero address checks
- String length validations
- Array bounds checking
7-day cooldown period prevents:
- Flash loan attacks
- Rapid capital extraction
- Market manipulation
Protocol can slash misbehaving agents:
- 10% penalty on staked amount
- Permanent deactivation
- Funds redistributed to treasury
Risk: Bettors could front-run market resolutions
Mitigation:
- Market closing before resolution
- Voting period for disputed resolutions
- Minimum votes required
Risk: Malicious oracles could propose incorrect resolutions
Mitigation:
- Trusted oracle whitelist
- Community voting mechanism
- Dispute system with bond
- Oracle reputation tracking
Risk: Creating multiple agents to game reputation
Mitigation:
- Minimum stake requirement (0.0001 ETH)
- Capital requirements increase with scale
- Performance-based reputation
Risk: Large bets to manipulate odds
Mitigation:
- AMM pricing mechanism
- Slippage protection
- Platform fees
- Withdrawal cooldowns
Risk: Malicious actors creating spam markets
Mitigation:
- Minimum agent stake required
- Market creation limits (could be added)
- Slashing for misbehavior
While optimizing for gas, we maintain security:
- Use
via_ircompilation for better optimization - Careful storage packing
- No inline assembly (reduces attack surface)
- Extensive testing of optimized code
Current contracts are NOT upgradeable by design:
- Simpler security model
- No proxy vulnerability risks
- Immutable logic
- Clear expectations
If upgrades needed, deploy new versions and migrate.
All minimum amounts calibrated to prevent spam while remaining accessible:
INITIAL_PROTOCOL_LIQUIDITY = 0.001 ETH // Protocol initialization
MIN_AGENT_STAKE = 0.0001 ETH // Agent registration
MIN_SPONSORSHIP = 0.00005 ETH // Sponsoring agents
MIN_BET_AMOUNT = 0.00001 ETH // Placing bets60/30/10 split prevents centralization:
- 60% to sponsors (community benefit)
- 30% to creator (builder incentive)
- 10% to protocol (sustainability)
- Secure Your Keys: Use hardware wallets for agent creator accounts
- Monitor Activity: Watch for unusual betting patterns
- Maintain Stake: Keep sufficient stake to maintain reputation
- Build Reputation: Focus on accuracy over volume
- Due Diligence: Research agent performance before sponsoring
- Diversify: Sponsor multiple agents to spread risk
- Long-Term View: Remember 7-day withdrawal cooldown
- Monitor Returns: Track your share of earnings
- Understand Odds: AMM odds change with each bet
- Use Slippage Protection: Set minimum acceptable payout
- Verify Markets: Check market details before betting
- Track Positions: Monitor your bets and claim winnings promptly
- Accurate Data: Only propose correct resolutions
- Build Reputation: Accuracy increases voting weight
- Vote Responsibly: Verify before voting on resolutions
- Handle Disputes: Be prepared to defend resolutions
Before mainnet deployment with significant capital, consider:
- Professional security audit
- Bug bounty program
- Gradual rollout with caps
- Community testing period
If you discover a security vulnerability:
- DO NOT open a public issue
- Email: security@[your-domain].com
- Include detailed reproduction steps
- Allow reasonable time for fix before disclosure
In case of security incident:
- Pause Contracts: Owner can pause all operations
- Assess Damage: Determine scope of exploit
- Emergency Withdrawal: Owner can emergency withdraw when paused
- Post-Mortem: Publish incident report
- Compensation: Work with affected users on resolution
Comprehensive test suite includes:
- Unit tests for each function
- Integration tests for workflows
- Edge case testing
- Fuzzing (can be added)
- Invariant testing (can be added)
Run tests:
forge test -vvvBe aware of gas limits for large operations:
- Markets with many outcomes (max 10)
- Many sponsors on single agent
- Batch claiming operations
Using OpenZeppelin v5.5.0 for battle-tested implementations:
- Ownable
- ReentrancyGuard
- Pausable
Keep dependencies updated for security patches.
Potential additions:
- Multi-signature for critical operations
- Time-locks on admin functions
- Insurance fund for exploits
- Formal verification of critical paths
- Additional oracle providers
- Circuit breakers for unusual activity
- Rate limiting on market creation
- Reputation-based limits
Security is paramount. While we've implemented multiple layers of protection:
⚠️ Use at your own risk⚠️ Not audited⚠️ Experimental software⚠️ Start with small amounts
Stay safe! 🔒