Skip to content

Commit

Permalink
implementation of blockscout verification script.
Browse files Browse the repository at this point in the history
first glance: it seems not to be able to verify proxies
  • Loading branch information
SurfingNerd committed Jul 10, 2024
1 parent 665ad98 commit c83385f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
19 changes: 16 additions & 3 deletions tasks/make_spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import fs from 'fs';
import path from 'path';
import { task } from "hardhat/config";

import { InitialContractsConfiguration, NetworkConfiguration } from './types';

const ProxyContractName = "TransparentUpgradeableProxy";
Expand All @@ -17,6 +16,8 @@ task("make_spec_hbbft", "used to make a spec file")
console.log("initial funding address: ", taskArgs.initialFundAddress);
console.log("Using initial contracts file: ", taskArgs.initContracts);

let blocscoutVerificationScript = "#!/bin/sh\n";

const initialContracts = InitialContractsConfiguration.fromFile(taskArgs.initContracts);
const networkConfig = NetworkConfiguration.create(taskArgs.initDataFile);

Expand Down Expand Up @@ -49,14 +50,24 @@ task("make_spec_hbbft", "used to make a spec file")
const initializerArgs = initialContracts.getContractInitializerArgs(contractName, networkConfig);

await initialContracts.core[i].compileContract(hre);
await initialContracts.core[i].compileProxy(
let initializerDataHex = await initialContracts.core[i].compileProxy(
hre,
ProxyContractName,
initialContracts.core[i].implementationAddress!, // address _logic,
networkConfig.owner!, // contract initial owner
initializerArgs // bytes _data
);

// example:
// npx hardhat verify --network alpha3 0x1000000000000000000000000000000000000000
let implementationAddress = initialContracts.core[i].implementationAddress
let proxyAddress = initialContracts.core[i].proxyAddress;
blocscoutVerificationScript += `### ${contractName} ###\n`;
blocscoutVerificationScript += `echo "verifying ${contractName} on ${implementationAddress}"\n`;
blocscoutVerificationScript += `npx hardhat verify --network alpha3 ${implementationAddress}\n`;
blocscoutVerificationScript += `echo "verifying proxy for ${contractName} on ${proxyAddress}"\n`;
blocscoutVerificationScript += `npx hardhat verify --network alpha3 ${proxyAddress} ${implementationAddress} ${networkConfig.owner} ${initializerDataHex}\n`;

const contractSpec = initialContracts.core[i].toSpecAccount(taskArgs.useUpgradeProxy, 0);

spec.accounts = {
Expand Down Expand Up @@ -89,7 +100,9 @@ task("make_spec_hbbft", "used to make a spec file")
console.log('Saving spec_hbbft.json file ...');

fs.writeFileSync(path.join(__dirname, '..', 'spec_hbbft.json'), JSON.stringify(spec, null, ' '), 'utf-8');

let blockscoutVerifyFile = path.join(__dirname, '..', 'blockscout_verify.sh')
console.log("Storing batch file for blockscout verification: ", blockscoutVerifyFile);
fs.writeFileSync(blockscoutVerifyFile, blocscoutVerificationScript, "utf-8");
console.log('Done');
});

Expand Down
3 changes: 3 additions & 0 deletions tasks/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export class CoreContract {
return this.proxyAddress !== '';
}

// returns hex encoded initializer data.
async compileProxy(
hre: HardhatRuntimeEnvironment,
proxyContractName: string,
Expand All @@ -221,6 +222,8 @@ export class CoreContract {
const tx = await proxyFactory.getDeployTransaction(logicAddress, ownerAddress, initializerData);

this.proxyBytecode = tx.data;

return initializerData;
}

async compileContract(hre: HardhatRuntimeEnvironment) {
Expand Down

1 comment on commit c83385f

@SurfingNerd
Copy link
Owner Author

Choose a reason for hiding this comment

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

verifying chainspec deployed TransparentUpgradeableProxy is still a problem:

npx hardhat verify --network alpha3 0x1000000000000000000000000000000000000001 0x1000000000000000000000000000000000000000 0xDA0da0da0Da0Da0Da0DA00DA0da0da0DA0DA0dA0 0x464b5610000000000000000000000000da0da0da0da0da0da0da00da0da0da0da0da0da000000000000000000000000020000000000000000000000000000000000000010000000000000000000000003000000000000000000000000000000000000001000000000000000000000000110000000000000000000000000000000000000100000000000000000000000070000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000001e13380000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000baf401ca3188e4f0dcf90751a5c34790108ea68b00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001

[INFO] Sourcify Verification Skipped: Sourcify verification is currently disabled. To enable it, add the following entry to your Hardhat configuration:

sourcify: {
  enabled: true
}

Or set 'enabled' to false to hide this message.

For more information, visit https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-verify#verifying-on-sourcify
Verifying implementation: 0x1000000000000000000000000000000000000000
The contract 0x1000000000000000000000000000000000000000 has already been verified on the block explorer. If you're trying to verify a partially verified contract, please use the --force flag.
http://185.187.170.209:4000/address/0x1000000000000000000000000000000000000000#code

Verifying proxy: 0x1000000000000000000000000000000000000001
Successfully submitted source code for contract
@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol:TransparentUpgradeableProxy at 0x1000000000000000000000000000000000000001
for verification on the block explorer. Waiting for verification result...

We tried verifying your contract TransparentUpgradeableProxy 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...

Successfully submitted source code for contract
@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol:TransparentUpgradeableProxy at 0x1000000000000000000000000000000000000001
for verification on the block explorer. Waiting for verification result...

Could not find an event with any of the following topics in the logs for address 0x1000000000000000000000000000000000000001: AdminChanged(address,address), Upgraded(address)

If the proxy was recently deployed, the transaction may not be available on Etherscan yet. Try running the verify task again after waiting a few blocks.
Failed to verify directly using hardhat verify: The contract verification failed.
Reason: Fail - Unable to verify

Linking proxy 0x1000000000000000000000000000000000000001 with implementation
hardhat-verify found one or more errors during the verification process:

Etherscan:
Etherscan API call failed with status 400, response: {"message":"Unknown action","result":null,"status":"0"}

Please sign in to comment.