Skip to content

Commit

Permalink
Add verification script
Browse files Browse the repository at this point in the history
  • Loading branch information
zguesmi committed Sep 20, 2024
1 parent 0137a9a commit 353e30f
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 20 deletions.
24 changes: 4 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,9 @@ npx hardhat deploy --network <name>

### Verify contracts

- Add network configuration to Hardhat config file.
- Specify the correct evm version in the compiler config ('berlin', 'paris', ...).
- Clean and re-compile contracts.
- Use the following commands:

```
$ npx hardhat verify --network <name> <voucherImplAddress>
$ npx hardhat verify --network <name> <voucherUpgradeableBeaconAddress> \
<voucherImplAddress> <adminAddress> # constructor args
$ npx hardhat verify --network <name> <voucherHubImplAddress>
# initializeFunctionData = VoucherHub__factory.createInterface().encodeFunctionData('initialize', [
# <adminAddress>,
# <managerAddress>,
# <minterAddress>,
# <iexecPocoAddress>,
# <voucherUpgradeableBeaconAddress>,
# ])
$ npx hardhat verify --network <name> <voucherHubERC1967ProxyAddress> \
<voucherHubImplAddress> <initializeFunctionData> # constructor args
VOUCHER_UPGRADER_ADDRESS=<address> \
VOUCHER_MANAGER_ADDRESS=<address> \
VOUCHER_MINTER_ADDRESS=<address> \
npx hardhat run scripts/verify.ts --network <name>
```
63 changes: 63 additions & 0 deletions scripts/verify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// SPDX-FileCopyrightText: 2024 IEXEC BLOCKCHAIN TECH <[email protected]>
// SPDX-License-Identifier: Apache-2.0

import hre, { deployments, ethers } from 'hardhat';
import { UpgradeableBeacon__factory, VoucherHub__factory } from '../typechain-types';

/**
* Note: When verifying a proxy contract, Hardhat-verify combined with Openzeppelin Upgrades
* plugin is "generally" able to automatically detect and verify the implementation contract.
* Here we explicitly verify the implementation because some issues have been observed.
*/

(async () => {
const upgraderAddress = process.env.VOUCHER_UPGRADER_ADDRESS || '';
const managerAddress = process.env.VOUCHER_MANAGER_ADDRESS || '';
const minterAddress = process.env.VOUCHER_MINTER_ADDRESS || '';

const voucherImplAddress = (await deployments.get('VoucherImpl')).address;
const voucherUpgradableBeaconAddress = (await deployments.get('VoucherUpgradeableBeacon'))
.address;
const voucherHubImplAddress = (await deployments.get('VoucherHubImpl')).address;
const voucherHubERC1967ProxyAddress = (await deployments.get('VoucherHubERC1967Proxy')).address;

const beaconInitialOwnerAddress = await UpgradeableBeacon__factory.connect(
voucherUpgradableBeaconAddress,
ethers.provider,
).owner(); // Will not work if the owner was changed after deployment.
const voucherHub = VoucherHub__factory.connect(voucherHubERC1967ProxyAddress, ethers.provider);
const iexecPocoAddress = await voucherHub.getIexecPoco();

console.log('Verifying Voucher implementation');
await hre.run('verify:verify', {
address: voucherImplAddress,
constructorArguments: [],
});

console.log('Verifying Beacon proxy');
await hre.run('verify:verify', {
address: voucherUpgradableBeaconAddress,
constructorArguments: [voucherImplAddress, beaconInitialOwnerAddress],
});

console.log('Verifying VoucherHub implementation');
await hre.run('verify:verify', {
address: voucherHubImplAddress,
constructorArguments: [],
});

console.log('Verifying VoucherHub ERC1967 proxy');
await hre.run('verify:verify', {
address: voucherHubERC1967ProxyAddress,
constructorArguments: [
voucherHubImplAddress,
VoucherHub__factory.createInterface().encodeFunctionData('initialize', [
upgraderAddress,
managerAddress,
minterAddress,
iexecPocoAddress,
voucherUpgradableBeaconAddress,
]),
],
});
})().catch((error) => console.log(error));

0 comments on commit 353e30f

Please sign in to comment.