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

forge verify-bytecode #7319

Merged
merged 43 commits into from
Apr 10, 2024
Merged

Conversation

yash-atreya
Copy link
Member

Motivation

Ref #6893

Solution

Still a WIP

  1. Implement a new command forge verify-bytecode. Placing the source code for this under https://github.com/foundry-rs/foundry/tree/master/crates/forge/bin/cmd/verify as bytecode.rs

  2. Use ETH_RPC_URL to get runtime bytecode, etherscan api to get the constructor arguments and configs such as EVM version, compiler version, and optimizations. (https://docs.etherscan.io/api-endpoints/contracts#get-contract-source-code-for-verified-contract-source-codes) and lastly the creation code to be extracted from the creation_tx data.

  3. Re: --verfication-type flag — Sourcify indicates whether its a partial or full match. If the user has specified a different verification type to sourcify, we can either throw an error or warn and continue with partial verification as default.

  4. Re: verifying runtime code by running a fork at specified --block. If the block is not specified we can fetch the creationTxHash from etherscan and then use the ETH_RPC_URL to get block, run the fork and verify runtime code.

@yash-atreya yash-atreya marked this pull request as draft March 5, 2024 17:55
@yash-atreya
Copy link
Member Author

@klkvr @mattsse need some help here.
I'm trying to test this on WETH9. Here's the foundry project containing WETH9 local source code for it.

Here's the command I ran

RUST_LOG=info forge vb 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 WETH9 --rpc-url https://eth.merkle.io 

The creation code onchain does not match the locally built one. I'm probably missing something here, would appreciate your help.

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.

some nits

crates/forge/bin/cmd/verify/bytecode.rs Outdated Show resolved Hide resolved
crates/forge/bin/cmd/verify/bytecode.rs Outdated Show resolved Hide resolved
crates/forge/bin/cmd/verify/bytecode.rs Outdated Show resolved Hide resolved
@yash-atreya
Copy link
Member Author

#7326 created cyclical dependencies between forge and foundry_verify refactored VerifyBytecodeArgs to solve the issue.

@yash-atreya yash-atreya requested a review from mattsse March 6, 2024 21:32
@yash-atreya
Copy link
Member Author

@mattsse Facing an issue with forking and deploying the contract to verify the runtime bytecode.
I get the following error when on using provider::send_transaction to deploy the contract.

Error: 
(code: -32603, message: method eth_sendTransaction not supported, data: None)

I'm probably missing something about forking and its rpc.

crates/verify/src/bytecode.rs Outdated Show resolved Hide resolved
@yash-atreya yash-atreya marked this pull request as ready for review March 7, 2024 18:22
@yash-atreya yash-atreya marked this pull request as draft March 7, 2024 20:09
@yash-atreya
Copy link
Member Author

Facing some issues with constructor_args and metadata_hash being in varying locations in the bytecode. Have found a possible solution that should solve it.

@yash-atreya yash-atreya marked this pull request as ready for review March 11, 2024 17:20
@yash-atreya yash-atreya marked this pull request as ready for review April 5, 2024 20:46
@Evalir Evalir requested review from klkvr, mattsse and mds1 April 8, 2024 10:16
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.

looking good—some comments

crates/verify/src/bytecode.rs Outdated Show resolved Hide resolved
crates/verify/src/bytecode.rs Outdated Show resolved Hide resolved
@yash-atreya yash-atreya requested a review from Evalir April 8, 2024 17:33
crates/verify/src/bytecode.rs Outdated Show resolved Hide resolved
@yash-atreya yash-atreya requested a review from klkvr April 8, 2024 18:34
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.

few more nits

crates/verify/src/bytecode.rs Outdated Show resolved Hide resolved
crates/verify/src/bytecode.rs Outdated Show resolved Hide resolved
crates/verify/src/bytecode.rs Outdated Show resolved Hide resolved
@yash-atreya yash-atreya requested a review from mattsse April 9, 2024 15:07
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.

looking good to me, pending @mds1 / @mattsse / @DaniPopes

Copy link
Collaborator

@mds1 mds1 left a comment

Choose a reason for hiding this comment

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

This is working great, looks like all my feedback has been addressed, thank you! 🙌

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.

6 participants