-
Notifications
You must be signed in to change notification settings - Fork 6
HPB Gas Mechanism
Introduction: This document is based on version hpb-1.0.2.3. Since it involves transaction cost when it comes to transfer transaction and smart contract calculation, this article mainly introduces HPB Gas mechanism.
First 1 HPB = 1,000,000,000,000,000,000 Wei i.e. 1^18, 1 Gwei = 1,000,000,000 Wei. Transaction cost = Gas * Gas Price.
Unit | Wei | Kwei | babbage | femtohpb | mwei | lovelace | picohpb |
---|---|---|---|---|---|---|---|
Wei | 1 | 103 | 103 | 103 | 106 | 106 | 106 |
Unit | gwei | shannon | nanohpb | nano | szabo | microhpb | micro |
Wei | 109 | 109 | 109 | 109 | 1012 | 1012 | 1012 |
Unit | finney | millihpb | milli | hpb | khpb | grand | mhpb |
Wei | 1015 | 1015 | 1015 | 1018 | 1021 | 1021 | 1024 |
Unit | ghpb | thpb | phpb | ehpb | zhpb | yhpb | nhpb |
Wei | 1027 | 1030 | 1033 | 1036 | 1039 | 1042 | 1045 |
Unit | dhpb | vhpb | uhpb | ||||
Wei | 1048 | 1051 | 1054 |
In HPB main network, transaction cost for ordinary transaction and smart contract transaction is not the same. Generally speaking, in HPB ordinary transaction, the default Gas Units = 10. Gas price varies according to the competition among all HPB nodes and its default value in source code of this version is greater than 1Wei. In reality, the experience value is defined as Gas Price = 18Gwei.
Basic cost: Default Gas Units = 53000.
Data cost: The data field in the transaction, 1 per byte
Contract pre-compilation cost: The result is returned based on pre-compiled function. When the pre-compiled function evaluates, different instruction sets collect Gas in different ways. Simple instructions (such as Add, MUL, AND, OR, etc.) collect fixed Gas while complex instructions (such as memory operations MLOAD, SLOAD) collect based on used memory.
Basic cost: Default Gas Units = 10.
Data cost: The data field in the transaction, 1 per byte
Contract pre-compilation cost: The Gas calculation method is different depending on different types of smart contract called. Please refer to HPB source code as follow:
// Precompiled contract gas prices
EcrecoverGas uint64 = 3000 // Elliptic curve sender recovery gas price
Sha256BaseGas uint64 = 60 // Base price for a SHA256 operation
Sha256PerWordGas uint64 = 12 // Per-word price for a SHA256 operation
Ripemd160BaseGas uint64 = 600 // Base price for a RIPEMD160 operation
Ripemd160PerWordGas uint64 = 120 // Per-word price for a RIPEMD160 operation
IdentityBaseGas uint64 = 15 // Base price for a data copy operation
IdentityPerWordGas uint64 = 3 // Per-work price for a data copy operation
ModExpQuadCoeffDiv uint64 = 20 // Divisor for the quadratic particle of the big int modular exponentiation
Bn256AddGas uint64 = 500 // Gas needed for an elliptic curve addition
Bn256ScalarMulGas uint64 = 40000 // Gas needed for an elliptic curve scalar multiplication
Bn256PairingBaseGas uint64 = 100000 // Base price for an elliptic curve pairing check
Bn256PairingPerPointGas uint64 = 80000 // Per-point price for an elliptic curve pairing check
const (
MaximumExtraDataSize uint64 = 32 // Maximum size extra data may be after Genesis.
ExpByteGas uint64 = 10 // Times ceil(log256(exponent)) for the EXP instruction.
SloadGas uint64 = 50 // Multiplied by the number of 32-byte words that are copied (round up) for any *COPY operation and added.
CallValueTransferGas uint64 = 9000 // Paid for CALL when the value transfer is non-zero.
CallNewAccountGas uint64 = 25000 // Paid for CALL when the destination address didn't exist prior.
TxGas uint64 = 10 // Per transaction not creating a contract. NOTE: Not payable on data of calls between transactions. //for testnet
TxGasContractCreation uint64 = 53000 // Per transaction that creates a contract. NOTE: Not payable on data of calls between transactions.
TxDataZeroGas uint64 = 1 // Per byte of data attached to a transaction that equals zero. NOTE: Not payable on data of calls between transactions. //for testnet
QuadCoeffDiv uint64 = 512 // Divisor for the quadratic particle of the memory cost equation.
SstoreSetGas uint64 = 20000 // Once per SLOAD operation.
LogDataGas uint64 = 8 // Per byte in a LOG* operation's data.
CallStipend uint64 = 2300 // Free gas given at beginning of call.
Sha3Gas uint64 = 30 // Once per SHA3 operation.
Sha3WordGas uint64 = 6 // Once per word of the SHA3 operation's data.
SstoreResetGas uint64 = 5000 // Once per SSTORE operation if the zeroness changes from zero.
SstoreClearGas uint64 = 5000 // Once per SSTORE operation if the zeroness doesn't change.
SstoreRefundGas uint64 = 15000 // Once per SSTORE operation if the zeroness changes to zero.
JumpdestGas uint64 = 1 // Refunded gas, once per SSTORE operation if the zeroness changes to zero.
EpochDuration uint64 = 30000 // Duration between proof-of-work epochs.
CallGas uint64 = 40 // Once per CALL operation & message call transaction.
CreateDataGas uint64 = 200 //
CallCreateDepth uint64 = 1024 // Maximum depth of call/create stack.
ExpGas uint64 = 10 // Once per EXP instruction
LogGas uint64 = 375 // Per LOG* operation.
CopyGas uint64 = 3 //
StackLimit uint64 = 1024 // Maximum size of VM stack allowed.
TierStepGas uint64 = 0 // Once per operation, for a selection of them.
LogTopicGas uint64 = 375 // Multiplied by the * of the LOG*, per LOG transaction. e.g. LOG0 incurs 0 * c_txLogTopicGas, LOG4 incurs 4 * c_txLogTopicGas.
CreateGas uint64 = 32000 // Once per CREATE operation & contract-creation transaction.
SuicideRefundGas uint64 = 24000 // Refunded following a suicide operation.
MemoryGas uint64 = 3 // Times the address of the (highest referenced byte in memory + 1). NOTE: referencing happens on read, write and in instructions such as RETURN and CALL.
TxDataNonZeroGas uint64 = 1 // Per byte of data attached to a transaction that is not equal to zero. NOTE: Not payable on data of calls between transactions. //for testnet
MaxCodeSize = 24576 // Maximum bytecode to permit for a contract
In our common ETH wallet, Gas Price will be adjusted at different stages. Generally speaking, the wallet is set for users according to the network conditions. HPB Wallet also helps users set Gas Price by default. The default value of source code in this version is greater than 1Wei and the current experience value is 18Gwei. The same applies to Gas Price of HPB smart contract and the current Gas Price operating in smart contract is 18Gwei.
Q1: How to calculate Gas?
A1: Please refer to the calculation method in the above form.
Q2: How much does one transaction cost?
A2: First, it is necessary to determine which kind of transaction it belongs to: ordinary or smart contract. Then calculate according to the Gas in the above form, transaction cost = Gas * Gas Price. For example, Gas in ordinary transaction is a fixed value of 10 without the maximum or minimum one. Please also refer to the table above for smart contract transactions. Each transaction has a minimum Gas requirement. In addition, transaction costs can be set manually. If users wants to make faster transactions, the parameter Gas Price value can be adjusted.
Q3: How much Gas does ordinary transaction cost?
A3: Gas for ordinary transaction is a fixed value of 10.
Q4: How much Gas does smart contract transaction cost? A4: There is no upper limit for Gas in smart contracts.
Q5: Is it necessary to purchase HPB token so as to build on HPB main network when making Dapp?
A5: Yes
Q6: Does Dapp need to lock HPB Token?
A6: The current version does not need to lock, but it requires certain transaction fees in deployment process and in operation.
Q7: Can Dapp be built on the test platform?
A7: Yes, the test chain platform has smart contract functions. Now the latest test chain has not been completely released to the community for use. It will be provided to the community users when it is available and the test chain token will also provided.
Q8: How is the transaction fee allocated?
A8: The transaction fee will be awarded to the outbound nodes that maintains HPB main network.
Q9: How much does smart contract cost at minimum?
A9: For the transaction cost in smart contracts, please refer to the figures in the above form, transaction cost = Gas * Gas Price.
Besides, regarding to the transaction fee, please calculate according to the formula, for example: Take the current Gas Price = 18Gwei as an example, the ordinary contract operation transaction fee = 10 * 18Gwei, the minimum transaction cost for creating smart contract = 53000 * 18Gwei and the minimum transaction cost for executing smart contract = 10 * 18Gwei.
|中文(简体)版本 | |English Version|
Basics
R&D
- HPB-Consensus-Algorithm-Election-Mechanism
- HPB-BOE-Introduction
- HPB-Consensus-Algorithm--Compare
- HPB-Gas-Mechanism
- HPB-P2P-NetWork
- HPB-JSON-RPC-API-Index
- RLP-Agreement-Extended-Reading
- Interface-of-HPB-hardware-random-number-generator
- HPB-hardware-random-number-service
HPB Dapp Development
- Quick-Start-For-HPB-Developer
- HPB-Dapps-Introductions
- HPB-EVM-Contracts-Introductions
- HPB-Extended-Reading-on-EVM-Development
- An-Introduction-to-EVM-Virtual-Machines
- HPB-Smart-Contracts-Extended-Doc
- Best-Practice-of-Accessing-HPB-Main-Network-in-JS-version
- Best-Practice-of-HPB-Main-Network-Access-Java-Version
- Best-Practice-of-HPB-Smart-Contract
- Case-of-Transmission-from-Ethereum-DAPP-to-HPB-blockchain
- How-to-Write-a-Contract-Extended-Reading
- Development-Tool--Remix-Extended-Reading
- Solidity-Language-Extended-Reading
- Token-issuance-on-HPB-MainNet
- Migrating-a-Ethereum-DApp-to-the-HPB-MainNet
HPB Wallet Development
- An-Introduction-to-HPB-Wallet
- HPB-Wallet-for-Xcode-Integration
- Creating-the-HPB-Wallet
- Generating-Mnemonics-for-HPB Wallet
- HPB-Wallet-and-Middleware-Interface
HPB Mainnet/TestNet Entry
- HPB-Development-Node-Construction-Guild
- Guide-to-Server-Security-Reinforcement
- Build Node With Docker
- HPB-Private-Chain-Building-Guide
Developer Community