github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/core/vm/gas.go (about) 1 // This file is part of the go-sberex library. The go-sberex library is 2 // free software: you can redistribute it and/or modify it under the terms 3 // of the GNU Lesser General Public License as published by the Free 4 // Software Foundation, either version 3 of the License, or (at your option) 5 // any later version. 6 // 7 // The go-sberex library is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 // General Public License <http://www.gnu.org/licenses/> for more details. 11 12 package vm 13 14 import ( 15 "math/big" 16 17 "github.com/Sberex/go-sberex/params" 18 ) 19 20 const ( 21 GasQuickStep uint64 = 2 22 GasFastestStep uint64 = 3 23 GasFastStep uint64 = 5 24 GasMidStep uint64 = 8 25 GasSlowStep uint64 = 10 26 GasExtStep uint64 = 20 27 28 GasReturn uint64 = 0 29 GasStop uint64 = 0 30 GasContractByte uint64 = 200 31 ) 32 33 // calcGas returns the actual gas cost of the call. 34 // 35 // The cost of gas was changed during the homestead price change HF. To allow for EIP150 36 // to be implemented. The returned gas is gas - base * 63 / 64. 37 func callGas(gasTable params.GasTable, availableGas, base uint64, callCost *big.Int) (uint64, error) { 38 if gasTable.CreateBySuicide > 0 { 39 availableGas = availableGas - base 40 gas := availableGas - availableGas/64 41 // If the bit length exceeds 64 bit we know that the newly calculated "gas" for EIP150 42 // is smaller than the requested amount. Therefor we return the new gas instead 43 // of returning an error. 44 if callCost.BitLen() > 64 || gas < callCost.Uint64() { 45 return gas, nil 46 } 47 } 48 if callCost.BitLen() > 64 { 49 return 0, errGasUintOverflow 50 } 51 52 return callCost.Uint64(), nil 53 }