From c2200abcdde31411887e3b4750ce3df572cc63d8 Mon Sep 17 00:00:00 2001 From: hacheigriega Date: Tue, 26 Nov 2024 21:18:20 +0000 Subject: [PATCH] chore: make SEDAKeyIndex uint32 to avoid integer overflow conversion --- app/utils/seda_keys.go | 2 +- proto/buf.yaml | 2 +- proto/sedachain/batching/v1/batching.proto | 4 +++- proto/sedachain/batching/v1/query.proto | 4 ++-- x/batching/keeper/endblock.go | 4 ++-- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/utils/seda_keys.go b/app/utils/seda_keys.go index 9fe78c20..bcb6c2d0 100644 --- a/app/utils/seda_keys.go +++ b/app/utils/seda_keys.go @@ -20,7 +20,7 @@ import ( ) // SEDAKeyIndex enumerates the SEDA key indices. -type SEDAKeyIndex uint8 +type SEDAKeyIndex uint32 const ( SEDAKeyIndexSecp256k1 SEDAKeyIndex = iota diff --git a/proto/buf.yaml b/proto/buf.yaml index c9aa9081..3d213e18 100644 --- a/proto/buf.yaml +++ b/proto/buf.yaml @@ -10,7 +10,7 @@ breaking: - FILE lint: use: - - STANDARD + - DEFAULT - COMMENTS - FILE_LOWER_SNAKE_CASE except: diff --git a/proto/sedachain/batching/v1/batching.proto b/proto/sedachain/batching/v1/batching.proto index 6d468959..4241d035 100644 --- a/proto/sedachain/batching/v1/batching.proto +++ b/proto/sedachain/batching/v1/batching.proto @@ -34,7 +34,9 @@ message DataResultTreeEntries { repeated bytes entries = 1; } // ValidatorTreeEntry is an entry in the validator tree. message ValidatorTreeEntry { - bytes validator_address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress"]; + bytes validator_address = 1 + [ (gogoproto.casttype) = + "github.com/cosmos/cosmos-sdk/types.ValAddress" ]; uint32 voting_power_percent = 2; Secp256k1Entry secp256k1 = 3 [ (gogoproto.nullable) = false ]; } diff --git a/proto/sedachain/batching/v1/query.proto b/proto/sedachain/batching/v1/query.proto index 563ae916..cda472c0 100644 --- a/proto/sedachain/batching/v1/query.proto +++ b/proto/sedachain/batching/v1/query.proto @@ -36,7 +36,7 @@ service Query { } } -// BatchWithEntries is used by Batch Query to return a batch with its +// BatchWithEntries is used by Batch Query to return a batch with its // data result tree entries and validator tree entries. message BatchWithEntries { Batch batch = 1 [ (gogoproto.nullable) = false ]; @@ -66,7 +66,7 @@ message QueryBatchForHeightResponse { message QueryBatchesRequest { // pagination defines an optional pagination for the request. cosmos.base.query.v1beta1.PageRequest pagination = 1; - // with_unsigned indicates whether to return batches without + // with_unsigned indicates whether to return batches without // signatures or not. bool with_unsigned = 2; } diff --git a/x/batching/keeper/endblock.go b/x/batching/keeper/endblock.go index a2da07ce..cadb07da 100644 --- a/x/batching/keeper/endblock.go +++ b/x/batching/keeper/endblock.go @@ -182,13 +182,13 @@ func (k Keeper) ConstructValidatorTree(ctx sdk.Context) ([]types.ValidatorTreeEn } separator := []byte{utils.SEDASeparatorSecp256k1} - powerPercent := math.NewInt(power).MulRaw(1e8).Quo(totalPower).Uint64() + //nolint:gosec // G115: Max of powerPercent should be 1e8 < 2^64. + powerPercent := uint32(math.NewInt(power).MulRaw(1e8).Quo(totalPower).Uint64()) // A tree entry is (domain_separator | address | voting_power_percentage). treeEntry := make([]byte, len(separator)+len(ethAddr)+4) copy(treeEntry[:len(separator)], separator) copy(treeEntry[len(separator):len(separator)+len(ethAddr)], ethAddr) - //nolint:gosec // G115: Max of powerPercent should be 1e8 < 2^64. binary.BigEndian.PutUint32(treeEntry[len(separator)+len(ethAddr):], uint32(powerPercent)) entries = append(entries, types.ValidatorTreeEntry{