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

feat(forge verify-contract): --guess-constructor-args #6724

Merged
merged 9 commits into from
Mar 3, 2024

Conversation

klkvr
Copy link
Member

@klkvr klkvr commented Jan 7, 2024

Motivation

Ref #6334

Solution

  1. Added RpcOpts to VerifyArgs. If any valid eth_rpc_url is found in config and --chain is not specified, we are using explorer for chain_id from RPC. This should make UX cleaner (ref comment)
  2. Added --guess-constructor-args parameter which uses Etherscan API and RPC provider to fetch creation code of contracts created directly with create transaction or directly with default CREATE2 deployer.
  3. Added test for --guess-constructor-args. I wasn't able to run existing verification tests without some small updates to them (renaming --etherscan-key to --etherscan-api-key for example). Is there a chance that required env vars are not set in CI which leads to tests silently passing or I got something wrong?

The only way I can see to make --guess-constructor-args work for any contract is by implementing some kind of cast run with custom inspector which will be pretty long-running thing (some cast run's are taking several minutes on my machine). So not sure if such UX is really a best way to do it. Would be happy to get some ideas on how creation code for arbitrary contract could be fetched faster.

@klkvr klkvr force-pushed the klkvr/guess-constructor-args branch from 2b7d0b7 to e5e5e6d Compare February 25, 2024 11:36
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style nit,

I'll set the env vars in CI via secrets

crates/forge/bin/cmd/verify/etherscan/mod.rs Outdated Show resolved Hide resolved
@klkvr
Copy link
Member Author

klkvr commented Feb 26, 2024

made guess_constructor_args a separate function

also did some more testing and it seems that in some cases compile_file results in different bytecode, so changed project.compile_file to project.compile, it shouldn't take long as it compiles with the same settings, and will probably just use cache all the time

Copy link
Member

@Evalir Evalir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! only one doc nit, pending vars

crates/forge/bin/cmd/verify/etherscan/mod.rs Show resolved Hide resolved
Copy link
Member

@onbjerg onbjerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mattsse mattsse merged commit 3df3e0c into foundry-rs:master Mar 3, 2024
19 checks passed
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.

4 participants