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

Add support for Blockscout #1313

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open

Add support for Blockscout #1313

wants to merge 5 commits into from

Conversation

kronosapiens
Copy link
Member

@kronosapiens kronosapiens commented Dec 10, 2024

Closes #1286

Instructions:

Starting Blockscout (1 tab)

  1. Clone the Blockscout repo (https://github.com/blockscout/blockscout)
  2. Cd into blockscout/docker-compose and run docker compose -f hardhat-network.yml up (-d to daemonize)

Blockscout will start running on localhost:80 by default

Starting Hardhat (2 tabs)

  1. Run npx hardhat node as per usual
  2. Run npx hardhat deploy --network development as per usual

At this point Blockscout will start picking up the transactions

Todo:

Currently, contract verification is not working. This is as far as I've gotten:

>> npx hardhat verify --network development 0x777760996135F0791E2e1a74aFAa060711197777  --contract contracts/common/EtherRouter.sol:EtherRouter        
Successfully submitted source code for contract
contracts/common/EtherRouter.sol:EtherRouter at 0x777760996135F0791E2e1a74aFAa060711197777
for verification on the block explorer. Waiting for verification result...

We tried verifying your contract EtherRouter without including any unrelated one, but it failed.
Trying again with the full solc input used to compile and deploy it.
This means that unrelated contracts may be displayed on Etherscan...

hardhat-verify found one or more errors during the verification process:

Etherscan:
A network request failed. This is an error from the block explorer, not Hardhat. Error: Unexpected token '<', "<html>
<h"... is not valid JSON

I've debugged enough to confirm that the API is live, but for some reason the 2nd step (verifying with the full solc input) returns an HTML response, which breaks the verifier.

Resources:

https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-verify

https://docs.blockscout.com/devs/verification/hardhat-verification-plugin

Blockscout's issue tracking proxy contract support

@area
Copy link
Member

area commented Dec 16, 2024

The error in the second step is

<html>
<head><title>413 Request Entity Too Large</title></head>
<body>
<center><h1>413 Request Entity Too Large</h1></center>
<hr><center>nginx/1.27.3</center>
</body>
</html>

i.e. the concatenation of all the solidity files is too big to be posted to the API (no idea who's enforcing that limit, though).

@kronosapiens
Copy link
Member Author

Suggestion is to try and validate contracts through the Blockscout UI directly

@area
Copy link
Member

area commented Dec 18, 2024

Suggestion is to try and validate contracts through the Blockscout UI directly

Well, to start there and if that works then potentially write our own script to validate automatically in a more judicious way than the plugin tries to.

@area
Copy link
Member

area commented Jan 6, 2025

For anyone else testing this, if you run the docker-compose command, the containers have a restart policy of 'always', which means they will start whenever docker does. I only discovered this when something got in to a crash loop when I restarted my machine and started using all my CPU.

grep -irl "restart: always" | xargs sed -i.bak "s/restart: always/restart: on-failure/g"

run in the directory with the docker files will cause them to only restart on failure.

@area
Copy link
Member

area commented Jan 10, 2025

https://medium.com/@shaiv/testnet-faucets-sucks-try-this-block-explorer-with-your-local-hardhat-f434384d5244

This is a lot lighter weight, and supports at least some of what we want... maybe it does enough? I did have to edit it to ignore warnings when verifying a contract

-    if (compiledOutput.errors) {
+    if (compiledOutput.errors && compiledOutput.errors.filter(e => !e.formattedMessage.startsWith('Warning:')).length > 0) {

@kronosapiens
Copy link
Member Author

Noting that the Standard JSON Input for a contract build can be pulled out of Hardhat via:

> buildInfo = await hre.artifacts.getBuildInfo("contracts/colony/Colony.sol:Colony")
> require('fs').writeFileSync('input.json', JSON.stringify(buildInfo.input, null, 2));

@kronosapiens
Copy link
Member Author

kronosapiens commented Jan 22, 2025

Testing for contract-level verification, using the dependency contract at contracts/testHelpers/ChainId.sol

const ChainId = await ethers.getContractFactory("ChainId")
const chainId = await ChainId.deploy()
await chainId.deployed()
console.log("Contract deployed to:", chainId.address)
>>> Contract deployed to: 0x78876Ba649623A5cC3a370509fe4AD5aCa26dfB4
Screenshot 2025-01-22 at 4 00 36 PM

Was able to verify this contract, under the paris EVM version. For some reason, it gave a "partial match" whatever that means.

@area any idea why we're compiling for paris? I don't see that as an explicit setting in our hardhat config.

@kronosapiens
Copy link
Member Author

Now trying with Standard JSON Input:

buildInfo = await hre.artifacts.getBuildInfo("contracts/testHelpers/ChainId.sol:ChainId")
require('fs').writeFileSync('input.json', JSON.stringify(buildInfo.input, null, 2));

Then manually going into input.json and deleting all the sources except for

    "contracts/testHelpers/ChainId.sol": {
      "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n/*\n  This file is part of The Colony Network.\n\n  The Colony Network is free software: you can redistribute it and/or modify\n  it under the terms of the GNU General Public License as published by\n  the Free Software Foundation, either version 3 of the License, or\n  (at your option) any later version.\n\n  The Colony Network is distributed in the hope that it will be useful,\n  but WITHOUT ANY WARRANTY; without even the implied warranty of\n  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n  GNU General Public License for more details.\n\n  You should have received a copy of the GNU General Public License\n  along with The Colony Network. If not, see <http://www.gnu.org/licenses/>.\n*/\n\npragma solidity 0.8.27;\n\ncontract ChainId {\n  function getChainId() public view returns (uint256) {\n    return block.chainid;\n  }\n}\n"
    }

And then uploading the input.json to Blockscout. Now we have an exact match!

Screenshot 2025-01-22 at 4 16 56 PM

@area
Copy link
Member

area commented Jan 23, 2025

@area any idea why we're compiling for paris? I don't see that as an explicit setting in our hardhat config.

It's the hardhat default. The setting is conservative to stop people accidentally deploying contracts compiled to chains that they do not run on, as adding new opcodes to chains requires a hardfork and happens slowly. CreateX, for example, is only compiled for Paris.

@kronosapiens
Copy link
Member Author

kronosapiens commented Jan 24, 2025

Tried using hardhat-verify again. This time, I deleted every contract in contracts/ except for ChainId.sol and re-compiled:

const ChainId = await ethers.getContractFactory("ChainId")
const chainId = await ChainId.deploy()
await chainId.deployed()
console.log("Contract deployed to:", chainId.address)
>>> Contract deployed to: 0xefC85459223d1a30eFC4cEb01Af496A976A7D5b5

Then attempted to verify using command line, which works:

$ npx hardhat verify --network localhost 0xefC85459223d1a30eFC4cEb01Af496A976A7D5b5  --contract contracts/ChainId.sol:ChainId      
Successfully submitted source code for contract
contracts/ChainId.sol:ChainId at 0xefC85459223d1a30eFC4cEb01Af496A976A7D5b5
for verification on the block explorer. Waiting for verification result...

Successfully verified contract ChainId on the block explorer.
http://localhost:80/address/0xefC85459223d1a30eFC4cEb01Af496A976A7D5b5#code
Screenshot 2025-01-24 at 11 40 32 AM

@kronosapiens kronosapiens force-pushed the feat/blockscout branch 2 times, most recently from 064b8d4 to f251da1 Compare January 29, 2025 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Explore chain visualizers
2 participants