Zircuit
  • Introduction
  • Frequently Asked Questions (FAQ)
  • Tokenomics
    • Zircuit Token (ZRC)
    • Bridging ZRC to Zircuit
  • Build on Zircuit
    • Quick Start
    • Deploy on Zircuit
    • Zircuit LST/LRT Liquidity Hub
  • Architecture and Concepts
    • Architecture
      • Modular Prover Design
      • Template Proofs
      • Versions and Updates
    • Concepts
    • Sequencer Level Security (SLS)
    • Gas Pricing and Transaction Fees
    • Transaction Statuses
    • Supported Transaction Types
  • Research
    • Research
    • Publications and Grants
    • Talks and Panels
  • Dev Tools
    • Block Explorer
    • RPC Endpoints
    • Bridge
    • Verifying Contracts
    • ERC20 Tokens with Zircuit Canonical Bridge
    • Development Frameworks
    • CREATE2 Deployments
    • Oracles
    • Indexing and Subgraph
    • Relayers
    • Unsupported Opcodes
    • Precompiles
    • L1 Data Fee Calculation
  • Smart Contracts
    • L1 Contracts
    • L2 Contracts
    • Contract Addresses
    • Bridged Token Addresses
  • Security
    • Security
    • Privileged Roles
    • Bug Bounty
    • Audit Reports
  • Garfield Testnet
    • Garfield Testnet Quick Start
    • Garfield Testnet Bridging Prerequisites
      • Adding the Sepolia Network To Metamask
      • Adding The Zircuit Garfield Testnet Network To Metamask
      • Connecting Metamask To Zircuit’s Bridge
    • Deploy on the Zircuit Garfield Testnet
    • RPC Endpoints
    • Block Explorer
    • Verifying Contracts
    • Bridge
    • Faucet
    • Differences & Limitations
    • Contract Addresses
  • Testnet Legacy
    • Legacy Testnet Quick Start
    • Legacy Testnet Bridging Prerequisites
      • Adding The Sepolia Network To Metamask
      • Adding The Zircuit Legacy Testnet Network To Metamask
      • Connecting Metamask To Zircuit’s Bridge
    • Deploy on the Legacy Zircuit Testnet
    • RPC Endpoints
    • Block Explorer
    • Verifying Contracts
    • Bridge
    • Faucet
    • Contract Addresses
  • Bridging Step-by-Step
    • Prequisites
      • Adding The Zircuit Network To Metamask
    • Bridging From Sepolia To Zircuit
    • Bridging From Zircuit To Sepolia
    • Completing Withdrawals From Zircuit
    • Bridging ERC20 Tokens Manually
    • Binance Web3 Wallet Task Tutorial
      • Binance Web3 Wallet Tutorial: Bridging back to Ethereum
    • Exploring Bridging Behaviors with EIP-7702
Powered by GitBook
On this page
  1. Dev Tools

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 Garfield Testnet RPC urls on this page: RPC Endpoints.

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:

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

Get the raw RLP-encoded signed transaction:

cast tx $TX_HASH --rpc-url $RPC_URL --raw

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.

#!/usr/bin/env bash

# Usage: ./count_zero_bytes_hex.sh <hex string>
# Example: ./count_zero_bytes_hex.sh 00A1FF0033

hex="$1"

# Ensure we got a parameter
if [ -z "$hex" ]; then
  echo "Usage: $0 <hex string>"
  exit 1
fi

# Normalize to uppercase to keep comparison simple
hex_upper=$(echo "$hex" | tr '[:lower:]' '[:upper:]')

# The hex string length must be an even number for whole bytes (2 hex chars = 1 byte)
len=${#hex_upper}
if (( len % 2 != 0 )); then
  echo "Error: Hex string must have an even number of characters."
  exit 1
fi

zero_bytes=0
other_bytes=0

# Process two hex characters at a time
for ((i=0; i<len; i+=2)); do
  byte="${hex_upper:$i:2}"  # Extract 2-hex-character chunk

  if [ "$byte" == "00" ]; then
    ((zero_bytes++))
  else
    ((other_bytes++))
  fi
done

echo "Hex string:  $hex"
echo "Zero bytes:  $zero_bytes"
echo "Other bytes: $other_bytes"

In the Gas Pricing and 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:

(calldataGas/16)*(l1BaseFee*16*l1BaseFeeScalar + l1BlobBaseFee*l1BlobBaseFeeScalar)/1e6

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

calldataGas*(l1BaseFee*16*l1BaseFeeScalar + l1BlobBaseFee*l1BlobBaseFeeScalar)/16e6

PreviousPrecompilesNextL1 Contracts

Last updated 2 months ago