From 2b855e2131609a8b42ff795f647a918cfe7967df Mon Sep 17 00:00:00 2001 From: Mark Tyneway Date: Thu, 3 Jun 2021 15:50:29 -0700 Subject: [PATCH] dtl: remove stringify from db logic + more overflow protection (#1010) * dtl: remove stringify from db logic * l2geth: overflow protection * dtl: overflow protection * chore: add changeset --- .changeset/cold-ways-grow.md | 6 ++++ l2geth/rollup/client.go | 4 +-- .../src/db/transport-db.ts | 28 ++----------------- .../handlers/sequencer-batch-appended.ts | 4 +-- .../l2-ingestion/handlers/transaction.ts | 4 +-- .../src/types/database-types.ts | 4 +-- 6 files changed, 16 insertions(+), 34 deletions(-) create mode 100644 .changeset/cold-ways-grow.md diff --git a/.changeset/cold-ways-grow.md b/.changeset/cold-ways-grow.md new file mode 100644 index 000000000000..a79702ddfa1e --- /dev/null +++ b/.changeset/cold-ways-grow.md @@ -0,0 +1,6 @@ +--- +'@eth-optimism/l2geth': patch +'@eth-optimism/data-transport-layer': patch +--- + +Add extra overflow protection for the DTL types diff --git a/l2geth/rollup/client.go b/l2geth/rollup/client.go index 5f8cd3edd12b..8a5e0530ed8d 100644 --- a/l2geth/rollup/client.go +++ b/l2geth/rollup/client.go @@ -104,8 +104,8 @@ type decoded struct { Signature signature `json:"sig"` Value hexutil.Uint64 `json:"value"` GasLimit uint64 `json:"gasLimit,string"` - GasPrice uint64 `json:"gasPrice"` - Nonce uint64 `json:"nonce"` + GasPrice uint64 `json:"gasPrice,string"` + Nonce uint64 `json:"nonce,string"` Target *common.Address `json:"target"` Data hexutil.Bytes `json:"data"` } diff --git a/packages/data-transport-layer/src/db/transport-db.ts b/packages/data-transport-layer/src/db/transport-db.ts index ab98254bb06e..c1c50c4eac53 100644 --- a/packages/data-transport-layer/src/db/transport-db.ts +++ b/packages/data-transport-layer/src/db/transport-db.ts @@ -379,9 +379,7 @@ export class TransportDB { if (index === null) { return null } - let entry = await this.db.get(`${key}:index`, index) - entry = stringify(entry) - return entry + return this.db.get(`${key}:index`, index) } private async _getEntries( @@ -389,28 +387,6 @@ export class TransportDB { startIndex: number, endIndex: number ): Promise { - const entries = await this.db.range( - `${key}:index`, - startIndex, - endIndex - ) - const results = [] - for (const entry of entries) { - results.push(stringify(entry)) - } - return results - } -} - -const stringify = (entry) => { - if (entry === null || entry === undefined) { - return entry - } - if (entry.gasLimit) { - entry.gasLimit = BigNumber.from(entry.gasLimit).toString() - } - if (entry.decoded) { - entry.decoded.gasLimit = BigNumber.from(entry.decoded.gasLimit).toString() + return this.db.range(`${key}:index`, startIndex, endIndex) } - return entry } diff --git a/packages/data-transport-layer/src/services/l1-ingestion/handlers/sequencer-batch-appended.ts b/packages/data-transport-layer/src/services/l1-ingestion/handlers/sequencer-batch-appended.ts index 76cb9050b6c0..d2b2ebc3579b 100644 --- a/packages/data-transport-layer/src/services/l1-ingestion/handlers/sequencer-batch-appended.ts +++ b/packages/data-transport-layer/src/services/l1-ingestion/handlers/sequencer-batch-appended.ts @@ -257,8 +257,8 @@ const maybeDecodeSequencerBatchTransaction = ( const decodedTx = ethers.utils.parseTransaction(transaction) return { - nonce: BigNumber.from(decodedTx.nonce).toNumber(), - gasPrice: BigNumber.from(decodedTx.gasPrice).toNumber(), + nonce: BigNumber.from(decodedTx.nonce).toString(), + gasPrice: BigNumber.from(decodedTx.gasPrice).toString(), gasLimit: BigNumber.from(decodedTx.gasLimit).toString(), value: toRpcHexString(decodedTx.value), target: toHexString(decodedTx.to), // Maybe null this out for creations? diff --git a/packages/data-transport-layer/src/services/l2-ingestion/handlers/transaction.ts b/packages/data-transport-layer/src/services/l2-ingestion/handlers/transaction.ts index 0c2bb410b1cd..bc69cba8b175 100644 --- a/packages/data-transport-layer/src/services/l2-ingestion/handlers/transaction.ts +++ b/packages/data-transport-layer/src/services/l2-ingestion/handlers/transaction.ts @@ -50,8 +50,8 @@ export const handleSequencerBlock = { }, value: transaction.value, gasLimit: BigNumber.from(transaction.gas).toString(), - gasPrice: BigNumber.from(transaction.gasPrice).toNumber(), // ? - nonce: BigNumber.from(transaction.nonce).toNumber(), + gasPrice: BigNumber.from(transaction.gasPrice).toString(), + nonce: BigNumber.from(transaction.nonce).toString(), target: transaction.to, data: transaction.input, } diff --git a/packages/data-transport-layer/src/types/database-types.ts b/packages/data-transport-layer/src/types/database-types.ts index 470b402c3590..3ad73da3e4f7 100644 --- a/packages/data-transport-layer/src/types/database-types.ts +++ b/packages/data-transport-layer/src/types/database-types.ts @@ -6,8 +6,8 @@ export interface DecodedSequencerBatchTransaction { } value: string gasLimit: string - gasPrice: number - nonce: number + gasPrice: string + nonce: string target: string data: string }