Transaction Calculation
The math behind gas fee calculation on the VeChainThor blockchain.
What is gas?
Blockchain networks often refer to transaction fees as gas. Gas refers to the unit that measures the amount of computation effort required to execute operations on the blockchain network. This is a fee that is paid by the transaction sender and received by the blockchain network validator.
Intrinsic Gas Calculation
The VeChainThor blockchain transaction model is capable of containing clauses which allows a single transaction to carry out multiple tasks. Therefore, the total gas cost of the transaction needs to include all the clauses gas costs in the transaction.
The total gas, , required for a transaction can be computed as:
where
There are two types of
Regular transaction : 16,000
Contract creation : 48,000
is the number of bytes equal to zero within the data in the clause and the number of bytes not equal to zero
is the gas cost returned by the virtual machine for executing the clause.
Transaction Types
With the introduction of typed transactions, see VIP-252, the VeChainThor blockchain has become more extensible and forward compatible by enabling support for the introduction of new transaction types while ensuring backward compatibility with existing transactions. Currently there are two types of transaction on the VeChainThor blockchain. Transactions with a starting byte in the range [0x7f
, 0xfe
] are considered legacy transactions, which use the transaction format that existed before typed transactions. Dynamic fee transactions with a type 0x51
are dynamic fee transactions that are introduced with VIP-251. Both transactions has separate pricing mechanisms.
Dynamic Fee Transactions
The dynamic fee transaction introduces a fluctuating base fee that is burned and a user-set priority fee that is paid directly to the proposer. This transaction model enhances network security and user experience by transitioning from a fixed-fee model to a dynamic fee model, adjusting fees based on network congestion.
Dynamic Fee Transactions don't specify gasPrice
and instead use an in-protocol dynamically changing baseFee
per gas. At each block, the base fee per gas is adjusted to address network congestion as measured by a gas target, see VIP-251 for more details. Dynamic Fee Transactions include a maxPriorityFeePerGas
which specifies the maximum fee that a user is willing to pay per gas above the base fee in order to get their transaction prioritized; and a maxFeePerGas
which specifies the absolute maximum a user is willing to pay per unit of gas, this is the sum of the baseFee
and the maxPriorityFeePerGas
.
A Dynamic Fee Transaction always pays the base fee of the block it's included in, and it pays a priority fee as priced by maxPriorityFeePerGas
or if the base fee per gas plus maxPriorityFeePerGas
exceeds maxFeePerGas
it pays a priority fee as priced by maxFeePerGas
minus the base fee per gas. Any unused portion is returned to the user. The base fee is burned, and the priority fee is paid to the miner that included the transaction. A transaction's priority fee per gas incentivizes validators to include the transaction over other transactions with lower priority fees per gas.
Legacy Transactions
The legacy transaction model uses a fixed-fee model where the user sets a gasPrice
that they are willing to pay. Transactions with a type [0xc0
, 0xfe
] are legacy transactions that use the transaction format that existed before typed transactions were introduced with VIP-252.
Proof of Work
The VeChainThor blockchain allows for transaction-level proof of work (PoW) on legacy transactions and converts the proved work into extra gas price that will be used by the system to generate more reward to the block generator, the Authority Masternode, that validates the transaction. In other words, users can utilize their local computational power to make their transactions more likely to be included in a new block.
In particular, the computational work can be proved through fields Nonce
and BlockRef
in the transaction model. Let and represent the values of the transaction fields Nonce
and Gas
, respectively. We use to denote the number of the block indexed by transaction field BlockRef
and the number of the block that includes the transaction. Let denote the transaction without fields Nonce
and Signature
, the transaction sender's account address, the base gas price, the hash function and the recursive length prefix (RLP) encoding function.
The PoW, , is defined as:
The extra gas price, , is computed as:
with the following constraint
The VTHO reward for packing the transaction into a new block is computed as:
where is the gas price coefficient and the actual amount of gas used for executing the transaction.
From the above equations, we know that
Since is a valid block number,
BlockRef
must refer to an existing block, that is, it's value must equal the first four bytes of an existing block ID;The transaction must be packed into a block within the period of 30 blocks after block , or otherwise, the PoW would not be recognized by the system;
The extra gas price can not be greater than base gas price P.
Total Gas Price
The total gas price for the a legacy transaction sender is computed as:
and the total price for block generators as
Where is the gas used by the transaction and is the value of field GasPriceCoef
(a value between 0-255) and the extra gas price converted from the proven local computational work.
It can be seen that the gas price used to calculate the transaction cost depends solely on the input gas-price coefficient while the reward for packing the transaction into a block varies due to the transaction-level proof-of-work mechanism.
Last updated
Was this helpful?