From 3ae580845a3c1883d7e112b82cb5a0aeb43ce343 Mon Sep 17 00:00:00 2001 From: Brandon Anderson Date: Tue, 13 Sep 2022 12:25:22 -0700 Subject: [PATCH] New Pauser/UnPauser scripts for planned downtime on EVM bridges. --- smart-contracts/hardhat.config.ts | 2 +- smart-contracts/scripts/pauseBridge.ts | 59 ++++++++++++++++++++++++ smart-contracts/scripts/unPauseBridge.ts | 59 ++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 smart-contracts/scripts/pauseBridge.ts create mode 100644 smart-contracts/scripts/unPauseBridge.ts diff --git a/smart-contracts/hardhat.config.ts b/smart-contracts/hardhat.config.ts index c8f48eb103..9085e12ab2 100644 --- a/smart-contracts/hardhat.config.ts +++ b/smart-contracts/hardhat.config.ts @@ -15,7 +15,7 @@ const envconfig = dotenv.config(); const mainnetUrl = process.env["MAINNET_URL"] ?? "https://example.com"; const ropstenUrl = process.env["ROPSTEN_URL"] ?? "https://example.com"; -const activePrivateKey = process.env[process.env["ACTIVE_PRIVATE_KEY"] ?? "0xabcd"] ?? "0xabcd"; +const activePrivateKey = process.env["ACTIVE_PRIVATE_KEY"] ?? "0xabcd"; const keyList = activePrivateKey.indexOf(",") ? activePrivateKey.split(",") : [activePrivateKey]; const config: HardhatUserConfig = { diff --git a/smart-contracts/scripts/pauseBridge.ts b/smart-contracts/scripts/pauseBridge.ts new file mode 100644 index 0000000000..4cbfe24e9c --- /dev/null +++ b/smart-contracts/scripts/pauseBridge.ts @@ -0,0 +1,59 @@ +/** + * This script will pause the bridgebank smart contract to shut down EVM imports. + * Use with care. + * + * To use this script make sure the environment variable ACTIVE_PRIVATE_KEY is set to the pauser private key before running + * Make sure you have environment variable MAINNET_URL set to a HTTP/HTTPS Full/Archive Node for the EVM chain in communication + * Make sure the pauser address has at least 1 ETH before running + */ + +import { ethers } from "hardhat"; +import { BridgeBank__factory } from "../build"; + +const bridgeBankAddress = process.env["BRIDGEBANK_ADDRESS"] ?? "0xB5F54ac4466f5ce7E0d8A5cB9FE7b8c0F35B7Ba8"; + +async function pauseBridge() { + // Connect to BridgeBank and get User Info + const bridgebankFactory = await ethers.getContractFactory("BridgeBank") as BridgeBank__factory; + const bridgebank = await bridgebankFactory.attach(bridgeBankAddress); + const userAddress = await bridgebank.signer.getAddress(); + let paused = await bridgebank.paused(); + const balance = await bridgebank.signer.getBalance(); + + // Sanity Condition Checks + if (paused) { + console.error("Bridgebank is already paused, no actions to do"); + return; + } + + if (!(await bridgebank.pausers(userAddress))) { + console.error(`Private key has public address: ${userAddress}, which is not a valid pauser address`); + return; + } + + if (balance.lt(ethers.utils.parseEther("0.5"))) { + console.error(`Script requires a minimum of 0.5 ETH before it will attempt to run.`) + console.error(`Current balance is ${ethers.utils.formatEther(balance)} ETH`); + return; + } + + // Pause The Bridge + console.log("Sending the pause transaction"); + const tx = await bridgebank.pause(); + console.log("Transaction sent, waiting for transaction receipt"); + const receipt = await tx.wait(); + console.log(`Received transaction receipt. Transaction Hash: ${receipt.transactionHash}`); + + // Confirm the bridge is now paused + paused = await bridgebank.paused(); + if (paused) { + console.log("Confirmed the BridgeBank is now paused"); + } else { + console.error("We have received a pause transaction receipt but BridgeBank is not paused..."); + console.error("!!!!!CRITICAL CONDITION REACHED, CONTACT PEGGY TEAM IMMEDIATELY!!!!!") + } +} + +pauseBridge() + .then(() => console.log("Pauser Script has completed")) + .catch((error) => console.error("An error ocurred when attempting to pause bridgebank: ", error)) \ No newline at end of file diff --git a/smart-contracts/scripts/unPauseBridge.ts b/smart-contracts/scripts/unPauseBridge.ts new file mode 100644 index 0000000000..c693a4c1b4 --- /dev/null +++ b/smart-contracts/scripts/unPauseBridge.ts @@ -0,0 +1,59 @@ +/** + * This script will resume the bridgebank smart contract and allow EVM imports. + * Only use after the cause of the pause has been resolved! + * + * To use this script make sure the environment variable ACTIVE_PRIVATE_KEY is set to the unpauser private key before running + * Make sure you have environment variable MAINNET_URL set to a HTTP/HTTPS Full/Archive Node for the EVM chain in communication + * Make sure the unpauser address has at least 1 ETH before running + */ + +import { ethers } from "hardhat"; +import { BridgeBank__factory } from "../build"; + +const bridgeBankAddress = process.env["BRIDGEBANK_ADDRESS"] ?? "0xB5F54ac4466f5ce7E0d8A5cB9FE7b8c0F35B7Ba8"; + +async function unpauseBridge() { + // Connect to BridgeBank and get User Info + const bridgebankFactory = await ethers.getContractFactory("BridgeBank") as BridgeBank__factory; + const bridgebank = await bridgebankFactory.attach(bridgeBankAddress); + const userAddress = await bridgebank.signer.getAddress(); + let paused = await bridgebank.paused(); + const balance = await bridgebank.signer.getBalance(); + + // Sanity Condition Checks + if (!paused) { + console.error("Bridgebank is not paused, no actions to do"); + return; + } + + if (!(await bridgebank.pausers(userAddress))) { + console.error(`Private key has public address: ${userAddress}, which is not a valid unpauser address`); + return; + } + + if (balance.lt(ethers.utils.parseEther("0.5"))) { + console.error(`Script requires a minimum of 0.5 ETH before it will attempt to run.`) + console.error(`Current balance is ${ethers.utils.formatEther(balance)} ETH`); + return; + } + + // Pause The Bridge + console.log("Sending the unpause transaction"); + const tx = await bridgebank.unpause(); + console.log("Transaction sent, waiting for transaction receipt"); + const receipt = await tx.wait(); + console.log(`Received transaction receipt. Transaction Hash: ${receipt.transactionHash}`); + + // Confirm the bridge is now unpaused + paused = await bridgebank.paused(); + if (!paused) { + console.log("Confirmed the BridgeBank is now unpaused"); + } else { + console.error("We have received a unpause transaction receipt but BridgeBank is still paused..."); + console.error("!!!!!CRITICAL CONDITION REACHED, CONTACT PEGGY TEAM IMMEDIATELY!!!!!") + } +} + +unpauseBridge() + .then(() => console.log("Unpausing Script has completed")) + .catch((error) => console.error("An error ocurred when attempting to unpause bridgebank: ", error)) \ No newline at end of file