1

I'm trying to reproduce the following contract compilation on Etherscan: https://etherscan.io/address/0x7a250d5630b4cf539739df2c5dacb4c659f2488d#code.


Runtime bytecode on-chain

I can get the runtime bytecode on chain by calling eth_getCode for the contract address from a JSON RPC client connected to mainnet.

Here is the bytecode I get:

60806040526004361061018f5760003560e01c80638803dbee116100d6578063c45a01551161007f578063e8e3370011610059578063e8e3370014610c71578063f305d71914610cfe578063fb3bdb4114...

Runtime bytecode (Etherscan)

Here, looking at the etherscan contract information in the link above, I notice 3 key things: compiler version (0.6.6), optimisation runs (999999) and evm version (istanbul).

So I set up Solidity compilation as follows:

{
    "language": "Solidity",
    "sources":
    {
        "uniswap.sol":
        {
            "urls":
            [
                "./uniswap.sol"
            ]
        }
    },
    "settings": {
        "optimizer": {
            "runs": 999999
        },
        "evmVersion": "istanbul",
        "outputSelection": {
            "*": {
                "*": [ "evm.deployedBytecode" ]
            }
        }
    }
}

and ran with:

solc --standard-json --allow-paths .

But I'm getting slightly different bytecode:

60806040526004361061018f5760003560e01c80638803dbee116100d6578063c45a01551161007f578063e8e3370011610059578063e8e337001461131e578063f305d71914611406578063fb3bdb4114...

What could be wrong in the reproduction and how may I amend it? Can constructor arguments change runtime bytecode if immutable values are used?

6
  • Did you check it with Bytecode Verifier by Consensys, also this article Verify Ethereum Contracts Using Web3.js and Solc may help understand what may be wrong.
    – Ismael
    Oct 3 '20 at 16:32
  • @Ismael Thanks for sharing the article! From what I understand, the verifier is out of date. I've gone through all the steps in the article and have not diverged from them - unfortunately I'm getting the same outcome.
    – Peteris
    Oct 5 '20 at 19:37
  • Did you enable the optimizer "enabled": true?
    – Ismael
    Oct 5 '20 at 22:24
  • Possibly related: the optimizer has changed in v0.6.12. Oct 6 '20 at 7:45
  • @Ismael - amazing, that was it. There are now only about ~100 characters that are different in the respective constructor bytecodes after removing constructor arguments.
    – Peteris
    Oct 6 '20 at 10:58
1

After some comments we found the optimizer wasn't enabled

The setting for the optimizer has to be modified to add a "enabled", so it look like this:

"settings": {
    "optimizer": {
        "enabled": true,
        "runs": 999999
    },
    ....
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.