Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unverified contracts with "similiar code" not handled [APE-1451] #104

Open
fubuloubu opened this issue Oct 9, 2023 · 5 comments
Open

Unverified contracts with "similiar code" not handled [APE-1451] #104

fubuloubu opened this issue Oct 9, 2023 · 5 comments

Comments

@fubuloubu
Copy link
Member

example:
https://etherscan.io/address/0x5777d92f208679db4b9778590fa3cab3ac9e2168#code

raises:

ERROR (ape): Error with contract ABI: Expecting value: line 1 column 1 (char 0)
ERROR (ape): (ContractNotFoundError) Failed to get contract type for address '0x5777d92f208679DB4b9778590Fa3CAB3aC9e2168'. Contract may need verification.
@vany365 vany365 changed the title Unverified contracts with "similiar code" not handled Unverified contracts with "similiar code" not handled [APE-1451] Oct 9, 2023
@salparadi
Copy link

salparadi commented Dec 13, 2023

I just came across this and dug a little. There isn't a way to see the "similar code" contract via the API. So while I don't have a true fix, I have a band-aid for the issue I came across: Uniswap V3 pools. For some reason not all of them are verified despite Uniswap saying they should be on deploy (some certainly do get verified automatically). Not sure this is worth implementing, but figured I would add this here for consideration and maybe to get someone smarter than I thinking creatively.

So when ape-etherscan comes across a pool that isn't verified, get info on the contract creation:

https://api.etherscan.io/api?module=contract&action=getcontractcreation&contractaddresses=0x9e31EfFFE1e016f514F774F43d91A85eBBC11564

That returns something like this:

{
    "status": "1",
    "message": "OK",
    "result": [
        {
            "contractAddress": "0x9e31efffe1e016f514f774f43d91a85ebbc11564",
            "contractCreator": "0x80bb828aa8935b716af2a481db357d3a453db9ea",
            "txHash": "0x97672a1f8b4a8b4ae6d1522396fdb9567a132b030b04b2727dca6a61f35a04c6"
        }
    ]
}

Pull out the txHash and you can call the eth_getTransactionByHash endpoint to get info about the transaction

https://api.etherscan.io/api?module=proxy&action=eth_getTransactionByHash&txhash=0x97672a1f8b4a8b4ae6d1522396fdb9567a132b030b04b2727dca6a61f35a04c6

That returns a bunch of JSON. Pull out the to value and check it against some sort of list of curated important addresses. This is the part that is messy and not ideal. For example, to support unverified V3 Pools, you could use the address below which is the Uniswap V3: Positions NFT address. It seems all pool creation transactions are sent to this address. Save the generic V3 ABI somewhere as they are all the same.

if to == 0xC36442b4a4522E871399CD717aBDD847Ab11FE88

   grab the abi constant and save the details to the contract cache for the original unverified contract.

I recognize this isn't perfect.

@fubuloubu
Copy link
Member Author

makes me wonder if we should index and publish all the pools that were never published lol

@antazoey
Copy link
Member

antazoey commented Feb 2, 2024

It should be working! https://github.com/ApeWorX/ape-etherscan/blob/main/ape_etherscan/verify.py#L402-L403

I have seen it work plenty of times.
Something else may be going on here, circumstantial

Edit: sorry I thought this ticket was for verification but it is for retrieval, so idk actually!

@fubuloubu
Copy link
Member Author

Edit: sorry I thought this ticket was for verification but it is for retrieval, so idk actually!

Yeah, this is when a contract is not verified on etherscan but it still has some ABI information because it is "similar to" another contract (matching bytecode, but basically unsure about the initcode matching)

This is common for contracts created via "factory pattern" that produces a lot of child contracts with the same code

@Ninjagod1251
Copy link

Ninjagod1251 commented Jul 30, 2024

we stumbled on a solution for this error. @salparadi A solution to the "Etherscan doesn't have the ABI for this unverified contract" issue would be to BYPASS this check.

Check out this snippet and see if it can work for you:
ApeWorX/uniswap-sdk#4 (comment)

It is an alternative solution which solves the issue specifically for Uniswap pools contracts.
Since it bypasses ever having to go talk to etherscan in the first place.
We are loading the type from the package resource bundled with the Uniswap sdk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants