Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deep Source Security Issues #7617

Merged
merged 8 commits into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion beacon-chain/blockchain/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func reportSlotMetrics(stateSlot, headSlot, clockSlot uint64, finalizedCheckpoin
}

// reportEpochMetrics reports epoch related metrics.
func reportEpochMetrics(ctx context.Context, postState *stateTrie.BeaconState, headState *stateTrie.BeaconState) error {
func reportEpochMetrics(ctx context.Context, postState, headState *stateTrie.BeaconState) error {
currentEpoch := postState.Slot() / params.BeaconConfig().SlotsPerEpoch

// Validator instances
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/helpers/slot_epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func WeakSubjectivityCheckptEpoch(valCount uint64) (uint64, error) {

// VotingPeriodStartTime returns the current voting period's start time
// depending on the provided genesis and current slot.
func VotingPeriodStartTime(genesis uint64, slot uint64) uint64 {
func VotingPeriodStartTime(genesis, slot uint64) uint64 {
startTime := genesis
startTime +=
(slot - (slot % (params.BeaconConfig().EpochsPerEth1VotingPeriod * params.BeaconConfig().SlotsPerEpoch))) *
Expand Down
8 changes: 0 additions & 8 deletions beacon-chain/core/state/benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func BenchmarkExecuteStateTransition_FullBlock(b *testing.B) {
block, err := benchutil.PreGenFullBlock()
require.NoError(b, err)

b.N = runAmount
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := state.ExecuteStateTransition(context.Background(), cleanStates[i], block)
Expand All @@ -64,7 +63,6 @@ func BenchmarkExecuteStateTransition_WithCache(b *testing.B) {
_, err = state.ExecuteStateTransition(context.Background(), beaconState, block)
require.NoError(b, err, "Failed to process block, benchmarks will fail")

b.N = runAmount
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := state.ExecuteStateTransition(context.Background(), cleanStates[i], block)
Expand Down Expand Up @@ -97,7 +95,6 @@ func BenchmarkHashTreeRoot_FullState(b *testing.B) {
beaconState, err := benchutil.PreGenState2FullEpochs()
require.NoError(b, err)

b.N = 50
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := beaconState.HashTreeRoot(context.Background())
Expand All @@ -115,7 +112,6 @@ func BenchmarkHashTreeRootState_FullState(b *testing.B) {
_, err = beaconState.HashTreeRoot(ctx)
require.NoError(b, err)

b.N = 50
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := beaconState.HashTreeRoot(ctx)
Expand All @@ -131,7 +127,6 @@ func BenchmarkMarshalState_FullState(b *testing.B) {
b.Run("Proto_Marshal", func(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()
b.N = 1000
for i := 0; i < b.N; i++ {
_, err := proto.Marshal(natState)
require.NoError(b, err)
Expand All @@ -141,7 +136,6 @@ func BenchmarkMarshalState_FullState(b *testing.B) {
b.Run("Fast_SSZ_Marshal", func(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()
b.N = 1000
for i := 0; i < b.N; i++ {
_, err := natState.MarshalSSZ()
require.NoError(b, err)
Expand All @@ -161,7 +155,6 @@ func BenchmarkUnmarshalState_FullState(b *testing.B) {
b.Run("Proto_Unmarshal", func(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()
b.N = 1000
for i := 0; i < b.N; i++ {
require.NoError(b, proto.Unmarshal(protoObject, &pb.BeaconState{}))
}
Expand All @@ -170,7 +163,6 @@ func BenchmarkUnmarshalState_FullState(b *testing.B) {
b.Run("Fast_SSZ_Unmarshal", func(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()
b.N = 1000
for i := 0; i < b.N; i++ {
sszState := &pb.BeaconState{}
require.NoError(b, sszState.UnmarshalSSZ(sszObject))
Expand Down
1 change: 0 additions & 1 deletion beacon-chain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ func main() {

if err := app.Run(os.Args); err != nil {
log.Error(err.Error())
os.Exit(1)
}
}

Expand Down
2 changes: 0 additions & 2 deletions beacon-chain/rpc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ go_library(
"//beacon-chain/sync:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//proto/beacon/rpc/v1:go_default_library",
"//proto/slashing:go_default_library",
"//shared/featureconfig:go_default_library",
"//shared/params:go_default_library",
"//shared/traceutil:go_default_library",
Expand All @@ -41,7 +40,6 @@ go_library(
"@com_github_sirupsen_logrus//:go_default_library",
"@io_opencensus_go//plugin/ocgrpc:go_default_library",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//connectivity:go_default_library",
"@org_golang_google_grpc//credentials:go_default_library",
"@org_golang_google_grpc//peer:go_default_library",
"@org_golang_google_grpc//reflection:go_default_library",
Expand Down
20 changes: 6 additions & 14 deletions beacon-chain/rpc/beacon/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,33 +266,25 @@ func (bs *Server) chainHeadRetrieval(ctx context.Context) (*ethpb.ChainHead, err
return nil, status.Error(codes.Internal, "Could not get genesis block")
}

var b *ethpb.SignedBeaconBlock

finalizedCheckpoint := bs.FinalizationFetcher.FinalizedCheckpt()
if isGenesis(finalizedCheckpoint) {
b = genBlock
} else {
b, err = bs.BeaconDB.Block(ctx, bytesutil.ToBytes32(finalizedCheckpoint.Root))
if !isGenesis(finalizedCheckpoint) {
b, err := bs.BeaconDB.Block(ctx, bytesutil.ToBytes32(finalizedCheckpoint.Root))
if err != nil || b == nil || b.Block == nil {
return nil, status.Error(codes.Internal, "Could not get finalized block")
}
}

justifiedCheckpoint := bs.FinalizationFetcher.CurrentJustifiedCheckpt()
if isGenesis(justifiedCheckpoint) {
b = genBlock
} else {
b, err = bs.BeaconDB.Block(ctx, bytesutil.ToBytes32(justifiedCheckpoint.Root))
if !isGenesis(justifiedCheckpoint) {
b, err := bs.BeaconDB.Block(ctx, bytesutil.ToBytes32(justifiedCheckpoint.Root))
if err != nil || b == nil || b.Block == nil {
return nil, status.Error(codes.Internal, "Could not get justified block")
}
}

prevJustifiedCheckpoint := bs.FinalizationFetcher.PreviousJustifiedCheckpt()
if isGenesis(prevJustifiedCheckpoint) {
b = genBlock
} else {
b, err = bs.BeaconDB.Block(ctx, bytesutil.ToBytes32(prevJustifiedCheckpoint.Root))
if !isGenesis(prevJustifiedCheckpoint) {
b, err := bs.BeaconDB.Block(ctx, bytesutil.ToBytes32(prevJustifiedCheckpoint.Root))
if err != nil || b == nil || b.Block == nil {
return nil, status.Error(codes.Internal, "Could not get prev justified block")
}
Expand Down
59 changes: 0 additions & 59 deletions beacon-chain/rpc/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ import (
chainSync "github.com/prysmaticlabs/prysm/beacon-chain/sync"
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
pbrpc "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
slashpb "github.com/prysmaticlabs/prysm/proto/slashing"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/traceutil"
"github.com/sirupsen/logrus"
"go.opencensus.io/plugin/ocgrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/peer"
"google.golang.org/grpc/reflection"
Expand Down Expand Up @@ -95,11 +93,6 @@ type Service struct {
stateNotifier statefeed.Notifier
blockNotifier blockfeed.Notifier
operationNotifier opfeed.Notifier
slasherConn *grpc.ClientConn
slasherProvider string
slasherCert string
slasherCredentialError error
slasherClient slashpb.SlasherClient
stateGen *stategen.State
connectedRPCClients map[net.Addr]bool
clientConnectionLock sync.Mutex
Expand Down Expand Up @@ -133,8 +126,6 @@ type Config struct {
PeerManager p2p.PeerManager
DepositFetcher depositcache.DepositFetcher
PendingDepositFetcher depositcache.PendingDepositsFetcher
SlasherProvider string
SlasherCert string
StateNotifier statefeed.Notifier
BlockNotifier blockfeed.Notifier
OperationNotifier opfeed.Notifier
Expand Down Expand Up @@ -178,8 +169,6 @@ func NewService(ctx context.Context, cfg *Config) *Service {
stateNotifier: cfg.StateNotifier,
blockNotifier: cfg.BlockNotifier,
operationNotifier: cfg.OperationNotifier,
slasherProvider: cfg.SlasherProvider,
slasherCert: cfg.SlasherCert,
stateGen: cfg.StateGen,
enableDebugRPCEndpoints: cfg.EnableDebugRPCEndpoints,
connectedRPCClients: make(map[net.Addr]bool),
Expand Down Expand Up @@ -334,58 +323,13 @@ func (s *Service) Start() {
}()
}

func (s *Service) startSlasherClient() {
var dialOpt grpc.DialOption
if s.slasherCert != "" {
creds, err := credentials.NewClientTLSFromFile(s.slasherCert, "")
if err != nil {
log.Errorf("Could not get valid credentials: %v", err)
s.slasherCredentialError = err
}
dialOpt = grpc.WithTransportCredentials(creds)
} else {
dialOpt = grpc.WithInsecure()
log.Warn("You are using an insecure gRPC connection! Please provide a certificate and key to use a secure connection.")
}
slasherOpts := []grpc.DialOption{
dialOpt,
grpc.WithStatsHandler(&ocgrpc.ClientHandler{}),
grpc.WithStreamInterceptor(middleware.ChainStreamClient(
grpc_opentracing.StreamClientInterceptor(),
grpc_prometheus.StreamClientInterceptor,
)),
grpc.WithUnaryInterceptor(middleware.ChainUnaryClient(
grpc_opentracing.UnaryClientInterceptor(),
grpc_prometheus.UnaryClientInterceptor,
)),
}
conn, err := grpc.DialContext(s.ctx, s.slasherProvider, slasherOpts...)
if err != nil {
log.Errorf("Could not dial endpoint: %s, %v", s.slasherProvider, err)
return
}
if conn.GetState() != connectivity.Ready {
log.Errorf("Slasher status is %s, please verify slasher is up", conn.GetState())
return
}

log.Info("Successfully started hash slinging slasher©️ gRPC connection")
s.slasherConn = conn
s.slasherClient = slashpb.NewSlasherClient(s.slasherConn)
}

// Stop the service.
func (s *Service) Stop() error {
s.cancel()
if s.listener != nil {
s.grpcServer.GracefulStop()
log.Debug("Initiated graceful stop of gRPC server")
}
if s.slasherConn != nil {
if err := s.slasherConn.Close(); err != nil {
return err
}
}
return nil
}

Expand All @@ -394,9 +338,6 @@ func (s *Service) Status() error {
if s.credentialError != nil {
return s.credentialError
}
if s.slasherCredentialError != nil {
return s.slasherCredentialError
}
return nil
}

Expand Down
1 change: 0 additions & 1 deletion beacon-chain/state/stateutil/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func BenchmarkMerkleize_Buffered(b *testing.B) {

b.ResetTimer()
b.ReportAllocs()
b.N = 1000
for i := 0; i < b.N; i++ {
_, err := newMerkleize(roots, 8192, 8192)
require.NoError(b, err)
Expand Down
4 changes: 2 additions & 2 deletions shared/testutil/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestGenerateFullBlock_PassesStateTransition(t *testing.T) {
}
block, err := GenerateFullBlock(beaconState, privs, conf, beaconState.Slot())
require.NoError(t, err)
beaconState, err = state.ExecuteStateTransition(context.Background(), beaconState, block)
_, err = state.ExecuteStateTransition(context.Background(), beaconState, block)
require.NoError(t, err)
}

Expand All @@ -32,7 +32,7 @@ func TestGenerateFullBlock_ThousandValidators(t *testing.T) {
}
block, err := GenerateFullBlock(beaconState, privs, conf, beaconState.Slot())
require.NoError(t, err)
beaconState, err = state.ExecuteStateTransition(context.Background(), beaconState, block)
_, err = state.ExecuteStateTransition(context.Background(), beaconState, block)
require.NoError(t, err)
}

Expand Down
6 changes: 2 additions & 4 deletions shared/tos/tos.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ TERMS AND CONDITIONS: https://github.com/prysmaticlabs/prysm/blob/master/TERMS_O


Type "accept" to accept this terms and conditions [accept/decline]:`
acceptTosPromptErrText = `
Could not scan text input. If you are trying to run in non-interactive environment, you
acceptTosPromptErrText = `Could not scan text input, if you are trying to run in non-interactive environment, you
should use --accept-terms-of-use flag (only once) after reading the terms and conditions here:
https://github.com/prysmaticlabs/prysm/blob/master/TERMS_OF_SERVICE.md
`
https://github.com/prysmaticlabs/prysm/blob/master/TERMS_OF_SERVICE.md`
)

var (
Expand Down
5 changes: 0 additions & 5 deletions validator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os"
"runtime"
runtimeDebug "runtime/debug"
"time"

joonix "github.com/joonix/log"
"github.com/prysmaticlabs/prysm/shared/cmd"
Expand All @@ -27,9 +26,6 @@ import (
prefixed "github.com/x-cray/logrus-prefixed-formatter"
)

// connTimeout defines a period after which connection to beacon node is cancelled.
const connTimeout = 10 * time.Second

var log = logrus.WithField("prefix", "main")

func startNode(ctx *cli.Context) error {
Expand Down Expand Up @@ -172,6 +168,5 @@ func main() {

if err := app.Run(os.Args); err != nil {
log.Error(err.Error())
os.Exit(1)
}
}