State Variables
GLOBAL_NONE
GLOBAL_MSG_SENDER
GLOBAL_BLOCK_TIMESTAMP
GLOBAL_MSG_DATA
GLOBAL_BLOCK_NUMBER
GLOBAL_TX_ORIGIN
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. |
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. |
metadata | ForeignCallEncodedIndex[] |
Name | Type | Description |
---|---|---|
retVal | 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[] | |
metadata | ForeignCallEncodedIndex[] | |
policyId | uint256 |
Name | Type | Description |
---|---|---|
retVal | ForeignCallReturnValue | the foreign calls return value |
evaluateForeignCallForRuleMappedTrackerKey
_foreignCallGetMappedTrackerValue
evaluateForeignCallForRuleEncodedValues
Processes encoded values from function arguments for foreign call encodingName | Type | Description |
---|---|---|
fc | ForeignCall | The ForeignCall struct containing call configuration |
argType | ParamTypes | The parameter type for the current argument |
functionArguments | bytes | The encoded arguments from the calling function |
encodedCall | bytes | Current encoded call data being built |
lengthToAppend | uint256 | Current length of dynamic data to append |
dynamicData | bytes | Current dynamic data portion of the call |
i | uint256 | Current parameter index being processed |
Name | Type | Description |
---|---|---|
<none> | bytes | encodedCall Updated encoded call data |
<none> | uint256 | lengthToAppend Updated length of dynamic data |
<none> | bytes | dynamicData Updated dynamic data portion |
evaluateForeignCallForRulePlaceholderValues
Processes placeholder values for foreign call encodingName | Type | Description |
---|---|---|
fc | ForeignCall | The ForeignCall struct containing call configuration |
retVals | bytes[] | Array of return values from previous operations |
metadata | ForeignCallEncodedIndex[] | Array of encoded index metadata for parameter resolution |
encodedCall | bytes | Current encoded call data being built |
lengthToAppend | uint256 | Current length of dynamic data to append |
i | uint256 | Current parameter index being processed |
dynamicData | bytes | Current dynamic data portion of the call |
Name | Type | Description |
---|---|---|
<none> | bytes | encodedCall Updated encoded call data |
<none> | uint256 | lengthToAppend Updated length of dynamic data |
<none> | bytes | dynamicData Updated dynamic data portion |
concatenateCallOnMemory
_handleGlobalVarForForeignCall
Handles global variable processing for foreign call encoding Internal function that processes global variable types and encodes them appropriately for foreign call argumentsName | Type | Description |
---|---|---|
fc | ForeignCall | The ForeignCall struct containing the call configuration and parameter types |
argType | ParamTypes | The expected parameter type for the global variable in the foreign call |
globalVarType | uint8 | An uint8 identifier representing which global variable to process: |
encodedCall | bytes | The current encoded call data being built for the foreign call |
lengthToAppend | uint256 | The current length of dynamic data to be appended |
dynamicData | bytes | The current dynamic data portion of the encoded call |
Name | Type | Description |
---|---|---|
<none> | bytes | encodedCall The updated encoded call data with the global variable parameter added |
<none> | uint256 | lengthToAppend The updated length of dynamic data after processing |
<none> | bytes | dynamicData The updated dynamic data portion after processing |
_checkPolicy
Checks a specific policy for compliance.Name | Type | Description |
---|---|---|
_policyId | uint256 | The ID of the policy to check. |
_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. |
_kind | PlaceholderType | the type of placeholders to build |
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. |
_kind | PlaceholderType | the type of placeholders to build |
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 |
---|---|---|
<none> | 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. |
_mightNeedHashing | bool |
_updateMappedTrackerValue
This function updates the tracker value with the information provided for a mapped trackerName | Type | Description |
---|---|---|
_policyId | uint256 | Policy id being evaluated. |
_trackerId | uint256 | ID of the tracker to update. |
_trackerValue | uint256 | Value to update within the tracker |
_mappedTrackerKey | uint256 |
_getMappedTrackerValue
_updateMappedTrackerValue
Internal function to update the value of a mapped 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. |
_mappedTrackerKey | uint256 | |
_mightNeedHashing | bool |
_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. |
_handleForeignCall
Processes foreign calls within the rules engine Internal helper function that delegates to evaluateForeignCalls and extracts the return value and type This function is used during rules processing to execute external contract calls and retrieve their results for rule evaluationName | Type | Description |
---|---|---|
_policyId | uint256 | The unique identifier of the policy associated with the foreign call |
_callingFunctionArgs | bytes | Arguments from the original function call, passed to the foreign call as needed |
typeSpecificIndex | uint256 | Index referencing the specific foreign call configuration to execute |
retVals | bytes[] | Array containing previously computed return values that might be used as inputs for this call |
metadata | ForeignCallEncodedIndex[] |
Name | Type | Description |
---|---|---|
<none> | bytes | The encoded return data from the foreign call |
<none> | ParamTypes | The parameter type of the foreign call’s return value |
_handleGlobalVar
Handles global variables in the rules engine Internal function that processes global variable types and returns their encoded values with corresponding parameter types Used to access blockchain context variables like msg.sender, block.timestamp, etc. during rule evaluationName | Type | Description |
---|---|---|
globalVarType | uint256 | An uint8 identifier representing which global variable to retrieve - GLOBAL_MSG_SENDER (1): The sender of the current call - GLOBAL_BLOCK_TIMESTAMP (2): Current block timestamp - GLOBAL_MSG_DATA (3): Complete calldata - GLOBAL_BLOCK_NUMBER (4): Current block number - GLOBAL_TX_ORIGIN (5): Original transaction sender |
Name | Type | Description |
---|---|---|
<none> | bytes | bytes Encoded value of the requested global variable |
<none> | ParamTypes | Parameter type enum value corresponding to the global variable |
_handleTrackerValue
Retrieves tracker values from storage based on policy ID and placeholder information Internal function that fetches either a regular tracker value or a mapped tracker value depending on the tracker’s configuration. For mapped trackers, it uses the placeholder’s mappedTrackerKey to fetch the specific value from the mapping.Name | Type | Description |
---|---|---|
_policyId | uint256 | The unique identifier of the policy containing the tracker |
placeholder | Placeholder | A Placeholder struct containing metadata about the tracker: - typeSpecificIndex: The ID of the tracker within the policy - mappedTrackerKey: The key to use for mapped trackers (ignored for regular trackers) |
Name | Type | Description |
---|---|---|
<none> | bytes | bytes The encoded value of the requested tracker |
_handleRegularParameter
Extracts function parameters from calldata based on placeholder type information *Internal pure function that handles different parameter types and retrieves their values from calldata- For dynamic types (strings, bytes): calls _getDynamicVariableFromCalldata to follow offsets
- For arrays: extracts the length from the offset indicated in calldata
- For value types: extracts 32 bytes directly from the specified position*
Name | Type | Description |
---|---|---|
_callingFunctionArgs | bytes | The raw calldata containing encoded function arguments |
placeholder | Placeholder | A Placeholder struct containing: - pType: Parameter type enum indicating how to decode the data - typeSpecificIndex: Position in calldata to read from (slot index for value types) |
Name | Type | Description |
---|---|---|
<none> | bytes | bytes The extracted parameter value as bytes (must be decoded according to pType) |
_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. |
_kind | PlaceholderType |
_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 |
_kind | PlaceholderType |
_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 |
_kind | PlaceholderType |
_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 |
_kind | PlaceholderType | the type of placeholders to build |
_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 |
---|---|---|
<none> | 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 |