Overview
TheValidation abstract contract provides input validation logic for DAO creation in the Agora ecosystem. It ensures that DAO names, descriptions, and categories meet specific requirements before a DAO is deployed, preventing invalid or malicious data from being stored on-chain.
Contract: AgoraDaoFactory/Validation.solType: Abstract Contract
Inherited By:
AgoraDaoFactory
Purpose
The Validation contract serves as a security and data quality layer that:- Validates string length constraints for names and descriptions
- Ensures required fields are not empty
- Validates category IDs against available categories
- Prevents gas waste from excessively long strings
Functions
_createDao
Internal validation function called before creating a new DAO.The proposed name for the DAO
The proposed description for the DAO
Index of the selected category in the _daoCategories array
Array of available DAO categories (passed from factory state)
Validation Rules
Name Requirements
Rule: Must be at least 1 byte
Error: “Dao name must not be empty”
Reason: Ensures every DAO has an identifiable name
Error: “Dao name must not be empty”
Reason: Ensures every DAO has an identifiable name
Rule: Must not exceed 50 bytes
Error: “The name of the DAO is very long”
Reason: Prevents excessive gas costs and ensures UI compatibility
Error: “The name of the DAO is very long”
Reason: Prevents excessive gas costs and ensures UI compatibility
Description Requirements
Rule: Must be at least 1 byte
Error: “DAO description must not be empty”
Reason: Requires DAOs to provide context about their purpose
Error: “DAO description must not be empty”
Reason: Requires DAOs to provide context about their purpose
Rule: Must not exceed 500 bytes
Error: “The description of the DAO is very long”
Reason: Balances detailed descriptions with gas efficiency
Error: “The description of the DAO is very long”
Reason: Balances detailed descriptions with gas efficiency
Category Validation
Rule: Category ID must be a valid index in the categories array
Error: “Invalid category ID.”
Reason: Ensures the DAO is assigned to an existing, valid category
Error: “Invalid category ID.”
Reason: Ensures the DAO is assigned to an existing, valid category
Usage in AgoraDaoFactory
The validation function is called at the beginning ofAgoraDaoFactory.createDao():
Error Handling
All validation errors cause the transaction to revert with descriptive error messages:| Error Message | Cause | Solution |
|---|---|---|
| ”Dao name must not be empty” | Empty name string | Provide a name with at least 1 character |
| ”The name of the DAO is very long” | Name exceeds 50 bytes | Shorten the name to 50 bytes or less |
| ”DAO description must not be empty” | Empty description string | Provide a description with at least 1 character |
| ”The description of the DAO is very long” | Description exceeds 500 bytes | Shorten the description to 500 bytes or less |
| ”Invalid category ID.” | Category ID out of bounds | Use a valid category index (0 to categories.length - 1) |
Validation Examples
Valid DAO Creation
Invalid Examples
Gas Considerations
Why Length Limits Matter
- Storage Costs: Longer strings cost more gas to store on-chain
- Read Costs: Retrieving long strings from storage is expensive
- Array Operations: When returning all DAOs, long strings increase gas costs
- UI Performance: Reasonable limits ensure smooth frontend rendering
Byte Length vs Character Count
Important: The validation usesbytes().length, not character count. This means:
Future Improvements
The contract includes a TODO comment indicating potential future enhancements:- Challenge: Checking uniqueness requires iterating through all existing DAO names
- Gas Concern: This operation becomes increasingly expensive as more DAOs are created
- Potential Solutions:
- Off-chain name verification before transaction
- Name hash mapping for O(1) lookups
- Allow duplicates but add DAO ID to distinguish
Testing Validation
Integration with Factory
The validation contract is designed as an abstract contract inherited by AgoraDaoFactory:- Separates validation logic from business logic
- Makes validation rules easy to test in isolation
- Allows validation to be extended or overridden in child contracts
- Keeps the factory contract focused on DAO creation and management