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

feat(forge): allow --verifier custom option #9311

Merged
merged 4 commits into from
Nov 14, 2024

Conversation

grandizzy
Copy link
Collaborator

@grandizzy grandizzy commented Nov 13, 2024

Motivation

Closes #9220
Closes #8254
Closes #7466 (no need to pass chain param as it will be retrieved from provider / --rpc-url)
Closes #8100
image

  • allows custom verifiers to be defined as --verifier custom. adds --verifier-api-key for custom verifier keys
Verifier options:
      --verifier <VERIFIER>
          The contract verification provider to use
          
          [default: etherscan]

          Possible values:
          - etherscan
          - sourcify
          - blockscout
          - oklink
          - custom:     Custom verification provider, compatible with Etherscan API

      --verifier-api-key <VERIFIER_API_KEY>
          The verifier API KEY, if using a custom provider
          
          [env: VERIFIER_API_KEY=]

      --verifier-url <VERIFIER_URL>
          The verifier URL, if using a custom provider
          
          [env: VERIFIER_URL=]
  • could be passed as cli arg, e.g.
forge create \
  --rpc-url http://localhost:8545 \
  --private-key 0x12345.... \
  src/Counter.sol:Counter \
  --verify \
  --verifier custom \
  --verifier-url http://localhost:8888/api \
  --verifier-api-key 1234
forge verify-contract \
  0x59b670e9fA9D0A427751Af201D676719a970857b \
  --rpc-url http://localhost:8545 \
  --verifier custom \
  --verifier-url http://localhost:8888/api \
  --verifier-api-key 1234

or defined and implicitly taken from foundry.toml config, e.g.

[etherscan]
anvil-hardhat = { key = "1234", url = "http://localhost:8888/api" }
forge create \
  --rpc-url http://localhost:8545 \
  --private-key 0x12345.... \
  src/Counter.sol:Counter \
  --verify
forge verify-contract \
  0x59b670e9fA9D0A427751Af201D676719a970857b \
  --rpc-url http://localhost:8545
  • better user feedback for retry error handle, print console warning

image

Solution

@grandizzy grandizzy marked this pull request as ready for review November 13, 2024 13:34
@grandizzy
Copy link
Collaborator Author

I think would be nice to have a --verifier-api-key so custom verifiers args won't need the etherscan keyword at all...

pub verifier_url: Option<String>,

Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
@d-democrazy
Copy link

Having hardtime to verify contract on Core Testnet (EVM Compatible)
Testnet chain details:

  1. Chain ID: 1115
  2. RPC URL: https://rpc.test.btcs.network/
  3. Endpoint URL: https://api.test.btcs.network/
  4. Block explorer: https://scan.test.btcs.network/

CLI Command:
forge verify-contract 0xAC11A1fB819261c4015b94A50dEDC7683a01aB13 --rpc-url $CORE_TESTNET_RPC_URL --verifier custom --verifier-url https://api.test.btcs.network/api --verifier-api-key $CORE_TESTNET_API_KEY

Respond:

[⠊] Compiling...
No files changed, compilation skipped
Start verifying contract `0xAC11A1fB819261c4015b94A50dEDC7683a01aB13` deployed on 1115
2024-11-25T09:01:47.243277Z ERROR etherscan: Failed to deserialize response: data did not match any variant of untagged enum ResponseData res="{\"status\":401,\"error\":\"Unauthorized\",\"message\":\"401 Permission Verification Failed. This apikey is illegal!\"}"
Error: Failed to deserialize content: data did not match any variant of untagged enum ResponseData
{"status":401,"error":"Unauthorized","message":"401 Permission Verification Failed. This apikey is illegal!"}

Api key checking:
curl -X GET "https://api.test.btcs.network/api?module=account&action=balance&address=0x0000000000000000000000000000000000000000&apikey=27a066b93107401a81d635da00c0fa09

Respond:
{"status":"1","result":203867733802160000000000,"message":"OK"}

@grandizzy
Copy link
Collaborator Author

@d-democrazy looks like Block explorer is not etherscan API compatible, so not much we could do here, custom verifiers requires such - custom: Custom verification provider, compatible with Etherscan API

Dargon789 added a commit to Dargon789/foundry that referenced this pull request Nov 29, 2024
feat(forge): allow `--verifier custom` option (foundry-rs#9311)
rplusq pushed a commit to rplusq/foundry that referenced this pull request Nov 29, 2024
* feat(forge): allow `--verifier custom` option

* Changes after review: add description of custom verifier, reorg err message, add custom verifier api key

* Fix descriptions

* Update crates/verify/src/provider.rs

Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>

---------

Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
@grandizzy grandizzy added T-feature Type: feature C-forge Command: forge labels Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge T-feature Type: feature
Projects
Archived in project
3 participants