Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Support chained contract crunching with config file setup #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

KONFeature
Copy link

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:

  1. CLI (Existing Method, Unchanged): The standard command-line arguments for running the crunching process remain unchanged.

  2. 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:

  1. Iterate over each target, starting with the first one that can be computed (e.g., contract1.bin).
  2. Compute the init code hash using the Keccak-256 hash of the binary file's content.
  3. Start crunching using to find a suitable address.
  4. Once an address for contract1.bin is found that meets the specified thresholds (e.g., 5 leading zeroes or 7 total zeroes), stop for this target.
  5. Update a placeholder map with the found address and store the result.
  6. Proceed with the next target (e.g., proxy.bin), replacing placeholders in its binary content with the computed address from contract1.bin.
  7. 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.

@KONFeature KONFeature changed the title Feature: config file + address chaining Feature: Support chained contract crunching with config file setup Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant