Skip to content

Commit

Permalink
use upstream int overflow rule
Browse files Browse the repository at this point in the history
  • Loading branch information
gartnera committed Jul 10, 2024
1 parent 4c72d48 commit 0591d70
Show file tree
Hide file tree
Showing 69 changed files with 177 additions and 177 deletions.
4 changes: 2 additions & 2 deletions cmd/zetae2e/stress.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ func StressTest(cmd *cobra.Command, _ []string) {
// Get current nonce on zevm for DeployerAddress - Need to keep track of nonce at client level
blockNum := must(e2eTest.ZEVMClient.BlockNumber(ctx))

// #nosec G701 e2eTest - always in range
// #nosec G115 e2eTest - always in range
nonce := must(e2eTest.ZEVMClient.NonceAt(ctx, deployerAccount.EVMAddress(), big.NewInt(int64(blockNum))))

// #nosec G701 e2e - always in range
// #nosec G115 e2e - always in range
zevmNonce = big.NewInt(int64(nonce))

// -------------- TEST BEGINS ------------------
Expand Down
2 changes: 1 addition & 1 deletion cmd/zetatool/filterdeposit/btc.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func getHashList(cfg *config.Config, tssAddress string) ([]Deposit, error) {
if strings.Compare("0014", scriptpubkey[:4]) == 0 && targetAddr == tssAddress {
entry := Deposit{
hash,
// #nosec G701 parsing json requires float64 type from blockstream
// #nosec G115 parsing json requires float64 type from blockstream
uint64(vout0["value"].(float64)),
}
list = append(list, entry)
Expand Down
4 changes: 2 additions & 2 deletions cmd/zetatool/filterdeposit/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ func getTSSDeposits(tssAddress string, startBlock uint64, endBlock uint64, apiKe
client := etherscan.New(etherscan.Mainnet, apiKey)
deposits := make([]Deposit, 0)

// #nosec G701 these block numbers need to be *int for this particular client package
// #nosec G115 these block numbers need to be *int for this particular client package
startInt := int(startBlock)
// #nosec G701
// #nosec G115
endInt := int(endBlock)
txns, err := client.NormalTxByAddress(tssAddress, &startInt, &endInt, 0, 0, true)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion contrib/rpctest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func main() {
if bn < 0 {
panic("Block number must be non-negative")
}
// #nosec G701 check as positive
// #nosec G115 check as positive
bnUint64 := uint64(bn)

if false {
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2etests/test_update_bytecode_zrc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestUpdateBytecodeZRC20(r *runner.E2ERunner, _ []string) {
r.ZEVMAuth,
r.ZEVMClient,
big.NewInt(5),
// #nosec G701 test - always in range
// #nosec G115 test - always in range
uint8(coin.CoinType_Gas),
)
require.NoError(r, err)
Expand Down
6 changes: 3 additions & 3 deletions e2e/runner/accounting.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ func (r *E2ERunner) CheckBtcTSSBalance() error {

// check the balance in TSS is greater than the total supply on ZetaChain
// the amount minted to initialize the pool is subtracted from the total supply
// #nosec G701 test - always in range
// #nosec G115 test - always in range
if int64(btcBalance*1e8) < (zrc20Supply.Int64() - 10000000) {
// #nosec G701 test - always in range
// #nosec G115 test - always in range
return fmt.Errorf(
"BTC: TSS Balance (%d) < ZRC20 TotalSupply (%d)",
int64(btcBalance*1e8),
zrc20Supply.Int64()-10000000,
)
}
// #nosec G701 test - always in range
// #nosec G115 test - always in range
r.Logger.Info(
"BTC: Balance (%d) >= ZRC20 TotalSupply (%d)",
int64(btcBalance*1e8),
Expand Down
2 changes: 1 addition & 1 deletion e2e/runner/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (r *E2ERunner) ProveEthTransaction(receipt *ethtypes.Receipt) {
txHash := receipt.TxHash
blockHash := receipt.BlockHash

// #nosec G701 test - always in range
// #nosec G115 test - always in range
txIndex := int(receipt.TransactionIndex)

block, err := r.EVMClient.BlockByHash(r.Ctx, blockHash)
Expand Down
2 changes: 1 addition & 1 deletion pkg/chains/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

// NonceMarkAmount uses special value to mark current nonce in UTXO
func NonceMarkAmount(nonce uint64) int64 {
// #nosec G701 always in range
// #nosec G115 always in range
return int64(nonce) + BtcNonceMarkOffset()
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/coin/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func GetCoinType(coin string) (CoinType, error) {
if coinInt < 0 || coinInt > 3 {
return CoinType_Cmd, fmt.Errorf("invalid coin type %d", coinInt)
}
// #nosec G701 always in range
// #nosec G115 always in range
return CoinType(coinInt), nil
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/mempool/custom_proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (h *CustomProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHand
return func(ctx sdk.Context, req abci.RequestPrepareProposal) abci.ResponsePrepareProposal {
var maxBlockGas uint64
if b := ctx.ConsensusParams().Block; b != nil {
// #nosec G701 range checked, cosmos-sdk forked code
// #nosec G115 range checked, cosmos-sdk forked code
maxBlockGas = uint64(b.MaxGas)
}

Expand All @@ -89,7 +89,7 @@ func (h *CustomProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHand
// XXX: We pass nil as the memTx because we have no way of decoding the
// txBz. We'd need to break (update) the ProposalTxVerifier interface.
// As a result, we CANNOT account for block max gas.
// #nosec G701 range checked, cosmos-sdk forked code
// #nosec G115 range checked, cosmos-sdk forked code
stop := h.txSelector.SelectTxForProposal(uint64(req.MaxTxBytes), maxBlockGas, nil, txBz)
if stop {
break
Expand Down Expand Up @@ -148,7 +148,7 @@ func (h *CustomProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHand
panic(err)
}
} else {
// #nosec G701 range checked, cosmos-sdk forked code
// #nosec G115 range checked, cosmos-sdk forked code
stop := h.txSelector.SelectTxForProposal(uint64(req.MaxTxBytes), maxBlockGas, memTx, txBz)
if stop {
break
Expand Down Expand Up @@ -218,7 +218,7 @@ func (h *CustomProposalHandler) ProcessProposalHandler() sdk.ProcessProposalHand
totalTxGas += gasTx.GetGas()
}

// #nosec G701 range checked, cosmos-sdk forked code
// #nosec G115 range checked, cosmos-sdk forked code
if totalTxGas > uint64(maxBlockGas) {
return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/proofs/ethereum/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (m *Proof) Verify(rootHash common.Hash, key int) ([]byte, error) {
return nil, errors.New("key not found")
}
var indexBuf []byte
// #nosec G701 range is valid
// #nosec G115 range is valid
indexBuf = rlp.AppendUint64(indexBuf[:0], uint64(key))
return trie.VerifyProof(rootHash, indexBuf, m)
}
Expand All @@ -133,7 +133,7 @@ func (t *Trie) GenerateProof(txIndex int) (*Proof, error) {
return nil, errors.New("transaction index out of range")
}
var indexBuf []byte
// #nosec G701 checked as non-negative
// #nosec G115 checked as non-negative
indexBuf = rlp.AppendUint64(indexBuf[:0], uint64(txIndex))
proof := NewProof()
err := t.Prove(indexBuf, 0, proof)
Expand All @@ -157,7 +157,7 @@ func NewTrie(list types.DerivableList) Trie {
// order is correct.
var indexBuf []byte
for i := 1; i < list.Len() && i <= 0x7f; i++ {
// #nosec G701 iterator
// #nosec G115 iterator
indexBuf = rlp.AppendUint64(indexBuf[:0], uint64(i))
value := encodeForDerive(list, i, valueBuf)
hasher.Update(indexBuf, value)
Expand All @@ -168,7 +168,7 @@ func NewTrie(list types.DerivableList) Trie {
hasher.Update(indexBuf, value)
}
for i := 0x80; i < list.Len(); i++ {
// #nosec G701 iterator
// #nosec G115 iterator
indexBuf = rlp.AppendUint64(indexBuf[:0], uint64(i))
value := encodeForDerive(list, i, valueBuf)
hasher.Update(indexBuf, value)
Expand Down
2 changes: 1 addition & 1 deletion pkg/proofs/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func NewBitcoinProof(txBytes []byte, path []byte, index uint) *Proof {
BitcoinProof: &bitcoin.Proof{
TxBytes: txBytes,
Path: path,
// #nosec G701 always in range
// #nosec G115 always in range
Index: uint32(index),
},
},
Expand Down
4 changes: 2 additions & 2 deletions rpc/backend/account_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (b *Backend) GetProof(
return nil, fmt.Errorf("not able to query block number greater than MaxInt64")
}

// #nosec G701 range checked
// #nosec G115 range checked
height = int64(bn)
}

Expand Down Expand Up @@ -212,7 +212,7 @@ func (b *Backend) GetTransactionCount(address common.Address, blockNum rpctypes.
return nil, fmt.Errorf("not able to query block number greater than MaxInt64")
}
height := blockNum.Int64()
// #nosec G701 range checked
// #nosec G115 range checked
currentHeight := int64(bn)

if height > currentHeight {
Expand Down
10 changes: 5 additions & 5 deletions rpc/backend/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (b *Backend) TendermintBlockByNumber(blockNum rpctypes.BlockNumber) (*tmrpc
if n > math.MaxInt64 {
return nil, fmt.Errorf("block number %d is greater than max int64", n)
}
// #nosec G701 range checked
// #nosec G115 range checked
height = int64(n)
}
resBlock, err := b.clientCtx.Client.Block(b.ctx, &height)
Expand Down Expand Up @@ -494,15 +494,15 @@ func (b *Backend) RPCBlockFromTendermintBlock(
rpcTx, err = rpctypes.NewRPCTransaction(
tx,
common.BytesToHash(block.Hash()),
// #nosec G701 non negative value
// #nosec G115 non negative value
uint64(block.Height),
// #nosec G701 non negative value
// #nosec G115 non negative value
uint64(txIndex),
baseFee,
b.chainID,
)
} else {
// #nosec G701 non negative value
// #nosec G115 non negative value
rpcTx, err = rpctypes.NewRPCTransactionFromIncompleteMsg(ethMsg, common.BytesToHash(block.Hash()), uint64(block.Height), uint64(txIndex), baseFee, b.chainID, txsAdditional[txIndex])
}
if err != nil {
Expand Down Expand Up @@ -556,7 +556,7 @@ func (b *Backend) RPCBlockFromTendermintBlock(
// block gas limit has exceeded, other txs must have failed with same reason.
break
}
// #nosec G701 non negative value
// #nosec G115 non negative value
gasUsed += uint64(txsResult.GetGasUsed())
}

Expand Down
8 changes: 4 additions & 4 deletions rpc/backend/chain_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,14 @@ func (b *Backend) FeeHistory(
if blockNumber > math.MaxInt64 {
return nil, fmt.Errorf("not able to query block number greater than MaxInt64")
}
// #nosec G701 range checked
// #nosec G115 range checked
blockEnd = int64(blockNumber)
}

if userBlockCount > math.MaxInt64 {
return nil, fmt.Errorf("not able to query block count greater than MaxInt64")
}
// #nosec G701 range checked
// #nosec G115 range checked
blocks := int64(userBlockCount)
maxBlockCount := int64(b.cfg.JSONRPC.FeeHistoryCap)
if blocks > maxBlockCount {
Expand Down Expand Up @@ -220,7 +220,7 @@ func (b *Backend) FeeHistory(

// fetch block
for blockID := blockStart; blockID <= blockEnd; blockID++ {
// #nosec G701 range checked
// #nosec G115 range checked
index := int32(blockID - blockStart)
// tendermint block
tendermintblock, err := b.TendermintBlockByNumber(rpctypes.BlockNumber(blockID))
Expand Down Expand Up @@ -297,7 +297,7 @@ func (b *Backend) SuggestGasTipCap(baseFee *big.Int) (*big.Int, error) {
// MaxDelta = BaseFee * (GasLimit - GasLimit / ElasticityMultiplier) / (GasLimit / ElasticityMultiplier) / Denominator
// = BaseFee * (ElasticityMultiplier - 1) / Denominator
// ```
// #nosec G701 range checked
// #nosec G115 range checked
maxDelta := baseFee.Int64() * (int64(params.Params.ElasticityMultiplier) - 1) / int64(
params.Params.BaseFeeChangeDenominator,
)
Expand Down
28 changes: 14 additions & 14 deletions rpc/backend/tx_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (b *Backend) GetTransactionByHash(txHash common.Hash) (*rpctypes.RPCTransac
var ethMsg *evmtypes.MsgEthereumTx
// if additional fields are empty we can try to get MsgEthereumTx from sdk.Msg array
if additional == nil {
// #nosec G701 always in range
// #nosec G115 always in range
if int(res.TxIndex) >= len(resBlock.Block.Txs) {
b.logger.Error("tx out of bounds")
return nil, fmt.Errorf("tx out of bounds")
Expand Down Expand Up @@ -85,7 +85,7 @@ func (b *Backend) GetTransactionByHash(txHash common.Hash) (*rpctypes.RPCTransac
msgs, _ := b.EthMsgsFromTendermintBlock(resBlock, blockRes)
for i := range msgs {
if msgs[i].Hash == hexTx {
// #nosec G701 always in range
// #nosec G115 always in range
res.EthTxIndex = int32(i)
break
}
Expand Down Expand Up @@ -115,9 +115,9 @@ func (b *Backend) GetTransactionByHash(txHash common.Hash) (*rpctypes.RPCTransac
return rpctypes.NewTransactionFromMsg(
ethMsg,
common.BytesToHash(resBlock.BlockID.Hash.Bytes()),
// #nosec G701 always positive
// #nosec G115 always positive
uint64(res.Height),
// #nosec G701 always positive
// #nosec G115 always positive
uint64(res.EthTxIndex),
baseFee,
b.chainID,
Expand Down Expand Up @@ -184,7 +184,7 @@ func (b *Backend) GetTransactionReceipt(hash common.Hash) (map[string]interface{
var ethMsg *evmtypes.MsgEthereumTx
// if additional fields are empty we can try to get MsgEthereumTx from sdk.Msg array
if additional == nil {
// #nosec G701 always in range
// #nosec G115 always in range
if int(res.TxIndex) >= len(resBlock.Block.Txs) {
b.logger.Error("tx out of bounds")
return nil, fmt.Errorf("tx out of bounds")
Expand Down Expand Up @@ -221,7 +221,7 @@ func (b *Backend) GetTransactionReceipt(hash common.Hash) (map[string]interface{
return nil, nil
}
for _, txResult := range blockRes.TxsResults[0:res.TxIndex] {
// #nosec G701 always positive
// #nosec G115 always positive
cumulativeGasUsed += uint64(txResult.GasUsed)
}
cumulativeGasUsed += res.CumulativeGasUsed
Expand Down Expand Up @@ -251,7 +251,7 @@ func (b *Backend) GetTransactionReceipt(hash common.Hash) (map[string]interface{
}

// parse tx logs from events
// #nosec G701 always in range
// #nosec G115 always in range
logs, err := TxLogsFromEvents(blockRes.TxsResults[res.TxIndex].Events, int(res.MsgIndex))
if err != nil {
b.logger.Debug("failed to parse logs", "hash", hexTx, "error", err.Error())
Expand All @@ -262,7 +262,7 @@ func (b *Backend) GetTransactionReceipt(hash common.Hash) (map[string]interface{
msgs, _ := b.EthMsgsFromTendermintBlock(resBlock, blockRes)
for i := range msgs {
if msgs[i].Hash == hexTx {
// #nosec G701 always in range
// #nosec G115 always in range
res.EthTxIndex = int32(i)
break
}
Expand All @@ -281,7 +281,7 @@ func (b *Backend) GetTransactionReceipt(hash common.Hash) (map[string]interface{
var txType uint8

if txData == nil {
// #nosec G701 always in range
// #nosec G115 always in range
txType = uint8(additional.Type)
*to = additional.Recipient
} else {
Expand Down Expand Up @@ -411,7 +411,7 @@ func (b *Backend) GetTxByTxIndex(
index uint,
) (*ethermint.TxResult, *rpctypes.TxResultAdditionalFields, error) {
if b.indexer != nil {
// #nosec G701 always in range
// #nosec G115 always in range
txRes, err := b.indexer.GetByBlockAndIndex(height, int32(index))
if err == nil {
return txRes, nil, nil
Expand All @@ -424,7 +424,7 @@ func (b *Backend) GetTxByTxIndex(
evmtypes.AttributeKeyTxIndex, index,
)
txResult, txAdditional, err := b.queryTendermintTxIndexer(query, func(txs *rpctypes.ParsedTxs) *rpctypes.ParsedTx {
// #nosec G701 always in range
// #nosec G115 always in range
return txs.GetTxByTxIndex(int(index))
})
if err != nil {
Expand Down Expand Up @@ -472,7 +472,7 @@ func (b *Backend) GetTransactionByBlockAndIndex(
return nil, nil
}

// #nosec G701 always in range
// #nosec G115 always in range
i := int(idx)
ethMsgs, additionals := b.EthMsgsFromTendermintBlock(block, blockRes)
if i >= len(ethMsgs) {
Expand All @@ -497,9 +497,9 @@ func (b *Backend) GetTransactionByBlockAndIndex(
return rpctypes.NewTransactionFromMsg(
msg,
common.BytesToHash(block.Block.Hash()),
// #nosec G701 always positive
// #nosec G115 always positive
uint64(block.Block.Height),
// #nosec G701 always positive
// #nosec G115 always positive
uint64(idx),
baseFee,
b.chainID,
Expand Down
Loading

0 comments on commit 0591d70

Please sign in to comment.