foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.17k stars 1.7k forks source link

`forge script --verify` intermittently generates bytecode mismatch #6780

Open hensha256 opened 8 months ago

hensha256 commented 8 months ago

Component

Forge

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

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 commented 7 months ago

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

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 commented 7 months ago

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.

mhxw commented 6 months ago

Component

组件

Forge

锻造

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

您是否确保所有这些都是最新的?

  • [x] Foundry 铸造厂
  • [x] Foundryup 铸造

What version of Foundry are you on?

你用的是什么版本的铸造厂?

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

Forge0.2.0(68c36632024-01-11T00:37:40.946762000Z)

What command(s) is the bug in?

错误出现在哪些命令中?

forge script --verify

伪造脚本,核实

Operating System

操作系统

macOS (Apple Silicon)

苹果硅(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:

当尝试部署和验证一个契约时,all in 1命令有时会成功部署契约,但是在验证时会抛出错误:

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.

在启用 via-ir 的情况下,使用 solid0.8.17部署 Uniswap 的 UniversalRouter。

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.

然后我检查了一个不同的回购提交(52be38e407ce07f2e84c7e101673f32e72bd0f09) ,合同能够部署和验证,没有问题。

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.

这个问题在某些方面与人们在 # 3507中所描述的相似,但是似乎对人们有效的解决方案是添加 viaIR: true to The json output,并在 etherscanner 上手动验证。当我尝试这个,它似乎锻造现在已经正确设置 viaIR 为真在 json-所以这个解决方案没有解决我的问题。

Component

Forge

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

  • [x] Foundry
  • [x] 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.

me too

foundryup: installed - forge 0.2.0 (f625d0f 2024-04-02T00:16:42.810315000Z)
foundryup: installed - cast 0.2.0 (f625d0f 2024-04-02T00:16:42.803795000Z)
foundryup: installed - anvil 0.2.0 (f625d0f 2024-04-02T00:16:42.824772000Z)
foundryup: installed - chisel 0.2.0 (f625d0f 2024-04-02T00:16:42.782965000Z)
[profile.default]
src = 'contracts'
out = 'out'
libs = ['lib']
via_ir = true
solc_version = '0.8.17'
optimizer_runs = 1_000_000
fs_permissions = [{ access = "read", path = "./script/deployParameters/"}]
auto_detect_remappings = false
bytecode_hash = "none"
cbor_metadata = false
sparse_mode = false

[fmt]
line_length = 120
quote_style = 'single'

[profile.lite.optimizer_details.yulDetails]
optimizerSteps = ''
pegahcarter commented 3 months ago

You may have success here migrating to bun.