Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/four-mugs-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@eth-optimism/core-utils': minor
'@eth-optimism/sdk': minor
---

Add suppory for finalizing legacy withdrawals after the Bedrock migration
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const command = args[0]
switch (command) {
case 'decodeVersionedNonce': {
const input = BigNumber.from(args[1])
const [nonce, version] = decodeVersionedNonce(input)
const { nonce, version } = decodeVersionedNonce(input)

const output = utils.defaultAbiCoder.encode(
['uint256', 'uint256'],
Expand Down
21 changes: 13 additions & 8 deletions packages/core-utils/src/optimism/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ const nonceMask = BigNumber.from(
'0x0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
)

export const big0 = BigNumber.from(0)
export const big1 = BigNumber.from(1)

/**
* Encodes the version into the nonce.
*
Expand All @@ -34,8 +31,16 @@ export const encodeVersionedNonce = (
*
* @param nonce
*/
export const decodeVersionedNonce = (nonce: BigNumber): BigNumber[] => {
return [nonce.and(nonceMask), nonce.shr(240)]
export const decodeVersionedNonce = (
nonce: BigNumber
): {
version: BigNumber
nonce: BigNumber
} => {
return {
version: nonce.shr(240),
nonce: nonce.and(nonceMask),
}
}

/**
Expand Down Expand Up @@ -104,10 +109,10 @@ export const encodeCrossDomainMessage = (
gasLimit: BigNumber,
data: string
) => {
const [, version] = decodeVersionedNonce(nonce)
if (version.eq(big0)) {
const { version } = decodeVersionedNonce(nonce)
if (version.eq(0)) {
return encodeCrossDomainMessageV0(target, sender, data, nonce)
} else if (version.eq(big1)) {
} else if (version.eq(1)) {
return encodeCrossDomainMessageV1(
nonce,
sender,
Expand Down
9 changes: 4 additions & 5 deletions packages/core-utils/src/optimism/hashing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import {
decodeVersionedNonce,
encodeCrossDomainMessageV0,
encodeCrossDomainMessageV1,
big0,
big1,
} from './encoding'

/**
Expand All @@ -34,6 +32,7 @@ export interface OutputRootProof {
* Bedrock proof data required to finalize an L2 to L1 message.
*/
export interface BedrockCrossChainMessageProof {
l2OutputIndex: number
outputRootProof: OutputRootProof
withdrawalProof: string[]
}
Expand Down Expand Up @@ -65,10 +64,10 @@ export const hashCrossDomainMessage = (
gasLimit: BigNumber,
data: string
) => {
const [, version] = decodeVersionedNonce(nonce)
if (version.eq(big0)) {
const { version } = decodeVersionedNonce(nonce)
if (version.eq(0)) {
return hashCrossDomainMessagev0(target, sender, data, nonce)
} else if (version.eq(big1)) {
} else if (version.eq(1)) {
return hashCrossDomainMessagev1(
nonce,
sender,
Expand Down
Loading