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 script --verify intermittently generates bytecode mismatch #6780

Closed
2 tasks done
hensha256 opened this issue Jan 12, 2024 · 4 comments
Closed
2 tasks done

forge script --verify intermittently generates bytecode mismatch #6780

hensha256 opened this issue Jan 12, 2024 · 4 comments
Labels
C-forge Command: forge Cmd-forge-script Command: forge script T-bug Type: bug T-to-investigate Type: to investigate
Milestone

Comments

@hensha256
Copy link

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (68c3663 2024-01-11T00:37:40.946762000Z)

What command(s) is the bug in?

forge script --verify

Operating System

macOS (Apple Silicon)

Describe the bug

When trying to deploy and verify a contract, all in 1 command, forge sometimes successfully deploys the contract, but then throws and error when verifying:

Details: Fail - Unable to verify. Compiled contract deployment bytecode does NOT match the transaction deployment bytecode.

The exact command being run was:

forge script --broadcast --skip-simulation \
--rpc-url "https://arb1.arbitrum.io/rpc" \
--private-key XX \
--sig 'run()' \
script/deployParameters/DeployArbitrum.s.sol:DeployArbitrum \
--etherscan-api-key XX \
--verify

to deploy Uniswap's UniversalRouter, using solidity 0.8.17, with via-ir enabled. The commit in question is 6a9846bfa6f488404b69128afdcc7522fa34496d.

I encountered this issue on all chains that we tried (Arbitrum, Optimism, Sepolia). We additionally tried from another device to deploy the same commit and the same issue occurred.

I then checked out a different commit of the repo (52be38e407ce07f2e84c7e101673f32e72bd0f09), and the contract was able to deploy and verify with no issues.

The issue is similar in aspects to what people have described in #3507, however the solution that seemed to work for people there was to add viaIR:true to the json output, and verify manually on etherscan. When I tried this, it seems forge already now correct sets viaIR to true in the json - so this solution did not fix my issue.

@lifeofjer
Copy link

I am also having this issue, and have tried every possible resolution from reviewing the foundry repo issues:

  • Polygon Network
  • Custom implementation of the OpenZeppelin ERC721 libraries

forge verify-contract <CONTRACT_ADDRESS_HERE> <CONTRACT_SRC_HERE> --evm-version london --compiler-version v0.8.17+commit.8df45f5f --num-of-optimizations 200 --chain-id 137 --watch --constructor-args <ABI_ENCODED_ARGS_HERE> --etherscan-api-key <ETHERSCAN_API_KEY_HERE> --via-ir

Current foundry version:

forge 0.2.0 (9b73e06 2024-02-22T00:16:42.490626000Z)

@sambacha
Copy link
Contributor

Depending on your foundry.toml configuration, certain options can lead to non-deterministic build output. Below are some settings that help enforce a more deterministic output in building/deploying

[profile.default]

# @see {@link https://github.com/foundry-rs/foundry/issues/4060}
auto_detect_remappings = false
bytecode_hash = "none"
cbor_metadata = false
sparse_mode = false

[profile.default.optimizer_details]
# constantOptimizer = true
yul = true

Important

A bug in Solidity v0.8.13-v0.8.21 causes the viaIR-generated bytecode to differ depending on how the dependencies are imported. For more details, see PaulRBerg's report on Twitter.

@pegahcarter
Copy link
Contributor

You may have success here migrating to bun.

@zerosnacks zerosnacks added C-forge Command: forge Cmd-forge-script Command: forge script T-to-investigate Type: to investigate labels Jun 27, 2024
@zerosnacks zerosnacks added this to the v1.0.0 milestone Jul 26, 2024
@grandizzy
Copy link
Collaborator

@hensha256 this should be fixed in latest versions (#3507), please retry and reopen if still an issue. thank you!

@grandizzy grandizzy closed this as not planned Won't fix, can't repro, duplicate, stale Oct 29, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Foundry Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge Cmd-forge-script Command: forge script T-bug Type: bug T-to-investigate Type: to investigate
Projects
Archived in project
Development

No branches or pull requests

6 participants