Functions
checkPolicies
Evaluates the conditions associated with all applicable rules and returns the result. Primary entry point for policy checks.Name | Type | Description |
---|---|---|
arguments | bytes | Function arguments, including the function signature and the arguments to be passed to the function. |
Name | Type | Description |
---|---|---|
retVal | uint256 | 1 if all rules pass, 0 if any rule fails. TODO: refine the parameters to this function. contractAddress is not necessary as it’s the message caller |
evaluateForeignCalls
Evaluates foreign calls within the rules engine processor. This function processes and evaluates calls to external contracts or systems as part of the rules engine’s logic. Ensure that the necessary validations and security checks are in place when interacting with foreign calls.Name | Type | Description |
---|---|---|
policyId | uint256 | Id of the policy. |
callingFunctionArgs | bytes | representation of the calling function arguments |
foreignCallIndex | uint256 | Index of the foreign call. |
retVals | bytes[] | array of return values from previous foreign calls, trackers, etc. |
Name | Type | Description |
---|---|---|
returnValue | ForeignCallReturnValue | The output of the foreign call. |
evaluateForeignCallForRule
encodes the arguments and places a foreign call, returning the calls return value as long as it is successfulName | Type | Description |
---|---|---|
fc | ForeignCall | the Foreign Call structure |
functionArguments | bytes | the arguments of the rules calling function (to be passed to the foreign call as needed) |
retVals | bytes[] |
Name | Type | Description |
---|---|---|
retVal | ForeignCallReturnValue | the foreign calls return value |
_checkPolicy
Checks a specific policy for compliance.Name | Type | Description |
---|---|---|
_policyId | uint256 | The ID of the policy to check. |
_contractAddress | address | The address of the contract being evaluated. |
_arguments | bytes | Function arguments for the policy evaluation. |
Name | Type | Description |
---|---|---|
retVal | bool | True if the policy passes, false otherwise. |
_evaluateRulesAndExecuteEffects
Evaluates rules and executes their effects based on the evaluation results.Name | Type | Description |
---|---|---|
_ruleData | mapping(uint256 ruleId => RuleStorageSet) | The mapping of rule IDs to rule storage sets. |
_policyId | uint256 | The ID of the policy being evaluated. |
_applicableRules | uint256[] | An array of applicable rule IDs. |
_callingFunctionArgs | bytes | The arguments for the calling function. |
Name | Type | Description |
---|---|---|
_retVal | bool | True if all rules pass, false otherwise. |
_evaluateIndividualRule
evaluates an individual rules condition(s)Name | Type | Description |
---|---|---|
_rule | Rule | the rule structure containing the instruction set, with placeholders, to execute |
_policyId | uint256 | Policy id being evaluated. |
_callingFunctionArgs | bytes | the values to replace the placeholders in the instruction set with. |
Name | Type | Description |
---|---|---|
response | bool | the result of the rule condition evaluation |
_buildArguments
Constructs the arguments required for building the rule’s place holders.Name | Type | Description |
---|---|---|
_rule | Rule | The storage reference to the Rule struct containing the rule’s details. |
_policyId | uint256 | The unique identifier of the policy associated with the rule. |
_callingFunctionArgs | bytes | The calldata containing the arguments for the calling function. |
_effect | bool | A boolean indicating whether the rule has an effect or not. |
Name | Type | Description |
---|---|---|
<none> | bytes[] | A tuple containing: - An array of bytes representing the constructed arguments. - An array of Placeholder structs used for argument substitution. |
<none> | Placeholder[] |
_run
Internal function to decode the arguments and do the comparisons.Name | Type | Description |
---|---|---|
_prog | uint256[] | An array of uint256 representing the program to be executed. |
_placeHolders | Placeholder[] | An array of Placeholder structs used within the program. |
_policyId | uint256 | The ID of the policy associated with the program execution. |
_arguments | bytes[] | An array of bytes containing additional arguments for the program. |
Name | Type | Description |
---|---|---|
_ans | bool | A boolean indicating the result of the program execution. |
_updateTrackerValue
This function updates the tracker value with the information providedName | Type | Description |
---|---|---|
_policyId | uint256 | Policy id being evaluated. |
_trackerId | uint256 | ID of the tracker to update. |
_trackerValue | uint256 | Value to update within the tracker |
_updateTrackerValue
Internal function to update the value of a tracker associated with a specific policy.Name | Type | Description |
---|---|---|
_policyId | uint256 | The ID of the policy to which the tracker belongs. |
_trackerId | uint256 | The ID of the tracker whose value is being updated. |
_trackerValue | bytes | The new value to be assigned to the tracker, encoded as bytes. |
_loadApplicableRules
Loads applicable rules for a given calling function.Name | Type | Description |
---|---|---|
_ruleData | mapping(uint256 ruleId => RuleStorageSet) | The mapping of rule IDs to rule storage sets. |
_policy | Policy | The policy structure containing the rules. |
_callingFunction | bytes4 | The function signature to match rules against. |
Name | Type | Description |
---|---|---|
<none> | uint256[] | An array of applicable rule IDs. |
_getAbsoluteAssembly
Calculates the absolute value of a signed integer.Name | Type | Description |
---|---|---|
_value | int256 | The signed integer value to convert to its absolute value. |
Name | Type | Description |
---|---|---|
<none> | uint256 | result The absolute value of the input number as an unsigned integer. |
_doEffects
Internal function to process the effects of a rule.Name | Type | Description |
---|---|---|
_rule | Rule | The rule being processed, stored in the contract’s storage. |
_policyId | uint256 | The ID of the policy associated with the rule. |
_effects | Effect[] | An array of effects to be applied as part of the rule execution. |
_callingFunctionArgs | bytes | Encoded calldata containing arguments for the calling function. |
_buildEvent
Define event to be firedName | Type | Description |
---|---|---|
_rule | Rule | the rule struct event is associated to |
_isDynamicParam | bool | static or dynamic event parameters |
_policyId | uint256 | policy Id |
_message | bytes32 | Event Message String |
_effectStruct | Effect | effect struct |
_callingFunctionArgs | bytes | calling function arguments |
_fireDynamicEvent
Fire dynamic EventName | Type | Description |
---|---|---|
_rule | Rule | the rule struct event is associated to |
_policyId | uint256 | policy Id |
_message | bytes32 | Event Message String |
_callingFunctionArgs | bytes | calling function arguments |
_fireEvent
Internal function to trigger an event based on the provided policy ID, message, and effect structure.Name | Type | Description |
---|---|---|
_policyId | uint256 | The unique identifier of the policy associated with the event. |
_message | bytes32 | A bytes32 message that provides context or details about the event. |
_effectStruct | Effect | A struct containing the effect data to be processed during the event. |
_evaluateExpression
Evaluate an effect expressionName | Type | Description |
---|---|---|
_rule | Rule | the rule structure containing the instruction set, with placeholders, to execute |
_policyId | uint256 | the policy id |
_callingFunctionArgs | bytes | arguments of the calling function |
_instructionSet | uint256[] | instruction set |
_doRevert
Internal pure function to revert the transaction with a custom error message.Name | Type | Description |
---|---|---|
_message | string | The custom error message to include in the revert. |
_getDynamicVariableFromCalldata
Extracts a dynamic variable from the provided calldata at the specified index. This function is a pure function and does not modify state.Name | Type | Description |
---|---|---|
_data | bytes | The calldata containing the dynamic variables. |
_index | uint256 | The index of the dynamic variable to extract. |
Name | Type | Description |
---|---|---|
_retVal | bytes | The extracted dynamic variable as a bytes array. |
_getDynamicValueArrayData
Retrieves a portion of dynamic value array data from the provided inputs. This function extracts a segment of dynamic data based on the specified length and offset.Name | Type | Description |
---|---|---|
_data | bytes | The calldata input containing the original data. |
_dynamicData | bytes | The memory input containing the dynamic data to process. |
_length | uint256 | The total length of the dynamic data array. |
_lengthToAppend | uint256 | The length of data to append to the result. |
_offset | uint256 | The starting position in the dynamic data array to begin extraction. |
Name | Type | Description |
---|---|---|
<none> | bytes | A tuple containing: - A bytes memory object representing the extracted data. - A uint256 value indicating the updated offset after extraction. |
<none> | uint256 |