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

Can not verify deployed contract #852

Closed
2 tasks done
piavgh opened this issue Mar 7, 2022 · 21 comments
Closed
2 tasks done

Can not verify deployed contract #852

piavgh opened this issue Mar 7, 2022 · 21 comments
Labels
C-forge Command: forge Cmd-forge-create Command: forge create P-high Priority: high T-bug Type: bug

Comments

@piavgh
Copy link

piavgh commented Mar 7, 2022

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.1.0 (2ff2b33 2022-03-06T00:10:54.403068+00:00)

What command(s) is the bug in?

forge verify-contract

Operating System

macOS (amd)

Describe the bug

The code of contract is here: https://github.com/piavgh/simple-ens-foundry

I deployed the contract using this command:

forge create --rpc-url https://eth-ropsten.alchemyapi.io/v2/<alchemy-key> --constructor-args "geek" --private-key <my-private-key> src/Domains.sol:Domains

Then I verified it with

forge verify-contract --chain-id 3 --num-of-optimizations 200 --constructor-args 0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000046765656b00000000000000000000000000000000000000000000000000000000 --compiler-version v0.8.10+commit.fc410830 0x19f4cd4bc239b8c32f264bf13efbe31a0fc4194d src/Domains.sol:Domains <my-etherscan-api-key>

I tried with different values of --num-of-optimizations: 0, 200 (default), 1000000, and even skip this argument, but all of them give the same value when I tried the forge verify-check:

Error:
   0: Contract verification failed:
      Response: `NOTOK`
      Details: `Fail - Unable to verify`

Location:
   cli/src/cmd/verify.rs:126

Backtrace omitted.
Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
@piavgh piavgh added the T-bug Type: bug label Mar 7, 2022
@mattsse
Copy link
Member

mattsse commented Mar 7, 2022

perhaps related to #811

@onbjerg onbjerg added C-forge Command: forge Cmd-forge-create Command: forge create P-high Priority: high labels Mar 7, 2022
@nnnnicholas
Copy link

nnnnicholas commented Mar 22, 2022

I believe the root of the problem is the Etherscan API Key

An API request with Invalid API Key:
{"status":"0","message":"NOTOK","result":"Invalid API Key"}

source: https://info.etherscan.com/api-return-errors/

However I am having the same issue despite attempting to verify with multiple API Keys and via the Etherscan website, too.

The problem may have to do with using unversioned OpenZeppelin imports in the contract. See here https://forum.openzeppelin.com/t/how-to-verify-a-contract-on-etherscan-bscscan-polygonscan/14225#use-versioned-imports-in-remix-10

@piavgh
Copy link
Author

piavgh commented Mar 23, 2022

I believe the root of the problem is the Etherscan API Key

An API request with Invalid API Key:
{"status":"0","message":"NOTOK","result":"Invalid API Key"}

source: https://info.etherscan.com/api-return-errors/

However I am having the same issue despite attempting to verify with multiple API Keys and via the Etherscan website, too.

The problem may have to do with using unversioned OpenZeppelin imports in the contract. See here https://forum.openzeppelin.com/t/how-to-verify-a-contract-on-etherscan-bscscan-polygonscan/14225#use-versioned-imports-in-remix-10

I don't think so. I use the same key but I was able to verify contract with hardhat

@adamxyzxyz
Copy link

hey guys, has this been resolved? having the exact same issue

@pyk
Copy link
Contributor

pyk commented Apr 6, 2022

It seems that this caused by the forge flatten is only stripping the license and solidity version but not the pragma

for example:

pragma solidity 0.8.11;
pragma experimental ABIEncoderV2;

pragma solidity 0.8.11; is removed but not the pragma experimental ABIEncoderV2;

@piavgh
Copy link
Author

piavgh commented Apr 11, 2022

@pyk : I can verify a simple counter contract with the newest version of foundry.

But somehow with this contract, it's still failed: https://github.com/piavgh/simple-ens-foundry

  • To get the constructor args:
cast abi-encode "constructor(string)" "geek"
0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000046765656b00000000000000000000000000000000000000000000000000000000
  • To deploy the contract:
forge create --rpc-url https://eth-ropsten.alchemyapi.io/v2/<my_alchemy_key> --constructor-args 0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000046765656b00000000000000000000000000000000000000000000000000000000 --private-key <my_private_key> src/Domains.sol:Domains
  • To verify the contract:
