-
Notifications
You must be signed in to change notification settings - Fork 22
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
Changes from 3 commits
f9cc3ac
a55e367
7484334
bdaa0a1
98e3a40
9552925
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
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 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]} | ||
|
||
// Verify the reconstructed signature | ||
expectedSig, err := types.ReconstructSignatures(map[types.OperatorID][]byte{1: msgs[0].PartialSignature, 3: msgs[2].PartialSignature}) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
|
||
return &PartialSigContainerTest{ | ||
Name: "duplicate", | ||
Quorum: ks.Threshold, | ||
ValidatorPubKey: ks.ValidatorPK.Serialize(), | ||
SignatureMsgs: msgs, | ||
ExpectedError: "could not reconstruct a valid signature", | ||
ExpectedResult: expectedSig.Serialize(), | ||
ExpectedQuorum: false, | ||
} | ||
} |
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, | ||
} | ||
} | ||
Comment on lines
+10
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. @GalRogozinski 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 |
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, | ||
} | ||
} |
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, | ||
} | ||
} |
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, | ||
} | ||
} |
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 | ||
} |
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.
I am actually surprised that this doesn't err...
you think we need this? anyhow if there is an
expectedError
thenexpectedResult
isn't checkedThere 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.
Indeed isn't checked and we don't need. It's only confusing so I'll drop.