Skip to content

Commit

Permalink
dtl: remove stringify from db logic + more overflow protection (#1010)
Browse files Browse the repository at this point in the history
* dtl: remove stringify from db logic

* l2geth: overflow protection

* dtl: overflow protection

* chore: add changeset
  • Loading branch information
tynes committed Jun 25, 2021
1 parent 87002d1 commit 2b855e2
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 34 deletions.
6 changes: 6 additions & 0 deletions .changeset/cold-ways-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@eth-optimism/l2geth': patch
'@eth-optimism/data-transport-layer': patch
---

Add extra overflow protection for the DTL types
4 changes: 2 additions & 2 deletions l2geth/rollup/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down
28 changes: 2 additions & 26 deletions packages/data-transport-layer/src/db/transport-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,38 +379,14 @@ export class TransportDB {
if (index === null) {
return null
}
let entry = await this.db.get<TEntry>(`${key}:index`, index)
entry = stringify(entry)
return entry
return this.db.get<TEntry>(`${key}:index`, index)
}

private async _getEntries<TEntry extends Indexed>(
key: string,
startIndex: number,
endIndex: number
): Promise<TEntry[] | []> {
const entries = await this.db.range<TEntry>(
`${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<TEntry>(`${key}:index`, startIndex, endIndex)
}
return entry
}
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
4 changes: 2 additions & 2 deletions packages/data-transport-layer/src/types/database-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export interface DecodedSequencerBatchTransaction {
}
value: string
gasLimit: string
gasPrice: number
nonce: number
gasPrice: string
nonce: string
target: string
data: string
}
Expand Down

0 comments on commit 2b855e2

Please sign in to comment.