Commit 12869fe9 authored by Mark Tyneway's avatar Mark Tyneway

sdk: update withdrawal gas limit

parent 6346058d
...@@ -26,6 +26,7 @@ import { ...@@ -26,6 +26,7 @@ import {
BedrockCrossChainMessageProof, BedrockCrossChainMessageProof,
decodeVersionedNonce, decodeVersionedNonce,
encodeVersionedNonce, encodeVersionedNonce,
getChainId,
} from '@eth-optimism/core-utils' } from '@eth-optimism/core-utils'
import { getContractInterface, predeploys } from '@eth-optimism/contracts' import { getContractInterface, predeploys } from '@eth-optimism/contracts'
import * as rlp from 'rlp' import * as rlp from 'rlp'
...@@ -403,7 +404,8 @@ export class CrossChainMessenger { ...@@ -403,7 +404,8 @@ export class CrossChainMessenger {
let gasLimit: BigNumber let gasLimit: BigNumber
let messageNonce: BigNumber let messageNonce: BigNumber
if (version.eq(0)) { if (version.eq(0)) {
gasLimit = migratedWithdrawalGasLimit(encoded) const chainID = await getChainId(this.l2Provider)
gasLimit = migratedWithdrawalGasLimit(encoded, chainID)
messageNonce = resolved.messageNonce messageNonce = resolved.messageNonce
} else { } else {
const receipt = await this.l2Provider.getTransactionReceipt( const receipt = await this.l2Provider.getTransactionReceipt(
......
...@@ -41,10 +41,17 @@ export const hashMessageHash = (messageHash: string): string => { ...@@ -41,10 +41,17 @@ export const hashMessageHash = (messageHash: string): string => {
/** /**
* Compute the min gas limit for a migrated withdrawal. * Compute the min gas limit for a migrated withdrawal.
*/ */
export const migratedWithdrawalGasLimit = (data: string): BigNumber => { export const migratedWithdrawalGasLimit = (
data: string,
chainID: number
): BigNumber => {
// Compute the gas limit and cap at 25 million // Compute the gas limit and cap at 25 million
const dataCost = BigNumber.from(hexDataLength(data)).mul(16) const dataCost = BigNumber.from(hexDataLength(data)).mul(16)
let minGasLimit = dataCost.add(200_000) let overhead = 200_000
if (chainID !== 420) {
overhead = 1_000_000
}
let minGasLimit = dataCost.add(overhead)
if (minGasLimit.gt(25_000_000)) { if (minGasLimit.gt(25_000_000)) {
minGasLimit = BigNumber.from(25_000_000) minGasLimit = BigNumber.from(25_000_000)
} }
......
...@@ -7,11 +7,13 @@ import { ...@@ -7,11 +7,13 @@ import {
hashMessageHash, hashMessageHash,
} from '../../src/utils/message-utils' } from '../../src/utils/message-utils'
const goerliChainID = 420
describe('Message Utils', () => { describe('Message Utils', () => {
describe('migratedWithdrawalGasLimit', () => { describe('migratedWithdrawalGasLimit', () => {
it('should have a max of 25 million', () => { it('should have a max of 25 million', () => {
const data = '0x' + 'ff'.repeat(15_000_000) const data = '0x' + 'ff'.repeat(15_000_000)
const result = migratedWithdrawalGasLimit(data) const result = migratedWithdrawalGasLimit(data, goerliChainID)
expect(result).to.eq(BigNumber.from(25_000_000)) expect(result).to.eq(BigNumber.from(25_000_000))
}) })
...@@ -25,7 +27,7 @@ describe('Message Utils', () => { ...@@ -25,7 +27,7 @@ describe('Message Utils', () => {
] ]
for (const test of tests) { for (const test of tests) {
const result = migratedWithdrawalGasLimit(test.input) const result = migratedWithdrawalGasLimit(test.input, goerliChainID)
expect(result).to.eq(test.result) expect(result).to.eq(test.result)
} }
}) })
......
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