-
Notifications
You must be signed in to change notification settings - Fork 2
Simon/snapshots #218
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
base: simon/test_utils_folder
Are you sure you want to change the base?
Simon/snapshots #218
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## simon/test_utils_folder #218 +/- ##
===========================================================
- Coverage 87.95% 87.60% -0.35%
===========================================================
Files 47 49 +2
Lines 9064 9365 +301
Branches 9064 9365 +301
===========================================================
+ Hits 7972 8204 +232
- Misses 645 709 +64
- Partials 447 452 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
1faa085 to
3720e8f
Compare
gilcu3
left a comment
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 did not find any big issue, but did have a lot of suggestions, therefore marking the review as "Request changes". Most of them should be quite easy to solve though.
Once that is done, I can do a quick pass again and approve.
| let max_malicious = 2; | ||
| let participants = generate_participants(5); | ||
|
|
||
| let f = Polynomial::generate_polynomial(None, max_malicious, &mut OsRng).unwrap(); |
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.
same, please lets use deterministic tests
| } | ||
|
|
||
| #[test] | ||
| fn test_snapshot_on_ecdsa_protocol() { |
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 think this test does not belong to this file, as here we are just implementing general snapshot structs. Not sure what the proper place would be though.
| } | ||
|
|
||
| #[test] | ||
| fn test_snapshot_on_ecdsa_protocol() { |
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.
as far I can see this only runs presign, so the function name is a bit misleading
| pub fn run_protocol_with_snapshots<T>( | ||
| mut ps: Vec<(Participant, Box<dyn Protocol<Output = T>>)>, | ||
| ) -> Result<(Vec<(Participant, T)>, ProtocolSnapshot), ProtocolError> { | ||
| // Get the participants | ||
| let participants: Vec<_> = ps.iter().map(|(p, _)| *p).collect(); | ||
| // Build the snapshot | ||
| let mut protocol_snapshots = ProtocolSnapshot::new_empty(participants); | ||
|
|
||
| // Compute the participants indices | ||
| let indices: HashMap<Participant, usize> = | ||
| ps.iter().enumerate().map(|(i, (p, _))| (*p, i)).collect(); | ||
|
|
||
| let size = ps.len(); | ||
| let mut out = Vec::with_capacity(size); | ||
| while out.len() < size { | ||
| for i in 0..size { | ||
| while { | ||
| let action = ps[i].1.poke()?; | ||
| match action { | ||
| Action::Wait => false, | ||
| Action::SendMany(m) => { | ||
| for j in 0..size { | ||
| if i == j { | ||
| continue; | ||
| } | ||
| let from = ps[i].0; | ||
| let to = ps[j].0; | ||
| protocol_snapshots | ||
| .push_message(to, from, m.clone()) | ||
| .ok_or_else(|| { | ||
| ProtocolError::Other( | ||
| "Participant not found in snapshot".to_string(), | ||
| ) | ||
| })?; | ||
| ps[j].1.message(from, m.clone()); | ||
| } | ||
| true | ||
| } | ||
| Action::SendPrivate(to, m) => { | ||
| let from = ps[i].0; | ||
| protocol_snapshots | ||
| .push_message(to, from, m.clone()) | ||
| .ok_or_else(|| { | ||
| ProtocolError::Other( | ||
| "Participant not found in snapshot".to_string(), | ||
| ) | ||
| })?; | ||
| ps[indices[&to]].1.message(from, m); | ||
| true | ||
| } | ||
| Action::Return(r) => { | ||
| out.push((ps[i].0, r)); | ||
| false | ||
| } | ||
| } | ||
| } {} | ||
| } | ||
| } | ||
| Ok((out, protocol_snapshots)) | ||
| } |
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.
This function has an almost identical implementation to the previous one. It would be nice to refactor them so that the logic is only implemented once (in a third function)
| use rand_chacha::{rand_core::SeedableRng, ChaCha12Rng}; | ||
|
|
||
| /// Used for deterministic Rngs and only in testing | ||
| #[derive(Debug, Clone, PartialEq, Eq)] |
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.
This feels a bit strange, but I guess if they are implemented for ChaCha12Rng then its nice for us to have them as well
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'm generally happy to see many traits being eagerly derived as per https://rust-lang.github.io/api-guidelines/interoperability.html?highlight=trait#types-eagerly-implement-common-traits-c-common-traits
netrome
left a comment
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.
Some nits from my side, but overall I think it looks good. I agree with the general comments about test organization from Reynaldo.
The only blockers I see are:
- Some docstrings are a bit confusing right now.
- The tests that use OsRng should be made deterministic.
| use rand_chacha::{rand_core::SeedableRng, ChaCha12Rng}; | ||
|
|
||
| /// Used for deterministic Rngs and only in testing | ||
| #[derive(Debug, Clone, PartialEq, Eq)] |
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'm generally happy to see many traits being eagerly derived as per https://rust-lang.github.io/api-guidelines/interoperability.html?highlight=trait#types-eagerly-implement-common-traits-c-common-traits
|
|
||
| use crate::{participants::Participant, protocol::MessageData}; | ||
|
|
||
| /// Constructor for specific (sender, messages) pairs transmitted during a protocol run |
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.
This is not a constructor. Is the docstring stale or would it be sufficient to just say something like
| /// Constructor for specific (sender, messages) pairs transmitted during a protocol run | |
| /// A single received message during a protocol run |
| } | ||
| } | ||
|
|
||
| /// Registers a particular participant's view of the received messages |
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.
Nit: "Registers" sounds confusing here since this is a data structure, not a behavior.
| /// Registers a particular participant's view of the received messages | |
| /// A participant's view of their received messages |
| } | ||
|
|
||
| #[test] | ||
| fn test_snapshot_on_ecdsa_protocol() { |
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.
If I understand this correctly, the purpose of the test is to verify that the protocol is deterministic. How about naming it something like:
| fn test_snapshot_on_ecdsa_protocol() { | |
| fn ecdsa_presign__should_return_same_snapshot_when_executed_twice() { |
Closes #145