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

Pseudo slashing for invalid signers #4269

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
8da8b53
added new field for consensus message - InvalidSigners
ssd04 Jul 4, 2022
765a83b
first implementation for pseudo slashing
ssd04 Jul 6, 2022
514622f
temp version for p2p pubsub
ssd04 Jul 6, 2022
6dcfb39
add custom type for invalid signers
ssd04 Jul 7, 2022
7b78941
first implementation for pseudo slashing: fix unit tests
ssd04 Jul 7, 2022
947f8b8
validity checks for invalisSigners consensus message type + use json …
ssd04 Jul 7, 2022
044b165
p2p: added additional field with marshalled pubsub message to p2p mes…
ssd04 Jul 8, 2022
c2dece2
use original marshalled p2p message instead of json marshalling
ssd04 Jul 8, 2022
c70ac05
added new field for consensus message - number of InvalidSigners
ssd04 Jul 11, 2022
d5e629f
reverted new field for consensus message - number of InvalidSigners
ssd04 Jul 12, 2022
46968f9
added interface for p2p message handling
ssd04 Jul 12, 2022
fbdc098
use p2p message signing component in subround endround
ssd04 Jul 12, 2022
5e2d918
subround endround: unit test for invalid signers verification
ssd04 Jul 12, 2022
53e3bec
p2p: remove marshalled data field
ssd04 Jul 13, 2022
d01da9f
consensus: use p2p message instead of marshalled data
ssd04 Jul 13, 2022
73c46eb
unit tests for consensus core and message validator
ssd04 Jul 13, 2022
9919dc3
cleanup unused core:
ssd04 Jul 13, 2022
a0b5f11
consensus: more unit tests for end round + comment updates
ssd04 Jul 13, 2022
fccb94d
flag check for invalid signers + peer honesty change
ssd04 Jul 13, 2022
6cd0194
fix should send flag on error
ssd04 Jul 13, 2022
d185fe3
bls worker: more checks for invalid signers consensus message
ssd04 Jul 19, 2022
4736186
bls worker: more checks for invalid signers consensus message - fix u…
ssd04 Jul 19, 2022
887d6ed
use single signer to verify sig share; add keyGenerator to consensus …
ssd04 Jul 19, 2022
c818111
use single signer to verify sig share; add keyGenerator to consensus …
ssd04 Jul 19, 2022
9250e77
fix mocks: remove reference to peer blacklist
ssd04 Jul 19, 2022
86e1b51
add message signer mock
ssd04 Jul 19, 2022
4f3b53f
consensus state: rlock for get message with signature
ssd04 Aug 2, 2022
984ac90
Merge branch 'feat/optimise-consensus-sigcheck' into pseudo-slashing-…
ssd04 Sep 15, 2022
67f385a
spos endround: comments and log updates
ssd04 Sep 15, 2022
e6609d0
consensus worker: remove TODO comment
ssd04 Sep 15, 2022
d759b60
Merge branch 'feat/optimise-consensus-sigcheck' into merge-optimize-c…
ssd04 Sep 26, 2022
33334b0
Merge pull request #4509 from ElrondNetwork/merge-optimize-consensus-…
ssd04 Sep 26, 2022
f850519
Merge branch 'feat/optimise-consensus-sigcheck' into merge-optimize-c…
ssd04 Oct 5, 2022
f60633f
Merge pull request #4557 from ElrondNetwork/merge-optimize-consensus-…
ssd04 Oct 5, 2022
4272475
fixes after review: more check, small refactoring, comments update
ssd04 Oct 19, 2022
d92dc33
fix linter issue
ssd04 Oct 19, 2022
387e6f9
added more unit tests for received invalid signers info
ssd04 Oct 19, 2022
63d7e98
fix comment typo
ssd04 Oct 20, 2022
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
8 changes: 8 additions & 0 deletions consensus/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ type ScheduledProcessor interface {
IsInterfaceNil() bool
}

// P2PSigningHandler defines the behaviour of a component able to verify p2p message signature
type P2PSigningHandler interface {
Verify(message p2p.MessageP2P) error
Serialize(messages []p2p.MessageP2P) ([]byte, error)
Deserialize(messagesBytes []byte) ([]p2p.MessageP2P, error)
IsInterfaceNil() bool
}

