> ## Documentation Index
> Fetch the complete documentation index at: https://docs-hosting.axiomesh.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Gas and Fees

To prevent Distributed Denial of Service (DDoS) attacks, all transactions that change the blockchain's ledger state (non-read-only) require a certain amount of Gas to be consumed. The calculation method of Gas fee on `AxiomLedger` is similar to Ethereum's.

## Basic Description

Gas is a common mechanism in blockchains. The original intention of Gas is to prevent users from DDoS attacks on the blockchain system. The Gas model is similar to cloud computing, except that cloud computing charges by time
units, while Gas charges based on the computational resources consumed:

$\text{Gas Fee}=\text{Gas Used} \times \text{Gas Price}$

where `Gas Fee` is the total cost that a user need to pay for the transaction, `Gas Used` is the computational resources
consumed during execution, `Gas Price` is the price per Gas unit.

## Gas Limit

Some smart contracts may have infinite loop by accident. To prevent costing too much Gas, users can set Gas limit manually,
otherwise `AxiomLedger` will automatically  set Gas limit to $10^8$.

<Warning> Please note: Manually setting Gas limit over $10^8$ will be ignored.</Warning>

## Dynamic Gas Price

In our system, Gas can not only prevent DDoS attacks, but also dynamically adjust for network conditions. We call this
model the dynamic Gas price model.

The dynamic algorithm is as follows:

<img src="https://mintcdn.com/axiomesh/YSDcEa2uhMBY3fPk/en/images/dynamic_gas_price.png?fit=max&auto=format&n=YSDcEa2uhMBY3fPk&q=85&s=c7a77386afcd728748b84f07d357e072" alt="dynamic_gas_price" width="1862" height="542" data-path="en/images/dynamic_gas_price.png" />

The basic idea of this algorithm is that the Gas price in the current block will change based on the situation of the parent block. Specifically, it will linearly fluctuate based on the proportion of transactions packed in the parent block to the maximum allowed number of transactions in the block, with a maximum fluctuation of 12.5%.

## Gas Price Bound

To keep the Gas price fluctuating within a reasonable range, we have set upper and lower bounds for the Gas price. In
testnet, the upper bound is 10000 `GMol`, and the lower bound is 1000 `GMol`.

As for initial state, Gas price is set to 5000 `GMol`.
