Skip to content

Commit

Permalink
enable cryptorand analyzer in slasher (prysmaticlabs#7417)
Browse files Browse the repository at this point in the history
  • Loading branch information
farazdagi authored Oct 2, 2020
1 parent b589ddd commit e36e925
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
1 change: 1 addition & 0 deletions nogo_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"only_files": {
"beacon-chain/.*": "",
"shared/.*": "",
"slasher/.*": "",
"validator/.*": ""
},
"exclude_files": {
Expand Down
1 change: 1 addition & 0 deletions slasher/db/testing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/slasher/db/testing",
visibility = ["//slasher:__subpackages__"],
deps = [
"//shared/rand:go_default_library",
"//shared/testutil:go_default_library",
"//slasher/db:go_default_library",
"//slasher/db/kv:go_default_library",
Expand Down
8 changes: 2 additions & 6 deletions slasher/db/testing/setup_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,20 @@
package testing

import (
"crypto/rand"
"fmt"
"math/big"
"os"
"path"
"testing"

"github.com/prysmaticlabs/prysm/shared/rand"
"github.com/prysmaticlabs/prysm/shared/testutil"
slasherDB "github.com/prysmaticlabs/prysm/slasher/db"
"github.com/prysmaticlabs/prysm/slasher/db/kv"
)

// SetupSlasherDB instantiates and returns a SlasherDB instance.
func SetupSlasherDB(t testing.TB, spanCacheEnabled bool) *kv.Store {
randPath, err := rand.Int(rand.Reader, big.NewInt(1000000))
if err != nil {
t.Fatalf("Could not generate random file path: %v", err)
}
randPath := rand.NewDeterministicGenerator().Int()
p := path.Join(testutil.TempDir(), fmt.Sprintf("/%d", randPath))
if err := os.RemoveAll(p); err != nil {
t.Fatalf("Failed to remove directory: %v", err)
Expand Down
1 change: 1 addition & 0 deletions slasher/detection/testing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//shared/params:go_default_library",
"//shared/rand:go_default_library",
"@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_default_library",
],
)
6 changes: 3 additions & 3 deletions slasher/detection/testing/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
package testing

import (
"crypto/rand"

ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/rand"
)

// SignedBlockHeader given slot, proposer index this function generates signed block header.
Expand Down Expand Up @@ -43,7 +42,8 @@ func BlockHeader(slot uint64, proposerIdx uint64) (*ethpb.BeaconBlockHeader, err

func genRandomByteArray(length int) ([]byte, error) {
blk := make([]byte, length)
_, err := rand.Read(blk)
randGen := rand.NewDeterministicGenerator()
_, err := randGen.Read(blk)
return blk, err
}

Expand Down

0 comments on commit e36e925

Please sign in to comment.