Pre-release — The API surface may change. Unaudited.
Callcium LogoCallcium

Constraint

Fluent API operators for building Constraints.

struct Constraint {
    /// SCOPE_CONTEXT or SCOPE_CALLDATA.
    uint8 scope;
    /// BE16-encoded path to the target value.
    bytes path;
    /// Encoded operators. Each item = opCode(1) || data.
    bytes[] operators;
}

arg(uint16)

Creates a constraint targeting a top-level argument.

function arg(uint16 p0) pure returns (Constraint memory);

arg(uint16, uint16)

Creates a constraint targeting a nested path of depth 2.

function arg(uint16 p0, uint16 p1) pure returns (Constraint memory);

arg(uint16, uint16, uint16)

Creates a constraint targeting a nested path of depth 3.

function arg(uint16 p0, uint16 p1, uint16 p2) pure returns (Constraint memory);

arg(uint16, uint16, uint16, uint16)

Creates a constraint targeting a nested path of depth 4.

function arg(uint16 p0, uint16 p1, uint16 p2, uint16 p3) pure returns (Constraint memory);

arg(bytes)

Creates a constraint from a pre-encoded BE16 path.

function arg(bytes memory path) pure returns (Constraint memory);
function blockNumber() pure returns (Constraint memory);

Returns

NameTypeDescription
<none>ConstraintA context-scoped constraint for block.number.
function blockTimestamp() pure returns (Constraint memory);

Returns

NameTypeDescription
<none>ConstraintA context-scoped constraint for block.timestamp.
function chainId() pure returns (Constraint memory);

Returns

NameTypeDescription
<none>ConstraintA context-scoped constraint for block.chainid.
function msgSender() pure returns (Constraint memory);

Returns

NameTypeDescription
<none>ConstraintA context-scoped constraint for msg.sender.
function msgValue() pure returns (Constraint memory);

Returns

NameTypeDescription
<none>ConstraintA context-scoped constraint for msg.value.
function txOrigin() pure returns (Constraint memory);

Returns

NameTypeDescription
<none>ConstraintA context-scoped constraint for tx.origin.

Functions

eq

Requires the value to equal value.

function eq(Constraint memory c, uint256 value) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
valueuint256The expected value.

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

neq

Requires the value to not equal value.

function neq(Constraint memory c, uint256 value) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
valueuint256The excluded value.

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

gt

Requires the value to be strictly greater than bound.

function gt(Constraint memory c, uint256 bound) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
bounduint256The lower bound (exclusive).

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

lt

Requires the value to be strictly less than bound.

function lt(Constraint memory c, uint256 bound) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
bounduint256The upper bound (exclusive).

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

gte

Requires the value to be greater than or equal to bound.

function gte(Constraint memory c, uint256 bound) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
bounduint256The lower bound (inclusive).

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

lte

Requires the value to be less than or equal to bound.

function lte(Constraint memory c, uint256 bound) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
bounduint256The upper bound (inclusive).

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

between

Requires the value to be within [min, max] inclusive.

function between(Constraint memory c, uint256 min, uint256 max) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
minuint256The lower bound (inclusive).
maxuint256The upper bound (inclusive).

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

eq

Requires the signed value to equal value.

function eq(Constraint memory c, int256 value) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
valueint256The expected value.

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

neq

Requires the signed value to not equal value.

function neq(Constraint memory c, int256 value) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
valueint256The excluded value.

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

gt

Requires the signed value to be strictly greater than bound.

function gt(Constraint memory c, int256 bound) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
boundint256The lower bound (exclusive).

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

lt

Requires the signed value to be strictly less than bound.

function lt(Constraint memory c, int256 bound) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
boundint256The upper bound (exclusive).

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

gte

Requires the signed value to be greater than or equal to bound.

function gte(Constraint memory c, int256 bound) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
boundint256The lower bound (inclusive).

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

lte

Requires the signed value to be less than or equal to bound.

function lte(Constraint memory c, int256 bound) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
boundint256The upper bound (inclusive).

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

between

Requires the signed value to be within [min, max] inclusive.

function between(Constraint memory c, int256 min, int256 max) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
minint256The lower bound (inclusive).
maxint256The upper bound (inclusive).

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

eq

Requires the value to equal value (address).

