Feature: Support chained contract crunching with config file setup
This PR introduces a new way to run create2crunch that allows chaining multiple contract crunching processes when they are interdependent. This feature is particularly useful for scenarios like deploying contracts under an ERC1967 proxy, where the proxy address depends on the initial logic address.
Key Changes:
With this PR, there are now two ways to run create2crunch:
-
CLI (Existing Method, Unchanged): The standard command-line arguments for running the crunching process remain unchanged.
-
Config File (New Method):
- A configuration file can now be used to manage common settings (e.g., factory address, GPU device) and to specify the folder containing the binaries of the contracts to be crunched.
- Each target contract is defined individually:
- Targets are identified by their binary file name.
- Targets can expose placeholders, allowing the computed address of one contract to be used within another if there is a dependency.
- Custom stop thresholds for leading or total zeroes can be set for each target to determine when to stop crunching.
Example Use Case: ERC1967 Proxy
Consider a scenario where you have bin/contract1.bin representing the initial logic to be deployed, and bin/proxy.bin containing the proxy logic. The proxy.bin file might include something like:
0x603d3d8160223d3973${PLACEHOLDER_LOGIC}60095155f3363d3d373d3d363d7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc545af43d6000803e6038573d6000fd5b3d6000f3
The config file for this setup would look like:
bin_folder = "./bin"
factory_address = "0x4e59b44847b379578588920cA78FbF26c0B4956C"
calling_address = "0xdeadbeef"
gpu_device = 0
# Logic
[[targets]]
name = "contract1.bin"
placeholder_name = "PLACEHOLDER_LOGIC"
stop_thresholds = { leading_zeroes = 5, total_zeroes = 7 }
# Proxy
[[targets]]
name = "proxy.bin"
stop_thresholds = { leading_zeroes = 6, total_zeroes = 8 }
Workflow:
- Iterate over each target, starting with the first one that can be computed (e.g.,
contract1.bin). - Compute the init code hash using the Keccak-256 hash of the binary file's content.
- Start crunching using to find a suitable address.
- Once an address for
contract1.binis found that meets the specified thresholds (e.g., 5 leading zeroes or 7 total zeroes), stop for this target. - Update a placeholder map with the found address and store the result.
- Proceed with the next target (e.g.,
proxy.bin), replacing placeholders in its binary content with the computed address fromcontract1.bin. - Repeat this process for all targets.
Benefits:
- You can configure multiple contracts (e.g., 15 contracts) with dependencies, define custom thresholds for each, and let the system run without manual intervention.
- Allows for automated crunching and chaining, providing optimized addresses for complex deployments.
This feature enables a more flexible and powerful approach to crunching contracts with complex interdependencies, making it easier to achieve desirable addresses for deployments.