Skip to content

Commit

Permalink
Avoid unnecessary memory allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
natebeauregard committed Oct 30, 2024
1 parent 3bd7e74 commit 96c7b54
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions x/rollup/tx/l1_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,19 @@ func getL1GasUsed(tx sdk.Tx) (*big.Int, error) {
return nil, fmt.Errorf("failed to rlp encode tx: %w", err)
}

const signatureCost = 68 * 16
const zeroCost = 4
const oneCost = 16
const signatureCost = 68 * 16
zeroCostBig := big.NewInt(zeroCost)
oneCostBig := big.NewInt(oneCost)

// l1GasUsed calculation: l1GasUsed = (zeroes * 4 + ones * 16) + signatureCost
l1GasUsed := big.NewInt(signatureCost)
for _, b := range txBz {
if b == 0 {
l1GasUsed.Add(l1GasUsed, big.NewInt(zeroCost))
l1GasUsed.Add(l1GasUsed, zeroCostBig)
} else {
l1GasUsed.Add(l1GasUsed, big.NewInt(oneCost))
l1GasUsed.Add(l1GasUsed, oneCostBig)
}
}

Expand Down

0 comments on commit 96c7b54

Please sign in to comment.