foundry: bug(`forge test`): --fork-url etherscan: Failed to deserialize response

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 (73fb616 2023-12-19T00:16:21.131413571Z)

What command(s) is the bug in?

forge test --fork-url $SEPOLIA_RPC_URL

Operating System

Linux

Describe the bug

i found #3621 which is very similar to my issue to be closed in lieu of #6079, so i apologize if this is dup issue,

there is nothing special about my test, and everything passes and completes without issues. unlike @amusingaxl however, trace shows no problems with rate limiting, traces all look pretty standard:

Screenshot 2023-12-21 162915

2023-12-21T23:26:59.714575Z  WARN etherscanidentifier: could not get etherscan info: Serde(Error("expected value", line: 1, column: 1))

response (captcha):

<!DOCTYPE html>
<html lang="en-US">
<head>
    <title>Just a moment...</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta name="robots" content="noindex,nofollow">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <link href="/cdn-cgi/styles/challenges.css" rel="stylesheet">
    <meta http-equiv="refresh" content="375">
</head>
<body class="no-js">
    <div class="main-wrapper" role="main">
        <div class="main-content">
            <noscript>
                <div id="challenge-error-title">
                    <div class="h2">
                        <span class="icon-wrapper">
                            <div class="heading-icon warning-icon"></div>
                        </span>
                        <span id="challenge-error-text">Enable JavaScript and cookies to continue</span>
                    </div>
                </div>
            </noscript>
        </div>
    </div>
    <script>
        (function(){
            // challenge function
        }());
    </script>
</body>
</html>

i am working on a remote server thru vscode remote ssh, not sure if that’s a factor

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 27 (5 by maintainers)

Most upvoted comments

Thanks @0xV4L3NT1N3!

The HTML error that gets thrown originates from Blockscout due to a misclassification in the Alloy Chain’s configuration, adding a fix here: https://github.com/alloy-rs/chains/pull/109. Should land in Foundry soon.

In the meantime as a workaround @hernandp, please directly pass in the --verifier-url as follows: --verifier-url https://api-alfajores.celoscan.io/api with an accompanying --etherscan-api-key <API_KEY>.

Am able to reproduce it reliably on the Celoscan Alfajores testnet upon verification:

<!DOCTYPE html>
<html lang="en-US">

<head>
    <title>Just a moment...</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta name="robots" content="noindex,nofollow">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <style>
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0
        }

        html {
            line-height: 1.15;
            -webkit-text-size-adjust: 100%;
            color: #313131;
            font-family: system-ui, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, Noto Sans, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji
        }

        body {
            display: flex;
            flex-direction: column;
            height: 100vh;
            min-height: 100vh
        }

        .main-content {
            margin: 8rem auto;
            max-width: 60rem;
            padding-left: 1.5rem
        }

        @media (width <=720px) {
            .main-content {
                margin-top: 4rem
            }
        }

        .h2 {
            font-size: 1.5rem;
            font-weight: 500;
            line-height: 2.25rem
        }

        @media (width <=720px) {
            .h2 {
                font-size: 1.25rem;
                line-height: 1.5rem
            }
        }

        #challenge-error-text {
            background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMiIgaGVpZ2h0PSIzMiIgZmlsbD0ibm9uZSI+PHBhdGggZmlsbD0iI0IyMEYwMyIgZD0iTTE2IDNhMTMgMTMgMCAxIDAgMTMgMTNBMTMuMDE1IDEzLjAxNSAwIDAgMCAxNiAzbTAgMjRhMTEgMTEgMCAxIDEgMTEtMTEgMTEuMDEgMTEuMDEgMCAwIDEtMTEgMTEiLz48cGF0aCBmaWxsPSIjQjIwRjAzIiBkPSJNMTcuMDM4IDE4LjYxNUgxNC44N0wxNC41NjMgOS41aDIuNzgzem0tMS4wODQgMS40MjdxLjY2IDAgMS4wNTcuMzg4LjQwNy4zODkuNDA3Ljk5NCAwIC41OTYtLjQwNy45ODQtLjM5Ny4zOS0xLjA1Ny4zODktLjY1IDAtMS4wNTYtLjM4OS0uMzk4LS4zODktLjM5OC0uOTg0IDAtLjU5Ny4zOTgtLjk4NS40MDYtLjM5NyAxLjA1Ni0uMzk3Ii8+PC9zdmc+);
            background-repeat: no-repeat;
            background-size: contain;
            padding-left: 34px
        }

        @media (prefers-color-scheme:dark) {
            body {
                background-color: #222;
                color: #d9d9d9
            }
        }
    </style>
    <meta http-equiv="refresh" content="390">
