Skip to content

Commit

Permalink
chore: make SEDAKeyIndex uint32 to avoid integer overflow conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
hacheigriega committed Nov 26, 2024
1 parent 00a6060 commit c2200ab
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/utils/seda_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
)

// SEDAKeyIndex enumerates the SEDA key indices.
type SEDAKeyIndex uint8
type SEDAKeyIndex uint32

const (
SEDAKeyIndexSecp256k1 SEDAKeyIndex = iota
Expand Down
2 changes: 1 addition & 1 deletion proto/buf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ breaking:
- FILE
lint:
use:
- STANDARD
- DEFAULT
- COMMENTS
- FILE_LOWER_SNAKE_CASE
except:
Expand Down
4 changes: 3 additions & 1 deletion proto/sedachain/batching/v1/batching.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
}
Expand Down
4 changes: 2 additions & 2 deletions proto/sedachain/batching/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions x/batching/keeper/endblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Check failure on line 192 in x/batching/keeper/endblock.go

View workflow job for this annotation

GitHub Actions / golangci

unnecessary conversion (unconvert)

entries = append(entries, types.ValidatorTreeEntry{
Expand Down

0 comments on commit c2200ab

Please sign in to comment.