Skip to content

Commit

Permalink
Add script to verify contract upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
mzxyz committed May 22, 2024
1 parent 7e85417 commit ef5dbd2
Show file tree
Hide file tree
Showing 3 changed files with 388 additions and 1 deletion.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"upgrade": "ts-node --transpileOnly scripts/upgrade.ts",
"setup": "ts-node --transpileOnly scripts/startup.ts",
"verify": "ts-node --transpileOnly scripts/verify.ts",
"upgrade:verify": "ts-node --transpileOnly scripts/verifyUpgrade.ts",
"seed": "node -r ts-node/register/transpile-only -r dotenv/config scripts/seed.ts",
"kepler-e2e-test": "node -r ts-node/register/transpile-only test/e2e/kepler.e2e.ts"
},
Expand Down Expand Up @@ -86,6 +87,7 @@
"typechain": "^8.3.1",
"typescript": "^4.6.3",
"vuepress": "^1.9.7",
"web3": "^4.8.0",
"yargs": "^16.2.0"
},
"lint-staged": {
Expand Down
35 changes: 35 additions & 0 deletions scripts/verifyUpgrade.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Web3 from "web3";

import { argv } from "./setup";
import MainnetImpl from '../publish/mainnet.json';
import contracts from '../src/contracts';
import { getLogger } from './logger';

const main = async () => {
const target = argv.target ?? 'child';
const contractsImpl = MainnetImpl[target];
const web3 = new Web3('https://base.llamarpc.com');
const logger = getLogger('verifyUpgrade');

for (const name in contractsImpl) {
const contract = contractsImpl[name];
const address = contract.innerAddress;
if (!address) continue;

const contractInfo = contracts[name];
if (!contractInfo) {
logger.error(`Contract not found: ${name}`);
continue;
}

const localBytecode = contractInfo.deployedBytecode;
const remoteBytecode = await web3.eth.getCode(address);
if (remoteBytecode !== localBytecode) {
logger.info(`🚨 Bytecode mismatch for contract: ${name}`);
} else {
logger.info(`🚀 Contract verification succeed: ${name}`);
}
}
}

main();
Loading

0 comments on commit ef5dbd2

Please sign in to comment.