</head>
<body class="no-js">
    <div class="main-wrapper" role="main">
        <div class="main-content"><noscript>
                <div class="h2"><span id="challenge-error-text">Enable JavaScript and cookies to continue</span></div>
            </noscript></div>
    </div>
    <script>(function () { window._cf_chl_opt = { cvId: '3', cZone: "explorer.celo.org", ... }());</script>
</body>
</html>

I’ll reach out to Etherscan to see if we can get this fixed for Celo

Unfortunately it looks like there is no direct action Foundry can take here

trying to compile Optimism L2 on Sepolia Testnet getting the error even with –verifier etherscan --etherscan-api-key ************************ --verifier-url https://api-sepolia.etherscan.io/api The difference is in my case it returns Access Denied error using the latest forge version forge 0.2.0 (b320027 2024-01-12T00:17:44.209192793Z) please advise

2024-01-12T08:47:44.050530Z ERROR etherscan: Failed to deserialize response: expected value at line 1 column 1 res="<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />\n<title>403 - Forbidden: Access is denied.</title>\n<style type=\"text/css\">\r\n<!--\r\nbody{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}\r\nfieldset{padding:0 15px 10px 15px;} \r\nh1{font-size:2.4em;margin:0;color:#FFF;}\r\nh2{font-size:1.7em;margin:0;color:#CC0000;} \r\nh3{font-size:1.2em;margin:10px 0 0 0;color:#000000;} \r\n#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:\"trebuchet MS\", Verdana, sans-serif;color:#FFF;\r\nbackground-color:#555555;}\r\n#content{margin:0 0 0 2%;position:relative;}\r\n.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}\r\n-->\r\n</style>\n</head>\n<body>\n<div id=\"header\"><h1>Server Error</h1></div>\n<div id=\"content\">\n<div class=\"content-container\"><fieldset>\n<h2>403 - Forbidden: Access is denied.</h2>\n<h3>You do not have permission to view this directory or page using the credentials that you supplied.</h3>\n</fieldset></div>\n</div>\n<script>(function(){var js = \"window['__CF$cv$params']={r:'844422eafa618ec2',t:'MTcwNTA0OTI2NC4wNDAwMDA='};_cpo=document.createElement('script');_cpo.nonce='',_cpo.src='/cdn-cgi/challenge-platform/scripts/jsd/main.js',document.getElementsByTagName('head')[0].appendChild(_cpo);\";var _0xh = document.createElement('iframe');_0xh.height = 1;_0xh.width = 1;_0xh.style.position = 'absolute';_0xh.style.top = 0;_0xh.style.left = 0;_0xh.style.border = 'none';_0xh.style.visibility = 'hidden';document.body.appendChild(_0xh);function handler() {var _0xi = _0xh.contentDocument || _0xh.contentWindow.document;if (_0xi) {var _0xj = _0xi.createElement('script');_0xj.innerHTML = js;_0xi.getElementsByTagName('head')[0].appendChild(_0xj);}}if (document.readyState !== 'loading') {handler();} else if (window.addEventListener) {document.addEventListener('DOMContentLoaded', handler);} else {var prev = document.onreadystatechange || function () {};document.onreadystatechange = function (e) {prev(e);if (document.readyState !== 'loading') {document.onreadystatechange = prev;handler();}};}})();</script></body>\n</html>\n"

@zerosnacks thank you.

@grandizzy @zerosnacks Sidenote, manual submission of data to Celoscan using generated JSON with --show-json-standard-input in forge command line works. So I guess is the RPC/HTTP interfacing which is failing.

thanks, is that celoscan to support this? @zerosnacks wdyt?

@hernandp can you share a way to reproduce the issue? Thank you

It worked in Sepolia/Arbitrum Sepolia now, thanks.

In particular, Celo both Testnet/Mainnet does not support forge verify-contract and still displays this error.

I think this is all just related to receiving some kind of non-JSON formatted HTML error / gate page that Etherscan may throw. We could attempt to implement an error handler to give the user a more descriptive error but I don’t see a practical way we can actually resolve this. It clearly happens sporadically and under certain conditions.

This worked for me, though (probably because I was running from a script?) unset ETHERSCAN_API_KEY was insufficient, and I needed export ETHERSCAN_API_KEY="".

this one works for me

TL;DR: unsetting ETHERSCAN_API_KEY when running local tests & scripts resolved my issue.

This worked for me, though (probably because I was running from a script?) unset ETHERSCAN_API_KEY was insufficient, and I needed export ETHERSCAN_API_KEY="".

2023-12-21T23:26:59.714575Z  WARN etherscanidentifier: could not get etherscan info: Serde(Error("expected value", line: 1, column: 1))

and

ERROR etherscan: Failed to deserialize response: expected value at line 1 column 1

I ran into a similar issue (see above), here’s what I discovered:

  • When ETHERSCAN_API_KEY is set in the environment, forge will try resolving the etherscan API and fetch contracts info.
  • Even though the script being ran may not be broadcasting anything, is in offline mode and isn’t being provided with the --verify flag, forge will still execute the previous step multiples times anyways.

TL;DR: unsetting ETHERSCAN_API_KEY when running local tests & scripts resolved my issue.

PS: the etherscan key must be commented out from the .env if using it, as unsetting the variable doesn’t prevent forge from loading the environment file.