Skip to content

Commit c05a0c6

Browse files
Fix precision on the calculation of the backlog cost and the l1 gas p… (#3777)
* Fix precision on the calculation of the backlog cost and the l1 gas price in the case of blobs * Avoid rounding issues and nil pointer in l1 gas price calculation * Update execution/gethexec/sequencer.go * Avoid duplicate calculations and solve rounding problem --------- Co-authored-by: Joshua Colvin <[email protected]>
1 parent 7c2c994 commit c05a0c6

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

execution/gethexec/sequencer.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,10 +1432,20 @@ func (s *Sequencer) updateExpectedSurplus(ctx context.Context) (int64, error) {
14321432
if err != nil {
14331433
return 0, fmt.Errorf("error encountered getting blob base fee while updating expectedSurplus: %w", err)
14341434
}
1435-
blobFeePerByte.Mul(blobFeePerByte, blobTxBlobGasPerBlob)
1436-
blobFeePerByte.Div(blobFeePerByte, usableBytesInBlob)
1437-
l1GasPrice = blobFeePerByte.Int64() / 16
1438-
backlogCost = (backlogCallDataUnits * blobFeePerByte.Int64()) / 16
1435+
1436+
if backlogCallDataUnits == 0 {
1437+
blobFeePerByte.Mul(blobFeePerByte, blobTxBlobGasPerBlob)
1438+
blobFeePerByte.Div(blobFeePerByte, usableBytesInBlob)
1439+
l1GasPrice = blobFeePerByte.Int64() / 16
1440+
backlogCost = 0
1441+
} else {
1442+
// l1GasPrice can be zero because of roundings, hence backlogCost is calculated separately
1443+
backlogFee := big.NewInt(backlogCallDataUnits)
1444+
backlogFee.Mul(backlogFee, blobTxBlobGasPerBlob)
1445+
backlogFee.Div(backlogFee, usableBytesInBlob)
1446+
backlogCost = backlogFee.Int64() / 16
1447+
l1GasPrice = backlogCost / backlogCallDataUnits
1448+
}
14391449
}
14401450
case "CalldataPrice7623":
14411451
l1GasPrice = (header.BaseFee.Int64() * 40) / 16

0 commit comments

Comments
 (0)