Skip to content

bug(verify-bytecode) fails to verify deployed code due to way constructor arguments are applied #8505

Closed
@maurelian

Description

@maurelian

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 (62cdea8 2024-07-23T00:18:49.756549000Z)

What command(s) is the bug in?

forge verify-bytecode

Operating System

macOS (Apple Silicon)

Describe the bug

I am trying to verify the source code of a contract, and am successful with the init code but not the deployed bytecode.

It appears to me that there is an issue with how forge vb is applying constructor arguments to compute the deployed code, as I'm able to generate the matching deployed code using geth's evm utility.

Reproducing the failure

# clone the optimism monorepo, and do some navigation to get to the right state
git clone https://github.com/ethereum-optimism/optimism.git
cd optimism
git checkout c93958755b4f6ab7f95cc0b2459f39ca95c06684
cd packages/contracts-bedrock

# attempt to verify the contract
FOUNDRY_EVM_VERSION=london forge verify-bytecode 0x0d3495a95eC5720453C0d70a88Bf14fe13ebe969 OptimismMintableERC20Factory --constructor-args 0x6d0f65D59b55B0FEC5d2d15365154DcADC140BF3

The last command will output:

Verifying bytecode for contract OptimismMintableERC20Factory at address 0x0d3495a95eC5720453C0d70a88Bf14fe13ebe969
The provided constructor args do not match the constructor args from etherscan. This will result in a mismatch - Using the args from etherscan
Creation code matched with status partial
Runtime code did not match - this may be due to varying compiler settings

Verifying the issue

Contrary to the error message, the constructor arg is correct, as the address provided matches the last 32 bytes of the input code in the creation tx.

Additionally, I was able to manually compute the exact same onchain bytecode using the following process (executed in the same dir as above):

# get onchain code:
cast code 0x0d3495a95eC5720453C0d70a88Bf14fe13ebe969 > onchain.txt
# get locally compiled initcode
jq -r '.bytecode.object' forge-artifacts/OptimismMintableERC20Factory.sol/OptimismMintableERC20Factory.json > initcode.txt
# compute deployed code by appending the abi encoded constructor args to the initcode
evm --code $(cat initcode.txt)0000000000000000000000006d0f65d59b55b0fec5d2d15365154dcadc140bf3 run > computed.txt
# get a diff of the hex files, successful if empty
diff <(hexdump -C onchain.txt) <(hexdump -C computed.txt)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions