Skip to content

assertions

On-chain assertions backed by the assertions.eth contract: verify view return values and chain state atomically. Requires load assertions.

load assertions

Config variables are set with set (fully qualified, including the module prefix) and are only readable by their own module and the user script.

VariableTypeDefaultDescription
$assertions:addressaddressOverride the resolved assertions contract address (forks / testing).
$assertions:combinatorsaddressOverride the resolved combinators contract address (forks / testing).
CommandDescription
assertions:assertAssert that an on-chain expression satisfies a comparison, on-chain.
assertions:assert-balanceAssert the native balance of an account, on-chain.
assertions:assert-block-numberAssert the current block number, on-chain.
assertions:assert-chainidAssert the chain ID equals an expected value, on-chain.
assertions:assert-codeAssert an address has deployed code, on-chain.
assertions:assert-codehashAssert an address has a specific code hash, on-chain.
assertions:assert-no-codeAssert an address has no deployed code, on-chain.
assertions:assert-timestampAssert the current block timestamp, on-chain.
HelperReturnsDescription
@assertions:absdiff!numberAbsolute difference
@assertions:balance!numberRead a balance on-chain at assertion time: the native balance for ETH, or an ERC-20 balanceOf for any token symbol or address.
@assertions:blocknumber!numberThe block number at assertion time (not at script build time).
@assertions:bool!boolCompose live comparisons with on-chain logic (and, or, xor, not), evaluated at assertion time via the combinators contract.
@assertions:bytelen!numberThe raw byte length of the return data of a call, on-chain (a uint256[] with n items is 64 + n*32 bytes).
@assertions:bytes!numberBitwise word operations computed on-chain (& `
@assertions:chainid!numberThe chain id at assertion time, read on-chain — unlike assert-chainid it composes into expressions.
@assertions:charset!boolWhether every byte of the string return of a call is in a character class, checked on-chain — only-lowercase is @charset!(call a-z).
@assertions:codehashbytes32Read the code hash of an address at script build time, with EXTCODEHASH semantics: bytes32(0) for a nonexistent account (zero nonce, balance and code), keccak256 of the code otherwise. Matches what @codehash! reads on-chain at assertion time.
@assertions:codehash!bytes32The EXTCODEHASH of an account, read on-chain at assertion time: bytes32(0) for a nonexistent account, keccak256 of the code otherwise. The account can be a :: call resolving to an address, such as a proxy implementation.
@assertions:hash!bytes32keccak256 of the raw return data of a call, computed on-chain — compare structs, arrays or long strings against a precomputed hash.
@assertions:includes!boolWhether the string return of a call contains a substring, checked on-chain — exact byte sequence, case-sensitive, no wildcards.
@assertions:invoke!anyCall a read-only function with live arguments at assertion time: the target and any argument may be a :: call or an on-chain helper, compiled to the combinators invoke primitive.
@assertions:len!numberThe decoded length of the dynamic return value of a call, on-chain: element count for arrays, byte length for string/bytes.
@assertions:max!numberMaximum of two or more values, computed on-chain at assertion time.
@assertions:min!numberMinimum of two or more values, computed on-chain at assertion time.
@assertions:not!anyNegation computed on-chain, dispatched on the operand: logical not for booleans (stays a bool), bitwise complement of the raw 32-byte word for numbers and bytes32. Never a conversion — cast explicitly with @bytes!(x) first if needed.
@assertions:num!numberCompose live calls and constants with on-chain arithmetic (+ - * / % ^, xor), evaluated at assertion time via the combinators contract.
@assertions:split!stringSplit the string return of a call on a delimiter and select one segment, on-chain. A negative index counts from the end (-1 = last segment).
@assertions:timestamp!numberThe block timestamp at assertion time (not at script build time).