github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/execution/engine/gas.go (about)

     1  // Copyright Monax Industries Limited
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  package engine
     5  
     6  import (
     7  	"math/big"
     8  
     9  	"github.com/hyperledger/burrow/execution/errors"
    10  )
    11  
    12  const (
    13  	GasSha3          uint64 = 1
    14  	GasGetAccount    uint64 = 1
    15  	GasStorageUpdate uint64 = 1
    16  	GasCreateAccount uint64 = 1
    17  
    18  	GasBaseOp  uint64 = 0 // TODO: make this 1
    19  	GasStackOp uint64 = 1
    20  
    21  	GasEcRecover     uint64 = 1
    22  	GasSha256Word    uint64 = 1
    23  	GasSha256Base    uint64 = 1
    24  	GasRipemd160Word uint64 = 1
    25  	GasRipemd160Base uint64 = 1
    26  	GasExpModWord    uint64 = 1
    27  	GasExpModBase    uint64 = 1
    28  	GasIdentityWord  uint64 = 1
    29  	GasIdentityBase  uint64 = 1
    30  )
    31  
    32  // Try to deduct gasToUse from gasLeft.  If ok return false, otherwise
    33  // set err and return true.
    34  func UseGasNegative(gasLeft *big.Int, gasToUse uint64) errors.CodedError {
    35  	delta := new(big.Int).SetUint64(gasToUse)
    36  	if gasLeft.Cmp(delta) >= 0 {
    37  		gasLeft.Sub(gasLeft, delta)
    38  	} else {
    39  		return errors.Codes.InsufficientGas
    40  	}
    41  	return nil
    42  }