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

Tests - Partial signatures container #338

Merged
merged 6 commits into from
Feb 6, 2024
Merged

Conversation

MatheusFranco99
Copy link
Contributor

@MatheusFranco99 MatheusFranco99 commented Jan 3, 2024

Spec Test

New test type to verify partial signature container functionality.

Tests:

  • One signature
  • Quorum
  • Duplicated
  • Duplicated with quorum
  • Invalid

Solving one element of issue 25.

Comment on lines 22 to 25
expectedSig, err := types.ReconstructSignatures(map[types.OperatorID][]byte{1: msgs[0].PartialSignature, 3: msgs[2].PartialSignature})
if err != nil {
panic(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.

I am actually surprised that this doesn't err...
you think we need this? anyhow if there is an expectedError then expectedResult isn't checked

Copy link
Contributor Author

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.

Comment on lines +10 to +36
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,
}
}
Copy link
Contributor

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?

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 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.

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

@MatheusFranco99 should we add an issue for those two tests, or they exist in other PRs?

Copy link
Contributor Author

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, the Runner is supposed to do it and we have the tests for it.

Copy link
Contributor

@y0sher y0sher left a comment

Choose a reason for hiding this comment

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

please answer my question but approving in case no change is needed.

@GalRogozinski GalRogozinski merged commit 2a317a8 into main Feb 6, 2024
2 checks passed
@GalRogozinski GalRogozinski deleted the test-psig-container branch February 6, 2024 08:55
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.

4 participants