// SignatureHandler defines the behaviour of a component that handles signatures in consensus
type SignatureHandler interface {
Reset(pubKeys []string) error
Expand Down
2 changes: 2 additions & 0 deletions consensus/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func NewConsensusMessage(
aggregateSignature []byte,
leaderSignature []byte,
currentPid core.PeerID,
invalidSigners []byte,
) *Message {
return &Message{
BlockHeaderHash: blHeaderHash,
Expand All @@ -36,5 +37,6 @@ func NewConsensusMessage(
AggregateSignature: aggregateSignature,
LeaderSignature: leaderSignature,
OriginatorPid: currentPid.Bytes(),
InvalidSigners: invalidSigners,
}
}
116 changes: 88 additions & 28 deletions consensus/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions consensus/message.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ message Message {
bytes AggregateSignature = 11;
bytes LeaderSignature = 12;
bytes OriginatorPid = 13;
bytes InvalidSigners = 14;
}
1 change: 1 addition & 0 deletions consensus/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func TestConsensusMessage_NewConsensusMessageShouldWork(t *testing.T) {
nil,
nil,
"pid",
nil,
)

assert.NotNil(t, cnsMsg)
Expand Down
24 changes: 23 additions & 1 deletion consensus/mock/consensusDataContainerMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type ConsensusCoreMock struct {
marshalizer marshal.Marshalizer
blsPrivateKey crypto.PrivateKey
blsSingleSigner crypto.SingleSigner
keyGenerator crypto.KeyGenerator
multiSignerContainer cryptoCommon.MultiSignerContainer
roundHandler consensus.RoundHandler
shardCoordinator sharding.Coordinator
Expand All @@ -38,6 +39,7 @@ type ConsensusCoreMock struct {
fallbackHeaderValidator consensus.FallbackHeaderValidator
nodeRedundancyHandler consensus.NodeRedundancyHandler
scheduledProcessor consensus.ScheduledProcessor
messageSigningHandler consensus.P2PSigningHandler
signatureHandler consensus.SignatureHandler
}

Expand Down Expand Up @@ -186,11 +188,16 @@ func (ccm *ConsensusCoreMock) PrivateKey() crypto.PrivateKey {
return ccm.blsPrivateKey
}

// SingleSigner returns the bls single signer stored in the ConsensusStore
// SingleSigner returns the bls single signer stored in the ConsensusCore
func (ccm *ConsensusCoreMock) SingleSigner() crypto.SingleSigner {
return ccm.blsSingleSigner
}

// KeyGenerator -
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L191: ConsensusCore instead ConsensusStore and also in some other files (2 more files)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

func (ccm *ConsensusCoreMock) KeyGenerator() crypto.KeyGenerator {
return ccm.keyGenerator
}

// PeerHonestyHandler -
func (ccm *ConsensusCoreMock) PeerHonestyHandler() consensus.PeerHonestyHandler {
return ccm.peerHonestyHandler
Expand Down Expand Up @@ -231,6 +238,21 @@ func (ccm *ConsensusCoreMock) SetNodeRedundancyHandler(nodeRedundancyHandler con
ccm.nodeRedundancyHandler = nodeRedundancyHandler
}

// MessageSigningHandler -
func (ccm *ConsensusCoreMock) MessageSigningHandler() consensus.P2PSigningHandler {
return ccm.messageSigningHandler
}

// SetMessageSigningHandler -
func (ccm *ConsensusCoreMock) SetMessageSigningHandler(messageSigningHandler consensus.P2PSigningHandler) {
ccm.messageSigningHandler = messageSigningHandler
}

// SetKeyGenerator -
func (ccm *ConsensusCoreMock) SetKeyGenerator(keyGenerator crypto.KeyGenerator) {
ccm.keyGenerator = keyGenerator
}

// SignatureHandler -
func (ccm *ConsensusCoreMock) SignatureHandler() consensus.SignatureHandler {
return ccm.signatureHandler
Expand Down
14 changes: 11 additions & 3 deletions consensus/mock/keyGenMock.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mock

import (
"github.com/ElrondNetwork/elrond-go-crypto"
crypto "github.com/ElrondNetwork/elrond-go-crypto"
)

// PrivateKeyMock mocks a private key implementation
Expand Down Expand Up @@ -84,12 +84,20 @@ func (keyGen *KeyGenMock) GeneratePair() (crypto.PrivateKey, crypto.PublicKey) {

// PrivateKeyFromByteArray generates the private key from it's byte array representation
func (keyGen *KeyGenMock) PrivateKeyFromByteArray(b []byte) (crypto.PrivateKey, error) {
return keyGen.PrivateKeyFromByteArrayMock(b)
if keyGen.PrivateKeyFromByteArrayMock != nil {
return keyGen.PrivateKeyFromByteArrayMock(b)
}

return &PrivateKeyMock{}, nil
}

// PublicKeyFromByteArray generates a public key from it's byte array representation
func (keyGen *KeyGenMock) PublicKeyFromByteArray(b []byte) (crypto.PublicKey, error) {
return keyGen.PublicKeyFromByteArrayMock(b)
if keyGen.PublicKeyFromByteArrayMock != nil {
return keyGen.PublicKeyFromByteArrayMock(b)
}

return &PublicKeyMock{}, nil
}

// CheckPublicKeyValid verifies the validity of the public key
Expand Down
48 changes: 48 additions & 0 deletions consensus/mock/messageSigningHandlerMock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package mock

import (
"encoding/json"

"github.com/ElrondNetwork/elrond-go/p2p"
"github.com/ElrondNetwork/elrond-go/p2p/message"
)

// MessageSignerMock implements P2PSigningHandler interface but it does nothing as it is disabled
type MessageSignerMock struct {
}

// Verify does nothing
func (ms *MessageSignerMock) Verify(message p2p.MessageP2P) error {
return nil
}

// Serialize will serialize the list of p2p messages
func (ms *MessageSignerMock) Serialize(messages []p2p.MessageP2P) ([]byte, error) {
messagesBytes, err := json.Marshal(messages)
if err != nil {
return nil, err
}

return messagesBytes, nil
}

// Deserialize will unmarshal into a list of p2p messages
func (ms *MessageSignerMock) Deserialize(messagesBytes []byte) ([]p2p.MessageP2P, error) {
var messages []*message.Message
err := json.Unmarshal(messagesBytes, &messages)
if err != nil {
return nil, err
}

messages2 := make([]p2p.MessageP2P, 0)
for _, msg := range messages {
messages2 = append(messages2, msg)
}

return messages2, nil
}

// IsInterfaceNil returns true if there is no value under the interface
func (ms *MessageSignerMock) IsInterfaceNil() bool {
return ms == nil
}