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.

Verifying with ABIEncoderV2 troubles

See original GitHub issue

Hi there,

Trying to verify some contracts using ABIEncoderV2 and I seem to be running into trouble. Here is a simple repo demonstrating the issue.

https://github.com/mrwillis/abiencoder-truffle-verification

I read in the README the pragma experimental ABIEncoderV2 has to come before the solidity pragma, but I’ve tried both orders and neither seems to work. Have also tried using a higher solidity version (0.6.11), but also fails.

Any ideas?

Output using debug:

julian@julian-wilson:~/betx/abiencoder-truffle-verification$ truffle run verify MetaCoin --network rinkeby --debug DEBUG logging is turned ON Running truffle-plugin-verify v0.3.11 Verifying MetaCoin Reading artifact file at /home/julian/betx/abiencoder-truffle-verification/build/contracts/MetaCoin.json Retrieving constructor parameters from https://api-rinkeby.etherscan.io/api?apiKey=[key]&module=account&action=txlist&address=0x9E8C724d9EAf24C34CcA3bDC7De469492051af84&page=1&sort=asc&offset=1 Constructor parameters received: 0x Flattening source file /home/julian/betx/abiencoder-truffle-verification/contracts/MetaCoin.sol Sending verify request with POST arguments: { “apikey”: “[key]”, “module”: “contract”, “action”: “verifysourcecode”, “contractaddress”: “0x9E8C724d9EAf24C34CcA3bDC7De469492051af84”, “sourceCode”: “pragma solidity 0.5.16;\npragma experimental ABIEncoderV2;\n\n\n// SPDX-License-Identifier: MIT\nlibrary ConvertLib {\n\tfunction convert(uint amount,uint conversionRate) internal pure returns (uint convertedAmount)\n\t{\n\t\treturn amount * conversionRate;\n\t}\n}\n\n// SPDX-License-Identifier: MIT\n// This is just a simple example of a coin-like contract.\n// It is not standards compatible and cannot be expected to talk to other\n// coin/token contracts. If you want to create a standards-compliant\n// token, see: https://github.com/ConsenSys/Tokens. Cheers!\ncontract MetaCoin {\n\tmapping (address => uint) balances;\n\n\tevent Transfer(address indexed _from, address indexed _to, uint256 _value);\n\n\tconstructor() public {\n\t\tbalances[tx.origin] = 10000;\n\t}\n\n\tfunction sendCoin(address receiver, uint amount) public returns(bool sufficient) {\n\t\tif (balances[msg.sender] < amount) return false;\n\t\tbalances[msg.sender] -= amount;\n\t\tbalances[receiver] += amount;\n\t\temit Transfer(msg.sender, receiver, amount);\n\t\treturn true;\n\t}\n\n\tfunction getBalanceInEth(address addr) public view returns(uint){\n\t\treturn ConvertLib.convert(getBalance(addr),2);\n\t}\n\n\tfunction getBalance(address addr) public view returns(uint) {\n\t\treturn balances[addr];\n\t}\n}”, “codeformat”: “solidity-single-file”, “contractname”: “MetaCoin”, “compilerversion”: “v0.5.16+commit.9c3226ce”, “optimizationUsed”: 1, “runs”: 200, “constructorArguements”: “” } Checking status of verification request 3vngcqycsnakc8wa4i92bbg5imqtdsw7byksdcfibmfwtvcyt5 Fail - Unable to verify Failed to verify 1 contract(s): MetaCoin

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rkaliscommented, Aug 13, 2020

Hey @Enigmatic331 I have been working on allowing the user to provide their license manually (--license MIT). And using @mrwillis’ example repo I ran into the issue that the source code is failing the verification through truffle-plugin-verify and through the Api demo page, but succeeding the verification on the web form.

This is the data sent to the API:

