Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

No side-effects in getters #39

Closed
wants to merge 8 commits into from
Closed

Conversation

dvdplm
Copy link
Contributor

@dvdplm dvdplm commented Mar 25, 2024

The get_signers() method has side effects, which is a bit of a code smell. The deduplication
and sanity checks should not run as part of a getter. The naming is not idiomatic in rust, where
get_ prefixes are considered redundant. Finally, the deduplication method crashes the process
if the dedup'd number of signers falls below the threshold, which is annoying to users of the
library.

Ideally the refactoring should continue one more step and run the deduplication&checks every
time a Signer is added, but that is future work.

This PR also makes the signers a private member, and enforces sorting&deduplication in the setter, guaranteeing a valid list of signers at all times.

fix: idiomatic name for getters
@dvdplm dvdplm requested a review from a team as a code owner March 25, 2024 12:47
@dvdplm dvdplm requested review from 4l0n50 and Nashtare March 25, 2024 12:47
src/sign/signature.rs Outdated Show resolved Hide resolved
benches/sign.rs Outdated Show resolved Hide resolved
dvdplm added 3 commits March 25, 2024 13:56
Make signers a private member of AggregatorState
Make state a private member on SignatureAggregator
Prefer returning Result to asserts
src/error.rs Outdated Show resolved Hide resolved
src/sign/signature.rs Outdated Show resolved Hide resolved
src/sign/signature.rs Outdated Show resolved Hide resolved
src/sign/signature.rs Outdated Show resolved Hide resolved
dvdplm and others added 4 commits March 27, 2024 16:09
Co-authored-by: Hamy Ratoanina <[email protected]>
change: move `dedup_signers` inside `include_signers`
change: use `signers()` everywhere
change: add a `TooManySigners` error
@dvdplm
Copy link
Contributor Author

dvdplm commented Apr 9, 2024

@Nashtare Is there anything else I can do to get this one over the finish line?

Copy link
Member

@Nashtare Nashtare left a comment

Choose a reason for hiding this comment

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

Apologies for the delay, my review got stuck in pending and then I got busy with other things. Overall LGTM, just a couple nits open to discussion

///
/// # Returns
///
/// A slice of [`Signer`]s.
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather have it mention A reference to the internal list of Signer`s, to emphasize that it's borrowed

/// # Panics
///
/// If the [`signer.participant_index`] doesn't match the [`public_key.index`] .
/// # Returns error if the [`signer.participant_index`] does not match the
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// # Returns error if the [`signer.participant_index`] does not match the
/// # Errors if the [`signer.participant_index`] does not match the

Comment on lines +488 to +489
// Deduplicate partipating [`Signer`]s and check that there is
// the correct number of signers given the [`ThresholdParameters`].
Copy link
Member

Choose a reason for hiding this comment

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

the second part of the comment is kind of misleading, we're checking that it does not exceed the number of participants (as it technically can't have more parties involved than there are registered). It doesn't check against the threshold. But it doesn't check that we gathered enough signers to meet the threshold for instance

Error::TooManySigners(signers, n_param) => {
write!(
f,
"Too many signers ({}) given the DKG instance parameters ({}).",
Copy link
Member

Choose a reason for hiding this comment

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

nit: parameters may refer to both N and T here, maybe emphasize that we're talking about the total number of participants? (although it may be implied, as we don't mind having more signers than the threshold, just out of clarity).

Comment on lines +478 to +481
) -> FrostResult<C, ()> {
if participant_index != public_key.index {
return Err(Error::IndexMismatch(participant_index, public_key.index));
}
Copy link
Member

Choose a reason for hiding this comment

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

It's fine as out of scope of this PR, but I think this is the kind of function signature that could be simplified. As the index is part of the PK, we could remove the need to pass participant_index. (granted that applications still enforce correct provenance of this message, as described in the docs).

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. Happy to take a look at this in an upcoming PR.

@dvdplm
Copy link
Contributor Author

dvdplm commented Apr 11, 2024

@Nashtare Given the I don't have push access to this branch, would you be ok merging this as-is and I'll address the comments and concerns in a separate PR (by way of a fork, as a normal contributor)?

@dvdplm
Copy link
Contributor Author

dvdplm commented Apr 11, 2024

#43 addresses the documentation tweaks raised here.

EDIT: I guess #43 is actually more of a replacement for this one. Or alternatively, someone on the team needs to resolve the merge conflicts here, then merge, and then merge #43. Whichever is preferred.

@Nashtare
Copy link
Member

Replaced by #43

@Nashtare Nashtare closed this Apr 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants