Skip to content

Commit

Permalink
fix(core): assert block gas limit is sufficiently high in parsing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-goldman committed Apr 29, 2023
1 parent 7ee54af commit ed81039
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/khaki-bees-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chugsplash/core': patch
---

Assert block gas limit is sufficiently high in parsing logic
3 changes: 3 additions & 0 deletions packages/core/src/config/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
isDataHexString,
isLiveNetwork,
isContractDeployed,
assertValidBlockGasLimit,
} from '../utils'
import {
UserChugSplashConfig,
Expand Down Expand Up @@ -2141,6 +2142,8 @@ export const parseAndValidateChugSplashConfig = async (
// If the user disabled some safety checks, log warnings related to that
logUnsafeOptions(userConfig, cre.silent, cre.stream)

await assertValidBlockGasLimit(provider)

// Validate top level config and contract options
await assertValidUserConfigFields(userConfig, provider, cre, exitOnFailure)

Expand Down
8 changes: 2 additions & 6 deletions packages/core/src/languages/solidity/predeploys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
getGasPriceOverrides,
isLiveNetwork,
getImpersonatedSigner,
assertValidBlockGasLimit,
} from '../../utils'
import { EXECUTOR_ROLE } from '../../constants'
import {
Expand Down Expand Up @@ -82,12 +83,7 @@ export const initializeChugSplash = async (
executors: string[],
logger?: Logger
): Promise<void> => {
// Check that the block gas limit is reasonably high on this network. Although we can lower 15M to
// 10M or less, we err on the side of safety for now. This number should never be lower than 6M
// because it costs ~5.3M gas to deploy the ChugSplashManager V1, which is at the contract size
// limit.
const { gasLimit: blockGasLimit } = await provider.getBlock('latest')
assert(blockGasLimit.gte(15_000_000), `Block gas limit is too low.`)
await assertValidBlockGasLimit(provider)

const chugsplashConstructorArgs = getChugSplashConstructorArgs()

Expand Down
18 changes: 18 additions & 0 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1298,3 +1298,21 @@ export const getImpersonatedSigner = async (

return provider.getSigner(address)
}

/**
* Assert that the block gas limit is reasonably high on a network.
*/
export const assertValidBlockGasLimit = async (
provider: providers.Provider
) => {
const { gasLimit: blockGasLimit } = await provider.getBlock('latest')

// Although we can lower this from 15M to 10M or less, we err on the side of safety for now. This
// number should never be lower than 5.5M because it costs ~5.3M gas to deploy the
// ChugSplashManager V1, which is at the contract size limit.
if (blockGasLimit.lt(15_000_000)) {
throw new Error(
`Block gas limit is too low. Got: ${blockGasLimit.toString()}. Expected: 15M+`
)
}
}

0 comments on commit ed81039

Please sign in to comment.