eth-brownie / brownie

A Python-based development and testing framework for smart contracts targeting the Ethereum Virtual Machine.
https://eth-brownie.readthedocs.io
MIT License
2.64k stars 550 forks source link

Contracts compiled with Brownie won't verify on Etherscan #766

Closed Netherdrake closed 3 years ago

Netherdrake commented 4 years ago

Environment information

What was wrong?

For about half the contacts compiled and deployed via brownie I'm struggling to verify the bytecode on Etherscan.

After deploying a contract with Contract.deploy(...) I would use truffle-flattener to generate a single solidity file, and https://abi.hashex.org/ to re-create abi-encoded constructor arguments.

I made sure to always check the right compiler version and optimization params.

Here is my brownie config:

compiler:
  evm_version: null
  solc:
    version: 0.6.12
    optimizer:
      enabled: true
      runs: 200
    remappings:
      - "@openzeppelin=OpenZeppelin/openzeppelin-contracts@3.1.0"

When I compile the same contract trough Remix (https://remix.ethereum.org/) it verifies without issues.

Compiled with Brownie: https://etherscan.io/address/0xFD01f7a212eAa4aCAdB986fCb74951D510594c8E#code

Compiled with Remix: https://etherscan.io/address/0x214f2421950de2ee4ff6a394ed677cf296efec0f#code

I really like Brownie and would like to use it to deploy contracts (instead of having to do them by hand via Remix). Any ideas for how to debug this?

iamdefinitelyahuman commented 4 years ago

Hi,

Likely the issue you're running into is related to the compiler version or an optimization setting, but it's hard to say for sure. I think the best solution to this is to have Brownie submitting the source code to etherscan via their API.

Etherscan's API accepts either flattened single-file contracts, or standard JSON compiler input. I'm not sure which method I prefer.. as an end user I find the flattened files easier to read, but for composability with other tooling the JSON input is a much cleaner approach. Also generating the JSON input is a part of Brownie's compilation process and so much more straightforward to submit as opposed to having to add logic for flattening.

Some work toward submitting via the API has been done in #651 but it isn't finished yet. It's been on my TODO list for a minute now, but unfortunately never made it to the top. If you have the bandwidth to work on it I'll happily accept a PR :pray: otherwise, best I can offer is that it definitely will happen, but I can't can't say for sure when it will happen.

Netherdrake commented 4 years ago

I tried to quickly modify https://github.com/eth-brownie/brownie/blob/master/brownie/project/compiler/__init__.py to dump standard json input, but etherscan did not accept it.

I will experiment a bit with compiler version and try disabling optimization.

sabotagebeats commented 3 years ago

@iamdefinitelyahuman I believe found the appropriate json, but how can I find the appropriately deployed hex constructor ABI to submit to etherscan?

matnad commented 3 years ago

Implemented in #914