@@ -3,41 +3,45 @@ pragma solidity 0.8.27;
33
44import {IAdvancedChecker, Check} from "./interfaces/IAdvancedChecker.sol " ;
55
6+ /// @notice Tracks validation status for pre, main, and post checks.
7+ /// @dev Used to maintain check state in AdvancedPolicy.
68struct CheckStatus {
9+ /// @dev Pre-check completion status.
710 bool pre;
11+ /// @dev Number of completed main checks.
812 uint8 main;
13+ /// @dev Post-check completion status.
914 bool post;
1015}
1116
1217/// @title AdvancedChecker.
13- /// @notice Abstract base contract which can be extended to implement a specific `AdvancedChecker`.
14- /// @dev The `AdvancedChecker` contract builds upon the `BaseChecker` by introducing additional validation phases.
15- /// It allows for pre-condition (`PRE`), main (`MAIN`), and post-condition (`POST`) checks, with the option to skip
16- /// pre and post checks based on constructor parameters. The `_check` method orchestrates the validation process
17- /// based on the specified check type.
18+ /// @notice Multi-phase validation checker with pre, main, and post checks.
19+ /// @dev Base contract for implementing complex validation logic with configurable check phases.
1820abstract contract AdvancedChecker is IAdvancedChecker {
19- /// @notice Flag to determine if pre-condition checks should be skipped .
21+ /// @notice Controls whether pre-condition checks are required .
2022 bool public immutable SKIP_PRE;
2123
22- /// @notice Flag to determine if post-condition checks should be skipped .
24+ /// @notice Controls whether post-condition checks are required .
2325 bool public immutable SKIP_POST;
2426
25- /// @notice Flag to determine if main checks can be executed multiple times.
27+ /// @notice Controls whether main check can be executed multiple times.
2628 bool public immutable ALLOW_MULTIPLE_MAIN;
2729
28- /// @param _skipPre Indicates whether to skip pre-condition checks.
29- /// @param _skipPost Indicates whether to skip post-condition checks.
30- /// @param _allowMultipleMain Indicates whether the main check can be executed multiple times.
30+ /// @notice Sets up checker configuration.
31+ /// @param _skipPre Skip pre-condition validation.
32+ /// @param _skipPost Skip post-condition validation.
33+ /// @param _allowMultipleMain Allow multiple main validations.
3134 constructor (bool _skipPre , bool _skipPost , bool _allowMultipleMain ) {
3235 SKIP_PRE = _skipPre;
3336 SKIP_POST = _skipPost;
3437 ALLOW_MULTIPLE_MAIN = _allowMultipleMain;
3538 }
3639
37- /// @notice Public method to check the validity of the provided evidence for a given address and check type.
38- /// @param subject The address to be checked.
39- /// @param evidence The evidence associated with the check.
40- /// @param checkType The type of check to perform (PRE, MAIN, POST).
40+ /// @notice Entry point for validation checks.
41+ /// @param subject Address to validate.
42+ /// @param evidence Validation data.
43+ /// @param checkType Type of check (PRE, MAIN, POST).
44+ /// @return checked Validation result.
4145 function check (
4246 address subject ,
4347 bytes memory evidence ,
@@ -46,37 +50,46 @@ abstract contract AdvancedChecker is IAdvancedChecker {
4650 return _check (subject, evidence, checkType);
4751 }
4852
49- /// @notice Internal method to orchestrate the validation process based on the specified check type.
50- /// @param subject The address to be checked.
51- /// @param evidence The evidence associated with the check.
52- /// @param checkType The type of check to perform (PRE, MAIN, POST).
53+ /// @notice Core validation logic router.
54+ /// @dev Directs to appropriate check based on type and configuration.
55+ /// @param subject Address to validate.
56+ /// @param evidence Validation data.
57+ /// @param checkType Check type to perform.
58+ /// @return checked Validation result.
59+ /// @custom:throws PreCheckSkipped If PRE check attempted when skipped.
60+ /// @custom:throws PostCheckSkipped If POST check attempted when skipped.
5361 function _check (address subject , bytes memory evidence , Check checkType ) internal view returns (bool checked ) {
54- if (SKIP_PRE && checkType == Check.PRE) revert PreCheckSkipped ();
55- if (SKIP_POST && checkType == Check.POST) revert PostCheckSkipped ();
62+ // Validate skip conditions first.
63+ if (checkType == Check.PRE && SKIP_PRE) revert PreCheckSkipped ();
64+ if (checkType == Check.POST && SKIP_POST) revert PostCheckSkipped ();
5665
57- if (! SKIP_PRE && checkType == Check.PRE) {
58- return _checkPre (subject, evidence);
59- }
60-
61- if (! SKIP_POST && checkType == Check.POST) {
62- return _checkPost (subject, evidence);
63- }
64-
65- return _checkMain (subject, evidence);
66+ // Route to appropriate check.
67+ return
68+ checkType == Check.PRE
69+ ? _checkPre (subject, evidence)
70+ : checkType == Check.POST
71+ ? _checkPost (subject, evidence)
72+ : _checkMain (subject, evidence);
6673 }
6774
68- /// @notice Internal method for performing pre-condition checks.
69- /// @param subject The address to be checked.
70- /// @param evidence The evidence associated with the check.
75+ /// @notice Pre-condition validation implementation.
76+ /// @dev Override to implement pre-check logic.
77+ /// @param subject Address to validate.
78+ /// @param evidence Validation data.
79+ /// @return checked Validation result.
7180 function _checkPre (address subject , bytes memory evidence ) internal view virtual returns (bool checked ) {}
7281
73- /// @notice Internal method for performing main checks.
74- /// @param subject The address to be checked.
75- /// @param evidence The evidence associated with the check.
82+ /// @notice Main validation implementation.
83+ /// @dev Override to implement main check logic.
84+ /// @param subject Address to validate.
85+ /// @param evidence Validation data.
86+ /// @return checked Validation result.
7687 function _checkMain (address subject , bytes memory evidence ) internal view virtual returns (bool checked ) {}
7788
78- /// @notice Internal method for performing post-condition checks.
79- /// @param subject The address to be checked.
80- /// @param evidence The evidence associated with the check.
89+ /// @notice Post-condition validation implementation.
90+ /// @dev Override to implement post-check logic.
91+ /// @param subject Address to validate.
92+ /// @param evidence Validation data.
93+ /// @return checked Validation result.
8194 function _checkPost (address subject , bytes memory evidence ) internal view virtual returns (bool checked ) {}
8295}
0 commit comments