Constructor for Offchain Fuzzing
When fuzzing a contract offchain, you may need to provide constructor arguments to initialize the contract state. ItyFuzz provides two methods to pass in constructor arguments. These arguments are necessary for initializing the state of the contract when deployed.
Method 1: CLI Arguments
The first method is to pass in the constructor arguments directly as CLI arguments.
When you run ItyFuzz using the CLI, you can include the --constructor-args
flag followed by a string that specifies the arguments for each constructor.
The format is as follows:
For example, if you have two contracts, main
and main2
, both having a bytes32
and a uint256
as constructor arguments, you would pass them in like this:
Method 2: Server Forwarding
The second method is to use our server to forward requests to a user-specified RPC, and cli will fetch the constructor arguments from the transactions sent to the RPC.
Firstly, go to the /server
directory, and install the necessary packages:
Then, start the server using the following command:
By default, the server will forward requests to http://localhost:8545
, which is the default address for Ganache, if you do not have a local blockchain running, you can use Ganache to start one. If you wish to forward requests to another location, you can specify the address as a command-line argument like so:
Once the server is running, you can deploy your contract to localhost:5001
using a tool of your choice.
For example, you can use Foundry to deploy your contract through the server:
Finally, you can fetch the constructor arguments using the --fetch-tx-data
flag:
ItyFuzz will fetch the constructor arguments from the transactions forwarded to the RPC through the server.
Last updated