Skip to content

forge verify-bytecode#7319

Merged
DaniPopes merged 43 commits into
foundry-rs:masterfrom
yash-atreya:yash/verify-bytecode
Apr 10, 2024
Merged

forge verify-bytecode#7319
DaniPopes merged 43 commits into
foundry-rs:masterfrom
yash-atreya:yash/verify-bytecode

Conversation

@yash-atreya

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor 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.

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

some nits

Comment thread crates/forge/bin/cmd/verify/bytecode.rs Outdated
Comment thread crates/forge/bin/cmd/verify/bytecode.rs Outdated
Comment thread crates/forge/bin/cmd/verify/bytecode.rs Outdated
@yash-atreya

Copy link
Copy Markdown
Contributor 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
Copy Markdown
Contributor 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.

Comment thread crates/verify/src/bytecode.rs Outdated
@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
Copy Markdown
Contributor 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

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

looking good—some comments

Comment thread crates/verify/src/bytecode.rs
Comment thread crates/verify/src/bytecode.rs Outdated
@yash-atreya yash-atreya requested a review from Evalir April 8, 2024 17:33
Comment thread crates/verify/src/bytecode.rs Outdated
@yash-atreya yash-atreya requested a review from klkvr April 8, 2024 18:34

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

few more nits

Comment thread crates/verify/src/bytecode.rs Outdated
Comment thread crates/verify/src/bytecode.rs Outdated
Comment thread crates/verify/src/bytecode.rs Outdated
@yash-atreya yash-atreya requested a review from mattsse April 9, 2024 15:07

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

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

@mds1 mds1 left a comment

Copy link
Copy Markdown
Collaborator

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