Skip to content

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

Merged
mattsse merged 9 commits into
foundry-rs:masterfrom
klkvr:klkvr/guess-constructor-args
Mar 3, 2024
Merged

feat(forge verify-contract): --guess-constructor-args#6724
mattsse merged 9 commits into
foundry-rs:masterfrom
klkvr:klkvr/guess-constructor-args

Conversation

@klkvr

@klkvr klkvr commented Jan 7, 2024

Copy link
Copy Markdown
Member

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

@mattsse mattsse left a comment

Copy link
Copy Markdown
Member

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

Comment thread crates/forge/bin/cmd/verify/etherscan/mod.rs Outdated
@klkvr

klkvr commented Feb 26, 2024

Copy link
Copy Markdown
Member Author

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

@Evalir Evalir left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread crates/forge/bin/cmd/verify/etherscan/mod.rs

@onbjerg onbjerg left a comment

Copy link
Copy Markdown
Member

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
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