fees

package
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2021 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const TxGasPrice uint64 = feeScalar + (feeScalar / 2)

TxGasPrice is a constant that determines the result of `eth_gasPrice` It is scaled upwards by 50% tx.gasPrice is hard coded to 1500 * wei and all transactions must set that gas price.

Variables

View Source
var BigTenThousand = new(big.Int).SetUint64(tenThousand)
View Source
var BigTxGasPrice = new(big.Int).SetUint64(TxGasPrice)

BigTxGasPrice is the L2GasPrice as type big.Int

Functions

func Ceilmod

func Ceilmod(a, b *big.Int) *big.Int

func DecodeL2GasLimit

func DecodeL2GasLimit(gasLimit *big.Int) *big.Int

DecodeL2GasLimit decodes the L2 gas limit from an encoded L2 gas limit

func DecodeL2GasLimitU64

func DecodeL2GasLimitU64(gasLimit uint64) uint64

func EncodeTxGasLimit

func EncodeTxGasLimit(data []byte, l1GasPrice, l2GasLimit, l2GasPrice *big.Int) *big.Int

EncodeTxGasLimit computes the `tx.gasLimit` based on the L1/L2 gas prices and the L2 gas limit. The L2 gas limit is encoded inside of the lower order bits of the number like so: [ | l2GasLimit ]

[      tx.gaslimit      ]

The lower order bits must be large enough to fit the L2 gas limit, so 10**8 is chosen. If higher order bits collide with any bits from the L2 gas limit, the L2 gas limit will not be able to be decoded. An explicit design goal of this scheme was to make the L2 gas limit be human readable. The entire number is interpreted as the gas limit when computing the fee, so increasing the L2 Gas limit will increase the fee paid. The calculation is: l1GasLimit = zero_count(data) * 4 + non_zero_count(data) * 16 + overhead roundedL2GasLimit = ceilmod(l2GasLimit, 10_000) l1Fee = l1GasPrice * l1GasLimit l2Fee = l2GasPrice * roundedL2GasLimit sum = l1Fee + l2Fee scaled = sum / scalar rounded = ceilmod(scaled, tenThousand) roundedScaledL2GasLimit = roundedL2GasLimit / tenThousand result = rounded + roundedScaledL2GasLimit Note that for simplicity purposes, only the calldata is passed into this function when in reality the RLP encoded transaction should be. The additional cost is added to the overhead constant to prevent the need to RLP encode transactions during calls to `eth_estimateGas`

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL