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

Collective Signing using stream and with threshold support #36

Merged
merged 7 commits into from
Apr 9, 2020

Conversation

Gilthoniel
Copy link
Contributor

@Gilthoniel Gilthoniel commented Apr 8, 2020

This implements collective signing through the stream feature of Mino to mvoe from a flat approach to a distributed mesh of nodes. It also adds the threshold feature to require less than the number of participants.

@Gilthoniel Gilthoniel self-assigned this Apr 8, 2020
@Gilthoniel Gilthoniel requested a review from nkcr April 8, 2020 15:04
@Gilthoniel Gilthoniel added the R4M 🚀 The PR is ready to be reviewed and merged label Apr 8, 2020
@@ -136,6 +135,18 @@ func (cc Conodes) Len() int {
return len(cc)
}

// GetPublicKey implements crypto.CollectiveAuthority. It returns the public key
// associated with the address and its index.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would add a precision in the comment: its index from what?

Comment on lines 35 to 38
innerCtx, cancel := context.WithCancel(context.Background())

defer cancel()
sender, rcvr := a.rpc.Stream(innerCtx, ca)
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
innerCtx, cancel := context.WithCancel(context.Background())
defer cancel()
sender, rcvr := a.rpc.Stream(innerCtx, ca)
innerCtx, cancel := context.WithCancel(context.Background())
defer cancel()
sender, rcvr := a.rpc.Stream(innerCtx, ca)

}

// Each signature is individually verified so we can assume the aggregated
// is correct.
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
// is correct.
// signature is correct.

Comment on lines 82 to 83
err, ok := <-errs
if !ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

In this case I find it less misleading if we use more instead of ok, as it better describe the role of this boolean.

Suggested change
err, ok := <-errs
if !ok {
err, more := <-errs
if !more {


func (a thresholdActor) waitResp(errs <-chan error, maxErrs int, cancel func()) {
errCount := 0
for {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a

for err := range errs {
}

is what you want to do?

Copy link
Contributor

Choose a reason for hiding this comment

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

+ it should be really clear in the specification (mino/mod.go:Sender.Send) that the returned error chan MUST be closed, as this could just wait indefinitely. Actually we didn't mention it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I've updated the interface to comment that point.

mask = 0x7
)

// Signature is a threshold signature which includes a aggregated signature and
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
// Signature is a threshold signature which includes a aggregated signature and
// Signature is a threshold signature which includes an aggregated signature and

)

// Signature is a threshold signature which includes a aggregated signature and
// the mask of signers from the associated collective authority.
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if I am right: Is there N masks for N signers?

Suggested change
// the mask of signers from the associated collective authority.
// the masks of signers from the associated collective authority.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, there is one single mask composed of bits (it's a bitmask basically) but a slice of bytes is used as the length is dynamic depending on the number of participants.

func (s *Signature) GetIndices() []int {
indices := []int{}
for i, word := range s.mask {
for j := 0; j < 8; j++ {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would comment why 8 or use a constant

return false
}

i := index >> shift
Copy link
Contributor

Choose a reason for hiding this comment

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

I would find it much clearer to do i := index / 8, like this one can easily understand we are converting an absolute bit index to a corresponding byte slice index.

Copy link
Contributor

Choose a reason for hiding this comment

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

Here is a proposal that I find a bit clearer (and since you are already using 8 in GetIndices:

i := index / 8 // byte index from the slice
j := index % 8 // bit index from the byte

return s.mak[i]&(1<<j) != 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's actually quite a common pattern to use shift and a mask when dealing with divisions of power of 2 as this is much more efficient (quite a lot!).

@@ -0,0 +1,408 @@
package fake
Copy link
Contributor

Choose a reason for hiding this comment

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

I would explain a bit what one can do with this package

@nkcr
Copy link
Contributor

nkcr commented Apr 9, 2020

I'm curious: did you already try to change minoch to minogrpc in the test just to see if it works?

@Gilthoniel
Copy link
Contributor Author

No, I didn't. I left that to you ;)

@nkcr nkcr merged commit a94a360 into master Apr 9, 2020
@nkcr nkcr deleted the cosi_stream branch April 9, 2020 09:04
bbjubjub2494 pushed a commit to bbjubjub2494/dela that referenced this pull request Aug 3, 2024
Collective Signing using stream and with threshold support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R4M 🚀 The PR is ready to be reviewed and merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants