Skip to content
This repository has been archived by the owner on Dec 5, 2021. It is now read-only.

Commit

Permalink
fix[dtl]: fix dtl bug breaking verifiers (ethereum-optimism#1011)
Browse files Browse the repository at this point in the history
* fix[dtl]: fix dtl bug breaking verifiers

* tweaks so tests pass

* chore: add changeset
  • Loading branch information
smartcontracts committed Jun 7, 2021
1 parent e3dc90c commit a75f05b
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/quick-pandas-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/data-transport-layer': patch
---

Fixes a bug that prevented verifiers from syncing properly with the DTL
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import {
SEQUENCER_ENTRYPOINT_ADDRESS,
SEQUENCER_GAS_LIMIT,
parseSignatureVParam,
} from '../../../utils'

export const handleEventsSequencerBatchAppended: EventHandlerSet<
Expand Down Expand Up @@ -76,7 +77,7 @@ export const handleEventsSequencerBatchAppended: EventHandlerSet<
batchExtraData: batchSubmissionEvent.args._extraData,
}
},
parseEvent: (event, extraData) => {
parseEvent: (event, extraData, l2ChainId) => {
const transactionEntries: TransactionEntry[] = []

// It's easier to deal with this data if it's a Buffer.
Expand All @@ -103,7 +104,8 @@ export const handleEventsSequencerBatchAppended: EventHandlerSet<
)

const decoded = maybeDecodeSequencerBatchTransaction(
sequencerTransaction
sequencerTransaction,
l2ChainId
)

transactionEntries.push({
Expand Down Expand Up @@ -234,7 +236,8 @@ const parseSequencerBatchTransaction = (
}

const maybeDecodeSequencerBatchTransaction = (
transaction: Buffer
transaction: Buffer,
l2ChainId: number
): DecodedSequencerBatchTransaction | null => {
try {
const decodedTx = ethers.utils.parseTransaction(transaction)
Expand All @@ -247,7 +250,7 @@ const maybeDecodeSequencerBatchTransaction = (
target: toHexString(decodedTx.to), // Maybe null this out for creations?
data: toHexString(decodedTx.data),
sig: {
v: BigNumber.from(decodedTx.v).toNumber(),
v: parseSignatureVParam(decodedTx.v, l2ChainId),
r: toHexString(decodedTx.r),
s: toHexString(decodedTx.s),
},
Expand Down
13 changes: 11 additions & 2 deletions packages/data-transport-layer/src/services/l1-ingestion/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { fromHexString, EventArgsAddressSet } from '@eth-optimism/core-utils'
import { BaseService } from '@eth-optimism/common-ts'
import { JsonRpcProvider } from '@ethersproject/providers'
import { LevelUp } from 'levelup'
import { ethers, constants } from 'ethers'

/* Imports: Internal */
import { TransportDB } from '../../db/transport-db'
Expand All @@ -18,7 +19,6 @@ import { handleEventsTransactionEnqueued } from './handlers/transaction-enqueued
import { handleEventsSequencerBatchAppended } from './handlers/sequencer-batch-appended'
import { handleEventsStateBatchAppended } from './handlers/state-batch-appended'
import { L1DataTransportServiceOptions } from '../main/service'
import { constants } from 'ethers'

export interface L1IngestionServiceOptions
extends L1DataTransportServiceOptions {
Expand Down Expand Up @@ -65,6 +65,7 @@ export class L1IngestionService extends BaseService<L1IngestionServiceOptions> {
contracts: OptimismContracts
l1RpcProvider: JsonRpcProvider
startingL1BlockNumber: number
l2ChainId: number
} = {} as any

protected async _init(): Promise<void> {
Expand Down Expand Up @@ -114,6 +115,10 @@ export class L1IngestionService extends BaseService<L1IngestionServiceOptions> {
this.options.addressManager
)

this.state.l2ChainId = ethers.BigNumber.from(
await this.state.contracts.OVM_ExecutionManager.ovmCHAINID()
).toNumber()

const startingL1BlockNumber = await this.state.db.getStartingL1Block()
if (startingL1BlockNumber) {
this.state.startingL1BlockNumber = startingL1BlockNumber
Expand Down Expand Up @@ -295,7 +300,11 @@ export class L1IngestionService extends BaseService<L1IngestionServiceOptions> {
event,
this.state.l1RpcProvider
)
const parsedEvent = await handlers.parseEvent(event, extraData)
const parsedEvent = await handlers.parseEvent(
event,
extraData,
this.state.l2ChainId
)
await handlers.storeEvent(parsedEvent, this.state.db)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
padHexString,
SEQUENCER_ENTRYPOINT_ADDRESS,
SEQUENCER_GAS_LIMIT,
parseSignatureVParam,
} from '../../../utils'

export const handleSequencerBlock = {
Expand Down Expand Up @@ -43,7 +44,7 @@ export const handleSequencerBlock = {
if (transaction.queueOrigin === 'sequencer') {
const decodedTransaction: DecodedSequencerBatchTransaction = {
sig: {
v: BigNumber.from(transaction.v).toNumber() - 2 * chainId - 35,
v: parseSignatureVParam(transaction.v, chainId),
r: padHexString(transaction.r, 32),
s: padHexString(transaction.s, 32),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export type GetExtraDataHandler<TEventArgs, TExtraData> = (

export type ParseEventHandler<TEventArgs, TExtraData, TParsedEvent> = (
event: TypedEthersEvent<TEventArgs>,
extraData: TExtraData
extraData: TExtraData,
l2ChainId: number
) => TParsedEvent

export type StoreEventHandler<TParsedEvent> = (
Expand Down
9 changes: 9 additions & 0 deletions packages/data-transport-layer/src/utils/eth-tx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* Imports: External */
import { ethers } from 'ethers'

export const parseSignatureVParam = (
v: number | ethers.BigNumber,
chainId: number
): number => {
return ethers.BigNumber.from(v).toNumber() - 2 * chainId - 35
}
1 change: 1 addition & 0 deletions packages/data-transport-layer/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './common'
export * from './constants'
export * from './contracts'
export * from './validation'
export * from './eth-tx'
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { BigNumber, ethers } from 'ethers'

/* Imports: Internal */
import { expect } from '../../../../setup'
import { handleEventsSequencerBatchAppended } from '../../../../../src/services/l1-ingestion/handlers/sequencer-batch-appended'
import { SequencerBatchAppendedExtraData } from '../../../../../src/types'
import { l1TransactionData } from '../../../examples/l1-data'
import { blocksOnL2 } from '../../../examples/l2-data'

describe('Event Handlers: OVM_CanonicalTransactionChain.SequencerBatchAppended', () => {
describe('handleEventsSequencerBatchAppended.parseEvent', () => {
Expand All @@ -28,7 +28,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.SequencerBatchAppended',
}

it('should error on malformed transaction data', async () => {
const input1: [any, SequencerBatchAppendedExtraData] = [
const input1: [any, SequencerBatchAppendedExtraData, number] = [
{
args: {
_startingQueueIndex: ethers.constants.Zero,
Expand All @@ -40,6 +40,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.SequencerBatchAppended',
l1TransactionData: '0x00000',
...exampleExtraData,
},
0,
]

expect(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { expect } from '../../../../setup'

/* Imports: External */
import { BigNumber } from 'ethers'
import { Block } from '@ethersproject/abstract-provider'

import { expect } from '../../../../setup'
/* Imports: Internal */
import { handleEventsStateBatchAppended } from '../../../../../src/services/l1-ingestion/handlers/state-batch-appended'
import { StateBatchAppendedExtraData } from '../../../../../src/types'
import { l1StateBatchData } from '../../../examples/l1-data'
Expand Down Expand Up @@ -73,7 +76,11 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.StateBatchAppended', ()
l1TransactionHash:
'0x4ca72484e93cdb50fe1089984db152258c2bbffc2534dcafbfe032b596bd5b49',
}
const input1: [any, StateBatchAppendedExtraData] = [event, extraData]
const input1: [any, StateBatchAppendedExtraData, number] = [
event,
extraData,
0,
]

const output1 = handleEventsStateBatchAppended.parseEvent(...input1)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { expect } from '../../../../setup'

/* Imports: External */
import { ethers, BigNumber } from 'ethers'

import { expect } from '../../../../setup'
/* Imports: Internal */
import { handleEventsTransactionEnqueued } from '../../../../../src/services/l1-ingestion/handlers/transaction-enqueued'

const MAX_ITERATIONS = 128
Expand All @@ -22,7 +25,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', ()
// but it's probably better to get wider test coverage first.

it('should have a ctcIndex equal to null', () => {
const input1: [any, any] = [
const input1: [any, any, number] = [
{
blockNumber: 0,
args: {
Expand All @@ -32,6 +35,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', ()
},
},
null,
0,
]

const output1 = handleEventsTransactionEnqueued.parseEvent(...input1)
Expand All @@ -47,7 +51,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', ()
i < Number.MAX_SAFE_INTEGER;
i += Math.floor(Number.MAX_SAFE_INTEGER / MAX_ITERATIONS)
) {
const input1: [any, any] = [
const input1: [any, any, number] = [
{
blockNumber: i,
args: {
Expand All @@ -57,6 +61,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', ()
},
},
null,
0,
]

const output1 = handleEventsTransactionEnqueued.parseEvent(...input1)
Expand All @@ -73,7 +78,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', ()
i < Number.MAX_SAFE_INTEGER;
i += Math.floor(Number.MAX_SAFE_INTEGER / MAX_ITERATIONS)
) {
const input1: [any, any] = [
const input1: [any, any, number] = [
{
blockNumber: 0,
args: {
Expand All @@ -83,6 +88,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', ()
},
},
null,
0,
]

const output1 = handleEventsTransactionEnqueued.parseEvent(...input1)
Expand All @@ -99,7 +105,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', ()
i < Number.MAX_SAFE_INTEGER;
i += Math.floor(Number.MAX_SAFE_INTEGER / MAX_ITERATIONS)
) {
const input1: [any, any] = [
const input1: [any, any, number] = [
{
blockNumber: 0,
args: {
Expand All @@ -109,6 +115,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', ()
},
},
null,
0,
]

const output1 = handleEventsTransactionEnqueued.parseEvent(...input1)
Expand All @@ -125,7 +132,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', ()
i < Number.MAX_SAFE_INTEGER;
i += Math.floor(Number.MAX_SAFE_INTEGER / MAX_ITERATIONS)
) {
const input1: [any, any] = [
const input1: [any, any, number] = [
{
blockNumber: 0,
args: {
Expand All @@ -135,6 +142,7 @@ describe('Event Handlers: OVM_CanonicalTransactionChain.TransactionEnqueued', ()
},
},
null,
0,
]

const output1 = handleEventsTransactionEnqueued.parseEvent(...input1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { expect } from '../../../../setup'

/* Imports: Internal */
import { l2Block } from '../../../examples/l2-data'
import { handleSequencerBlock } from '../../../../../src/services/l2-ingestion/handlers/transaction'

Expand Down

0 comments on commit a75f05b

Please sign in to comment.