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

Optimistic signature aggregation by leader #4123

Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
43e7961
verify aggregated sig on end round by leader
ssd04 May 27, 2022
1125da5
verify aggregated sig on end round by leader: use current multi signer
ssd04 May 27, 2022
bd320be
added verify signature share if aggregated sig failed
ssd04 Jun 6, 2022
cdc4cd2
remove unit test for verify signature share
ssd04 Jun 6, 2022
af62643
verify sig share on fail, for nodes based on bitmap
ssd04 Jun 6, 2022
d8827be
handle err case on setInderInBitmap
ssd04 Jun 6, 2022
4b89afd
use signature subround jobs state instead of using custom bitmap
ssd04 Jun 7, 2022
b04812a
added unit tests for verify signature shared on agg sig verification …
ssd04 Jun 9, 2022
33e778b
use new temp multisigner to store only valid sig shares
ssd04 Jun 9, 2022
fcfee88
fix issues with multisigner saved state
ssd04 Jun 9, 2022
c222360
avoid resetting multiSigner data
ssd04 Jun 10, 2022
a3d5e90
return updated bitmap and aggregated signature
ssd04 Jun 21, 2022
f649a5f
remove store signature since multisigner is not reset anymore
ssd04 Jun 21, 2022
331bea8
update unit test to return more variables
ssd04 Jun 21, 2022
9973538
added separate function for agg sig after verification fail
ssd04 Jun 22, 2022
4650415
handle lower than threshold case when verification fail; remove log d…
ssd04 Jun 22, 2022
1b77058
unit tests for compute agg sig on valid nodes
ssd04 Jun 22, 2022
c5a24ad
cleanup log debug messages
ssd04 Jun 22, 2022
cdc7a39
added TODO for invalid sig shares slashing
ssd04 Jun 22, 2022
cc06e98
unit test for endround job by leader with verification fail
ssd04 Jun 22, 2022
b566237
fix commented unit test
ssd04 Jun 22, 2022
e129882
endRound unit test: verify num calls for verifySigShare
ssd04 Jun 24, 2022
4961c7a
fixes after review:
ssd04 Jun 24, 2022
291b6f9
decrease peer honesty for malicios signer, since it has been increase…
ssd04 Jun 24, 2022
fd192e7
include also increase factor since it was added optimistically
ssd04 Jun 24, 2022
31114b8
revert: use only increase factor
ssd04 Jun 24, 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
14 changes: 14 additions & 0 deletions consensus/spos/bls/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ func (sr *subroundEndRound) DoEndRoundJobByParticipant(cnsDta *consensus.Message
return sr.doEndRoundJobByParticipant(cnsDta)
}

func (sr *subroundEndRound) DoEndRoundJobByLeader() bool {
return sr.doEndRoundJobByLeader()
}

func (sr *subroundEndRound) HaveConsensusHeaderWithFullInfo(cnsDta *consensus.Message) (bool, data.HeaderHandler) {
return sr.haveConsensusHeaderWithFullInfo(cnsDta)
}
Expand All @@ -293,6 +297,16 @@ func (sr *subroundEndRound) IsOutOfTime() bool {
return sr.isOutOfTime()
}

func (sr *subroundEndRound) VerifyNodesOnAggSigVerificationFail(multiSigner crypto.MultiSigner) error {
return sr.verifyNodesOnAggSigVerificationFail(multiSigner)
}

func (sr *subroundEndRound) ComputeAggSigOnValidNodes(
multiSigner crypto.MultiSigner,
) ([]byte, []byte, error) {
return sr.computeAggSigOnValidNodes(multiSigner)
}

