Skip to content

Commit

Permalink
refactor(contracts): make advanced policy flags immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
0xjei committed Nov 29, 2024
1 parent 1c2416d commit cad1311
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions packages/contracts/contracts/src/AdvancedChecker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ struct CheckStatus {
/// based on the specified check type.
abstract contract AdvancedChecker is IAdvancedChecker {
/// @notice Flag to determine if pre-condition checks should be skipped.
bool public skipPre;
bool public immutable SKIP_PRE;

/// @notice Flag to determine if post-condition checks should be skipped.
bool public skipPost;
bool public immutable SKIP_POST;

/// @notice Flag to determine if main checks can be executed multiple times.
bool public allowMultipleMain;
bool public immutable ALLOW_MULTIPLE_MAIN;

/// @param _skipPre Indicates whether to skip pre-condition checks.
/// @param _skipPost Indicates whether to skip post-condition checks.
/// @param _allowMultipleMain Indicates whether the main check can be executed multiple times.
constructor(bool _skipPre, bool _skipPost, bool _allowMultipleMain) {
skipPre = _skipPre;
skipPost = _skipPost;
allowMultipleMain = _allowMultipleMain;
SKIP_PRE = _skipPre;
SKIP_POST = _skipPost;
ALLOW_MULTIPLE_MAIN = _allowMultipleMain;
}

/// @notice Public method to check the validity of the provided evidence for a given address and check type.
Expand All @@ -51,14 +51,14 @@ abstract contract AdvancedChecker is IAdvancedChecker {
/// @param evidence The evidence associated with the check.
/// @param checkType The type of check to perform (PRE, MAIN, POST).
function _check(address subject, bytes memory evidence, Check checkType) internal view returns (bool checked) {
if (skipPre && checkType == Check.PRE) revert PreCheckSkipped();
if (skipPost && checkType == Check.POST) revert PostCheckSkipped();
if (SKIP_PRE && checkType == Check.PRE) revert PreCheckSkipped();
if (SKIP_POST && checkType == Check.POST) revert PostCheckSkipped();

if (!skipPre && checkType == Check.PRE) {
if (!SKIP_PRE && checkType == Check.PRE) {
return _checkPre(subject, evidence);
}

if (!skipPost && checkType == Check.POST) {
if (!SKIP_POST && checkType == Check.POST) {
return _checkPost(subject, evidence);
}

Expand Down
8 changes: 4 additions & 4 deletions packages/contracts/contracts/src/AdvancedPolicy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ abstract contract AdvancedPolicy is IAdvancedPolicy, Policy {
}

if (checkType == Check.PRE) {
if (!ADVANCED_CHECKER.skipPost() && enforced[msg.sender][subject].pre) {
if (!ADVANCED_CHECKER.SKIP_POST() && enforced[msg.sender][subject].pre) {
revert AlreadyEnforced();
} else {
enforced[msg.sender][subject].pre = true;
Expand All @@ -52,7 +52,7 @@ abstract contract AdvancedPolicy is IAdvancedPolicy, Policy {
if (enforced[msg.sender][subject].post) {
revert AlreadyEnforced();
} else {
if (!ADVANCED_CHECKER.skipPre() && !enforced[msg.sender][subject].pre) {
if (!ADVANCED_CHECKER.SKIP_PRE() && !enforced[msg.sender][subject].pre) {
revert PreCheckNotEnforced();
} else {
if (enforced[msg.sender][subject].main == 0) {
Expand All @@ -65,12 +65,12 @@ abstract contract AdvancedPolicy is IAdvancedPolicy, Policy {
} else {
if (
checkType == Check.MAIN &&
!ADVANCED_CHECKER.allowMultipleMain() &&
!ADVANCED_CHECKER.ALLOW_MULTIPLE_MAIN() &&
enforced[msg.sender][subject].main > 0
) {
revert MainCheckAlreadyEnforced();
} else {
if (checkType == Check.MAIN && !ADVANCED_CHECKER.skipPre() && !enforced[msg.sender][subject].pre) {
if (checkType == Check.MAIN && !ADVANCED_CHECKER.SKIP_PRE() && !enforced[msg.sender][subject].pre) {
revert PreCheckNotEnforced();
} else {
enforced[msg.sender][subject].main += 1;
Expand Down

0 comments on commit cad1311

Please sign in to comment.