📝
smartbch
  • Introduction
  • Whitepaper
  • FAQ
  • Mainnet
  • Testnets
  • Join Amber testnet as a Validator
  • Developer's Guide
    • Introduction
    • Deploy contracts using Truffle
    • Deploy contracts using Remix
    • JSON-RPC Endpoints
    • Staking Scheme
    • XHedge Smart Contract
    • Decision of the minimum gas price
  • Sha-Gate Bridge
    • Sha-Gate Specification
    • Sha-Gate Risk Analysis
    • Sha-Gate's Covenant
  • In-Depth Design Documents
    • Introduction
    • MoeingADS's General Ideas
    • MoeingADS's RabbitStore
    • MoeingADS's internal architecture
    • Benchmarking MoeingADS
    • Benchmarking MoeingEVM and MoeingADS
    • Benchmarking Testnet
    • Transaction Reordering in smartBCH
    • Transaction Parallel Execution in smartBCH
    • Send back-to-back Transactions
    • Data structures in world state
  • SmartBCH Evolution Proposals (SEPs)
    • SEP101: Store values with arbitrary length
    • SEP102: Adjustment of Used Gas
    • SEP109: On-chain Verification of Verifiable Random Functions
    • SEP18: Blockchain cheques on smartBCH
    • SEP20: Tokens on smartBCH
    • SEP206: Manipulate Native Token as a SEP20 Token
    • SEP201: Simple Stochastic Payment
  • Archives
    • Single Node Private Testnet
    • Multi-Node Testnet
    • Fake RPC Server for Testing
    • Test using MetaMask
Powered by GitBook
On this page
  • 1. Summary
  • 2. Abstract
  • 3. Motivation
  • 4. Status
  • 5. Specification
  • 6. License

Was this helpful?

  1. SmartBCH Evolution Proposals (SEPs)

SEP102: Adjustment of Used Gas

PreviousSEP101: Store values with arbitrary lengthNextSEP109: On-chain Verification of Verifiable Random Functions

Last updated 3 years ago

Was this helpful?

1. Summary

This SEP proposes an algorithm to adjust the used gas considering the real used gas and user-specified gas limit.

2. Abstract

In ethereum, at the beginning of a transaction, all the gas fee (gas_limit * gas_price) is deducted from the sender's balance. When it is finished, some gas fee (gas_remained * gas_price) is returned to the sender. So the sender effectively pays gas_used * gas_price to the network, where gas_used = gas_limit - gas_remained.

Here we propose a different way to calculate the returned fee, which also means chances to the fee that the sender effectively pays.

3. Motivation

Unlike go-ethereum, smartBCH's validator just packs all the transactions into block and propose it. The transactions are not executed before the block is proposed. Thus we can do the tx-reordering and parallel execution: the exact tx ordering is not decided until every node gets the transactions. So when a validator proposes a block, it does not know the exact gas consumption of the transactions. But we do need to set a block level gas consumption upper bound, such that a block does not takes too long to execute.

So, in smartBCH, the block's total gas limit is the threshold of the sum of all the transactions' gas limit, which is different from ethereum, where it is the sum of all the transactions' real used gas. Since the senders can specify a very high gas limit for the transactions which only use a small amount of gas, a block may only contain a small number of transactions with high gas limit, which stops the other transactions get packed into block.

So we must encourage users to estimated their transactions' gas consumptions more accurately and make sure the transaction's gas limit is close to the gas it really consumes. If your gas limit is not a good estimation of the actual gas consumption, there will be some penalty.

4. Status

This SEP has been implemented since genesis.

5. Specification

When transactions finish their execution, the returned gas fee is calculated as the following pseudo code:

gas_used = gas_limit - gas_remained
if gas_used * 4 < gas_limit then /*the estimated gas consumption is more than four times of real gas consumption*/
    gas_used = gas_limit /* no gas fee will be returned*/
else if gas_used * 2 < gas_limit then /*the estimated gas consumption is more than two times of real gas consumption*/
    gas_used = (gas_used + gas_limit) / 2
else then /*the estimated gas consumption is no larger than two times of real gas consumption*/
    /* return the gas fee just as ethereum*/
endif
returned_gas_fee = (gas_limit - gas_used) * gas_price

6. License

The content is licensed under .

CC0
SEP-102: Adjustment of Used Gas
1. Summary
2. Abstract
3. Motivation
4. Status
5. Specification
6. License