Commit b996c9ce authored by Mark Tyneway's avatar Mark Tyneway

contracts-bedrock: deploy time checks

Add deploy time checks to ensure that the config invariants are sane.
There is an invariant such that the L2 gas limit must be larger than
the amount of gas used by the system transaction plus the amount
of gas that deposits can purchase on L1. This invariant is held
checked in the migration code but not the typescript deployment
code.
parent fc56ded1
...@@ -8,11 +8,26 @@ import { assertContractVariable, deploy } from '../src/deploy-utils' ...@@ -8,11 +8,26 @@ import { assertContractVariable, deploy } from '../src/deploy-utils'
const uint128Max = ethers.BigNumber.from('0xffffffffffffffffffffffffffffffff') const uint128Max = ethers.BigNumber.from('0xffffffffffffffffffffffffffffffff')
const defaultResourceConfig = {
maxResourceLimit: 20_000_000,
elasticityMultiplier: 10,
baseFeeMaxChangeDenominator: 8,
minimumBaseFee: ethers.utils.parseUnits('1', 'gwei'),
systemTxMaxGas: 1_000_000,
maximumBaseFee: uint128Max,
}
const deployFn: DeployFunction = async (hre) => { const deployFn: DeployFunction = async (hre) => {
const batcherHash = hre.ethers.utils const batcherHash = hre.ethers.utils
.hexZeroPad(hre.deployConfig.batchSenderAddress, 32) .hexZeroPad(hre.deployConfig.batchSenderAddress, 32)
.toLowerCase() .toLowerCase()
const l2GenesisBlockGasLimit = hre.deployConfig.l2GenesisBlockGasLimit
const l2GasLimitLowerBound = defaultResourceConfig.systemTxMaxGas + defaultResourceConfig.maxResourceLimit
if (l2GenesisBlockGasLimit.lt(l2GasLimitLowerBound)) {
throw new Error(`L2 genesis block gas limit must be at least ${l2GasLimitLowerBound}`)
}
await deploy({ await deploy({
hre, hre,
name: 'SystemConfig', name: 'SystemConfig',
...@@ -21,16 +36,9 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -21,16 +36,9 @@ const deployFn: DeployFunction = async (hre) => {
hre.deployConfig.gasPriceOracleOverhead, hre.deployConfig.gasPriceOracleOverhead,
hre.deployConfig.gasPriceOracleScalar, hre.deployConfig.gasPriceOracleScalar,
batcherHash, batcherHash,
hre.deployConfig.l2GenesisBlockGasLimit, l2GenesisBlockGasLimit,
hre.deployConfig.p2pSequencerAddress, hre.deployConfig.p2pSequencerAddress,
{ defaultResourceConfig
maxResourceLimit: 20_000_000,
elasticityMultiplier: 10,
baseFeeMaxChangeDenominator: 8,
systemTxMaxGas: 1_000_000,
minimumBaseFee: ethers.utils.parseUnits('1', 'gwei'),
maximumBaseFee: uint128Max,
},
], ],
postDeployAction: async (contract) => { postDeployAction: async (contract) => {
await assertContractVariable( await assertContractVariable(
...@@ -56,12 +64,12 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -56,12 +64,12 @@ const deployFn: DeployFunction = async (hre) => {
) )
const config = await contract.resourceConfig() const config = await contract.resourceConfig()
assert(config.maxResourceLimit === 20_000_000) assert(config.maxResourceLimit === defaultResourceConfig.maxResourceLimit)
assert(config.elasticityMultiplier === 10) assert(config.elasticityMultiplier === defaultResourceConfig.elasticityMultiplier)
assert(config.baseFeeMaxChangeDenominator === 8) assert(config.baseFeeMaxChangeDenominator === defaultResourceConfig.baseFeeMaxChangeDenominator)
assert(config.systemTxMaxGas === 1_000_000) assert(config.systemTxMaxGas === defaultResourceConfig.systemTxMaxGas)
assert(ethers.utils.parseUnits('1', 'gwei').eq(config.minimumBaseFee)) assert(config.minimumBaseFee.eq(defaultResourceConfig.minimumBaseFee))
assert(config.maximumBaseFee.eq(uint128Max)) assert(config.maximumBaseFee.eq(defaultResourceConfig.maximumBaseFee))
}, },
}) })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment