1

I have a contract called Test , which uses a library called LCG. They are respectively defined in the .sol files with the same name as the contract:

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.4;

import "./LCG.sol";

contract Test {
    using LCG for LCG.iterator;
    LCG.iterator public x;

    constructor () {
        x.iterate();
    }
}

and

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.4;

library LCG {
    struct iterator {
        uint x;
    }

    function iterate (iterator storage i) external {
        i.x = i.x + 1;
    }
}

I deployed the contract to 0x1773c9913710bd3B9Ba3AFE4b08574C63631EE3e on Rinkeby. When I ask etherscan to verify the contract I get the following error message:

Compiler debug log:
Error! Unable to generate Contract ByteCode and ABI
Found the following ContractName(s) in source code: LCG.sol:LCG, Test.sol:Test
But we were unable to locate a matching bytecode (err_code_2)

and then

ByteCode (what we are looking for):
608060405234801561001057600080fd5b50600073e91f7cf9f5d9943f43171ab141c8f692ffa5bdbb63760ebcb390916040518263ffffffff1660e01b815260040161004b9190610087565b60006040518083038186803b15801561006357600080fd5b505af4158015610077573d6000803e3d6000fd5b505050506100a2565b8082525050565b600060208201905061009c6000830184610080565b92915050565b60b9806100b06000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80630c55699c14602d575b600080fd5b60336047565b604051603e91906060565b60405180910390f35b60008060000154905081565b605a816079565b82525050565b6000602082019050607360008301846053565b92915050565b600081905091905056fe{ipfs}64736f6c63430008040033

versus

We tried looking for a match from the list of compiled contract bytecode outputs (as listed below), but was unable to find an exact match.

1) LCG.sol:LCG 
6101a3610053600b82828239805160001a607314610046577f4e487b7100000000000000000000000000000000000000000000000000000000600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106100355760003560e01c8063760ebcb31461003a575b600080fd5b81801561004657600080fd5b50610061600480360381019061005c9190610094565b610063565b005b6001816000015461007491906100bd565b816000018190555050565b60008135905061008e81610156565b92915050565b6000602082840312156100a657600080fd5b60006100b48482850161007f565b91505092915050565b60006100c88261011d565b91506100d38361011d565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561010857610107610127565b5b828201905092915050565b6000819050919050565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b61015f81610113565b811461016a57600080fd5b5056fe{ipfs}64736f6c63430008040033

2) Test.sol:Test
608060405234801561001057600080fd5b50600073__$ba5a92dcf866592fe0e4658ad284226a6d$__63760ebcb390916040518263ffffffff1660e01b815260040161004b9190610087565b60006040518083038186803b15801561006357600080fd5b505af4158015610077573d6000803e3d6000fd5b505050506100a2565b8082525050565b600060208201905061009c6000830184610080565b92915050565b60b9806100b06000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80630c55699c14602d575b600080fd5b60336047565b604051603e91906060565b60405180910390f35b60008060000154905081565b605a816079565b82525050565b6000602082019050607360008301846053565b92915050565b600081905091905056fe{ipfs}64736f6c63430008040033

Somehow the compiled bytecode of Test.sol has those dollar signs inside (e.g. __$ba5a92dcf866592fe0e4658ad284226a6d$__6).

I also failed to verify when I put everything into one single file. What's going wrong?

0

1 Answer 1

2

This is the placeholder sign used for libraries. Maybe you're not providing the correct libraries?  The evm replaces the substring between the $ symbols with the library address during compilation. If the libraries are not provided then the resulting bytecode still has the placeholders.

(Credit for this answer goes to Viktor from Tenderly, thanks a lot!)

1
  • What about using libraries declared in a single .sol file? REMIX IDE compiled and deployed correctly this file, but Polygonscan verify failed with the error: "Error! Unable to generate Contract ByteCode and ABI" and say the ByteCode is different. I am very confused Aug 15, 2022 at 10:48

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.

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