github.com/arieschain/arieschain@v0.0.0-20191023063405-37c074544356/core/vm/gas.go (about)

     1  package vm
     2  
     3  import (
     4  	"math/big"
     5  
     6  	"github.com/quickchainproject/quickchain/params"
     7  )
     8  
     9  const (
    10  	GasQuickStep   uint64 = 2
    11  	GasFastestStep uint64 = 3
    12  	GasFastStep    uint64 = 5
    13  	GasMidStep     uint64 = 8
    14  	GasSlowStep    uint64 = 10
    15  	GasExtStep     uint64 = 20
    16  
    17  	GasReturn       uint64 = 0
    18  	GasStop         uint64 = 0
    19  	GasContractByte uint64 = 200
    20  )
    21  
    22  // calcGas returns the actual gas cost of the call.
    23  //
    24  // The cost of gas was changed during the homestead price change HF. To allow for EIP150
    25  // to be implemented. The returned gas is gas - base * 63 / 64.
    26  func callGas(gasTable params.GasTable, availableGas, base uint64, callCost *big.Int) (uint64, error) {
    27  	if gasTable.CreateBySuicide > 0 {
    28  		availableGas = availableGas - base
    29  		gas := availableGas - availableGas/64
    30  		// If the bit length exceeds 64 bit we know that the newly calculated "gas" for EIP150
    31  		// is smaller than the requested amount. Therefor we return the new gas instead
    32  		// of returning an error.
    33  		if callCost.BitLen() > 64 || gas < callCost.Uint64() {
    34  			return gas, nil
    35  		}
    36  	}
    37  	if callCost.BitLen() > 64 {
    38  		return 0, errGasUintOverflow
    39  	}
    40  
    41  	return callCost.Uint64(), nil
    42  }