Skip to content

Commit

Permalink
feat(sdk): support legacy withdraws after Bedrock (#4119)
Browse files Browse the repository at this point in the history
Adds support for finalizing legacy withdrawals after the Bedrock
migration. Cleans up some SDK code at the same time.
  • Loading branch information
smartcontracts committed Dec 1, 2022
1 parent 6a1abd2 commit c975c96
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 157 deletions.
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
2 changes: 1 addition & 1 deletion packages/contracts-bedrock/scripts/differential-testing.ts
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

0 comments on commit c975c96

Please sign in to comment.