Run checks
When proposing an action in a law, several validation checks are performed to ensure the action is valid and authorized. These checks are implemented in the checksAtPropose function.
Validation Process
1. Base Checks
The baseChecksAtPropose function in LawUtilities performs fundamental validations:
function baseChecksAtPropose(
ILaw.Conditions memory conditions,
bytes memory lawCalldata,
address powers,
uint256 nonce
) external viewParent Law Completion Check
Verifies if a parent law has been completed (if required)
Checks the state of the parent law's action
Reverts with
LawUtilities__ParentNotCompletedif parent law is not completed
Parent Law Block Check
Verifies if a parent law must not be completed
Checks the state of the parent law's action
Reverts with
LawUtilities__ParentBlocksCompletionif parent law is completed
2. Custom Checks
Laws can implement additional validation logic by overriding checksAtPropose:
Common custom checks include:
Role-based access control
Input parameter validation
State-dependent conditions
Time-based restrictions
Resource availability
Error Handling
The following errors may be thrown during proposal checks:
LawUtilities__ParentNotCompleted: Parent law has not been completedLawUtilities__ParentBlocksCompletion: Parent law is completed when it shouldn't beLawUtilities__StringTooShort: String parameter is too shortLawUtilities__StringTooLong: String parameter is too long
Best Practices
Comprehensive Validation
Validate all input parameters
Check all required conditions
Verify caller permissions
Ensure state consistency
Gas Optimization
Order checks from least to most expensive
Use early returns for invalid conditions
Cache frequently accessed values
Error Messages
Use clear and descriptive error messages
Include relevant context in errors
Follow consistent error naming
Security
Validate all external inputs
Check for reentrancy vulnerabilities
Verify caller permissions
Validate state transitions
Example Implementation
Last updated