|
| 1 | +'use strict' |
| 2 | + |
| 3 | +import { ethers } from 'ethers' |
| 4 | +import { task } from 'hardhat/config' |
| 5 | +import * as types from 'hardhat/internal/core/params/argumentTypes' |
| 6 | +import { hexStringEquals } from '@eth-optimism/core-utils' |
| 7 | +import { getContractFactory } from '../src/contract-defs' |
| 8 | + |
| 9 | +import { |
| 10 | + getInput, |
| 11 | + color as c, |
| 12 | + getArtifact, |
| 13 | + getEtherscanUrl, |
| 14 | + printComparison, |
| 15 | +} from '../src/validation-utils' |
| 16 | + |
| 17 | +task('validate:address-dictator') |
| 18 | + .addParam( |
| 19 | + 'dictator', |
| 20 | + 'Address of the AddressDictator to validate.', |
| 21 | + undefined, |
| 22 | + types.string |
| 23 | + ) |
| 24 | + .addParam( |
| 25 | + 'manager', |
| 26 | + 'Address of the Address Manager contract which would be updated by the Dictator.', |
| 27 | + undefined, |
| 28 | + types.string |
| 29 | + ) |
| 30 | + .addParam( |
| 31 | + 'multisig', |
| 32 | + 'Address of the multisig contract which should be the final owner', |
| 33 | + undefined, |
| 34 | + types.string |
| 35 | + ) |
| 36 | + .addOptionalParam( |
| 37 | + 'contractsRpcUrl', |
| 38 | + 'RPC Endpoint to query for data', |
| 39 | + process.env.CONTRACTS_RPC_URL, |
| 40 | + types.string |
| 41 | + ) |
| 42 | + .setAction(async (args) => { |
| 43 | + if (!args.contractsRpcUrl) { |
| 44 | + throw new Error( |
| 45 | + c.red('RPC URL must be set in your env, or passed as an argument.') |
| 46 | + ) |
| 47 | + } |
| 48 | + const provider = new ethers.providers.JsonRpcProvider(args.contractsRpcUrl) |
| 49 | + |
| 50 | + const network = await provider.getNetwork() |
| 51 | + console.log() |
| 52 | + console.log(c.cyan("First make sure you're on the right chain:")) |
| 53 | + console.log( |
| 54 | + `Reading from the ${c.red(network.name)} network (Chain ID: ${c.red( |
| 55 | + '' + network.chainId |
| 56 | + )})` |
| 57 | + ) |
| 58 | + await getInput(c.yellow('OK? Hit enter to continue.')) |
| 59 | + |
| 60 | + // eslint-disable-next-line @typescript-eslint/no-var-requires |
| 61 | + const dictatorArtifact = require('../artifacts/contracts/L1/deployment/AddressDictator.sol/AddressDictator.json') |
| 62 | + const dictatorCode = await provider.getCode(args.dictator) |
| 63 | + console.log( |
| 64 | + c.cyan(` |
| 65 | +Now validating the Address Dictator deployment at\n${getEtherscanUrl( |
| 66 | + network, |
| 67 | + args.dictator |
| 68 | + )}`) |
| 69 | + ) |
| 70 | + printComparison( |
| 71 | + 'Comparing deployed AddressDictator bytecode against local build artifacts', |
| 72 | + 'Deployed AddressDictator code', |
| 73 | + { name: 'Compiled bytecode', value: dictatorArtifact.deployedBytecode }, |
| 74 | + { name: 'Deployed bytecode', value: dictatorCode } |
| 75 | + ) |
| 76 | + |
| 77 | + // Connect to the deployed AddressDictator. |
| 78 | + const dictatorContract = getContractFactory('AddressDictator') |
| 79 | + .attach(args.dictator) |
| 80 | + .connect(provider) |
| 81 | + |
| 82 | + const finalOwner = await dictatorContract.finalOwner() |
| 83 | + printComparison( |
| 84 | + 'Comparing the finalOwner address in the AddressDictator to the multisig address', |
| 85 | + 'finalOwner', |
| 86 | + { name: 'multisig address', value: args.multisig }, |
| 87 | + { name: 'finalOwner ', value: finalOwner } |
| 88 | + ) |
| 89 | + |
| 90 | + const manager = await dictatorContract.manager() |
| 91 | + printComparison( |
| 92 | + 'Validating the AddressManager address in the AddressDictator', |
| 93 | + 'addressManager', |
| 94 | + { name: 'manager', value: args.manager }, |
| 95 | + { name: 'Address Manager', value: manager } |
| 96 | + ) |
| 97 | + await getInput(c.yellow('OK? Hit enter to continue.')) |
| 98 | + |
| 99 | + // Get names and addresses from the Dictator. |
| 100 | + const namedAddresses = await dictatorContract.getNamedAddresses() |
| 101 | + |
| 102 | + // In order to reduce noise for the user, we query the AddressManager identify addresses that |
| 103 | + // will not be changed, and skip over them in this block. |
| 104 | + const managerContract = getContractFactory('Lib_AddressManager') |
| 105 | + .attach(args.manager) |
| 106 | + .connect(provider) |
| 107 | + |
| 108 | + // Now we loop over those and compare the addresses/deployedBytecode to deployment artifacts. |
| 109 | + for (const pair of namedAddresses) { |
| 110 | + const currentAddress = await managerContract.getAddress(pair.name) |
| 111 | + const artifact = getArtifact(pair.name) |
| 112 | + const addressChanged = !hexStringEquals(currentAddress, pair.addr) |
| 113 | + if (addressChanged) { |
| 114 | + console.log( |
| 115 | + c.cyan(` |
| 116 | +Now validating the ${pair.name} deployment. |
| 117 | +Current address: ${getEtherscanUrl(network, currentAddress)} |
| 118 | +Upgraded address ${getEtherscanUrl(network, pair.addr)}`) |
| 119 | + ) |
| 120 | + |
| 121 | + const code = await provider.getCode(pair.addr) |
| 122 | + printComparison( |
| 123 | + `Verifying ${pair.name} source code against local deployment artifacts`, |
| 124 | + `Deployed ${pair.name} code`, |
| 125 | + { |
| 126 | + name: 'artifact.deployedBytecode', |
| 127 | + value: artifact.deployedBytecode, |
| 128 | + }, |
| 129 | + { name: 'Deployed bytecode ', value: code } |
| 130 | + ) |
| 131 | + |
| 132 | + // Identify contracts which inherit from Lib_AddressResolver, and check that they |
| 133 | + // have the right manager address. |
| 134 | + if (Object.keys(artifact)) { |
| 135 | + if (artifact.abi.some((el) => el.name === 'libAddressManager')) { |
| 136 | + const libAddressManager = await getContractFactory( |
| 137 | + 'Lib_AddressResolver' |
| 138 | + ) |
| 139 | + .attach(pair.addr) |
| 140 | + .connect(provider) |
| 141 | + .libAddressManager() |
| 142 | + |
| 143 | + printComparison( |
| 144 | + `Verifying ${pair.name} has the correct AddressManager address`, |
| 145 | + `The AddressManager address in ${pair.name}`, |
| 146 | + { name: 'Deployed value', value: libAddressManager }, |
| 147 | + { name: 'Expected value', value: manager } |
| 148 | + ) |
| 149 | + } |
| 150 | + } |
| 151 | + } |
| 152 | + await getInput(c.yellow('OK? Hit enter to continue.')) |
| 153 | + } |
| 154 | + console.log(c.green('AddressManager Validation complete!')) |
| 155 | + }) |
0 commit comments