function eq(Constraint memory c, address value) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
valueaddressThe expected address.

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

neq

Requires the value to not equal value (address).

function neq(Constraint memory c, address value) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
valueaddressThe excluded address.

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

eq

Requires the value to equal value (bytes32).

function eq(Constraint memory c, bytes32 value) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
valuebytes32The expected bytes32 value.

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

neq

Requires the value to not equal value (bytes32).

function neq(Constraint memory c, bytes32 value) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
valuebytes32The excluded bytes32 value.

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

eq

Requires the value to equal value (bool).

function eq(Constraint memory c, bool value) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
valueboolThe expected boolean.

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

neq

Requires the value to not equal value (bool).

function neq(Constraint memory c, bool value) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
valueboolThe excluded boolean.

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

isIn

Requires the value to be in the given address set.

function isIn(Constraint memory c, address[] memory values) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
valuesaddress[]The allowed addresses.

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

notIn

Requires the value to not be in the given address set.

function notIn(Constraint memory c, address[] memory values) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
valuesaddress[]The excluded addresses.

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

isIn

Requires the value to be in the given bytes32 set.

function isIn(Constraint memory c, bytes32[] memory values) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
valuesbytes32[]The allowed values.

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

notIn

Requires the value to not be in the given bytes32 set.

function notIn(Constraint memory c, bytes32[] memory values) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
valuesbytes32[]The excluded values.

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

isIn

Requires the value to be in the given uint256 set.

function isIn(Constraint memory c, uint256[] memory values) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
valuesuint256[]The allowed values.

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

notIn

Requires the value to not be in the given uint256 set.

function notIn(Constraint memory c, uint256[] memory values) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
valuesuint256[]The excluded values.

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

isIn

Requires the value to be in the given int256 set.

function isIn(Constraint memory c, int256[] memory values) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
valuesint256[]The allowed values.

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

notIn

Requires the value to not be in the given int256 set.

function notIn(Constraint memory c, int256[] memory values) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
valuesint256[]The excluded values.

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

lengthEq

Requires the dynamic type length to equal length.

function lengthEq(Constraint memory c, uint256 length) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
lengthuint256The expected length.

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

lengthGt

Requires the dynamic type length to be strictly greater than bound.

function lengthGt(Constraint memory c, uint256 bound) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
bounduint256The lower bound (exclusive).

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

lengthLt

Requires the dynamic type length to be strictly less than bound.

function lengthLt(Constraint memory c, uint256 bound) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
bounduint256The upper bound (exclusive).

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

lengthGte

Requires the dynamic type length to be greater than or equal to bound.

function lengthGte(Constraint memory c, uint256 bound) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
bounduint256The lower bound (inclusive).

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

lengthLte

Requires the dynamic type length to be less than or equal to bound.

function lengthLte(Constraint memory c, uint256 bound) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
bounduint256The upper bound (inclusive).

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

lengthBetween

Requires the dynamic type length to be within [min, max] inclusive.

function lengthBetween(Constraint memory c, uint256 min, uint256 max) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
minuint256The lower bound (inclusive).
maxuint256The upper bound (inclusive).

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

bitmaskAll

Requires all bits in mask to be set.

function bitmaskAll(Constraint memory c, uint256 mask) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
maskuint256The bitmask to check.

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

bitmaskAny

Requires at least one bit in mask to be set.

function bitmaskAny(Constraint memory c, uint256 mask) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
maskuint256The bitmask to check.

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

bitmaskNone

Requires no bits in mask to be set.

function bitmaskNone(Constraint memory c, uint256 mask) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
maskuint256The bitmask to check.

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

addOp

Appends a raw operator with its data payload.

function addOp(Constraint memory c, uint8 op, bytes memory data) internal pure returns (Constraint memory);

Parameters

NameTypeDescription
cConstraintThe constraint to extend.
opuint8The operator code byte.
databytesThe operator data payload.

Returns

NameTypeDescription
<none>ConstraintThe updated constraint.

Errors

InvalidRange

Thrown when the range minimum exceeds the maximum.

error InvalidRange();

EmptySet

Thrown when an empty set is passed to a set membership operator.

error EmptySet();

SetTooLarge

Thrown when a set exceeds the maximum element count (2047).

error SetTooLarge();

On this page