Cheatcodes
Learn about Kontrol's cheatcodes for testing and verification
Last updated
Was this helpful?
Learn about Kontrol's cheatcodes for testing and verification
Last updated
Was this helpful?
Kontrol implements many Foundry's cheatcodes, focusing on those most relevant for formal verification. These cheatcodes enable powerful testing and verification capabilities, with some additional functionality specific to symbolic execution and formal verification.
For a comprehensive technical reference of all cheatcodes and their implementations, see the .
If you notice a missing cheatcode, feel free to open an or directly to the project.
prank(address)
: Change msg.sender
for next call
prank(address,address)
: Change msg.sender
and tx.origin
startPrank(address)
: Impersonate msg.sender
until stopPrank
startPrank(address,address)
: Impersonate msg.sender
and tx.origin
until stopPrank
stopPrank()
: Stop impersonation
setArbitraryStorage(address)
: Make storage of an address symbolic
load(address,bytes32)
: Load storage slot
store(address,bytes32,bytes32)
: Set storage slot
copyStorage(address,address)
: Copy storage between contracts
deal(address,uint256)
: Set ETH/native token balance
etch(address,bytes)
: Set account code
getNonce(address)
: Get account nonce
setNonce(address,uint64)
: Set account nonce
warp(uint256)
: Set block timestamp
roll(uint256)
: Set block number
fee(uint256)
: Set block base fee
chainId(uint256)
: Set chain ID
coinbase(address)
: Set block coinbase
assume(bool)
: Add assumption for symbolic execution
randomUint()
: Generate a fresh symbolic uint
randomUint(uint256,uint256)
: Generate symbolic uint in range
randomBool()
: Generate symbolic bool
randomBytes(uint256)
: Generate symbolic bytes of a given size
randomAddress()
: Generate symbolic address
randomBytes4()
: Generate symbolic bytes4
randomBytes8()
: Generate symbolic bytes8
label(address,string)
: Label address for debugging
addr(uint256)
: Compute address from private key
expectRevert()
: Expect revert for next call
expectRevert(bytes4)
: Expect revert with specific selector
expectRevert(bytes)
: Expect revert with specific message
expectEmit(bool,bool,bool,bool)
: Expect event for next call
expectEmit(bool,bool,bool,bool,address)
: Expect event with specific emitter address
sign(uint256,bytes32)
: Sign digest with private key
mockCall(address,bytes,bytes)
: Mock call with calldata and returndata
mockFunction(address,address,bytes)
: Mock function by redirecting a call to a mock contract
symbolicStorage(address)
: Make storage of an address symbolic, alias for setArbitraryStorage
symbolicStorage(address,string)
: Make storage of an address symbolic with custom name
freshUInt(uint8)
: Generate symbolic uint of given size, alias for randomUint(uint256)
freshUInt(uint8,string)
: Generate symbolic uint of a given size with custom name
freshBool()
: Generate symbolic bool, alias for randomBool()
freshBool(string)
: Generate symbolic bool with custom name
freshBytes(uint256)
: Generate symbolic bytes of a given size, alias for randomBytes(uint256)
freshBytes(uint256,string)
: Generate symbolic bytes of a given size with custom name
freshAddress()
: Generate symbolic address, alias for randomAddress()
freshAddress(string)
: Generate symbolic address with custom name
infiniteGas()
: Assume the execution can use infinite gas
setGas(uint256)
: Set execution gas to the given value
forgetBranch(uint256,uint8,uint256)
: Forget branch condition during verification
allowChangesToStorage(address,uint256)
: Allow storage changes only to a specific address and slot
allowCallsToAddress(address)
: Allow calls only to a specific address
allowCalls(address,bytes)
: Allow calls only to a specific address and with specific calldata
expectStaticCall(address, bytes)
: Expect a STATICCALL
to an address with given calldata
expectDelegateCall(address, bytes)
: Expects a DELEGATECALL
to an address with given calldata
expectRegularCall(address, uint256, bytes)
: Expect CALL
to an address, with the given msg.value
and calldata
expectCreate(address, uint256, bytes)
: Expect CREATE
initiated by the specified address, with given msg.value
and bytecode
expectCreate2(address, uint256, bytes)
: Expects CREATE2
from the given address, sending specified msg.value
and bytecode
Use symbolic values for inputs that should be explored exhaustively
Use prank
to test access control and permission checks
Leverage symbolic storage for comprehensive storage and contract behavior analysis
Name your symbolic variables meaningfully when debugging
Mock external calls to control their behavior during verification and isolate the contract under test
Combine symbolic and concrete values strategically when appropriate
Some Foundry cheatcodes are not yet implemented in Kontrol, including:
Environment variable manipulation (setEnv
, envBool
, etc.)
File operations (readFile
, writeFile
, etc.)
Fork management (createFork
, selectFork
, etc.)
FFI operations
String conversion utilities
In the KEVM configuration, Kontrol's cheatcodes are organized into several key cells:
Used for simulating calls from different addresses:
<prevCaller>
: Current address of the contract initiating the prank
<prevOrigin>
: Current tx.origin
value
<newCaller>
and <newOrigin>
: Addresses to assign to msg.sender
and tx.origin
<active>
: Indicates if a prank is currently active
<depth>
: Current call depth at which the prank was invoked
<singleCall>
: Determines if the prank stops after next call or requires stopPrank
Used for testing expected reverts:
<isRevertExpected>
: Flags if the next call should revert
<expectedDepth>
: Depth at which the call should revert
<expectedReason>
: Expected revert message as Bytes
Used for verifying specific opcode calls:
<isOpcodeExpected>
: Flags if a call opcode is expected
<expectedAddress>
: Expected caller address
<expectedValue>
: Expected msg.value
<expectedData>
: Expected calldata
<opcodeType>
: Type of CALL*
opcode expected
Used for event verification:
<recordEvent>
: Flags if next event should be recorded
<isEventExpected>
: Flags if an event should match previously recorded
<checkedTopics>
: List of bools indicating which topics to check
<checkedData>
: Flag for checking data field
<expectedEventAddress>
: Address of expected event emitter
Used for controlling function calls and storage access during execution:
<isCallWhitelistActive>
: Enables whitelist mode for calls
<isStorageWhitelistActive>
: Enables whitelist mode for storage
<addressList>
: List of whitelisted addresses that are allowed to be called
<storageSlotList>
: List of whitelisted storage slots that are allowed to be modified
Used for mocking contract calls:
<mockCall>
: Collection of active mock calls per address
<mockAddress>
: Address with active mock calls
<mockValues>
: Map of calldata to returndata