foundry-rs/foundry

`forge verify-contract` does not work on bartio

Closed this issue · 4 comments

Component

Forge

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (7f41280 2024-11-30T00:24:04.195299000Z)

What command(s) is the bug in?

forge verify-contract

Operating System

macOS (Apple Silicon)

Describe the bug

I'm having issues verifying contracts that I already deployed on the bartio Berachain testnet network.
I've created a sample repo that only has the original foundry init . files and went through the steps below.
You can see the repo here: https://github.com/burrbear-dev/beratrail-verify?tab=readme-ov-file#deploy

forge --version
forge 0.2.0 (7f41280 2024-11-30T00:24:04.195299000Z)

# this WORKS : deploys correctly on BARTIO and verifies the contract
forge script script/Counter.s.sol:CounterScript \
  --account X_DEPLOYER2 \
  --rpc-url ${BARTIO_RPC_URL} \
  --broadcast \
  -vvvvv \
  --verify --verifier custom \
  --verifier-url 'https://api.routescan.io/v2/network/testnet/evm/80084/etherscan' \
  --verifier-api-key "verifyContract" \
  --chain 80084
# this deploys the contract but the verification steps fails:
forge create script/Counter.s.sol:CounterScript --broadcast \
  --rpc-url ${BARTIO_RPC_URL} --account X_DEPLOYER2 --verify --verifier custom \
  --verifier-url 'https://api.routescan.io/v2/network/testnet/evm/80084/etherscan' --verifier-api-key "verifyContract" \
  --chain 80084

[⠊] Compiling...
No files changed, compilation skipped
Enter keystore password:
Deployer: 0x235A2ac113014F9dcb8aBA6577F20290832dDEFd
Deployed to: 0xA4f4C07A01F7995587044c9F1f97440DF3dBbFBe
Transaction hash: 0xfe1f2d0bdd5da8a5e5a1e79ac9e2f252b3d5d597cda34f00f2fe7b42a1370ca4
Starting contract verification...
Waiting for custom to detect contract deployment...
Start verifying contract `0xA4f4C07A01F7995587044c9F1f97440DF3dBbFBe` deployed on 80084
Compiler version: 0.8.13

Submitting verification for [script/Counter.s.sol:CounterScript] 0xA4f4C07A01F7995587044c9F1f97440DF3dBbFBe.
Submitted contract for verification:
        Response: `OK`
        GUID: `adf0d2da-0853-569c-9727-8d1efb714e1f`
        URL: https://api.routescan.io/v2/network/testnet/evm/80084/address/0xa4f4c07a01f7995587044c9f1f97440df3dbbfbe
Contract verification status:
Response: `NOTOK`
Details: `Error: contract does not exist 80084 0xA4f4C07A01F7995587044c9F1f97440DF3dBbFBe`
# Trying to verify the contract deployed above (but where verification failed) does not work (?!)
❯ forge verify-contract 0xA4f4C07A01F7995587044c9F1f97440DF3dBbFBe src/Counter.sol:Counter --watch \
  --verifier custom --verifier-url 'https://api.routescan.io/v2/network/testnet/evm/80084/etherscan/api/' \
  --verifier-api-key "verifyContract" \
  --chain 80084 -vvvvv --rpc-url $BARTIO_RPC_URL
Start verifying contract `0xA4f4C07A01F7995587044c9F1f97440DF3dBbFBe` deployed on 80084

Submitting verification for [src/Counter.sol:Counter] 0xA4f4C07A01F7995587044c9F1f97440DF3dBbFBe.
Submitted contract for verification:
        Response: `OK`
        GUID: `5fe8e033-fe0e-591e-a796-bff70a63a613`
        URL: https://api.routescan.io/v2/network/testnet/evm/80084/etherscan/address/0xa4f4c07a01f7995587044c9f1f97440df3dbbfbe
