Skip to content

Commit

Permalink
chore: incorporate audit recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
hacheigriega committed Mar 13, 2024
1 parent 121923b commit 6e05483
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 1,149 deletions.
4 changes: 2 additions & 2 deletions cmd/sedad/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ func readInMnemonic(cmd *cobra.Command) (string, error) {

func configureValidatorFiles(config *cfg.Config) error {
keyFilePath := config.PrivValidatorKeyFile()
if err := os.MkdirAll(filepath.Dir(keyFilePath), 0o777); err != nil {
if err := os.MkdirAll(filepath.Dir(keyFilePath), 0o755); err != nil {
return fmt.Errorf("could not create directory %q: %w", filepath.Dir(keyFilePath), err)
}
stateFilePath := config.PrivValidatorStateFile()
if err := os.MkdirAll(filepath.Dir(stateFilePath), 0o777); err != nil {
if err := os.MkdirAll(filepath.Dir(stateFilePath), 0o755); err != nil {
return fmt.Errorf("could not create directory %q: %w", filepath.Dir(stateFilePath), err)
}

Expand Down
4 changes: 2 additions & 2 deletions e2e/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ func (v *validator) createConsensusKey() error {
config.Moniker = v.moniker

pvKeyFile := config.PrivValidatorKeyFile()
if err := tmos.EnsureDir(filepath.Dir(pvKeyFile), 0o777); err != nil {
if err := tmos.EnsureDir(filepath.Dir(pvKeyFile), 0o755); err != nil {
return err
}

pvStateFile := config.PrivValidatorStateFile()
if err := tmos.EnsureDir(filepath.Dir(pvStateFile), 0o777); err != nil {
if err := tmos.EnsureDir(filepath.Dir(pvStateFile), 0o755); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.21
require (
cosmossdk.io/api v0.7.2
cosmossdk.io/client/v2 v2.0.0-beta.1
cosmossdk.io/collections v0.4.0
cosmossdk.io/core v0.11.0
cosmossdk.io/errors v1.0.1
cosmossdk.io/log v1.3.0
Expand Down Expand Up @@ -32,6 +33,7 @@ require (
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2
github.com/hashicorp/go-metrics v0.5.2
github.com/hashicorp/go-plugin v1.5.2
github.com/ory/dockertest/v3 v3.10.0
github.com/pkg/errors v0.9.1
github.com/sedaprotocol/vrf-go v0.0.0-20231211075603-e5a17bb0b87c
Expand All @@ -51,7 +53,6 @@ require (
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.5 // indirect
cloud.google.com/go/storage v1.35.1 // indirect
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/x/nft v0.1.0 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
Expand Down Expand Up @@ -137,7 +138,6 @@ require (
github.com/hashicorp/go-getter v1.7.3 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-plugin v1.5.2 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
Expand Down
6 changes: 0 additions & 6 deletions go.work

This file was deleted.

1,129 changes: 0 additions & 1,129 deletions go.work.sum

This file was deleted.

19 changes: 12 additions & 7 deletions x/staking/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"fmt"
stdmath "math"

"cosmossdk.io/math"
Expand Down Expand Up @@ -52,36 +53,40 @@ func (k Keeper) TransferDelegation(ctx context.Context, fromAddr, toAddr sdk.Acc
// Check redelegation entry limits while we can still return early.
// Assume the worst case that we need to transfer all redelegation entries
mightExceedLimit := false
var cbErr error
err = k.IterateDelegatorRedelegations(ctx, fromAddr, func(toRedelegation types.Redelegation) (stop bool) {
// There's no redelegation index by delegator and dstVal or vice-versa.
// The minimum cardinality is to look up by delegator, so scan and skip.
if toRedelegation.ValidatorDstAddress != valAddr.String() {
return false
}

maxEntries, err := k.MaxEntries(ctx)
if err != nil {
panic(err)
cbErr = fmt.Errorf("error getting max entries: %w", err)
return true
}

valSrcAddr, err := sdk.ValAddressFromBech32(toRedelegation.ValidatorSrcAddress)
if err != nil {
panic(err)
cbErr = fmt.Errorf("error getting validator source address: %w", err)
return true
}
valDstAddr, err := sdk.ValAddressFromBech32(toRedelegation.ValidatorDstAddress)
if err != nil {
panic(err)
cbErr = fmt.Errorf("error getting validator destination address: %w", err)
return true
}

fromRedelegation, err := k.GetRedelegation(ctx, fromAddr, valSrcAddr, valDstAddr)
if err == nil && len(toRedelegation.Entries)+len(fromRedelegation.Entries) >= int(maxEntries) {
mightExceedLimit = true
return true
}
return false
})
if cbErr != nil {
return transferred, cbErr
}
if err != nil {
return transferred, nil
return transferred, err
}
if mightExceedLimit {
// avoid types.ErrMaxRedelegationEntries
Expand Down
2 changes: 1 addition & 1 deletion x/vesting/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func (m msgServer) Clawback(goCtx context.Context, msg *types.MsgClawback) (*typ
}

if !toClawBackStaking.IsZero() {
panic("failed to claw back full amount")
return nil, fmt.Errorf("failed to claw back full amount")
}
}

Expand Down

0 comments on commit 6e05483

Please sign in to comment.