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

rpc/backend/tracing.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func (b *Backend) TraceTransaction(hash common.Hash, config *evmtypes.TraceConfi
5050
}
5151

5252
// check tx index is not out of bound
53+
// #nosec G115 len() is always >= 0
5354
if uint32(len(blk.Block.Txs)) < transaction.TxIndex {
5455
b.logger.Debug("tx index out of bounds", "index", transaction.TxIndex, "hash", hash.String(), "height", blk.Block.Height)
5556
return nil, fmt.Errorf("transaction not included in block %v", blk.Block.Height)

rpc/backend/tx_info.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func (b *Backend) GetTransactionByHash(txHash common.Hash) (*rpctypes.RPCTransac
6969
msgs := b.EthMsgsFromTendermintBlock(block, blockRes)
7070
for i := range msgs {
7171
if msgs[i].Hash == hexTx {
72+
// #nosec G115 block size limit prevents out of range
7273
res.EthTxIndex = int32(i)
7374
break
7475
}
@@ -88,7 +89,9 @@ func (b *Backend) GetTransactionByHash(txHash common.Hash) (*rpctypes.RPCTransac
8889
return rpctypes.NewTransactionFromMsg(
8990
msg,
9091
common.BytesToHash(block.BlockID.Hash.Bytes()),
92+
// #nosec G115 height always in range
9193
uint64(res.Height),
94+
// #nosec G115 index always positive
9295
uint64(res.EthTxIndex),
9396
baseFee,
9497
b.chainID,
@@ -179,6 +182,7 @@ func (b *Backend) GetTransactionReceipt(hash common.Hash) (map[string]interface{
179182
return nil, nil
180183
}
181184
for _, txResult := range blockRes.TxsResults[0:res.TxIndex] {
185+
// #nosec G115 txResult.GasUsed always positive
182186
cumulativeGasUsed += uint64(txResult.GasUsed)
183187
}
184188
cumulativeGasUsed += res.CumulativeGasUsed
@@ -210,6 +214,7 @@ func (b *Backend) GetTransactionReceipt(hash common.Hash) (map[string]interface{
210214
msgs := b.EthMsgsFromTendermintBlock(resBlock, blockRes)
211215
for i := range msgs {
212216
if msgs[i].Hash == hexTx {
217+
// #nosec G115 block size limit prevents out of range
213218
res.EthTxIndex = int32(i)
214219
break
215220
}
@@ -235,8 +240,10 @@ func (b *Backend) GetTransactionReceipt(hash common.Hash) (map[string]interface{
235240

236241
// Inclusion information: These fields provide information about the inclusion of the
237242
// transaction corresponding to this receipt.
238-
"blockHash": common.BytesToHash(resBlock.Block.Header.Hash()).Hex(),
239-
"blockNumber": hexutil.Uint64(res.Height),
243+
"blockHash": common.BytesToHash(resBlock.Block.Header.Hash()).Hex(),
244+
// #nosec G115 height always positive
245+
"blockNumber": hexutil.Uint64(res.Height),
246+
// #nosec G115 index always positive
240247
"transactionIndex": hexutil.Uint64(res.EthTxIndex),
241248

242249
// sender and receiver (contract or EOA) addreses
@@ -330,6 +337,7 @@ func (b *Backend) GetTxByEthHash(hash common.Hash) (*ethermint.TxResult, error)
330337
// GetTxByTxIndex uses `/tx_query` to find transaction by tx index of valid ethereum txs
331338
func (b *Backend) GetTxByTxIndex(height int64, index uint) (*ethermint.TxResult, error) {
332339
if b.indexer != nil {
340+
// #nosec G115 not security relevant
333341
return b.indexer.GetByBlockAndIndex(height, int32(index))
334342
}
335343

@@ -339,6 +347,7 @@ func (b *Backend) GetTxByTxIndex(height int64, index uint) (*ethermint.TxResult,
339347
evmtypes.AttributeKeyTxIndex, index,
340348
)
341349
txResult, err := b.queryTendermintTxIndexer(query, func(txs *rpctypes.ParsedTxs) *rpctypes.ParsedTx {
350+
// #nosec G115 out of range would just result in confusing output
342351
return txs.GetTxByTxIndex(int(index))
343352
})
344353
if err != nil {
@@ -398,6 +407,7 @@ func (b *Backend) GetTransactionByBlockAndIndex(block *tmrpctypes.ResultBlock, i
398407
return nil, nil
399408
}
400409
} else {
410+
// #nosec G115 out of range would just result in confusing output
401411
i := int(idx)
402412
ethMsgs := b.EthMsgsFromTendermintBlock(block, blockRes)
403413
if i >= len(ethMsgs) {
@@ -417,6 +427,7 @@ func (b *Backend) GetTransactionByBlockAndIndex(block *tmrpctypes.ResultBlock, i
417427
return rpctypes.NewTransactionFromMsg(
418428
msg,
419429
common.BytesToHash(block.Block.Hash()),
430+
// #nosec G115 block height always in range
420431
uint64(block.Block.Height),
421432
uint64(idx),
422433
baseFee,

rpc/backend/utils.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ func (b *Backend) processBlock(
181181
b.logger.Debug("failed to decode transaction in block", "height", blockHeight, "error", err.Error())
182182
continue
183183
}
184+
// #nosec G115 gas used always positive
184185
txGasUsed := uint64(eachTendermintTxResult.GasUsed)
185186
for _, msg := range tx.GetMsgs() {
186187
ethMsg, ok := msg.(*evmtypes.MsgEthereumTx)

rpc/namespaces/ethereum/debug/api.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ func (a *API) BlockProfile(file string, nsec uint) error {
123123
runtime.SetBlockProfileRate(1)
124124
defer runtime.SetBlockProfileRate(0)
125125

126+
// #nosec G115 out of range would just result in confusing output
126127
time.Sleep(time.Duration(nsec) * time.Second)
127128
return writeProfile("block", file, a.logger)
128129
}
@@ -134,6 +135,7 @@ func (a *API) CpuProfile(file string, nsec uint) error { //nolint: golint, style
134135
if err := a.StartCPUProfile(file); err != nil {
135136
return err
136137
}
138+
// #nosec G115 out of range would just result in confusing output
137139
time.Sleep(time.Duration(nsec) * time.Second)
138140
return a.StopCPUProfile()
139141
}
@@ -153,6 +155,7 @@ func (a *API) GoTrace(file string, nsec uint) error {
153155
if err := a.StartGoTrace(file); err != nil {
154156
return err
155157
}
158+
// #nosec G115 out of range would just result in confusing output
156159
time.Sleep(time.Duration(nsec) * time.Second)
157160
return a.StopGoTrace()
158161
}
@@ -269,6 +272,7 @@ func (a *API) WriteMemProfile(file string) error {
269272
func (a *API) MutexProfile(file string, nsec uint) error {
270273
a.logger.Debug("debug_mutexProfile", "file", file, "nsec", nsec)
271274
runtime.SetMutexProfileFraction(1)
275+
// #nosec G115 out of range would only result in confusing output
272276
time.Sleep(time.Duration(nsec) * time.Second)
273277
defer runtime.SetMutexProfileFraction(0)
274278
return writeProfile("mutex", file, a.logger)
@@ -301,6 +305,7 @@ func (a *API) SetGCPercent(v int) int {
301305

302306
// GetHeaderRlp retrieves the RLP encoded for of a single header.
303307
func (a *API) GetHeaderRlp(number uint64) (hexutil.Bytes, error) {
308+
// #nosec G115 out of range would only result in confusing output
304309
header, err := a.backend.HeaderByNumber(rpctypes.BlockNumber(number))
305310
if err != nil {
306311
return nil, err
@@ -311,6 +316,7 @@ func (a *API) GetHeaderRlp(number uint64) (hexutil.Bytes, error) {
311316

312317
// GetBlockRlp retrieves the RLP encoded for of a single block.
313318
func (a *API) GetBlockRlp(number uint64) (hexutil.Bytes, error) {
319+
// #nosec G115 out of range would only result in confusing output
314320
block, err := a.backend.EthBlockByNumber(rpctypes.BlockNumber(number))
315321
if err != nil {
316322
return nil, err
@@ -321,6 +327,7 @@ func (a *API) GetBlockRlp(number uint64) (hexutil.Bytes, error) {
321327

322328
// PrintBlock retrieves a block and returns its pretty printed form.
323329
func (a *API) PrintBlock(number uint64) (string, error) {
330+
// #nosec G115 out of range would only result in confusing output
324331
block, err := a.backend.EthBlockByNumber(rpctypes.BlockNumber(number))
325332
if err != nil {
326333
return "", err

rpc/types/events.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package types
1717

1818
import (
1919
"fmt"
20+
"math"
2021
"strconv"
2122

2223
abci "github.com/cometbft/cometbft/abci/types"
@@ -135,6 +136,7 @@ func ParseTxResult(result *abci.ResponseDeliverTx, tx sdk.Tx) (*ParsedTxs, error
135136

136137
// some old versions miss some events, fill it with tx result
137138
if len(p.Txs) == 1 {
139+
// #nosec G115 result.GasUsed always positive
138140
p.Txs[0].GasUsed = uint64(result.GasUsed)
139141
}
140142

@@ -164,8 +166,9 @@ func ParseTxIndexerResult(txResult *tmrpctypes.ResultTx, tx sdk.Tx, getter func(
164166
}
165167

166168
return &ethermint.TxResult{
167-
Height: txResult.Height,
168-
TxIndex: txResult.Index,
169+
Height: txResult.Height,
170+
TxIndex: txResult.Index,
171+
// #nosec G115 parsedTx.MsgIndex always positive
169172
MsgIndex: uint32(parsedTx.MsgIndex),
170173
EthTxIndex: parsedTx.EthTxIndex,
171174
Failed: parsedTx.Failed,
@@ -251,6 +254,10 @@ func fillTxAttribute(tx *ParsedTx, key []byte, value []byte) error {
251254
if err != nil {
252255
return err
253256
}
257+
if txIndex > math.MaxInt32 {
258+
return fmt.Errorf("%s exceeds int32 range", value)
259+
}
260+
// #nosec G115 range checked
254261
tx.EthTxIndex = int32(txIndex)
255262
case evmtypes.AttributeKeyTxGasUsed:
256263
gasUsed, err := strconv.ParseUint(string(value), 10, 64)

0 commit comments

Comments
 (0)