Contract verification status:
Response: `NOTOK`
Details: `Error: Compilation successful, but bytecode does not match with deployed bytecode for address 0xA4f4C07A01F7995587044c9F1f97440DF3dBbFBe, please check your parameters`
# another try, this time with more specific params for compiler and evm version
# in case forge verify-contract has a but and does not pick them up from the foundry.toml
# also no go :(
❯ forge verify-contract 0xA4f4C07A01F7995587044c9F1f97440DF3dBbFBe src/Counter.sol:Counter --watch \
  --verifier custom --verifier-url 'https://api.routescan.io/v2/network/testnet/evm/80084/etherscan/api/' \
  --verifier-api-key "verifyContract" \
  --num-of-optimizations 200 --evm-version "cancun" --compiler-version "0.8.13" \
  --chain 80084 -vvvvv --rpc-url $BARTIO_RPC_URL

Start verifying contract `0xA4f4C07A01F7995587044c9F1f97440DF3dBbFBe` deployed on 80084
Compiler version: 0.8.13
Optimizations:    200

Submitting verification for [src/Counter.sol:Counter] 0xA4f4C07A01F7995587044c9F1f97440DF3dBbFBe.
Submitted contract for verification:
        Response: `OK`
        GUID: `14c8391f-684f-5bec-8088-66db9ce58e6a`
        URL: https://api.routescan.io/v2/network/testnet/evm/80084/etherscan/address/0xa4f4c07a01f7995587044c9f1f97440df3dbbfbe
Contract verification status:
Response: `NOTOK`
Details: `Pending in queue`
Warning: Verification is still pending... (7 tries remaining)
Contract verification status:
Response: `NOTOK`
Details: `Pending in queue`
Warning: Verification is still pending... (6 tries remaining)
Contract verification status:
Response: `NOTOK`
Details: `Error: Compilation successful, but bytecode does not match with deployed bytecode for address 0xA4f4C07A01F7995587044c9F1f97440DF3dBbFBe, please check your parameters`

Thank for your report! Something wrong with the verifier URL in forge create, it shows
URL: https://api.routescan.io/v2/network/testnet/evm/80084/address/0xa4f4c07a01f7995587044c9f1f97440df3dbbfbe hence contract not found, whereas right URL should be https://api.routescan.io/v2/network/testnet/evm/80084/etherscan/address/0xa4f4c07a01f7995587044c9f1f97440df3dbbfbe (etherscan missing)

also this one

sh_println!(
"Submitted contract for verification:\n\tResponse: `{}`\n\tGUID: `{}`\n\tURL: {}",
resp.message,
resp.result,
etherscan.address_url(args.address)
)?;

should probably be

args.verifier.verifier_url.clone().unwrap_or_else(|| etherscan.address_url(args.address))

in order to show real verification URL

also this one

sh_println!(
"Submitted contract for verification:\n\tResponse: `{}`\n\tGUID: `{}`\n\tURL: {}",
resp.message,
resp.result,
etherscan.address_url(args.address)
)?;

should probably be

args.verifier.verifier_url.clone().unwrap_or_else(|| etherscan.address_url(args.address))

in order to show real verification URL

This is not true, the client is already instantiated correctly

let etherscan_api_url = verifier_url
.or_else(|| etherscan_config.as_ref().map(|c| c.api_url.as_str()))
.map(str::to_owned);

@burrbear-dev verifiy fails because you used forge create to deploy script/Counter.s.sol:CounterScript contract but you verify a different one src/Counter.sol:Counter - hence the bytecode does not match with deployed bytecode error. You need to either forge create src/Counter.sol:Counter and verify as forge verify-contract 0x... src/Counter.sol:Counter or if you deploy the script with forge create script/Counter.s.sol:CounterScript then verify it as forge verify-contract 0x... script/Counter.s.sol:CounterScript (just checked and all works OK).

the other failure you see in forge create (they manifest for script as well) seems to be sporadic and likely block explorer API related (it returns 404 for address to be verified), for example this forge create attempt with verify worked OK

forge create src/Counter.sol:Counter --broadcast   --private-key 0x   --rpc-url $RPC_URL--verify --verifier custom   --verifier-url 'https://api.routescan.io/v2/network/testnet/evm/80084/etherscan' --verifier-api-key "verifyContract"   --chain 80084

image

Going to close this one for now as I don't think there are actions we could do to improve, please reopen if you still have issues. thank you!