Skip to content

Commit b1692f5

Browse files
committed
add gosec suppressions/fixes
1 parent 4a032cd commit b1692f5

File tree

25 files changed

+119
-45
lines changed

25 files changed

+119
-45
lines changed

app/ante/authz.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func NewAuthzLimiterDecorator(disabledMsgTypes []string) AuthzLimiterDecorator {
4949

5050
func (ald AuthzLimiterDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
5151
if err := ald.checkDisabledMsgs(tx.GetMsgs(), false, 0); err != nil {
52-
return ctx, errorsmod.Wrapf(errortypes.ErrUnauthorized, err.Error())
52+
return ctx, errorsmod.Wrapf(errortypes.ErrUnauthorized, "%v", err)
5353
}
5454
return next(ctx, tx, simulate)
5555
}

app/ante/fee_checker.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func checkTxFeeWithValidatorMinGasPrices(ctx sdk.Context, tx sdk.FeeTx) (sdk.Coi
120120

121121
// Determine the required fees by multiplying each required minimum gas
122122
// price by the gas limit, where fee = ceil(minGasPrice * gasLimit).
123+
// #nosec G115 always in range
123124
glDec := sdk.NewDec(int64(gas))
124125

125126
for i, gp := range minGasPrices {
@@ -132,6 +133,7 @@ func checkTxFeeWithValidatorMinGasPrices(ctx sdk.Context, tx sdk.FeeTx) (sdk.Coi
132133
}
133134
}
134135

136+
// #nosec G115 always in range
135137
priority := getTxPriority(feeCoins, int64(gas))
136138
return feeCoins, priority, nil
137139
}

app/ante/setup.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func (eeed EthEmitEventDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulat
8585
ctx.EventManager().EmitEvent(sdk.NewEvent(
8686
evmtypes.EventTypeEthereumTx,
8787
sdk.NewAttribute(evmtypes.AttributeKeyEthereumTxHash, msgEthTx.Hash),
88+
// #nosec G115 index always positive
8889
sdk.NewAttribute(evmtypes.AttributeKeyTxIndex, strconv.FormatUint(txIndex+uint64(i), 10)),
8990
))
9091
}

ethereum/eip712/domain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func createEIP712Domain(chainID uint64) apitypes.TypedDataDomain {
2525
domain := apitypes.TypedDataDomain{
2626
Name: "Cosmos Web3",
2727
Version: "1.0.0",
28-
ChainId: math.NewHexOrDecimal256(int64(chainID)), // #nosec G701
28+
ChainId: math.NewHexOrDecimal256(int64(chainID)), // #nosec G701 G115
2929
VerifyingContract: "cosmos",
3030
Salt: "0",
3131
}

ethereum/eip712/eip712_legacy.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ func LegacyWrapTxToTypedData(
5959
}
6060

6161
domain := apitypes.TypedDataDomain{
62-
Name: "Cosmos Web3",
63-
Version: "1.0.0",
62+
Name: "Cosmos Web3",
63+
Version: "1.0.0",
64+
// #nosec G115 chainID always positive
6465
ChainId: math.NewHexOrDecimal256(int64(chainID)),
6566
VerifyingContract: "cosmos",
6667
Salt: "0",

indexer/kv_indexer.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ func (kv *KVIndexer) IndexBlock(block *tmtypes.Block, txResults []*abci.Response
9797
txHash := common.HexToHash(ethMsg.Hash)
9898

9999
txResult := ethermint.TxResult{
100-
Height: height,
101-
TxIndex: uint32(txIndex),
100+
Height: height,
101+
// #nosec G115 index always positive
102+
TxIndex: uint32(txIndex),
103+
// #nosec G115 index always positive
102104
MsgIndex: uint32(msgIndex),
103105
EthTxIndex: ethTxIndex,
104106
}
@@ -180,7 +182,9 @@ func TxHashKey(hash common.Hash) []byte {
180182

181183
// TxIndexKey returns the key for db entry: `(block number, tx index) -> tx hash`
182184
func TxIndexKey(blockNumber int64, txIndex int32) []byte {
185+
// #nosec G115 block number always positive
183186
bz1 := sdk.Uint64ToBigEndian(uint64(blockNumber))
187+
// #nosec G115 index always positive
184188
bz2 := sdk.Uint64ToBigEndian(uint64(txIndex))
185189
return append(append([]byte{KeyPrefixTxIndex}, bz1...), bz2...)
186190
}
@@ -241,5 +245,6 @@ func parseBlockNumberFromKey(key []byte) (int64, error) {
241245
return 0, fmt.Errorf("wrong tx index key length, expect: %d, got: %d", TxIndexKeyLength, len(key))
242246
}
243247

248+
// #nosec G115 block number always in range
244249
return int64(sdk.BigEndianToUint64(key[1:9])), nil
245250
}

rpc/backend/account_info.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func (b *Backend) GetProof(address common.Address, storageKeys []string, blockNr
7777
return nil, fmt.Errorf("not able to query block number greater than MaxInt64")
7878
}
7979

80+
// #nosec G115 block number always in range
8081
height = int64(bn)
8182
}
8283

@@ -195,6 +196,7 @@ func (b *Backend) GetTransactionCount(address common.Address, blockNum rpctypes.
195196
return &n, err
196197
}
197198
height := blockNum.Int64()
199+
// #nosec G115 block number always in range
198200
currentHeight := int64(bn)
199201
if height > currentHeight {
200202
return &n, errorsmod.Wrapf(

rpc/backend/blocks.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ func (b *Backend) TendermintBlockByNumber(blockNum rpctypes.BlockNumber) (*tmrpc
179179
if err != nil {
180180
return nil, err
181181
}
182+
// #nosec G115 always in range
182183
height = int64(n)
183184
}
184185
resBlock, err := b.clientCtx.Client.Block(b.ctx, &height)
@@ -401,7 +402,9 @@ func (b *Backend) RPCBlockFromTendermintBlock(
401402
rpcTx, err := rpctypes.NewRPCTransaction(
402403
tx,
403404
common.BytesToHash(block.Hash()),
405+
// #nosec G115 block height always positive
404406
uint64(block.Height),
407+
// #nosec G115 txIndex always positive
405408
uint64(txIndex),
406409
baseFee,
407410
b.chainID,
@@ -457,6 +460,7 @@ func (b *Backend) RPCBlockFromTendermintBlock(
457460
// block gas limit has exceeded, other txs must have failed with same reason.
458461
break
459462
}
463+
// #nosec G115 gas used always positive
460464
gasUsed += uint64(txsResult.GetGasUsed())
461465
}
462466

rpc/backend/chain_info.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,11 @@ func (b *Backend) FeeHistory(
173173
if err != nil {
174174
return nil, err
175175
}
176+
// #nosec G115 block number always in range
176177
blockEnd = int64(blockNumber)
177178
}
178179

180+
// #nosec G115 not security relevant
179181
blocks := int64(userBlockCount)
180182
maxBlockCount := int64(b.cfg.JSONRPC.FeeHistoryCap)
181183
if blocks > maxBlockCount {
@@ -204,6 +206,7 @@ func (b *Backend) FeeHistory(
204206

205207
// fetch block
206208
for blockID := blockStart; blockID <= blockEnd; blockID++ {
209+
// #nosec G115 out of range would just result in confusing output
207210
index := int32(blockID - blockStart)
208211
// tendermint block
209212
tendermintblock, err := b.TendermintBlockByNumber(rpctypes.BlockNumber(blockID))

rpc/backend/node_info.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,10 @@ func (b *Backend) Syncing() (interface{}, error) {
8080
}
8181

8282
return map[string]interface{}{
83+
// #nosec G115 block height always positive
8384
"startingBlock": hexutil.Uint64(status.SyncInfo.EarliestBlockHeight),
84-
"currentBlock": hexutil.Uint64(status.SyncInfo.LatestBlockHeight),
85+
// #nosec G115 block height always positive
86+
"currentBlock": hexutil.Uint64(status.SyncInfo.LatestBlockHeight),
8587
// "highestBlock": nil, // NA
8688
// "pulledStates": nil, // NA
8789
// "knownStates": nil, // NA

0 commit comments

Comments
 (0)