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 ( ...@@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
) )
var ( var (
...@@ -82,8 +83,18 @@ func MigrateWithdrawal(withdrawal *LegacyWithdrawal, l1CrossDomainMessenger *com ...@@ -82,8 +83,18 @@ func MigrateWithdrawal(withdrawal *LegacyWithdrawal, l1CrossDomainMessenger *com
return nil, fmt.Errorf("cannot abi encode relayMessage: %w", err) 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 // Set the outer gas limit. This cannot be zero
gasLimit := uint64(len(data)*16 + 200_000) gasLimit := dataCost + 200_000
w := NewWithdrawal( w := NewWithdrawal(
versionedNonce, versionedNonce,
......
...@@ -18,16 +18,15 @@ import { ...@@ -18,16 +18,15 @@ import {
sleep, sleep,
remove0x, remove0x,
toHexString, toHexString,
fromHexString,
toRpcHexString, toRpcHexString,
hashCrossDomainMessage, hashCrossDomainMessage,
encodeCrossDomainMessageV0, encodeCrossDomainMessageV0,
encodeCrossDomainMessageV1, encodeCrossDomainMessageV1,
L2OutputOracleParameters,
BedrockOutputData, BedrockOutputData,
BedrockCrossChainMessageProof, BedrockCrossChainMessageProof,
decodeVersionedNonce, decodeVersionedNonce,
encodeVersionedNonce, encodeVersionedNonce,
calldataCost,
} 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'
...@@ -352,12 +351,13 @@ export class CrossChainMessenger { ...@@ -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 { return {
...resolved, ...resolved,
value, value,
minGasLimit: BigNumber.from(minGasLimit), minGasLimit,
messageNonce: encodeVersionedNonce( messageNonce: encodeVersionedNonce(
BigNumber.from(1), BigNumber.from(1),
resolved.messageNonce 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