-
Notifications
You must be signed in to change notification settings - Fork 24
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
Tests - Partial signatures container #338
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f9cc3ac
Partial sig container test spec [skip ci]
MatheusFranco99 a55e367
Add run test case [skip ci]
MatheusFranco99 7484334
Add tests
MatheusFranco99 bdaa0a1
Drop unnecessary expectedSig
MatheusFranco99 98e3a40
Merge branch 'main' into test-psig-container
GalRogozinski 9552925
generate-jsons
GalRogozinski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package partialsigcontainer | ||
|
||
import ( | ||
"github.com/bloxapp/ssv-spec/qbft" | ||
"github.com/bloxapp/ssv-spec/ssv/spectest/tests" | ||
"github.com/bloxapp/ssv-spec/types" | ||
"github.com/bloxapp/ssv-spec/types/testingutils" | ||
) | ||
|
||
func Duplicate() tests.SpecTest { | ||
|
||
// Create a test key set | ||
ks := testingutils.Testing4SharesSet() | ||
|
||
// Create PartialSignatureMessage for testing | ||
msg1 := testingutils.PostConsensusAttestationMsg(ks.Shares[1], 1, qbft.FirstHeight) | ||
msg2 := testingutils.PostConsensusAttestationMsg(ks.Shares[1], 1, qbft.FirstHeight) | ||
msg3 := testingutils.PostConsensusAttestationMsg(ks.Shares[2], 2, qbft.FirstHeight) | ||
msgs := []*types.PartialSignatureMessage{msg1.Message.Messages[0], msg2.Message.Messages[0], msg3.Message.Messages[0]} | ||
|
||
return &PartialSigContainerTest{ | ||
Name: "duplicate", | ||
Quorum: ks.Threshold, | ||
ValidatorPubKey: ks.ValidatorPK.Serialize(), | ||
SignatureMsgs: msgs, | ||
ExpectedError: "could not reconstruct a valid signature", | ||
ExpectedQuorum: false, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package partialsigcontainer | ||
|
||
import ( | ||
"github.com/bloxapp/ssv-spec/qbft" | ||
"github.com/bloxapp/ssv-spec/ssv/spectest/tests" | ||
"github.com/bloxapp/ssv-spec/types" | ||
"github.com/bloxapp/ssv-spec/types/testingutils" | ||
) | ||
|
||
func DuplicateQuorum() tests.SpecTest { | ||
|
||
// Create a test key set | ||
ks := testingutils.Testing4SharesSet() | ||
|
||
// Create PartialSignatureMessage for testing | ||
msg1 := testingutils.PostConsensusAttestationMsg(ks.Shares[1], 1, qbft.FirstHeight) | ||
msg12 := testingutils.PostConsensusAttestationMsg(ks.Shares[1], 1, qbft.FirstHeight) | ||
msg2 := testingutils.PostConsensusAttestationMsg(ks.Shares[2], 2, qbft.FirstHeight) | ||
msg3 := testingutils.PostConsensusAttestationMsg(ks.Shares[3], 3, qbft.FirstHeight) | ||
msgs := []*types.PartialSignatureMessage{msg1.Message.Messages[0], msg12.Message.Messages[0], msg2.Message.Messages[0], msg3.Message.Messages[0]} | ||
|
||
// Verify the reconstructed signature | ||
expectedSig, err := types.ReconstructSignatures(map[types.OperatorID][]byte{1: msgs[0].PartialSignature, 2: msgs[2].PartialSignature, 3: msgs[3].PartialSignature}) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
|
||
return &PartialSigContainerTest{ | ||
Name: "duplicate quorum", | ||
Quorum: ks.Threshold, | ||
ValidatorPubKey: ks.ValidatorPK.Serialize(), | ||
SignatureMsgs: msgs, | ||
ExpectedResult: expectedSig.Serialize(), | ||
ExpectedQuorum: true, | ||
} | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package partialsigcontainer | ||
|
||
import ( | ||
"github.com/bloxapp/ssv-spec/qbft" | ||
"github.com/bloxapp/ssv-spec/ssv/spectest/tests" | ||
"github.com/bloxapp/ssv-spec/types" | ||
"github.com/bloxapp/ssv-spec/types/testingutils" | ||
) | ||
|
||
func Invalid() tests.SpecTest { | ||
|
||
// Create a test key set | ||
ks := testingutils.Testing4SharesSet() | ||
|
||
// Create PartialSignatureMessage for testing | ||
msg1 := testingutils.PostConsensusAttestationMsg(ks.Shares[1], 1, qbft.FirstHeight) | ||
msg2 := testingutils.PostConsensusAttestationMsg(ks.Shares[1], 2, qbft.FirstHeight) // invalid signature | ||
msg3 := testingutils.PostConsensusAttestationMsg(ks.Shares[3], 3, qbft.FirstHeight) | ||
msgs := []*types.PartialSignatureMessage{msg1.Message.Messages[0], msg2.Message.Messages[0], msg3.Message.Messages[0]} | ||
|
||
// Verify the reconstructed signature | ||
expectedSig, err := types.ReconstructSignatures(map[types.OperatorID][]byte{1: msgs[0].PartialSignature, 2: msgs[1].PartialSignature, 3: msgs[2].PartialSignature}) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
|
||
return &PartialSigContainerTest{ | ||
Name: "invalid", | ||
Quorum: ks.Threshold, | ||
ValidatorPubKey: ks.ValidatorPK.Serialize(), | ||
SignatureMsgs: msgs, | ||
ExpectedError: "could not reconstruct a valid signature", | ||
ExpectedResult: expectedSig.Serialize(), | ||
ExpectedQuorum: true, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package partialsigcontainer | ||
|
||
import ( | ||
"github.com/bloxapp/ssv-spec/qbft" | ||
"github.com/bloxapp/ssv-spec/ssv/spectest/tests" | ||
"github.com/bloxapp/ssv-spec/types" | ||
"github.com/bloxapp/ssv-spec/types/testingutils" | ||
) | ||
|
||
func OneSignature() tests.SpecTest { | ||
|
||
// Create a test key set | ||
ks := testingutils.Testing4SharesSet() | ||
|
||
// Create PartialSignatureMessage for testing | ||
msg := testingutils.PostConsensusAttestationMsg(ks.Shares[1], 1, qbft.FirstHeight) | ||
msgs := []*types.PartialSignatureMessage{msg.Message.Messages[0]} | ||
|
||
// Verify the reconstructed signature | ||
expectedSig, err := types.ReconstructSignatures(map[types.OperatorID][]byte{1: msgs[0].PartialSignature}) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
|
||
return &PartialSigContainerTest{ | ||
Name: "one signature", | ||
Quorum: ks.Threshold, | ||
ValidatorPubKey: ks.ValidatorPK.Serialize(), | ||
SignatureMsgs: msgs, | ||
ExpectedError: "could not reconstruct a valid signature", | ||
ExpectedResult: expectedSig.Serialize(), | ||
ExpectedQuorum: false, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package partialsigcontainer | ||
|
||
import ( | ||
"github.com/bloxapp/ssv-spec/qbft" | ||
"github.com/bloxapp/ssv-spec/ssv/spectest/tests" | ||
"github.com/bloxapp/ssv-spec/types" | ||
"github.com/bloxapp/ssv-spec/types/testingutils" | ||
) | ||
|
||
func Quorum() tests.SpecTest { | ||
|
||
// Create a test key set | ||
ks := testingutils.Testing4SharesSet() | ||
|
||
// Create PartialSignatureMessage for testing | ||
msg1 := testingutils.PostConsensusAttestationMsg(ks.Shares[1], 1, qbft.FirstHeight) | ||
msg2 := testingutils.PostConsensusAttestationMsg(ks.Shares[2], 2, qbft.FirstHeight) | ||
msg3 := testingutils.PostConsensusAttestationMsg(ks.Shares[3], 3, qbft.FirstHeight) | ||
msgs := []*types.PartialSignatureMessage{msg1.Message.Messages[0], msg2.Message.Messages[0], msg3.Message.Messages[0]} | ||
|
||
// Verify the reconstructed signature | ||
expectedSig, err := types.ReconstructSignatures(map[types.OperatorID][]byte{1: msgs[0].PartialSignature, 2: msgs[1].PartialSignature, 3: msgs[2].PartialSignature}) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
|
||
return &PartialSigContainerTest{ | ||
Name: "quorum", | ||
Quorum: ks.Threshold, | ||
ValidatorPubKey: ks.ValidatorPK.Serialize(), | ||
SignatureMsgs: msgs, | ||
ExpectedResult: expectedSig.Serialize(), | ||
ExpectedQuorum: true, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package partialsigcontainer | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/bloxapp/ssv-spec/ssv" | ||
"github.com/bloxapp/ssv-spec/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type PartialSigContainerTest struct { | ||
Name string | ||
Quorum uint64 | ||
ValidatorPubKey []byte | ||
SignatureMsgs []*types.PartialSignatureMessage | ||
ExpectedError string | ||
ExpectedResult []byte | ||
ExpectedQuorum bool | ||
} | ||
|
||
func (test *PartialSigContainerTest) TestName() string { | ||
return "PartialSigContainer " + test.Name | ||
} | ||
|
||
func (test *PartialSigContainerTest) Run(t *testing.T) { | ||
ps := ssv.NewPartialSigContainer(test.Quorum) | ||
|
||
roots := make(map[[32]byte]bool) | ||
// Add signature messages | ||
for _, sigMsg := range test.SignatureMsgs { | ||
ps.AddSignature(sigMsg) | ||
roots[sigMsg.SigningRoot] = true | ||
} | ||
|
||
for root := range roots { | ||
|
||
// Check quorum | ||
require.Equal(t, test.ExpectedQuorum, ps.HasQuorum(root)) | ||
|
||
result, err := ps.ReconstructSignature(root, test.ValidatorPubKey) | ||
// Check the result and error | ||
if len(test.ExpectedError) > 0 { | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), test.ExpectedError) | ||
} else { | ||
require.NoError(t, err) | ||
require.EqualValues(t, test.ExpectedResult, result) | ||
} | ||
} | ||
} | ||
|
||
func (test *PartialSigContainerTest) GetPostState() (interface{}, error) { | ||
return nil, nil | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we test a scenario where we have a duplicate msg but one is signed correctly and the other not? what are we expecting in that case? I guess to take the valid.
it that the
Invalid
test?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PartialSigContainer internal functionality is to only add a partial signature for a (signer, signing root) once. It uses a map for that. If we try to add another partial sig for the same author (even if the first one is invalid and the second one is valid), it won't do anything because the map already has this entry. I.e. it doesn't do any validation before adding.
For the duplicate and quorum test (this one), as a black box, we expect the partial sig container to produce the correct signature even if we call AddSignature twice for the same message/signature.
The two test cases you said are not tested. It will raise an error when reconstructing the signature if we add the invalid one first.
The invalid test, actually, tests a quorum with wrong signatures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MatheusFranco99 should we add an issue for those two tests, or they exist in other PRs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GalRogozinski
Actually, I should have said the "single test case" he mentioned.
Receiving a first valid and then a second invalid message from the same author is not tested here but I don't see this as an issue. I think that the current
PartialSigContainer
module isn't supposed to do validation. On the other hand, theRunner
is supposed to do it and we have the tests for it.