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

Partial Signature Verification Aggregation #369

Merged
merged 36 commits into from
Mar 28, 2024

Conversation

MatheusFranco99
Copy link
Contributor

@MatheusFranco99 MatheusFranco99 commented Mar 21, 2024

Overview

This PR implements the reduction of signatures optimization for partial signature messages as described in this SIP.

Changes

  • Drop SignedPartialSignatureMessage's signature verification.
  • Stop verifying each beacon signature in favour of verifying the quorum of signatures through the reconstructed signature.
  • Add fall back function in case the reconstructed signature is wrong.
  • In case of duplicated different signatures (same signer), verify both and keep the correct one (if any).

Changed tests

  • Unknown signer: error message
  • Invalid beacon signature: add a quorum of messages to detect the invalid signature
  • Invalid signature: drop expected error regarding SignedPartialSignatureMessage's signature

New tests

  • Invalid quorum then valid quorum: produces an invalid quorum and then sends a fourth valid message to get a valid quorum

Improvement

New total duty time per number of consensus rounds.

1 Round 2 Rounds 3 Rounds
50% 80% 88%

New partial signature quorum processing time: 17%.

Comment on lines +60 to +70
// Check if signer is in committee
signerInCommittee := false
for _, operator := range b.Share.Committee {
if operator.OperatorID == signedMsg.Signer {
signerInCommittee = true
break
}
}
if !signerInCommittee {
return errors.New("unknown signer")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

hmmm

This is currently checked by MsgValidation ERR_PSIG_INVALID_SIG_ID?
Since MsgValidation isn't part of spec it is fine that you added this..

But now I made up my mind that MsgValidation should be an inseperable part of spec.
Once we add tests for this, we won't have to do those double checks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that message validation should belong to the spec

Comment on lines 126 to 132
// MarshalSSZ ssz marshals the SignedSSVMessage object
func (s *SignedSSVMessage) MarshalSSZ() ([]byte, error) {
return ssz.MarshalSSZ(s)
}

// MarshalSSZTo ssz marshals the SignedSSVMessage object to a target array
func (s *SignedSSVMessage) MarshalSSZTo(buf []byte) (dst []byte, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ok...
So we need to decide how to do this...

In #345 we added the SignedSSVMessage but we merged it to the fork branch because of this very encoding change...
I made this decision because I decided that the ssz encoding is anyhow the correct (consistent) way to go and I didn't take into account that this PR would need this.

I think we should rework #345 to remove the ssz encoding and add flat encoding so no fork

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed SignedSSVMessage from this PR.

@@ -9,10 +9,9 @@ import (
"github.com/bloxapp/ssv-spec/types/testingutils"
)

// InvalidMessageSignature tests PartialSignatureMessage signature invalid
// InvalidMessageSignature tests PartialSignatureMessage signature invalid. No error is generated since the SignedPartialSignatureMessage.Signature is no longer checked
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// InvalidMessageSignature tests PartialSignatureMessage signature invalid. No error is generated since the SignedPartialSignatureMessage.Signature is no longer checked
// InvalidMessageSignature tests PartialSignatureMessage signature invalid. No error is generated since the SignedPartialSignatureMessage. Signature is no longer checked. Wait for quorum before verifying.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The "no space" is intended. I wanted it to be: "SignedPartialSignatureMessage. Signature"


// invalidThenQuorumSyncCommitteeContributionSC returns state comparison object for the invalid then quorum SyncCommitteeContribution versioned spec test
// runner should finish since quorum is achieved
func invalidQuorumThenValidQuorumSyncCommitteeContributionSC() *comparable.StateComparison {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a friendly reminder that SC files were replaced by generated jsons.
However if you think this is a core test (looks like one) and that coding out the SC helps in verifying then this is great!!

@@ -14,7 +14,6 @@ import (
// InvalidThenQuorum tests a runner receiving an invalid message then a valid quorum, terminating successfully
func InvalidThenQuorum() tests.SpecTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the difference between this and InvalidQuorumThenQuorum?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • InvalidQuorumThenQuorum: tests an initial invalid quorum and, then, sends valid messages until a valid quorum is reached.
  • InvalidThenQuorum: test an invalid partial signature message being received and then, later, a valid quorum is reached.

@@ -8,7 +8,7 @@ import (
"github.com/bloxapp/ssv-spec/types/testingutils"
)

// InvalidMessageSignature tests SignedPartialSignatureMessage signature invalid
// InvalidMessageSignature tests SignedPartialSignatureMessage signature invalid. No error is generated since the SignedPartialSignatureMessage.Signature is no longer checked
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// InvalidMessageSignature tests SignedPartialSignatureMessage signature invalid. No error is generated since the SignedPartialSignatureMessage.Signature is no longer checked
// InvalidMessageSignature tests SignedPartialSignatureMessage signature invalid. No error is generated since the SignedPartialSignatureMessage. Signature is no longer checked.
// We wait for quorum to verify sig.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The "no space" is intended. I wanted it to be: "SignedPartialSignatureMessage. Signature"

@@ -32,7 +32,6 @@ func InvalidThenQuorum() tests.SpecTest {
OutputMessages: []*types.SignedPartialSignatureMessage{
testingutils.PreConsensusContributionProofMsg(ks.Shares[1], ks.Shares[1], 1, 1), // broadcasts when starting a new duty
},
ExpectedError: "failed processing sync committee selection proof message: invalid pre-consensus message: could not verify Beacon partial Signature: wrong signature",
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't the error happen on the first quorum?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The first invalid signature is overwritten by the correct one before a quorum is reached. Once the quorum is reached, all signatures stored are correct and no error is created

Copy link
Contributor

@GalRogozinski GalRogozinski left a comment

Choose a reason for hiding this comment

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

What about QBFT messages?

@MatheusFranco99
Copy link
Contributor Author

@GalRogozinski This PR is for partial signature messages

Copy link
Contributor

@GalRogozinski GalRogozinski left a comment

Choose a reason for hiding this comment

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

Looks good. We also need the SignedSSVMessage with no encoding change. In a different PR

@MatheusFranco99 MatheusFranco99 changed the title Reduce signatures in partial signatures steps - No fork Partial Signature Verification Aggregation Mar 27, 2024
Comment on lines +33 to +39
signatures := container.GetSignatures(root)

for operatorID, signature := range signatures {
if err := b.verifyBeaconPartialSignature(operatorID, signature, root); err != nil {
container.Remove(operatorID, root)
}
}
Copy link
Contributor

@y0sher y0sher Mar 28, 2024

Choose a reason for hiding this comment

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

  1. shouldn't we do another check here? or after calling FallBackAndVerifyEachSignature, what if we had a quorum of 4, then we realized one is invalid, don't we want to reconstruct again with the 3 left?
    or this is not possible since its a must we'll try first when have 3?
  2. I guess nothing else to do here regarding notifying the runner we no longer have quorum? since the quorum is calculated on the fly using the container?

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. we must have 3
  2. yes

@GalRogozinski GalRogozinski merged commit ebb6014 into main Mar 28, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants