Skip to content

Bold upgrade action QoL improvements #333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 71 additions & 15 deletions scripts/boldUpgradeCommon.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { BigNumber, providers } from 'ethers'
import { parseEther } from 'ethers/lib/utils'
import { isAddress, parseUnits } from 'ethers/lib/utils'
import fs from 'fs'

import { configs } from './files/configs'
import { ERC20__factory } from '../build/types'

export interface DeployedContracts {
bridge: string
Expand All @@ -15,13 +16,26 @@ export interface DeployedContracts {
challengeManager: string
boldAction: string
preImageHashLookup: string
prover0: string
proverMem: string
proverMath: string
proverHostIo: string
osp: string
}

// Chain id => RollupCreator contract
// Needed to obtain the updated v3.1.0 logic contracts in the preparation phase
export const rollupCreators: { [key: number]: string } = {
// L1
1: '0x43698080f40dB54DEE6871540037b8AB8fD0AB44',
11155111: '0x687Bc1D23390875a868Db158DA1cDC8998E31640',

// Arbitrum chains
42161: '0xB90e53fd945Cd28Ec4728cBfB566981dD571eB8b',
42170: '0xF916Bfe431B7A7AaE083273F5b862e00a15d60F4',
421614: '0x5F45675AC8DDF7d45713b2c7D191B287475C16cF',

// Other chains
8453: '0xDbe3e840569a0446CDfEbc65D7d429c5Da5537b7',
84532: '0x70cA29dA3B116A2c4A267c549bf7947d47f41e22',
}

export const getJsonFile = (fileLocation: string) => {
return JSON.parse(fs.readFileSync(fileLocation).toString())
}
Expand Down Expand Up @@ -105,6 +119,7 @@ export const validateConfig = async (
config: Config,
l1Rpc: providers.Provider
) => {
// check all config.contracts
if ((await l1Rpc.getCode(config.contracts.rollup)).length <= 2) {
throw new Error('rollup address is not a contract')
}
Expand All @@ -126,11 +141,17 @@ export const validateConfig = async (
if ((await l1Rpc.getCode(config.contracts.upgradeExecutor)).length <= 2) {
throw new Error('upgradeExecutor address is not a contract')
}
if (!isAddress(config.contracts.excessStakeReceiver)) {
throw new Error('excessStakeReceiver is not a valid address')
}

// check all the config.proxyAdmins exist
if ((await l1Rpc.getCode(config.proxyAdmins.outbox)).length <= 2) {
throw new Error('outbox proxy admin address is not a contract')
}
if ((await l1Rpc.getCode(config.proxyAdmins.inbox)).length <= 2) {
throw new Error('inbox proxy admin address is not a contract')
}
if ((await l1Rpc.getCode(config.proxyAdmins.bridge)).length <= 2) {
throw new Error('bridge proxy admin address is not a contract')
}
Expand All @@ -142,18 +163,27 @@ export const validateConfig = async (
}

// check all the settings exist
if (config.settings.challengeGracePeriodBlocks === 0) {
throw new Error('challengeGracePeriodBlocks is 0')
}
if (config.settings.confirmPeriodBlocks === 0) {
throw new Error('confirmPeriodBlocks is 0')
}
if (config.settings.stakeToken.length === 0) {
throw new Error('stakeToken address is empty')
if (config.settings.challengePeriodBlocks === 0) {
throw new Error('challengePeriodBlocks is 0')
}
if ((await l1Rpc.getCode(config.settings.stakeToken)).length <= 2) {
throw new Error('stakeToken address is not a contract')
}
if (config.settings.chainId === 0) {
throw new Error('chainId is 0')
}
if (config.settings.minimumAssertionPeriod === 0) {
throw new Error('minimumAssertionPeriod is 0')
}
if (config.settings.validatorAfkBlocks === 0) {
throw new Error('validatorAfkBlocks is 0')
}
if (config.settings.blockLeafSize === 0) {
throw new Error('blockLeafSize is 0')
}
Expand All @@ -166,22 +196,48 @@ export const validateConfig = async (
if (config.settings.numBigStepLevel === 0) {
throw new Error('numBigStepLevel is 0')
}
if (config.settings.maxDataSize === 0) {
throw new Error('maxDataSize is 0')
}

// check stake token amount
// (we expect stakeAmt to be at least 1 whole unit of the token)
const stakeAmount = BigNumber.from(config.settings.stakeAmt)
// check it's more than 1 eth
if (stakeAmount.lt(parseEther('1'))) {
const stakeToken = ERC20__factory.connect(config.settings.stakeToken, l1Rpc)
const decimals = await stakeToken.decimals()
if (stakeAmount.lt(parseUnits('1', decimals))) {
throw new Error('stakeAmt is less than 1 eth')
}
const miniStakeAmounts = config.settings.miniStakeAmounts.map(BigNumber.from)

// check mini stakes
const miniStakeAmounts = config.settings.miniStakeAmounts.map(BigNumber.from)
if (miniStakeAmounts.length !== config.settings.numBigStepLevel + 2) {
throw new Error('miniStakeAmts length is not numBigStepLevel + 2')
}

if (
!config.settings.disableValidatorWhitelist &&
config.validators.length === 0
) {
throw new Error('no validators')
// check validators and whitelist
if (!config.settings.disableValidatorWhitelist) {
if (config.validators.length === 0) {
throw new Error('no validators')
}

for (let i = 0; i < config.validators.length; i++) {
if (!isAddress(config.validators[i])) {
throw new Error(`Invalid address for validator ${i}`)
}
}
}

// check delaybuffer settings
if (config.settings.isDelayBufferable) {
if (config.settings.bufferConfig.max === 0) {
throw new Error('bufferConfig.max is 0')
}
if (config.settings.bufferConfig.threshold === 0) {
throw new Error('bufferConfig.threshold is 0')
}
if (config.settings.bufferConfig.replenishRateInBasis === 0) {
throw new Error('bufferConfig.replenishRateInBasis is 0')
}
}
}
Loading