Skip to content

Commit

Permalink
fix: Missing rule selector validation on primitives added
Browse files Browse the repository at this point in the history
  • Loading branch information
donosonaumczuk committed Jan 9, 2025
1 parent 20139fd commit 8eab952
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions contracts/core/base/RuleBasedPrimitive.sol
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ abstract contract RuleBasedPrimitive {
);
}
for (uint256 j = 0; j < ruleChange.selectorChanges.length; j++) {
_validateIsSupportedRuleSelector(
ruleChange.selectorChanges[j].ruleSelector,
entityId == 0 ? _supportedPrimitiveRuleSelectors() : _supportedEntityRuleSelectors()
);
rulesStorage._changeRulesSelectors(
ruleChanges[i].ruleAddress,
ruleChange.configSalt,
Expand All @@ -190,6 +194,18 @@ abstract contract RuleBasedPrimitive {
return new bytes4[](0);
}

function _validateIsSupportedRuleSelector(bytes4 ruleSelectorToValidate, bytes4[] memory supportedRuleSelectors)
internal
pure
{
for (uint256 i = 0; i < supportedRuleSelectors.length; i++) {
if (ruleSelectorToValidate == supportedRuleSelectors[i]) {
return;
}
}
revert();
}

function _beforeChangeRules(uint256 entityId, RuleChange[] calldata ruleChanges) internal virtual {
if (entityId == 0) {
_beforeChangePrimitiveRules(ruleChanges);
Expand Down

0 comments on commit 8eab952

Please sign in to comment.