Skip to content

Commit e0d7bdd

Browse files
committed
[cryptography] Golden: remove redundant output checks
1 parent b141ff2 commit e0d7bdd

1 file changed

Lines changed: 11 additions & 105 deletions

File tree

cryptography/src/bls12381/golden_dkg.rs

Lines changed: 11 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -174,20 +174,6 @@ pub enum Error {
174174
UnknownDealer(String),
175175
/// The caller's key is not in the set of players.
176176
UnknownPlayer,
177-
/// The sharing's participant count does not match the player set.
178-
SharingPlayersMismatch {
179-
/// Number of participants encoded in the public sharing.
180-
sharing_total: u32,
181-
/// Number of players exported alongside that sharing.
182-
players: usize,
183-
},
184-
/// The output quorum exceeds the number of exported players.
185-
InvalidQuorum {
186-
/// Number of players needed to reconstruct the key.
187-
quorum: u32,
188-
/// Number of exported players.
189-
players: usize,
190-
},
191177
/// The configured number of players exceeds the maximum supported by the
192178
/// provided [`Setup`]. Build a larger [`Setup`] (see [`Setup::new`]) or
193179
/// pre-check via [`Setup::supports`].
@@ -211,44 +197,26 @@ pub struct Output<P> {
211197
}
212198

213199
impl<P: Ord + Clone> Output<P> {
214-
/// Construct a validated round output.
200+
/// Construct a round output.
215201
///
216-
/// The exported quorum must not exceed the number of exported players, and
217-
/// the public sharing must have the same participant count as the player set.
218-
pub fn new(
202+
/// Assumes the caller has already validated participant counts via
203+
/// [`Info::new`], and that `public.total() == players.len()` and
204+
/// `quorum <= players.len()` by construction.
205+
fn new(
219206
summary: Summary,
220207
public: Sharing<MinPk>,
221208
quorum: NonZeroU32,
222209
dealers: Set<P>,
223210
players: Set<P>,
224-
) -> Result<Self, Error> {
225-
let participant_range = 1..u32::MAX as usize;
226-
if !participant_range.contains(&dealers.len()) {
227-
return Err(Error::NumDealers(dealers.len()));
228-
}
229-
if !participant_range.contains(&players.len()) {
230-
return Err(Error::NumPlayers(players.len()));
231-
}
232-
if public.total().get() as usize != players.len() {
233-
return Err(Error::SharingPlayersMismatch {
234-
sharing_total: public.total().get(),
235-
players: players.len(),
236-
});
237-
}
238-
if quorum.get() > players.len() as u32 {
239-
return Err(Error::InvalidQuorum {
240-
quorum: quorum.get(),
241-
players: players.len(),
242-
});
243-
}
244-
Ok(Self {
211+
) -> Self {
212+
Self {
245213
summary,
246214
public,
247215
quorum,
248216
dealers,
249217
players: players.clone(),
250218
revealed: players,
251-
})
219+
}
252220
}
253221

254222
/// Return the authoritative quorum for this round, i.e. the number of
@@ -671,13 +639,13 @@ pub fn observe(
671639
.cloned()
672640
.try_collect()
673641
.expect("selected dealers are unique");
674-
Output::new(
642+
Ok(Output::new(
675643
*info.summary(),
676644
sharing,
677645
info.player_quorum,
678646
dealers,
679647
info.players.clone(),
680-
)
648+
))
681649
}
682650

683651
/// Compute the public output and recover this player's private share.
@@ -749,7 +717,7 @@ pub fn play(
749717
info.player_quorum,
750718
dealers,
751719
info.players.clone(),
752-
)?;
720+
);
753721
let share = Share::new(my_index, Private::new(private));
754722
Ok((output, share))
755723
}
@@ -2090,68 +2058,6 @@ mod tests {
20902058
assert!(matches!(result, Err(Error::NumDealers(0))));
20912059
}
20922060

2093-
#[test]
2094-
fn output_rejects_public_total_mismatch() {
2095-
let mut rng = commonware_utils::test_rng();
2096-
let public = Sharing::new(
2097-
Mode::default(),
2098-
NonZeroU32::new(2).unwrap(),
2099-
Poly::commit(Poly::new(&mut rng, 0)),
2100-
);
2101-
let dealers: Set<PublicKey> = std::iter::once(PrivateKey::random(&mut rng).public())
2102-
.try_collect()
2103-
.unwrap();
2104-
let players: Set<PublicKey> = std::iter::once(PrivateKey::random(&mut rng).public())
2105-
.try_collect()
2106-
.unwrap();
2107-
2108-
let result = Output::new(
2109-
Summary::random(&mut rng),
2110-
public,
2111-
NonZeroU32::new(1).unwrap(),
2112-
dealers,
2113-
players,
2114-
);
2115-
assert!(matches!(
2116-
result,
2117-
Err(Error::SharingPlayersMismatch {
2118-
sharing_total: 2,
2119-
players: 1,
2120-
})
2121-
));
2122-
}
2123-
2124-
#[test]
2125-
fn output_rejects_quorum_larger_than_player_set() {
2126-
let mut rng = commonware_utils::test_rng();
2127-
let public = Sharing::new(
2128-
Mode::default(),
2129-
NonZeroU32::new(1).unwrap(),
2130-
Poly::commit(Poly::new(&mut rng, 0)),
2131-
);
2132-
let dealers: Set<PublicKey> = std::iter::once(PrivateKey::random(&mut rng).public())
2133-
.try_collect()
2134-
.unwrap();
2135-
let players: Set<PublicKey> = std::iter::once(PrivateKey::random(&mut rng).public())
2136-
.try_collect()
2137-
.unwrap();
2138-
2139-
let result = Output::new(
2140-
Summary::random(&mut rng),
2141-
public,
2142-
NonZeroU32::new(2).unwrap(),
2143-
dealers,
2144-
players,
2145-
);
2146-
assert!(matches!(
2147-
result,
2148-
Err(Error::InvalidQuorum {
2149-
quorum: 2,
2150-
players: 1,
2151-
})
2152-
));
2153-
}
2154-
21552061
#[test]
21562062
fn info_rejects_reshare_dealer_outside_previous_players() {
21572063
let mut rng = commonware_utils::test_rng();

0 commit comments

Comments
 (0)