4

I'm developing a contract in hardhat project. But now I want to write test by foundry. My problem is I'm using create2, but when running contract by hardhat and foundry they gave different addresses. I found the reason is the bytecode of contract from hardhat and foundry are different (10 ~ 20 bytes close the end). Here is my hardhat config + foundry toml.

hardhat.config.js

 config = {
  solidity: {
    version: "0.8.18",
    evmVersion: "london",
    settings: {
      optimizer: {
        enabled: true,
        runs: 200,
      },
    },
  },
...
}

foundry.toml

evm_version = 'london'
optimizer = true
optimizer_runs = 200
solc_version = '0.8.18'
via_ir = false

This is how they different, they have the same length, but different near the end enter image description here What reasons affect to bytecode?

6
  • This might be because of what bytecode are you trying to fetch. Maybe one of them outputs the creation code and another one simply runtime bytecode? Aug 9 at 10:58
  • I get log both compiled bytecode and runtime bytecode. The compiled and runtime bytecode are the same for each foundry(in out) and hardhat(in artifacts).
    – CT95
    Aug 10 at 1:35
  • I just updated the question, add image about how they r different.
    – CT95
    Aug 10 at 1:51
  • I'll amplify the issue. I am unaware of this behavior. I guess this issue on Git Hub is by you, I'll amplify this issue in my connections. github.com/foundry-rs/foundry/issues/5559 Aug 10 at 5:29
  • 2
    The issue can be solved by here:github.com/foundry-rs/foundry/issues/…
    – CT95
    Aug 11 at 7:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.