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

Signature handler component for consensus #4316

Merged
merged 20 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
811288a
added signing component for consensus:
ssd04 Jul 22, 2022
379055d
consensus signing: unit tests for aggSig and verifyAggSig
ssd04 Jul 22, 2022
4cb32fc
consensus: added signature handler interface
ssd04 Jul 22, 2022
8709e7f
signature holder component: renamings and comment updates
ssd04 Jul 22, 2022
36d9dbc
unit tests and mocks fixes
ssd04 Jul 22, 2022
93ca11b
update signature handler interface; remove own index from signatures …
ssd04 Jul 25, 2022
e525002
Merge branch 'feat/kosk-bls-multisigner' into signatures-holder-compo…
ssd04 Jul 29, 2022
a7c0c9d
integrate multisigner container; fix unit tests
ssd04 Aug 1, 2022
cd57cd1
fix multisigner mutex on set + unit tests
ssd04 Aug 1, 2022
d9473b0
create signature handler component for consensus
ssd04 Aug 1, 2022
f248531
remove single signer since it's not being used
ssd04 Aug 1, 2022
12f2d8d
add multi signer container stub
ssd04 Aug 1, 2022
f6cb500
consensus signing: remove multi signer set from signature handler, re…
ssd04 Aug 1, 2022
5b1e898
fixes after review:
ssd04 Aug 1, 2022
3be0b7e
fixes after review: renamings, removed TODO comment
ssd04 Aug 1, 2022
323d3f9
fixes after review: better checks for invalid input
ssd04 Aug 1, 2022
60b05ff
fixes after review: renamings, change mutex to read when applicable
ssd04 Aug 1, 2022
aac70c1
fix linter issues: return bool variable directly
ssd04 Aug 1, 2022
67ed8dd
unit tests for get current multi signer fail
ssd04 Aug 2, 2022
5969f45
fix after review: better slice allocation
ssd04 Aug 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion consensus/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/ElrondNetwork/elrond-go-core/core"
"github.com/ElrondNetwork/elrond-go-core/data"
"github.com/ElrondNetwork/elrond-go-crypto"
crypto "github.com/ElrondNetwork/elrond-go-crypto"
"github.com/ElrondNetwork/elrond-go/p2p"
)

Expand Down Expand Up @@ -147,3 +147,16 @@ type ScheduledProcessor interface {
IsProcessedOKWithTimeout() bool
IsInterfaceNil() bool
}

// SignatureHandler defines the behaviour of a component that handles signatures in consensus
type SignatureHandler interface {
Reset(pubKeys []string) error
CreateSignatureShare(msg []byte, index uint16, epoch uint32) ([]byte, error)
StoreSignatureShare(index uint16, sig []byte) error
SignatureShare(index uint16) ([]byte, error)
VerifySignatureShare(index uint16, sig []byte, msg []byte, epoch uint32) error
AggregateSigs(bitmap []byte, epoch uint32) ([]byte, error)
SetAggregatedSig([]byte) error
Verify(msg []byte, bitmap []byte, epoch uint32) error
IsInterfaceNil() bool
}
11 changes: 11 additions & 0 deletions consensus/mock/consensusDataContainerMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type ConsensusCoreMock struct {
fallbackHeaderValidator consensus.FallbackHeaderValidator
nodeRedundancyHandler consensus.NodeRedundancyHandler
scheduledProcessor consensus.ScheduledProcessor
signatureHandler consensus.SignatureHandler
}

// GetAntiFloodHandler -
Expand Down Expand Up @@ -230,6 +231,16 @@ func (ccm *ConsensusCoreMock) SetNodeRedundancyHandler(nodeRedundancyHandler con
ccm.nodeRedundancyHandler = nodeRedundancyHandler
}

// SignatureHandler -
func (ccm *ConsensusCoreMock) SignatureHandler() consensus.SignatureHandler {
return ccm.signatureHandler
}

// SetSignatureHandler -
AdoAdoAdo marked this conversation as resolved.
Show resolved Hide resolved
func (ccm *ConsensusCoreMock) SetSignatureHandler(signatureHandler consensus.SignatureHandler) {
ccm.signatureHandler = signatureHandler
}

