Commit 66cafc00 authored by Mark Tyneway's avatar Mark Tyneway

migration: update migrated withdrawal gas limit

More accurately computes the gas limit for a migrated
withdrawal. This is useful to prevent the gaslimit
for large transactions from going over the consensus
level block gas limit. It is unlikely for a transaction
to go over the block gas limit, but this is a preventative
fix just in case.
parent fe19972d
---
'@eth-optimism/sdk': patch
---
Update migrated withdrawal gaslimit calculation
......@@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
)
var (
......@@ -82,8 +83,18 @@ func MigrateWithdrawal(withdrawal *LegacyWithdrawal, l1CrossDomainMessenger *com
return nil, fmt.Errorf("cannot abi encode relayMessage: %w", err)
}
// Compute the cost of the calldata
dataCost := uint64(0)
for _, b := range data {
if b == 0 {
dataCost += params.TxDataZeroGas
} else {
dataCost += params.TxDataNonZeroGasEIP2028
}
}
// Set the outer gas limit. This cannot be zero
gasLimit := uint64(len(data)*16 + 200_000)
gasLimit := dataCost + 200_000
w := NewWithdrawal(
versionedNonce,
......
......@@ -18,16 +18,15 @@ import {
sleep,
remove0x,
toHexString,
fromHexString,
toRpcHexString,
hashCrossDomainMessage,
encodeCrossDomainMessageV0,
encodeCrossDomainMessageV1,
L2OutputOracleParameters,
BedrockOutputData,
BedrockCrossChainMessageProof,
decodeVersionedNonce,
encodeVersionedNonce,
calldataCost,
} from '@eth-optimism/core-utils'
import { getContractInterface, predeploys } from '@eth-optimism/contracts'
import * as rlp from 'rlp'
......@@ -352,12 +351,13 @@ export class CrossChainMessenger {
}
}
const minGasLimit = fromHexString(resolved.message).length * 16 + 200_000
const dataCost = calldataCost(resolved.message)
const minGasLimit = dataCost.add(200_000)
return {
...resolved,
value,
minGasLimit: BigNumber.from(minGasLimit),
minGasLimit,
messageNonce: encodeVersionedNonce(
BigNumber.from(1),
resolved.messageNonce
......
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