Commit 9445344a authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

Merge pull request #5668 from ethereum-optimism/mark/sdk/migrated-withdrawal-gas

message-utils: use BigNumber
parents d2951a33 75635aa0
...@@ -6,13 +6,13 @@ import { LowLevelMessage } from '../interfaces' ...@@ -6,13 +6,13 @@ import { LowLevelMessage } from '../interfaces'
const { hexDataLength } = utils const { hexDataLength } = utils
// Constants used by `CrossDomainMessenger.baseGas` // Constants used by `CrossDomainMessenger.baseGas`
const RELAY_CONSTANT_OVERHEAD = 200_000 const RELAY_CONSTANT_OVERHEAD = BigNumber.from(200_000)
const RELAY_PER_BYTE_DATA_COST = 16 const RELAY_PER_BYTE_DATA_COST = BigNumber.from(16)
const MIN_GAS_DYNAMIC_OVERHEAD_NUMERATOR = 64 const MIN_GAS_DYNAMIC_OVERHEAD_NUMERATOR = BigNumber.from(64)
const MIN_GAS_DYNAMIC_OVERHEAD_DENOMINATOR = 63 const MIN_GAS_DYNAMIC_OVERHEAD_DENOMINATOR = BigNumber.from(63)
const RELAY_CALL_OVERHEAD = 40_000 const RELAY_CALL_OVERHEAD = BigNumber.from(40_000)
const RELAY_RESERVED_GAS = 40_000 const RELAY_RESERVED_GAS = BigNumber.from(40_000)
const RELAY_GAS_CHECK_BUFFER = 5_000 const RELAY_GAS_CHECK_BUFFER = BigNumber.from(5_000)
/** /**
* Utility for hashing a LowLevelMessage object. * Utility for hashing a LowLevelMessage object.
...@@ -62,22 +62,26 @@ export const migratedWithdrawalGasLimit = ( ...@@ -62,22 +62,26 @@ export const migratedWithdrawalGasLimit = (
if (chainID === 420) { if (chainID === 420) {
overhead = BigNumber.from(200_000) overhead = BigNumber.from(200_000)
} else { } else {
// Dynamic overhead (EIP-150)
// We use a constant 1 million gas limit due to the overhead of simulating all migrated withdrawal
// transactions during the migration. This is a conservative estimate, and if a withdrawal
// uses more than the minimum gas limit, it will fail and need to be replayed with a higher
// gas limit.
const dynamicOverhead = MIN_GAS_DYNAMIC_OVERHEAD_NUMERATOR.mul(
1_000_000
).div(MIN_GAS_DYNAMIC_OVERHEAD_DENOMINATOR)
// Constant overhead // Constant overhead
overhead = BigNumber.from( overhead = RELAY_CONSTANT_OVERHEAD.add(dynamicOverhead)
RELAY_CONSTANT_OVERHEAD + .add(RELAY_CALL_OVERHEAD)
// Dynamic overhead (EIP-150) // Gas reserved for the worst-case cost of 3/5 of the `CALL` opcode's dynamic gas
(MIN_GAS_DYNAMIC_OVERHEAD_NUMERATOR * 1_000_000) / // factors. (Conservative)
MIN_GAS_DYNAMIC_OVERHEAD_DENOMINATOR + // Relay reserved gas (to ensure execution of `relayMessage` completes after the
// Gas reserved for the worst-case cost of 3/5 of the `CALL` opcode's dynamic gas // subcontext finishes executing) (Conservative)
// factors. (Conservative) .add(RELAY_RESERVED_GAS)
RELAY_CALL_OVERHEAD + // Gas reserved for the execution between the `hasMinGas` check and the `CALL`
// Relay reserved gas (to ensure execution of `relayMessage` completes after the // opcode. (Conservative)
// subcontext finishes executing) (Conservative) .add(RELAY_GAS_CHECK_BUFFER)
RELAY_RESERVED_GAS +
// Gas reserved for the execution between the `hasMinGas` check and the `CALL`
// opcode. (Conservative)
RELAY_GAS_CHECK_BUFFER
)
} }
let minGasLimit = dataCost.add(overhead) let minGasLimit = dataCost.add(overhead)
......
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