// IsInterfaceNil returns true if there is no value under the interface
func (ccm *ConsensusCoreMock) IsInterfaceNil() bool {
return ccm == nil
Expand Down
2 changes: 2 additions & 0 deletions consensus/mock/mockTestInitializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ func InitConsensusCoreWithMultiSigner(multiSigner crypto.MultiSigner) *Consensus
nodeRedundancyHandler := &NodeRedundancyHandlerStub{}
scheduledProcessor := &consensusMocks.ScheduledProcessorStub{}
multiSignerContainer := cryptoMocks.NewMultiSignerContainerMock(multiSigner)
signatureHandler := &SignatureHandlerStub{}

container := &ConsensusCoreMock{
blockChain: blockChain,
Expand All @@ -229,6 +230,7 @@ func InitConsensusCoreWithMultiSigner(multiSigner crypto.MultiSigner) *Consensus
fallbackHeaderValidator: fallbackHeaderValidator,
nodeRedundancyHandler: nodeRedundancyHandler,
scheduledProcessor: scheduledProcessor,
signatureHandler: signatureHandler,
}

return container
Expand Down
90 changes: 90 additions & 0 deletions consensus/mock/signatureHandlerStub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package mock

// SignatureHandlerStub implements SignatureHandler interface
type SignatureHandlerStub struct {
ResetCalled func(pubKeys []string) error
CreateSignatureShareCalled func(msg []byte, index uint16, epoch uint32) ([]byte, error)
StoreSignatureShareCalled func(index uint16, sig []byte) error
SignatureShareCalled func(index uint16) ([]byte, error)
VerifySignatureShareCalled func(index uint16, sig []byte, msg []byte, epoch uint32) error
AggregateSigsCalled func(bitmap []byte, epoch uint32) ([]byte, error)
SetAggregatedSigCalled func(_ []byte) error
VerifyCalled func(msg []byte, bitmap []byte, epoch uint32) error
}

// Reset -
func (stub *SignatureHandlerStub) Reset(pubKeys []string) error {
if stub.ResetCalled != nil {
return stub.ResetCalled(pubKeys)
}

return nil
}

// CreateSignatureShare -
func (stub *SignatureHandlerStub) CreateSignatureShare(msg []byte, index uint16, epoch uint32) ([]byte, error) {
if stub.CreateSignatureShareCalled != nil {
return stub.CreateSignatureShareCalled(msg, index, epoch)
}

return []byte("sigShare"), nil
}

// StoreSignatureShare -
func (stub *SignatureHandlerStub) StoreSignatureShare(index uint16, sig []byte) error {
if stub.StoreSignatureShareCalled != nil {
return stub.StoreSignatureShareCalled(index, sig)
}

return nil
}

// SignatureShare -
func (stub *SignatureHandlerStub) SignatureShare(index uint16) ([]byte, error) {
if stub.SignatureShareCalled != nil {
return stub.SignatureShareCalled(index)
}

return []byte("sigShare"), nil
}

// VerifySignatureShare -
func (stub *SignatureHandlerStub) VerifySignatureShare(index uint16, sig []byte, msg []byte, epoch uint32) error {
if stub.VerifySignatureShareCalled != nil {
return stub.VerifySignatureShareCalled(index, sig, msg, epoch)
}

return nil
}

// AggregateSigs -
func (stub *SignatureHandlerStub) AggregateSigs(bitmap []byte, epoch uint32) ([]byte, error) {
if stub.AggregateSigsCalled != nil {
return stub.AggregateSigsCalled(bitmap, epoch)
}

return []byte("aggSigs"), nil
}

// SetAggregatedSig -
func (stub *SignatureHandlerStub) SetAggregatedSig(sig []byte) error {
if stub.SetAggregatedSigCalled != nil {
return stub.SetAggregatedSigCalled(sig)
}

return nil
}

// Verify -
func (stub *SignatureHandlerStub) Verify(msg []byte, bitmap []byte, epoch uint32) error {
if stub.VerifyCalled != nil {
return stub.VerifyCalled(msg, bitmap, epoch)
}

return nil
}

// IsInterfaceNil -
func (stub *SignatureHandlerStub) IsInterfaceNil() bool {
return stub == nil
}
42 changes: 42 additions & 0 deletions consensus/signing/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package signing

import "errors"

// ErrInvalidSignature is raised for an invalid signature
var ErrInvalidSignature = errors.New("invalid signature was provided")

// ErrNilElement is raised when searching for a specific element but found nil
var ErrNilElement = errors.New("element is nil")

// ErrIndexNotSelected is raised when a not selected index is used for multi-signing
var ErrIndexNotSelected = errors.New("index is not selected")

// ErrNilBitmap is raised when a nil bitmap is used
var ErrNilBitmap = errors.New("bitmap is nil")

// ErrNoPrivateKeySet is raised when no private key was set
var ErrNoPrivateKeySet = errors.New("no private key was set")

// ErrNoPublicKeySet is raised when no public key was set for a multisignature
var ErrNoPublicKeySet = errors.New("no public key was set")

// ErrNilKeyGenerator is raised when a valid key generator is expected but nil used
var ErrNilKeyGenerator = errors.New("key generator is nil")

// ErrNilPublicKeys is raised when public keys are expected but received nil
var ErrNilPublicKeys = errors.New("public keys are nil")

// ErrNilMultiSignerContainer is raised when a nil multi signer container has been provided
var ErrNilMultiSignerContainer = errors.New("multi signer container is nil")

// ErrIndexOutOfBounds is raised when an out of bound index is used
var ErrIndexOutOfBounds = errors.New("index is out of bounds")

// ErrEmptyPubKeyString is raised when an empty public key string is used
var ErrEmptyPubKeyString = errors.New("public key string is empty")

// ErrNilMessage is raised when trying to verify a nil signed message or trying to sign a nil message
var ErrNilMessage = errors.New("message to be signed or to be verified is nil")

// ErrBitmapMismatch is raised when an invalid bitmap is passed to the multisigner
var ErrBitmapMismatch = errors.New("multi signer reported a mismatch in used bitmap")
Loading