Skip to content

Commit

Permalink
ignore the gosec G115 temporarily (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimmyExogenous authored Aug 27, 2024
1 parent 60c3f17 commit 702832d
Show file tree
Hide file tree
Showing 25 changed files with 50 additions and 26 deletions.
6 changes: 3 additions & 3 deletions app/ante/cosmos/fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ func checkTxFeeWithValidatorMinGasPrices(ctx sdk.Context, feeTx sdk.FeeTx) (sdk.
return nil, 0, err
}
}

priority := getTxPriority(feeCoins, int64(gas)) //#nosec G701 -- gosec warning about integer overflow is not relevant here
// #nosec G115 -- gosec warning about integer overflow is not relevant here
priority := getTxPriority(feeCoins, int64(gas))
return feeCoins, priority, nil
}

Expand All @@ -200,7 +200,7 @@ func checkFeeCoinsAgainstMinGasPrices(ctx sdk.Context, feeCoins sdk.Coins, gas u

// Determine the required fees by multiplying each required minimum gas
// price by the gas limit, where fee = ceil(minGasPrice * gasLimit).
glDec := sdk.NewDec(int64(gas)) //#nosec G701 -- gosec warning about integer overflow is not relevant here
glDec := sdk.NewDec(int64(gas)) // #nosec G115 -- gosec warning about integer overflow is not relevant here
for i, gp := range minGasPrices {
fee := gp.Amount.Mul(glDec)
requiredFees[i] = sdk.NewCoin(gp.Denom, fee.Ceil().RoundInt())
Expand Down
1 change: 1 addition & 0 deletions app/ante/evm/fee_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func NewDynamicFeeChecker(k DynamicFeeEVMKeeper) anteutils.TxFeeChecker {
func checkTxFeeWithValidatorMinGasPrices(ctx sdk.Context, tx sdk.FeeTx) (sdk.Coins, int64, error) {
feeCoins := tx.GetFee()
minGasPrices := ctx.MinGasPrices()
// #nosec G115
gas := int64(tx.GetGas()) //#nosec G701 -- checked for int overflow on ValidateBasic()

// Ensure that the provided fees meet a minimum threshold for the validator,
Expand Down
2 changes: 1 addition & 1 deletion app/tps_counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (tpc *tpsCounter) recordValue(ctx context.Context, latest, previous uint64,
return 0, nil
}

n := int64(latest - previous)
n := int64(latest - previous) // #nosec G115
if n < 0 {
// Perhaps we exceeded the uint64 limits then wrapped around, for the latest value.
// TODO: Perhaps log this?
Expand Down
5 changes: 5 additions & 0 deletions precompiles/assets/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func (p Precompile) DepositWithdrawParamsFromInputs(ctx sdk.Context, args []inte
if !ok || assetAddr == nil {
return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 1, "[]byte", args[1])
}
// #nosec G115
if uint32(len(assetAddr)) < clientChainAddrLength {
return nil, fmt.Errorf(exocmn.ErrInvalidAddrLength, len(assetAddr), clientChainAddrLength)
}
Expand All @@ -46,6 +47,7 @@ func (p Precompile) DepositWithdrawParamsFromInputs(ctx sdk.Context, args []inte
if !ok || stakerAddr == nil {
return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 2, "[]byte", args[2])
}
// #nosec G115
if uint32(len(stakerAddr)) < clientChainAddrLength {
return nil, fmt.Errorf(exocmn.ErrInvalidAddrLength, len(stakerAddr), clientChainAddrLength)
}
Expand Down Expand Up @@ -79,6 +81,7 @@ func (p Precompile) ClientChainInfoFromInputs(_ sdk.Context, args []interface{})
if addressLength < types.MinClientChainAddrLength {
return nil, fmt.Errorf(exocmn.ErrInvalidAddrLength, addressLength, types.MinClientChainAddrLength)
}
// #nosec G115
clientChain.AddressLength = uint32(addressLength)

name, ok := args[2].(string)
Expand Down Expand Up @@ -129,6 +132,7 @@ func (p Precompile) TokenFromInputs(ctx sdk.Context, args []interface{}) (types.
if !ok || assetAddr == nil {
return types.AssetInfo{}, fmt.Errorf(exocmn.ErrContractInputParaOrType, 1, "[]byte", args[1])
}
// #nosec G115
if uint32(len(assetAddr)) < clientChainAddrLength {
return types.AssetInfo{}, fmt.Errorf(exocmn.ErrInvalidAddrLength, len(assetAddr), clientChainAddrLength)
}
Expand All @@ -138,6 +142,7 @@ func (p Precompile) TokenFromInputs(ctx sdk.Context, args []interface{}) (types.
if !ok {
return types.AssetInfo{}, fmt.Errorf(exocmn.ErrContractInputParaOrType, 2, "uint8", args[2])
}
// #nosec G115
asset.Decimals = uint32(decimal)

tvlLimit, ok := args[3].(*big.Int)
Expand Down
2 changes: 2 additions & 0 deletions precompiles/delegation/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func (p Precompile) GetDelegationParamsFromInputs(ctx sdk.Context, args []interf
if !ok || assetAddr == nil {
return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 2, "[]byte", args[2])
}
// #nosec G115
if uint32(len(assetAddr)) < clientChainAddrLength {
return nil, fmt.Errorf(exocmn.ErrInvalidAddrLength, len(assetAddr), clientChainAddrLength)
}
Expand All @@ -52,6 +53,7 @@ func (p Precompile) GetDelegationParamsFromInputs(ctx sdk.Context, args []interf
if !ok || stakerAddr == nil {
return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 3, "[]byte", args[3])
}
// #nosec G115
if uint32(len(stakerAddr)) < clientChainAddrLength {
return nil, fmt.Errorf(exocmn.ErrInvalidAddrLength, len(stakerAddr), clientChainAddrLength)
}
Expand Down
2 changes: 2 additions & 0 deletions precompiles/reward/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (p Precompile) GetRewardParamsFromInputs(ctx sdk.Context, args []interface{
if !ok || assetAddr == nil {
return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 1, "[]byte", assetAddr)
}
// #nosec G115
if uint32(len(assetAddr)) < clientChainAddrLength {
return nil, fmt.Errorf(exocmn.ErrInvalidAddrLength, len(assetAddr), clientChainAddrLength)
}
Expand All @@ -44,6 +45,7 @@ func (p Precompile) GetRewardParamsFromInputs(ctx sdk.Context, args []interface{
if !ok || stakerAddr == nil {
return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 2, "[]byte", stakerAddr)
}
// #nosec G115
if uint32(len(stakerAddr)) < clientChainAddrLength {
return nil, fmt.Errorf(exocmn.ErrInvalidAddrLength, len(stakerAddr), clientChainAddrLength)
}
Expand Down
2 changes: 2 additions & 0 deletions precompiles/slash/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func (p Precompile) GetSlashParamsFromInputs(ctx sdk.Context, args []interface{}
if !ok || assetAddr == nil {
return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 1, "[]byte", assetAddr)
}
// #nosec G115
if uint32(len(assetAddr)) < clientChainAddrLength {
return nil, fmt.Errorf(exocmn.ErrInvalidAddrLength, len(assetAddr), clientChainAddrLength)
}
Expand All @@ -43,6 +44,7 @@ func (p Precompile) GetSlashParamsFromInputs(ctx sdk.Context, args []interface{}
if !ok || stakerAddr == nil {
return nil, fmt.Errorf(exocmn.ErrContractInputParaOrType, 2, "[]byte", stakerAddr)
}
// #nosec G115
if uint32(len(stakerAddr)) < clientChainAddrLength {
return nil, fmt.Errorf(exocmn.ErrInvalidAddrLength, len(stakerAddr), clientChainAddrLength)
}
Expand Down
2 changes: 2 additions & 0 deletions testutil/nullify/nullify.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func Fill(x interface{}) interface{} {
case reflect.Slice:
for i := 0; i < v.Len(); i++ {
obj := v.Index(i)
// #nosec G115
objPt := reflect.NewAt(obj.Type(), unsafe.Pointer(obj.UnsafeAddr())).Interface()
objPt = Fill(objPt)
obj.Set(reflect.ValueOf(objPt))
Expand All @@ -46,6 +47,7 @@ func Fill(x interface{}) interface{} {
s := reflect.ValueOf(coins).Elem()
f.Set(s)
default:
// #nosec G115
objPt := reflect.NewAt(f.Type(), unsafe.Pointer(f.UnsafeAddr())).Interface()
s := Fill(objPt)
f.Set(reflect.ValueOf(s))
Expand Down
2 changes: 1 addition & 1 deletion testutil/tx/cosmos.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func PrepareCosmosTx(

var fees sdk.Coins
if args.GasPrice != nil {
fees = sdk.Coins{{Denom: utils.BaseDenom, Amount: args.GasPrice.MulRaw(int64(args.Gas))}}
fees = sdk.Coins{{Denom: utils.BaseDenom, Amount: args.GasPrice.MulRaw(int64(args.Gas))}} // #nosec G115
} else {
fees = sdk.Coins{DefaultFee}
}
Expand Down
4 changes: 2 additions & 2 deletions types/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ func SafeInt64(value uint64) (int64, error) {
if value > uint64(math.MaxInt64) {
return 0, errorsmod.Wrapf(errortypes.ErrInvalidHeight, "uint64 value %v cannot exceed %v", value, int64(math.MaxInt64))
}

return int64(value), nil // #nosec G701 -- checked for int overflow already
// #nosec G115
return int64(value), nil
}

// SafeNewIntFromBigInt constructs Int from big.Int, return error if more than 256bits
Expand Down
2 changes: 1 addition & 1 deletion x/assets/keeper/client_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (k Keeper) GetAllClientChainInfo(ctx sdk.Context) (infos []assetstype.Clien
func (k Keeper) GetAllClientChainID(ctx sdk.Context) ([]uint32, error) {
ret := make([]uint32, 0)
opFunc := func(clientChain *assetstype.ClientChainInfo) error {
// #nosec G701 // already checked
// #nosec G115
ret = append(ret, uint32(clientChain.LayerZeroChainID))
return nil
}
Expand Down
4 changes: 3 additions & 1 deletion x/avs/keeper/avs.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (k *Keeper) GetAVSMinimumSelfDelegation(ctx sdk.Context, avsAddr string) (s
if err != nil {
return sdkmath.LegacyNewDec(0), errorsmod.Wrap(err, fmt.Sprintf("GetAVSMinimumSelfDelegation: key is %s", avsAddr))
}

// #nosec G115
return sdkmath.LegacyNewDec(int64(avsInfo.Info.MinSelfDelegation)), nil
}

Expand All @@ -69,6 +69,7 @@ func (k *Keeper) GetEpochEndAVSs(ctx sdk.Context, epochIdentifier string, ending
// the currentEpoch is 1, so we will return it.
// consider another AVS which will start at epoch 5. the current epoch is 4.
// it should be returned here, since the operator module should start tracking this.
// #nosec G115
if epochIdentifier == avsInfo.EpochIdentifier && endingEpochNumber >= int64(avsInfo.StartingEpoch)-1 {
avsList = append(avsList, avsInfo.AvsAddress)
}
Expand Down Expand Up @@ -96,6 +97,7 @@ func (k *Keeper) GetTaskChallengeEpochEndAVSs(ctx sdk.Context, epochIdentifier s
k.IterateTaskAVSInfo(ctx, func(_ int64, taskInfo types.TaskInfo) (stop bool) {
avsInfo := k.GetAVSInfoByTaskAddress(ctx, taskInfo.TaskContractAddress)
// Determine if the challenge period has passed, the range of the challenge period is the num marked (StartingEpoch) add TaskChallengePeriod
// #nosec G115
if epochIdentifier == avsInfo.EpochIdentifier && epochNumber > int64(taskInfo.TaskChallengePeriod)+int64(taskInfo.StartingEpoch) {
taskList = append(taskList, taskInfo)
}
Expand Down
10 changes: 6 additions & 4 deletions x/avs/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ func (k Keeper) AVSInfoUpdate(ctx sdk.Context, params *types.AVSRegisterOrDeregi
TaskAddr: params.TaskAddr,
MinStakeAmount: params.MinStakeAmount, // Effective at CurrentEpoch+1, avoid immediate effects and ensure that the first epoch time of avs is equal to a normal identifier
MinTotalStakeAmount: params.MinTotalStakeAmount,
AvsSlash: sdk.NewDecWithPrec(int64(params.AvsSlash), 2),
AvsReward: sdk.NewDecWithPrec(int64(params.AvsReward), 2),
AvsSlash: sdk.NewDecWithPrec(int64(params.AvsSlash), 2), // #nosec G115
AvsReward: sdk.NewDecWithPrec(int64(params.AvsReward), 2), // #nosec G115
}

return k.SetAVSInfo(ctx, avs)
Expand All @@ -109,6 +109,7 @@ func (k Keeper) AVSInfoUpdate(ctx sdk.Context, params *types.AVSRegisterOrDeregi
}

// If avs DeRegisterAction check UnbondingPeriod
// #nosec G115
if epoch.CurrentEpoch-int64(avsInfo.GetInfo().StartingEpoch) > int64(avsInfo.Info.AvsUnbondingPeriod) {
return errorsmod.Wrap(types.ErrUnbondingPeriod, fmt.Sprintf("not qualified to deregister %s", avsInfo))
}
Expand All @@ -123,6 +124,7 @@ func (k Keeper) AVSInfoUpdate(ctx sdk.Context, params *types.AVSRegisterOrDeregi
return errorsmod.Wrap(types.ErrUnregisterNonExistent, fmt.Sprintf("the avsaddress is :%s", params.AvsAddress))
}
// If avs UpdateAction check UnbondingPeriod
// #nosec G115
if int64(avsInfo.Info.AvsUnbondingPeriod) < (epoch.CurrentEpoch - int64(avsInfo.GetInfo().StartingEpoch)) {
return errorsmod.Wrap(types.ErrUnbondingPeriod, fmt.Sprintf("not qualified to deregister %s", avsInfo))
}
Expand Down Expand Up @@ -171,10 +173,10 @@ func (k Keeper) AVSInfoUpdate(ctx sdk.Context, params *types.AVSRegisterOrDeregi
avs.MinTotalStakeAmount = params.MinTotalStakeAmount
}
if params.AvsSlash > 0 {
avs.AvsSlash = sdk.NewDecWithPrec(int64(params.AvsSlash), 2)
avs.AvsSlash = sdk.NewDecWithPrec(int64(params.AvsSlash), 2) // #nosec G115
}
if params.AvsReward > 0 {
avs.AvsReward = sdk.NewDecWithPrec(int64(params.AvsReward), 2)
avs.AvsReward = sdk.NewDecWithPrec(int64(params.AvsReward), 2) // #nosec G115
}
avs.AvsAddress = params.AvsAddress
avs.StartingEpoch = uint64(epoch.CurrentEpoch + 1)
Expand Down
2 changes: 1 addition & 1 deletion x/dogfood/keeper/opt_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (k Keeper) GetOperatorOptOutFinishEpoch(
}
// max int64 is 9 quintillion, and max uint64 is double of that.
// it is too far in the future to be a concern.
return int64(sdk.BigEndianToUint64(bz)) // #nosec G701 // see above.
return int64(sdk.BigEndianToUint64(bz)) // #nosec G115
}

// DeleteOperatorOptOutFinishEpoch deletes the epoch at which an operator's opt out will be
Expand Down
2 changes: 1 addition & 1 deletion x/dogfood/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func SafeUint64ToInt64(id uint64) (int64, bool) {
if id > math.MaxInt64 {
return 0, false
}
return int64(id), true // #nosec G701 // already checked.
return int64(id), true // #nosec G115 // already checked.
}

// HistoricalInfoKey returns the key to historical info to a given block height
Expand Down
5 changes: 3 additions & 2 deletions x/evm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,9 @@ func (k *Keeper) traceTx(

tCtx := &tracers.Context{
BlockHash: txConfig.BlockHash,
TxIndex: int(txConfig.TxIndex),
TxHash: txConfig.TxHash,
// #nosec G115
TxIndex: int(txConfig.TxIndex),
TxHash: txConfig.TxHash,
}

if traceConfig.Tracer != "" {
Expand Down
4 changes: 2 additions & 2 deletions x/evm/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*t

// Observe which users define a gas limit >> gas used. Note, that
// gas_limit and gas_used are always > 0
gasLimit := sdk.NewDec(int64(tx.Gas()))
gasRatio, err := gasLimit.QuoInt64(int64(response.GasUsed)).Float64()
gasLimit := sdk.NewDec(int64(tx.Gas())) // #nosec G115
gasRatio, err := gasLimit.QuoInt64(int64(response.GasUsed)).Float64() // #nosec G115
if err == nil {
telemetry.SetGaugeWithLabels(
[]string{"tx", "msg", "ethereum_tx", "gas_limit", "per", "gas_used"},
Expand Down
4 changes: 2 additions & 2 deletions x/evm/keeper/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ func (k *Keeper) ApplyMessageWithConfig(ctx sdk.Context,
// calculate a minimum amount of gas to be charged to sender if GasLimit
// is considerably higher than GasUsed to stay more aligned with Tendermint gas mechanics
// for more info https://github.com/evmos/ethermint/issues/1085
gasLimit := sdk.NewDec(int64(msg.Gas()))
gasLimit := sdk.NewDec(int64(msg.Gas())) // #nosec G115
minGasMultiplier := k.GetMinGasMultiplier(ctx)
minimumGasUsed := gasLimit.Mul(minGasMultiplier)

Expand All @@ -423,7 +423,7 @@ func (k *Keeper) ApplyMessageWithConfig(ctx sdk.Context,
if msg.Gas() < leftoverGas {
return nil, errorsmod.Wrapf(types.ErrGasOverflow, "message gas limit < leftover gas (%d < %d)", msg.Gas(), leftoverGas)
}

// #nosec G115
gasUsed := sdk.MaxDec(minimumGasUsed, sdk.NewDec(int64(temporaryGasUsed))).TruncateInt().Uint64()
// reset leftoverGas, to be used by the tracer
leftoverGas = msg.Gas() - gasUsed
Expand Down
2 changes: 1 addition & 1 deletion x/operator/keeper/common_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
func CalculateUSDValue(assetAmount sdkmath.Int, price sdkmath.Int, assetDecimal uint32, priceDecimal uint8) sdkmath.LegacyDec {
assetValue := assetAmount.Mul(price)
assetValueDec := sdkmath.LegacyNewDecFromBigInt(assetValue.BigInt())
// #nosec G701
// #nosec G115
divisor := sdkmath.NewIntWithDecimal(1, int(assetDecimal)+int(priceDecimal))
return assetValueDec.QuoInt(divisor)
}
4 changes: 3 additions & 1 deletion x/oracle/client/cli/tx_create_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ func CmdCreatePrice() *cobra.Command {
argLength -= 3
i += 3
prices[0].Prices = append(prices[0].Prices, &types.PriceTimeDetID{
Price: price,
Price: price,
// #nosec G115
Decimal: int32(decimal),
Timestamp: timestamp,
DetID: detID,
Expand All @@ -75,6 +76,7 @@ func CmdCreatePrice() *cobra.Command {
feederID,
prices,
basedBlock,
// #nosec G115
int32(nonce),
)
if err := msg.ValidateBasic(); err != nil {
Expand Down
1 change: 1 addition & 0 deletions x/oracle/keeper/aggregator/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (f *filter) addPSource(pSources []*types.PriceSource, validator string) (li
for _, pSource := range pSources {
// check conflicts or duplicate data for the same roundID within the same source
if len(pSource.Prices[0].DetID) > 0 {
// #nosec G115
k := validator + strconv.Itoa(int(pSource.SourceID))
detIDs := f.validatorSource[k]
if detIDs == nil {
Expand Down
4 changes: 2 additions & 2 deletions x/oracle/keeper/prices.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (k Keeper) GetSpecifiedAssetsPrice(ctx sdk.Context, assetID string) (types.
}
return types.Price{
Value: v,
Decimal: uint8(price.Decimal),
Decimal: uint8(price.Decimal), // #nosec G115
}, nil
}

Expand Down Expand Up @@ -117,7 +117,7 @@ func (k Keeper) GetMultipleAssetsPrices(ctx sdk.Context, assets map[string]inter
}
prices[assetID] = types.Price{
Value: v,
Decimal: uint8(price.Decimal),
Decimal: uint8(price.Decimal), // #nosec G115
}
}
}
Expand Down
1 change: 1 addition & 0 deletions x/oracle/keeper/recent_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func (k Keeper) GetAllRecentMsgAsMap(ctx sdk.Context) (result map[int64][]*types
var val types.RecentMsg
k.cdc.MustUnmarshal(iterator.Value(), &val)
// list = append(list, val)
// #nosec G115
result[int64(val.Block)] = val.Msgs
}

Expand Down
1 change: 1 addition & 0 deletions x/oracle/keeper/recent_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func (k Keeper) GetAllRecentParamsAsMap(ctx sdk.Context) (result map[int64]*type
for ; iterator.Valid(); iterator.Next() {
var val types.RecentParams
k.cdc.MustUnmarshal(iterator.Value(), &val)
// #nosec G115
result[int64(val.Block)] = val.Params
}

Expand Down
2 changes: 1 addition & 1 deletion x/oracle/keeper/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func recacheAggregatorContext(ctx sdk.Context, agc *aggregator.AggregatorContext
// no cache, this is the very first running, so go to initial process instead
return false
}

// #nosec G115
if int64(h.Block) >= from {
from = int64(h.Block) + 1
}
Expand Down

0 comments on commit 702832d

Please sign in to comment.