Skip to content

Commit

Permalink
Merge pull request #307 from pimlicolabs/fix/arbitrum-divide-by-zero
Browse files Browse the repository at this point in the history
  • Loading branch information
mouseless-eth authored Oct 1, 2024
2 parents 0bde900 + 7d58634 commit b092766
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/handlers/gasPriceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class ArbitrumManager {
}

public saveL1BaseFee(baseFee: bigint) {
if (baseFee === 0n) {
return
}

const queue = this.queueL1BaseFee
const last = queue.length > 0 ? queue[queue.length - 1] : null
const timestamp = Date.now()
Expand All @@ -66,6 +70,10 @@ class ArbitrumManager {
}

public saveL2BaseFee(baseFee: bigint) {
if (baseFee === 0n) {
return
}

const queue = this.queueL2BaseFee
const last = queue.length > 0 ? queue[queue.length - 1] : null
const timestamp = Date.now()
Expand Down Expand Up @@ -93,6 +101,19 @@ class ArbitrumManager {
)
}

public async getMaxL1BaseFee() {
const queue = this.queueL1BaseFee

if (queue.length === 0) {
return maxUint128
}

return queue.reduce(
(acc: bigint, cur) => maxBigInt(cur.baseFee, acc),
queue[0].baseFee
)
}

public async getMaxL2BaseFee() {
const queue = this.queueL2BaseFee

Expand Down
5 changes: 5 additions & 0 deletions src/utils/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,11 @@ export async function calcArbitrumPreVerificationGas(
gasPriceManager.arbitrumManager.saveL2BaseFee(l2BaseFee)

if (validate) {
if (l1BaseFeeEstimate === 0n) {
l1BaseFeeEstimate =
await gasPriceManager.arbitrumManager.getMaxL1BaseFee()
}

// gasEstimateL1Component source: https://github.com/OffchainLabs/nitro/blob/5cd7d6913eb6b4dedb08f6ea49d7f9802d2cc5b9/execution/nodeInterface/NodeInterface.go#L515-L551
const feesForL1 = (gasForL1 * l2BaseFee) / l1BaseFeeEstimate

Expand Down

0 comments on commit b092766

Please sign in to comment.