L1 Data Fee Calculation

This page describes how to calculate the L1 data fee for a specific transaction on a Zircuit network.

Retrieve the parameters

To perform the calculation the following parameters are needed:

  • L1 base fee

  • L1 base fee scalar

  • L1 blob base fee

  • L1 blob base fee scalar

They are available by calling the Gas Price Oracle smart contract predeployed on every Zircuit network on this address: 0x420000000000000000000000000000000000000F

To retrieve them we can use Foundry's cast. You will need the block number in which the transaction was included to retrieve the parameters from the right point in time. You will also need a valid RPC url. For example you'll find the RPC urls on this page:

RPCs

L1 base fee:

cast call 0x420000000000000000000000000000000000000F "l1BaseFee()(uint256)" --rpc-url $RPC_URL --block $BLOCK_NUMBER

L1 base fee scalar:

cast call 0x420000000000000000000000000000000000000F "baseFeeScalar()(uint256)" --rpc-url $RPC_URL --block $BLOCK_NUMBER

L1 blob base fee:

cast call 0x420000000000000000000000000000000000000F "blobBaseFee()(uint256)" --rpc-url $RPC_URL --block $BLOCK_NUMBER

L1 blob base fee scalar:

Get the raw RLP-encoded signed transaction:

Zero-bytes and non zero-bytes are accounted differently, so the next step is to count all the zero bytes and all the non-zero bytes in the tx. Here is a shell script that does it. Remember to remove the "0x" at the beginning when you provide it the raw tx.

In the Gas Pricing & Transaction Fees it's specified the cost of zero bytes is 4 and the cost of non-zero bytes is 16. So your calldatagas will be zero-bytes*4 + non-zero-bytes*16.

Now that you have all the info you need, you can just apply the following formula:

That is equivalent to the following formula better fitted for precision under integer arithmetic:

Last updated

Was this helpful?