// GetStringValue gets the name of the message type
func GetStringValue(messageType consensus.MessageType) string {
return getStringValue(messageType)
Expand Down
96 changes: 96 additions & 0 deletions consensus/spos/bls/subroundEndRound.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ElrondNetwork/elrond-go-core/core/check"
"github.com/ElrondNetwork/elrond-go-core/data"
"github.com/ElrondNetwork/elrond-go-core/display"
crypto "github.com/ElrondNetwork/elrond-go-crypto"
"github.com/ElrondNetwork/elrond-go/common"
"github.com/ElrondNetwork/elrond-go/consensus"
"github.com/ElrondNetwork/elrond-go/consensus/spos"
Expand Down Expand Up @@ -197,6 +198,30 @@ func (sr *subroundEndRound) doEndRoundJobByLeader() bool {
return false
}

currentMultiSigner := sr.MultiSigner()
err = currentMultiSigner.SetAggregatedSig(sig)
if err != nil {
log.Debug("doEndRoundJobByLeader.SetAggregatedSig", "error", err.Error())
return false
}

err = currentMultiSigner.Verify(sr.GetData(), bitmap)
if err != nil {
log.Debug("doEndRoundJobByLeader.Verify", "error", err.Error())

err = sr.verifyNodesOnAggSigVerificationFail(currentMultiSigner)
AdoAdoAdo marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
log.Debug("doEndRoundJobByLeader.verifyNodesOnAggSigVerificationFail", "error", err.Error())
return false
}

bitmap, sig, err = sr.computeAggSigOnValidNodes(currentMultiSigner)
if err != nil {
log.Debug("doEndRoundJobByLeader.computeAggSigOnValidNodes", "error", err.Error())
return false
}
}

err = sr.Header.SetPubKeysBitmap(bitmap)
if err != nil {
log.Debug("doEndRoundJobByLeader.SetPubKeysBitmap", "error", err.Error())
Expand Down Expand Up @@ -281,6 +306,77 @@ func (sr *subroundEndRound) doEndRoundJobByLeader() bool {
return true
}

// TODO:
// - slashing for invalid sig shares
// - handle sig share verifications concurrently
func (sr *subroundEndRound) verifyNodesOnAggSigVerificationFail(
multiSigner crypto.MultiSigner,
) error {
pubKeys := sr.ConsensusGroup()

for i, pk := range pubKeys {
isJobDone, err := sr.JobDone(pk, SrSignature)
if err != nil || !isJobDone {
continue
}

sigShare, err := multiSigner.SignatureShare(uint16(i))
if err != nil {
return err
}

isSuccessfull := true
err = multiSigner.VerifySignatureShare(uint16(i), sigShare, sr.GetData(), nil)
if err != nil {
isSuccessfull = false

err = sr.SetJobDone(pk, SrSignature, false)
Copy link
Contributor

Choose a reason for hiding this comment

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

also the sr.PeerHonestyHandler() should be decreased? maybe twice? It was increased once on the receivedSignature and now it was found it is invalid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 will include in the next PR when slashing will be applied

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as discussed, decreased peerHonesty here to be in line with the old setup, since the peerHonesty has been increased optimistically for the malicious signer

if err != nil {
return err
}
}

log.Trace("verifyNodesOnAggSigVerificationFail: verifying signature share", "public key", pk, "is successfull", isSuccessfull)
}

return nil
}

func (sr *subroundEndRound) computeAggSigOnValidNodes(
multiSigner crypto.MultiSigner,
) ([]byte, []byte, error) {
threshold := sr.Threshold(sr.Current())
numValidSigShares := sr.ComputeSize(SrSignature)

if numValidSigShares < threshold {
return nil, nil, fmt.Errorf("%w: number of valid sig shares lower than threshold, numSigShares: %d, threshold: %d",
spos.ErrInvalidNumSigShares, numValidSigShares, threshold)
}

bitmap := sr.GenerateBitmap(SrSignature)
err := sr.checkSignaturesValidity(bitmap)
if err != nil {
return nil, nil, err
}

sig, err := multiSigner.AggregateSigs(bitmap)
if err != nil {
return nil, nil, err
}

err = multiSigner.SetAggregatedSig(sig)
if err != nil {
return nil, nil, err
}

err = multiSigner.Verify(sr.GetData(), bitmap)
AdoAdoAdo marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, nil, err
}

return bitmap, sig, nil
}

func (sr *subroundEndRound) createAndBroadcastHeaderFinalInfo() {
cnsMsg := consensus.NewConsensusMessage(
sr.GetData(),
Expand Down
Loading