Skip to content

Commit

Permalink
chore: Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
dudong2 committed Aug 31, 2024
1 parent e234684 commit 62e533e
Show file tree
Hide file tree
Showing 18 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion app/ante/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ func (mfd EthMempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulat

evmDenom := params.EvmDenom
feeAmt := ethMsg.GetFee()
glDec := sdk.NewDec(int64(ethMsg.GetGas()))
glDec := sdk.NewDec(int64(ethMsg.GetGas())) //#nosec G115
requiredFee := ctx.MinGasPrices().AmountOf(evmDenom).Mul(glDec)
if sdk.NewDecFromBigInt(feeAmt).LT(requiredFee) {
return ctx, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "insufficient fees; got: %s required: %s", feeAmt, requiredFee)
Expand Down
2 changes: 1 addition & 1 deletion ethereum/eip712/eip712.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func WrapTxToTypedData(
domain := apitypes.TypedDataDomain{
Name: "Cosmos Web3",
Version: "1.0.0",
ChainId: math.NewHexOrDecimal256(int64(chainID)),
ChainId: math.NewHexOrDecimal256(int64(chainID)), //#nosec G115
VerifyingContract: "cosmos",
Salt: "0",
}
Expand Down
6 changes: 3 additions & 3 deletions indexer/kv_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ func (kv *KVIndexer) IndexBlock(block *tmtypes.Block, txResults []*abci.Response

txResult := ethermint.TxResult{
Height: height,
TxIndex: uint32(txIndex),
MsgIndex: uint32(msgIndex),
TxIndex: uint32(txIndex), //#nosec G115
MsgIndex: uint32(msgIndex), //#nosec G115
EthTxIndex: ethTxIndex,
}
if result.Code != abci.CodeTypeOK {
Expand Down Expand Up @@ -226,5 +226,5 @@ func parseBlockNumberFromKey(key []byte) (int64, error) {
return 0, fmt.Errorf("wrong tx index key length, expect: %d, got: %d", TxIndexKeyLength, len(key))
}

return int64(sdk.BigEndianToUint64(key[1:9])), nil
return int64(sdk.BigEndianToUint64(key[1:9])), nil //#nosec G115
}
2 changes: 1 addition & 1 deletion rpc/backend/account_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (b *Backend) GetProof(address common.Address, storageKeys []string, blockNr
return nil, fmt.Errorf("not able to query block number greater than MaxInt64")
}

height = int64(bn)
height = int64(bn) //#nosec G115
}

clientCtx := b.clientCtx.WithHeight(height)
Expand Down
2 changes: 1 addition & 1 deletion rpc/backend/blocks_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (b *Backend) GetTendermintBlockByNumber(blockNum rpctypes.BlockNumber) (*tm
if err != nil {
return nil, err
}
height = int64(n)
height = int64(n) //#nosec G115
}
resBlock, err := b.clientCtx.Client.Block(b.ctx, &height)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions rpc/backend/chain_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ func (b *Backend) FeeHistory(
if err != nil {
return nil, err
}
blockEnd = int64(blockNumber)
blockEnd = int64(blockNumber) //#nosec G115
}
userBlockCountInt := int64(userBlockCount)
userBlockCountInt := int64(userBlockCount) //#nosec G115
maxBlockCount := int64(b.cfg.JSONRPC.FeeHistoryCap)
if userBlockCountInt > maxBlockCount {
return nil, fmt.Errorf("FeeHistory user block count %d higher than %d", userBlockCountInt, maxBlockCount)
Expand Down Expand Up @@ -181,7 +181,7 @@ func (b *Backend) FeeHistory(

// fetch block
for blockID := blockStart; blockID < blockEnd; blockID++ {
index := int32(blockID - blockStart)
index := int32(blockID - blockStart) //#nosec G115
// tendermint block
tendermintblock, err := b.GetTendermintBlockByNumber(rpctypes.BlockNumber(blockID))
if tendermintblock == nil {
Expand Down
2 changes: 1 addition & 1 deletion rpc/backend/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (b *Backend) TraceTransaction(hash common.Hash, config *evmtypes.TraceConfi
}

// check tx index is not out of bound
if uint32(len(blk.Block.Txs)) < transaction.TxIndex {
if uint32(len(blk.Block.Txs)) < transaction.TxIndex { //#nosec G115
b.logger.Debug("tx index out of bounds", "index", transaction.TxIndex, "hash", hash.String(), "height", blk.Block.Height)
return nil, fmt.Errorf("transaction not included in block %v", blk.Block.Height)
}
Expand Down
10 changes: 5 additions & 5 deletions rpc/backend/tx_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (b *Backend) GetTransactionByHash(txHash common.Hash) (*rpctypes.RPCTransac
msgs := b.GetEthereumMsgsFromTendermintBlock(block, blockRes)
for i := range msgs {
if msgs[i].Hash == hexTx {
res.EthTxIndex = int32(i)
res.EthTxIndex = int32(i) //#nosec G115
break
}
}
Expand Down Expand Up @@ -182,7 +182,7 @@ func (b *Backend) GetTransactionReceipt(hash common.Hash) (map[string]interface{
msgs := b.GetEthereumMsgsFromTendermintBlock(resBlock, blockRes)
for i := range msgs {
if msgs[i].Hash == hexTx {
res.EthTxIndex = int32(i)
res.EthTxIndex = int32(i) //#nosec G115
break
}
}
Expand Down Expand Up @@ -296,7 +296,7 @@ func (b *Backend) GetTxByEthHash(hash common.Hash) (*ethermint.TxResult, error)
// GetTxByTxIndex uses `/tx_query` to find transaction by tx index of valid ethereum txs
func (b *Backend) GetTxByTxIndex(height int64, index uint) (*ethermint.TxResult, error) {
if b.indexer != nil {
return b.indexer.GetByBlockAndIndex(height, int32(index))
return b.indexer.GetByBlockAndIndex(height, int32(index)) //#nosec G115
}

// fallback to tendermint tx indexer
Expand All @@ -305,7 +305,7 @@ func (b *Backend) GetTxByTxIndex(height int64, index uint) (*ethermint.TxResult,
evmtypes.AttributeKeyTxIndex, index,
)
txResult, err := b.queryTendermintTxIndexer(query, func(txs *rpctypes.ParsedTxs) *rpctypes.ParsedTx {
return txs.GetTxByTxIndex(int(index))
return txs.GetTxByTxIndex(int(index)) //#nosec G115
})
if err != nil {
return nil, sdkerrors.Wrapf(err, "GetTxByTxIndex %d %d", height, index)
Expand Down Expand Up @@ -364,7 +364,7 @@ func (b *Backend) GetTransactionByBlockAndIndex(block *tmrpctypes.ResultBlock, i
return nil, nil
}
} else {
i := int(idx)
i := int(idx) //#nosec G115
ethMsgs := b.GetEthereumMsgsFromTendermintBlock(block, blockRes)
if i >= len(ethMsgs) {
b.logger.Debug("block txs index out of bound", "index", i)
Expand Down
16 changes: 8 additions & 8 deletions rpc/namespaces/ethereum/debug/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (a *API) BlockProfile(file string, nsec uint) error {
runtime.SetBlockProfileRate(1)
defer runtime.SetBlockProfileRate(0)

time.Sleep(time.Duration(nsec) * time.Second)
time.Sleep(time.Duration(nsec) * time.Second) //#nosec G115
return writeProfile("block", file, a.logger)
}

Expand All @@ -121,7 +121,7 @@ func (a *API) CpuProfile(file string, nsec uint) error { //nolint: golint, style
if err := a.StartCPUProfile(file); err != nil {
return err
}
time.Sleep(time.Duration(nsec) * time.Second)
time.Sleep(time.Duration(nsec) * time.Second) //#nosec G115
return a.StopCPUProfile()
}

Expand All @@ -140,7 +140,7 @@ func (a *API) GoTrace(file string, nsec uint) error {
if err := a.StartGoTrace(file); err != nil {
return err
}
time.Sleep(time.Duration(nsec) * time.Second)
time.Sleep(time.Duration(nsec) * time.Second) //#nosec G115
return a.StopGoTrace()
}

Expand Down Expand Up @@ -256,7 +256,7 @@ func (a *API) WriteMemProfile(file string) error {
func (a *API) MutexProfile(file string, nsec uint) error {
a.logger.Debug("debug_mutexProfile", "file", file, "nsec", nsec)
runtime.SetMutexProfileFraction(1)
time.Sleep(time.Duration(nsec) * time.Second)
time.Sleep(time.Duration(nsec) * time.Second) //#nosec G115
defer runtime.SetMutexProfileFraction(0)
return writeProfile("mutex", file, a.logger)
}
Expand Down Expand Up @@ -288,7 +288,7 @@ func (a *API) SetGCPercent(v int) int {

// GetHeaderRlp retrieves the RLP encoded for of a single header.
func (a *API) GetHeaderRlp(number uint64) (hexutil.Bytes, error) {
header, err := a.backend.HeaderByNumber(rpctypes.BlockNumber(number))
header, err := a.backend.HeaderByNumber(rpctypes.BlockNumber(number)) //#nosec G115
if err != nil {
return nil, err
}
Expand All @@ -298,7 +298,7 @@ func (a *API) GetHeaderRlp(number uint64) (hexutil.Bytes, error) {

// GetBlockRlp retrieves the RLP encoded for of a single block.
func (a *API) GetBlockRlp(number uint64) (hexutil.Bytes, error) {
block, err := a.backend.BlockByNumber(rpctypes.BlockNumber(number))
block, err := a.backend.BlockByNumber(rpctypes.BlockNumber(number)) //#nosec G115
if err != nil {
return nil, err
}
Expand All @@ -308,7 +308,7 @@ func (a *API) GetBlockRlp(number uint64) (hexutil.Bytes, error) {

// PrintBlock retrieves a block and returns its pretty printed form.
func (a *API) PrintBlock(number uint64) (string, error) {
block, err := a.backend.BlockByNumber(rpctypes.BlockNumber(number))
block, err := a.backend.BlockByNumber(rpctypes.BlockNumber(number)) //#nosec G115
if err != nil {
return "", err
}
Expand All @@ -318,7 +318,7 @@ func (a *API) PrintBlock(number uint64) (string, error) {

// SeedHash retrieves the seed hash of a block.
func (a *API) SeedHash(number uint64) (string, error) {
_, err := a.backend.HeaderByNumber(rpctypes.BlockNumber(number))
_, err := a.backend.HeaderByNumber(rpctypes.BlockNumber(number)) //#nosec G115
if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion rpc/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
if blckNum > math.MaxInt64 {
return fmt.Errorf("block number larger than int64")
}
*bn = BlockNumber(blckNum)
*bn = BlockNumber(blckNum) //#nosec G115

return nil
}
Expand Down
4 changes: 2 additions & 2 deletions rpc/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func ParseTxIndexerResult(txResult *tmrpctypes.ResultTx, tx sdk.Tx, getter func(
return &ethermint.TxResult{
Height: txResult.Height,
TxIndex: txResult.Index,
MsgIndex: uint32(parsedTx.MsgIndex),
MsgIndex: uint32(parsedTx.MsgIndex), //#nosec G115
EthTxIndex: parsedTx.EthTxIndex,
Failed: parsedTx.Failed,
GasUsed: parsedTx.GasUsed,
Expand Down Expand Up @@ -236,7 +236,7 @@ func fillTxAttribute(tx *ParsedTx, key []byte, value []byte) error {
if err != nil {
return err
}
tx.EthTxIndex = int32(txIndex)
tx.EthTxIndex = int32(txIndex) //#nosec G115
case evmtypes.AttributeKeyTxGasUsed:
gasUsed, err := strconv.ParseUint(string(value), 10, 64)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion types/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func SafeInt64(value uint64) (int64, error) {
return 0, sdkerrors.Wrapf(sdkerrors.ErrInvalidHeight, "uint64 value %v cannot exceed %v", value, int64(math.MaxInt64))
}

return int64(value), nil
return int64(value), nil //#nosec G115
}

// SafeNewIntFromBigInt constructs Int from big.Int, return error if more than 256bits
Expand Down
2 changes: 1 addition & 1 deletion x/evm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ func (k *Keeper) traceTx(

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

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 @@ -64,8 +64,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 @@ -436,15 +436,15 @@ 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)

if msg.Gas() < leftoverGas {
return nil, sdkerrors.Wrapf(types.ErrGasOverflow, "message gas limit < leftover gas (%d < %d)", msg.Gas(), leftoverGas)
}
temporaryGasUsed := msg.Gas() - leftoverGas
gasUsed := sdk.MaxDec(minimumGasUsed, sdk.NewDec(int64(temporaryGasUsed))).TruncateInt().Uint64()
gasUsed := sdk.MaxDec(minimumGasUsed, sdk.NewDec(int64(temporaryGasUsed))).TruncateInt().Uint64() //#nosec G115
// reset leftoverGas, to be used by the tracer
leftoverGas = msg.Gas() - gasUsed

Expand Down
4 changes: 2 additions & 2 deletions x/evm/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func CreateRandomValidEthTx(ctx *simulateContext,
return nil, err
}
// we suppose that gasLimit should be larger than estimateGas to ensure tx validity
gasLimit := estimateGas + uint64(ctx.rand.Intn(int(sdktx.MaxGasWanted-estimateGas)))
gasLimit := estimateGas + uint64(ctx.rand.Intn(int(sdktx.MaxGasWanted-estimateGas))) //#nosec G115
ethChainID := ctx.keeper.ChainID()
chainConfig := ctx.keeper.GetParams(ctx.context).ChainConfig.EthereumConfig(ethChainID)
gasPrice := ctx.keeper.GetBaseFee(ctx.context, chainConfig)
Expand Down Expand Up @@ -254,7 +254,7 @@ func EstimateGas(ctx *simulateContext, from, to *common.Address, data *hexutil.B
// Transferable amount is between the range [0, spendable), spendable = balance - gasFeeCap * GasLimit.
func RandomTransferableAmount(ctx *simulateContext, address common.Address, estimateGas uint64, gasFeeCap *big.Int) (amount *big.Int, err error) {
balance := ctx.keeper.GetBalance(ctx.context, address)
feeLimit := new(big.Int).Mul(gasFeeCap, big.NewInt(int64(estimateGas)))
feeLimit := new(big.Int).Mul(gasFeeCap, big.NewInt(int64(estimateGas))) //#nosec G115
if (feeLimit.Cmp(balance)) > 0 {
return nil, ErrNoEnoughBalance
}
Expand Down
4 changes: 2 additions & 2 deletions x/feemarket/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func (k *Keeper) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) {
// this will be keep BaseFee protected from un-penalized manipulation
// more info here https://github.com/evmos/ethermint/pull/1105#discussion_r888798925
minGasMultiplier := k.GetParams(ctx).MinGasMultiplier
limitedGasWanted := sdk.NewDec(int64(gasWanted)).Mul(minGasMultiplier)
gasWanted = sdk.MaxDec(limitedGasWanted, sdk.NewDec(int64(gasUsed))).TruncateInt().Uint64()
limitedGasWanted := sdk.NewDec(int64(gasWanted)).Mul(minGasMultiplier) //#nosec G115
gasWanted = sdk.MaxDec(limitedGasWanted, sdk.NewDec(int64(gasUsed))).TruncateInt().Uint64() //#nosec G115
k.SetBlockGasWanted(ctx, gasWanted)

defer func() {
Expand Down
2 changes: 1 addition & 1 deletion x/feemarket/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ func (k Keeper) BlockGas(c context.Context, _ *types.QueryBlockGasRequest) (*typ
gas := k.GetBlockGasWanted(ctx)

return &types.QueryBlockGasResponse{
Gas: int64(gas),
Gas: int64(gas), //#nosec G115
}, nil
}

0 comments on commit 62e533e

Please sign in to comment.