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

Verify proxy/implementation on etherscan #541

Draft
wants to merge 10 commits into
base: develop
Choose a base branch
from
1 change: 1 addition & 0 deletions DEPLOYMENT_CHECKLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ To deploy run `yarn deploy --network NETWORK` in `packages/contracts` and replac
- [ ] Go to the blockchain explorer and verify that each address is verified
- [ ] If it is not try to verfiy it with `npx hardhat verify --network NETWORK ADDRESS CONTRUCTOR-ARGS`. More infos on how to use this command can be found here: [https://hardhat.org/hardhat-runner/docs/guides/verifying](https://hardhat.org/hardhat-runner/docs/guides/verifying)
- [ ] If it is a proxy try to activate the blockchain explorer's proxy feature
- [ ] Try running `yarn verifyProxies --network <network>` to automate this
jordaniza marked this conversation as resolved.
Show resolved Hide resolved
- [ ] If the proxies are not verified with the `Similar Match Source Code` feature
- [ ] Verify one of the proxies
- [ ] Check if the other proxies are now verified with `Similar Match Source Code`
Expand Down
1 change: 1 addition & 0 deletions UPDATE_CHECKLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ If the deployer **is** allowed to create a proposal
- [ ] Go to the blockchain explorer and verify that each address is verified
- [ ] If it is not try to verfiy it with `npx hardhat verify --network NETWORK ADDRESS CONTRUCTOR-ARGS`. More infos on how to use this command can be found here: [https://hardhat.org/hardhat-runner/docs/guides/verifying](https://hardhat.org/hardhat-runner/docs/guides/verifying)
- [ ] If it is a proxy try to activate the blockchain explorer's proxy feature
- [ ] Try running `yarn verifyProxies --network <network>` to automate this
jordaniza marked this conversation as resolved.
Show resolved Hide resolved
- [ ] If the proxies are not verified with the `Similar Match Source Code` feature
- [ ] Remove `import '@openzeppelin/hardhat-upgrades'` from `packages/contracts/hardhat.config.ts`
- [ ] Verify one of the proxies
Expand Down
14 changes: 5 additions & 9 deletions packages/contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,15 @@ Please do not use the issue tracker for security issues.

## Etherscan verification

To try out Etherscan verification, you first need to deploy a contract to an Ethereum testnet that's supported by Etherscan, such as [goerli](https://goerli.etherscan.io) or [sepolia](https://sepolia.etherscan.io).
Verification of contracts is currently handled by the etherscan verify plugin, invoked as a hardhat deploy stage. Contracts are bound to the HRE during deployment and then used as part of verification.

In this project, copy the `.env.example` file to a file named .env, and then edit it to fill in the details. Enter your Etherscan API key, your Goerli node URL (eg from Alchemy), and the private key of the account which will send the deployment transaction. With a valid .env file in place, first deploy your contract:
Make sure you have your Etherscan key setup in the HH config before running the deploy script.

```shell
hardhat run --network goerli scripts/sample-script.ts
```
### Proxy Verification

Then, copy the deployment address and paste it in to replace `DEPLOYED_CONTRACT_ADDRESS` in this command:
To avoid having to manually set 'Is this a Proxy?' in etherscan, you may call the Proxy Verification script, once your contracts have been verified. To do this run: `yarn verifyProxies --network <network>`.

```shell
npx hardhat verify --network goerli DEPLOYED_CONTRACT_ADDRESS "Hello, Hardhat!"
```
This can be run multiple times provided you haven't used the `--reset` flag to clear the deployment data. The etherscan API can be a little flaky at times so be patient with it and try multiple times if necessary.
Comment on lines +67 to +69
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would bet that this is because of rate limiting. Have you tried waiting 6s between the requests as we do it in our deploy script?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe it is: the error messaging indicates the contracts cannot be found sometimes, although this appears to be inconsistent. I think it may be due to delays in indexing the contracts on the explorers, and propagating the data.

Copy link
Contributor

@heueristik heueristik Mar 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had the same problem with Polygon. In this case, we added a one-time delay to the script.

// add a timeout for polygon because the call to `implementation()` can fail for newly deployed contracts in the first few seconds
if (network.name === 'polygon') {
console.log(`Waiting 30secs for ${network.name} to finish up...`);
await setTimeout(30000);
}

I think having a script that runs robustly and doesn't need to be executed multiple times, is important.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will take a look, if it doesn't work I will shelf the PR for now to avoid getting stuck on it.


## Testing with Previous Contract Versions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
}
};
export default func;
func.tags = ['New', 'Verify'];
func.tags = ['New', 'Verify', 'VerifyContracts'];
jordaniza marked this conversation as resolved.
Show resolved Hide resolved
func.runAtTheEnd = true;
func.skip = (hre: HardhatRuntimeEnvironment) =>
Promise.resolve(isLocal(hre.network));
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {isLocal} from '../../../utils/environment';
import {
collectProxyWithImplementation,
generateExplorerIsThisAProxyURL,
handleLinkProxyRequest,
} from '../../../utils/etherscan';
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';

/**
* This script can be run manually after the deployment of the contracts and contract verification,
* call `yarn verifyProxies --network <network>` to run this script.
*
* It searches deployments for proxies and their implementations and links them on Etherscan.
* This avoids the need to call 'Is this a proxy?' for each contract using the UI.
* The script will request the linkage for all proxies and implementations and return a GUID to check the status
* of the request.
*
* The API is inconsistent when linking proxies, so we don't include this as part of the default deployment process.
*/
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log('\nLinking Proxies on Etherscan');

const url = generateExplorerIsThisAProxyURL(hre);
const verifyData = collectProxyWithImplementation(
await hre.deployments.all()
);

console.log(
`Linking ${verifyData.length} proxies on Etherscan, please be patient.`
);

for (const {proxy, implementation} of verifyData) {
await handleLinkProxyRequest(url, proxy, implementation);
}
};
export default func;

func.tags = ['New', 'Verify', 'VerifyProxies'];
func.dependencies = ['VerifyContracts'];
func.runAtTheEnd = true;

func.skip = (hre: HardhatRuntimeEnvironment) => {
const verifyProxies = process.env.VERIFY_PROXIES === 'true';
return Promise.resolve(isLocal(hre.network) || !verifyProxies);
};
1 change: 1 addition & 0 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"flatten": "hardhat flatten",
"analyze": "mythx analyze",
"deploy": "hardhat deploy",
"verifyProxies": "VERIFY_PROXIES=true yarn deploy --tags VerifyProxies",
"deploy:local": "yarn deploy --network localhost --reset",
"dev": "yarn hardhat node --hostname 0.0.0.0",
"prepublishOnly": "yarn build && yarn build:npm",
Expand Down
Loading
Loading