question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Etherscan verification fails when using library

See original GitHub issue

Environment information

  • brownie Version: v1.17.0
  • solc Version: 0.8.9
  • Python Version: 3.9
  • OS: linux

pragma solidity 0.8.9;

library MerkleLib {

    function verifyProof(bytes32 root, bytes32 leaf, bytes32[] memory proof) public pure returns (bool) {
        bytes32 currentHash = leaf;

        for (uint i = 0; i < proof.length; i += 1) {
            currentHash = parentHash(currentHash, proof[i]);
        }

        return currentHash == root;
    }

    function parentHash(bytes32 a, bytes32 b) public pure returns (bytes32) {
        if (a < b) {
            return keccak256(abi.encode(a, b));
        } else {
            return keccak256(abi.encode(b, a));
        }
    }

}

contract Test {
    using MerkleLib for bytes32;

    constructor() {
        bytes32 root = bytes32(0);
        bytes32 leaf = bytes32(0);
        bytes32[] memory proof = new bytes32[](1);
        root.verifyProof(leaf, proof);
    }
}

This code compiles and runs. However, if I try to publish_source, it fails. Commenting out the verifyProof line allows it to be published. I believe this is not related to the recent flattener update, as this issue was on earlier versions of brownie as well.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
skellet0rcommented, Nov 8, 2021

ah ok I see, just verified myself and the culprit is unlinked libraries. Just will require properly adding the below to the standard json input sent to etherscan

    "libraries": {
      // The top level key is the the name of the source file where the library is used.
      // If remappings are used, this source file should match the global path
      // after remappings were applied.
      // If this key is an empty string, that refers to a global level.
      "myFile.sol": {
        "MyLib": "0x123123..."
      }
0reactions
skellet0rcommented, Nov 12, 2021

Odd, if you have a repo I could test against I can dig a little deeper to see what other layers are missing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot verify contracts with libraries on Etherscan
Since the last week I have not been able to verify contracts on Etherscan if they use libraries. I was able to do...
Read more >
Etherscan fails verification even for the matching bytecodes
Hi, I've found the weird issue that etherscan fails to match the bytecodes during verification by JSON-input even when they are the same...
Read more >
Error in plugin @nomiclabs/hardhat-etherscan: The ...
Error in plugin @nomiclabs/hardhat-etherscan: The contract verification failed. Reason: Fail - Unable to verify - with arguments · Ask Question.
Read more >
Verify Smart Contracts with Etherscan Plugins
Both plugins can be used to automate the process of verifying contracts by locally detecting which contracts to verify and which Solidity libraries...
Read more >
Verifying your contracts | Ethereum development ...
Verifying a contract means making its source code public, along with the compiler ... The first thing you need is an API key...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found