{
  "apikey": "<redacted>",
  "module": "contract",
  "action": "verifysourcecode",
  "contractaddress": "0xF177FF5d7D91381cDDcF79cC73DbFfDa8D471383",
  "sourceCode": "// SPDX-License-Identifier: MIT\n\npragma experimental ABIEncoderV2;\npragma solidity 0.6.11;\n\n\n// \nlibrary ConvertLib {\n\n\tstruct TestStruct {\n\t\tuint256 name;\n\t}\n\n\tfunction convert(uint amount,uint conversionRate) internal pure returns (uint convertedAmount)\n\t{\n\t\treturn amount * conversionRate;\n\t}\n}\n\n// \n// This is just a simple example of a coin-like contract.\n// It is not standards compatible and cannot be expected to talk to other\n// coin/token contracts. If you want to create a standards-compliant\n// token, see: https://github.com/ConsenSys/Tokens. Cheers!\ncontract MetaCoin {\n\tmapping (address => uint) balances;\n\n\tevent Transfer(address indexed _from, address indexed _to, uint256 _value);\n\n\tconstructor() public {\n\t\tbalances[tx.origin] = 10000;\n\t}\n\n\tfunction sendCoin(address receiver, uint amount) public returns(bool sufficient) {\n\t\tif (balances[msg.sender] < amount) return false;\n\t\tbalances[msg.sender] -= amount;\n\t\tbalances[receiver] += amount;\n\t\temit Transfer(msg.sender, receiver, amount);\n\t\treturn true;\n\t}\n\n\tfunction getBalanceInEth(address addr) public view returns(uint){\n\t\treturn ConvertLib.convert(getBalance(addr),2);\n\t}\n\n\tfunction getBalance(address addr) public view returns(uint) {\n\t\treturn balances[addr];\n\t}\n\n\tfunction test(ConvertLib.TestStruct memory testObj) public pure {\n\t\trequire(testObj.name > 10);\n\t}\n}",
  "codeformat": "solidity-single-file",
  "contractname": "MetaCoin",
  "compilerversion": "v0.6.11+commit.5ef660b1",
  "optimizationUsed": 0,
  "runs": 200,
  "constructorArguements": "",
  "licenseType": 3
}

The address above is not verified yet, so you can use it in testing. Since the --license stuff is currently just WIP, it’s not published anywhere it might be difficult to test for you guys. Let me know if you want me to publish a “beta” tag to NPM or something.

1reaction
rkaliscommented, Aug 3, 2020

Hey @mrwillis, I must have completely missed the notification for this issue, apologies!

One thing I noticed is that the flattened code contains two SPDX license identifiers, which is currently not working (see comments in #27). After removing it, the code still doesn’t seem to be verifying correctly. After updating the Solidity version to v0.6.11 like you mentioned before and moving the experimental pragma one line up, it now verifies correctly. I’m not sure what the cause of the failure is for v0.5.16, but if it is working correctly for v0.6, then that I’d say that is good enough.

So the main cause of this failure was probably the duplicate SPDX identifiers. I still need to come up with a good fix for that. Something I’m thinking might be to detect whether there are multiple identifiers, and if so, we strip out all of them and require the user to provide a license manually e.g. --license MIT.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inability to verify contract with ABIEncoderV2 on Etherscan
Can anyone lend support to the hypothesis that it is lack of support for ABIEncoderV2 that is still causing code verification problems?
Read more >
Solidity Optimizer and ABIEncoderV2 Bugs
How to check if contract is vulnerable. The bug only manifests itself when all of the following conditions are met: Storage data involving ......
Read more >
Solidity 0.6.8 Release Announcement
Problem : When ABIEncoderV2 is enabled, string literals passed directly to ... to contain a callvalue check that results in contract creation reverting, ......
Read more >
ethereum/solidity - Gitter
Having problems verifying contracts compiled with solc 0.6.12 and ABIEncoderV2 . ... @elenadimitrova "verifying" as in "verifying on etherscan"?
Read more >
FAQ — Remix - Ethereum IDE 1 documentation
A: Old versions of solidity compiler had this problem with chrome. Please change the compiler ... Q: How to verify a contract that...
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