forge verify-contract --chain-id 3 --constructor-args 0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000046765656b00000000000000000000000000000000000000000000000000000000 --compiler-version v0.8.10+commit.fc410830 0x50d496f74a36ff6c4397440b31d26c8108eae5b5 src/Domains.sol:Domains <my_etherscan_key>
  • To verify check:
forge verify-check --chain-id 3 7janbc6hd9kicjdvvcj6fcacmnzpegijkytn5flhdxmgkivcv9 <my_etherscan_key>

The result is still:

Error:
   0: Contract verification failed:
      Response: `NOTOK`
      Details: `Fail - Unable to verify`

@wminshew
Copy link

wminshew commented Apr 11, 2022

haven't had any luck on the latest foundry master branch (includes #1242) as well with the below setup. Not entirely sure if I should be opening up a new issue or tagging on to this one

repo https://github.com/0xSplits/splits-vesting; commands:
make contract=VestingModuleFactory deploy-ropsten (need ALCHEMY_ROPSTEN_KEYand PRIVATE_KEY set in .env.local)
then
make contract=VestingModuleFactory address={address} chain-id=3 verify

@sambacha
Copy link
Contributor

haven't had any luck on the latest foundry master branch as well with the below setup. Not entirely sure if I should be opening up a new issue or tagging on to this one

repo https://github.com/0xSplits/splits-vesting; commands:

make contract=VestingModuleFactory deploy-ropsten (need ALCHEMY_ROPSTEN_KEYand PRIVATE_KEY set in .env.local)

then

make contract=VestingModuleFactory address={address} chain-id=3 verify

I forked this repo and was able to duplicate your issue. Have you tried adding extra output metadata to your build? I think etherscan needs the additional information in metadata for deployments that have multiple libraries etc

@wminshew
Copy link

I forked this repo and was able to duplicate your issue. Have you tried adding extra output metadata to your build? I think etherscan needs the additional information in metadata for deployments that have multiple libraries etc

hi -- would love to try this.. where can I learn more about how to do this?

@wminshew
Copy link

(after some conversation on telegram)

tried cleaning & redeploying w bytecode_hash = 'ipfs' but still couldn't verify

@mattsse
Copy link
Member

mattsse commented Apr 11, 2022

@piavgh can you have a look at #1263 ?

this should tell you what went wrong here

@mattsse
Copy link
Member

mattsse commented Apr 11, 2022

@wminshew was able to deploy and verify successfully on #1198

@wminshew
Copy link

@wminshew was able to deploy and verify successfully on #1198

just tried with that PR both with bytecode_hash set to none and again with ipfs -- no luck. Can't imagine how it could be succeeding for you but not for me..

@piavgh
Copy link
Author

piavgh commented Apr 12, 2022

@piavgh can you have a look at #1263 ?

this should tell you what went wrong here

Thanks for the info, but I'm not sure if I understand it fully. Do you mean that it still has a bug or my verification procedure is incorrect?

I tried to deploy the contract with arg:

cast abi-encode "constructor(string)" "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000046765656b00000000000000000000000000000000000000000000000000000000"

which is

0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000c23078303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303032303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303436373635363536623030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030000000000000000000000000000000000000000000000000000000000000

but it's still failed when verify

@mattsse
Copy link
Member

mattsse commented Apr 12, 2022

ok, thanks for trying again @piavgh!
I think I've found the last issue here #1278

with that fix I was able to successfully verify via cli on goerli: https://goerli.etherscan.io/address/0x2e7a3b5a0346b2b390a125c0ac8181236d19ca3c#code

sorry about all of this, working with the etherscan API is a bit hard

@piavgh
Copy link
Author

piavgh commented Apr 12, 2022

@mattsse : thanks for your time.

But can you please list each command that you've used to verify it? (so that I can follow)

I'm using the latest version of forge after running foundryup: forge 0.2.0 (90617a5 2022-04-12T00:07:56.005103+00:00), and I'm following the procedure that I described in the issue (and use both cases of cast abi-encode), but it's still failed.

In the meantime, I will try with goerli to see if it has any different result.

@mattsse
Copy link
Member

mattsse commented Apr 12, 2022

just did another test with the current master

