IInvariantChecker
Title: IInvariantChecker
Interface for the InvariantChecker module — a registry of named invariants
(bytes32 → target + selector) that can be checked on-chain via staticcall.
Functions
getInvariant
Returns the target address and function selector registered for key.
function getInvariant(bytes32 key) external view returns (address target, bytes4 selector);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The invariant key to query. |
Returns
| Name | Type | Description |
|---|---|---|
| target | address | The contract address to call. |
| selector | bytes4 | The function selector to invoke. |
checkInvariant
Performs the staticcall check for key and reverts on violation or call failure.
Reverts with InvariantNotRegistered if the key is unregistered.
Reverts with InvariantViolatedError if the call returns false.
Reverts with InvariantCheckFailed if the staticcall reverts.
function checkInvariant(bytes32 key) external view;Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The invariant key to check. |
checkInvariants
Checks multiple invariants in order, reverting on the first failure.
function checkInvariants(bytes32[] calldata keys) external view;Parameters
| Name | Type | Description |
|---|---|---|
| keys | bytes32[] | The array of invariant keys to check sequentially. |
registerInvariant
Registers or updates an invariant.
Requires DEFAULT_ADMIN_ROLE. Reverts if target == address(0).
Emits InvariantRegistered.
function registerInvariant(bytes32 key, address target, bytes4 selector) external;Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The invariant key. |
| target | address | The contract address to call (must not be address(0)). |
| selector | bytes4 | The function selector to invoke (must return a bool). |
unregisterInvariant
Removes a registered invariant.
Requires DEFAULT_ADMIN_ROLE. Reverts with InvariantNotRegistered if key is not registered.
Emits InvariantUnregistered.
function unregisterInvariant(bytes32 key) external;Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The invariant key to remove. |
Events
InvariantRegistered
Emitted when an invariant is registered or updated.
event InvariantRegistered(bytes32 indexed key, address target, bytes4 selector);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The invariant key. |
| target | address | The contract address to call. |
| selector | bytes4 | The function selector to invoke (must return bool). |
InvariantUnregistered
Emitted when an invariant is unregistered.
event InvariantUnregistered(bytes32 indexed key);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The invariant key that was removed. |
InvariantViolated
Emitted when an invariant check returns false.
event InvariantViolated(bytes32 indexed key, bytes returnData);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The invariant key that was violated. |
| returnData | bytes | The raw return data from the staticcall. |
Errors
InvariantNotRegistered
Thrown when checkInvariant is called for a key that has not been registered.
error InvariantNotRegistered(bytes32 key);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The unregistered invariant key. |
InvariantViolatedError
Thrown when the staticcall returns false, indicating an invariant violation.
error InvariantViolatedError(bytes32 key);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The invariant key whose check returned false. |
InvariantCheckFailed
Thrown when the staticcall itself reverts (e.g., invalid target, out-of-gas).
error InvariantCheckFailed(bytes32 key);Parameters
| Name | Type | Description |
|---|---|---|
| key | bytes32 | The invariant key whose staticcall failed. |
InvariantInvalidTarget
Thrown when registerInvariant is called with target == address(0).
error InvariantInvalidTarget();