forge create --chain goerli --rpc-url "$ETH_RPC_URL" --constructor-args "geek" --private-key "$GOERLI_PK" src/Domains.sol:Domains         
forge verify-contract --chain-id goerli --constructor-args 000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000046765656b00000000000000000000
000000000000000000000000000000000000 --compiler-version v0.8.10+commit.fc410830 0xc3fe616452de64c289ae20db2b1d2224e126f123 --optimizer-runs 200 src/Domains.sol:Domains "$ETHERSCAN_API"
forge verify-check --chain-id goerli xpmq925drkg29s8dxqfegtkcvbvh8md6wk2rbmbsvqybdbywtq "$ETHERSCAN_API"

https://goerli.etherscan.io/address/0xc3fe616452de64c289ae20db2b1d2224e126f123

there was a fix in #1278 that just landed

@piavgh
Copy link
Author

piavgh commented Apr 13, 2022

just did another test with the current master

forge create --chain goerli --rpc-url "$ETH_RPC_URL" --constructor-args "geek" --private-key "$GOERLI_PK" src/Domains.sol:Domains         
forge verify-contract --chain-id goerli --constructor-args 000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000046765656b00000000000000000000
000000000000000000000000000000000000 --compiler-version v0.8.10+commit.fc410830 0xc3fe616452de64c289ae20db2b1d2224e126f123 --optimizer-runs 200 src/Domains.sol:Domains "$ETHERSCAN_API"
forge verify-check --chain-id goerli xpmq925drkg29s8dxqfegtkcvbvh8md6wk2rbmbsvqybdbywtq "$ETHERSCAN_API"

https://goerli.etherscan.io/address/0xc3fe616452de64c289ae20db2b1d2224e126f123

there was a fix in #1278 that just landed

I found out that on goerli I can verify it successfully => https://goerli.etherscan.io/address/0xc6720d6323ce0537ebb7be2c724deeefcd931284#code, while on ropsten or rinkeby, it keeps failing

If you have time, please try it on rinkeny or ropsten to see that you have the same problem :D

@mattsse
Copy link
Member

mattsse commented Apr 13, 2022

interesting, will do

@onbjerg
Copy link
Member

onbjerg commented Apr 16, 2022

Just verified on Rinkeby: https://rinkeby.etherscan.io/address/0x30b8add9d1c2cc440b33561b5e38a535680c5131#code

forge create --chain rinkeby --rpc-url "$ETH_RPC_URL" --constructor-args "geek" --private-key "$PK" src/Domains.sol:Domains
forge verify-contract --chain-id rinkeby --constructor-args (cast abi-encode "constructor(string)" "geek")

And Ropsten: https://ropsten.etherscan.io/address/0x48a42c5ed4f6fb093189f9b1b9e0d24dbd97cde0#code

forge create --chain ropsten --rpc-url "$ETH_RPC_URL" --constructor-args "geek" --private-key "$PK" src/Domains.sol:Domains
forge verify-contract --chain-id ropsten --constructor-args (cast abi-encode "constructor(string)" "geek") --compiler-version "v0.8.10+commit.fc410830" --optimizer-runs 200 0x48a42c5ed4f6fb093189f9b1b9e0d24dbd97cde0 src/Domains.sol:Domains

@piavgh
Copy link
Author

piavgh commented Apr 16, 2022

Just verified on Rinkeby: https://rinkeby.etherscan.io/address/0x30b8add9d1c2cc440b33561b5e38a535680c5131#code

forge create --chain rinkeby --rpc-url "$ETH_RPC_URL" --constructor-args "geek" --private-key "$PK" src/Domains.sol:Domains
forge verify-contract --chain-id rinkeby --constructor-args (cast abi-encode "constructor(string)" "geek")

And Ropsten: https://ropsten.etherscan.io/address/0x48a42c5ed4f6fb093189f9b1b9e0d24dbd97cde0#code

forge create --chain ropsten --rpc-url "$ETH_RPC_URL" --constructor-args "geek" --private-key "$PK" src/Domains.sol:Domains
forge verify-contract --chain-id ropsten --constructor-args (cast abi-encode "constructor(string)" "geek") --compiler-version "v0.8.10+commit.fc410830" --optimizer-runs 200 0x48a42c5ed4f6fb093189f9b1b9e0d24dbd97cde0 src/Domains.sol:Domains

I confirm that using the latest version of foundry, I can verify the contract successfully on both ropsten and rinkeby. Will close this issue

@piavgh piavgh closed this as completed Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge Cmd-forge-create Command: forge create P-high Priority: high T-bug Type: bug
Projects
None yet
Development

No branches or pull requests

8 participants