-
Notifications
You must be signed in to change notification settings - Fork 313
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
Fix clippy warnings and format README #71
Conversation
Readme was formatted by https://github.com/DavidAnson/vscode-markdownlint |
hi @kigawas - As a side comment we are working on adding tags which will make life easier for all. |
We can merge this PR first and resolve conflicts later |
moved some dependencies to |
For 1, mainly in this commit Rational: use multi_party_ecdsa::protocols::multi_party_ecdsa::gg_2018::party_i::{
KeyGenBroadcastMessage1 as KeyGenCommit, KeyGenDecommitMessage1 as KeyGenDecommit,
};
use curv::cryptographic_primitives::proofs::sigma_dlog::DLogProof;
use curv::cryptographic_primitives::secret_sharing::feldman_vss::VerifiableSS;
use curv::FE;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum KeyGenMessage {
CommitAndDecommit(PeerIndex, KeyGenCommit, KeyGenDecommit),
VSS(PeerIndex, VerifiableSS),
SecretShare(PeerIndex, FE),
Proof(PeerIndex, DLogProof),
}
impl PartialEq for KeyGenMessage {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::CommitAndDecommit(ia, ca, da), Self::CommitAndDecommit(ib, cb, db)) => {
ia == ib
&& ca.com == cb.com && ca.e == cb.e
&& da.blind_factor == db.blind_factor
&& da.y_i == db.y_i
}
(Self::VSS(ia, vssa), Self::VSS(ib, vssb)) => ia == ib && vssa == vssb,
(Self::SecretShare(ia, ssa), Self::SecretShare(ib, ssb)) => ia == ib && ssa == ssb,
(Self::Proof(ia, pa), Self::Proof(ib, pb)) => ia == ib && pa == pb,
_ => false,
}
}
} |
For 2, I only remove the redundant // test.rs
#[cfg(test)]
mod tests { // <- no need
fn test_a() {}
fn test_b() {}
} // lib.rs
mod test; to // test.rs
fn test_a() {}
fn test_b() {} // lib.rs
#[cfg(test)]
mod test; |
This should also be applied to bench |
Also add test of checking signature against other secp256k1 library (https://github.com/sorpaas/libsecp256k1-rs) |
some examples for new variables: I don't understand why they are necessary ? 2)I think that It is impossible to implement PatrtialEq from outside the library if some elements in the struct are private. Usually when there's a PartialEq derive it means that it is was required by some other library. Therefore I am not very excited with removing them for now |
If you add more variables, you have to add new names Simply deriving PartialEq is not enough, user has to adapt it to his own needs, which means that comparing two messages are equal or what makes them equal should be left to user's implementation. It's certainly possible, the example above was copied from real codes I'm writing. And if you define "messages", obviously they are used outside, and their fields should be public. |
Of course, deriving PartialEq for all messages is also a solution, which makes user write less codes. I have no preference for this though, both of them are okay |
Cargo.toml
Outdated
serde_json = "1.0" | ||
libsecp256k1 = "0.2.2" |
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.
why is this dependency needed?
I don't see it consumed anywhere.
Also curv
uses secp256k1
and not libsecp256k1
and for a very good reason I believe - secp256k1
uses C bindings for libsecp256k1 in C, which is by far the most battle tested library for secp256k1...
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 for testing signature against another secp256k1 repo
Rust wrapper of C bindings for libsecp256k1 is not reliable as you think, see rust-bitcoin/rust-secp256k1#163
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.
Of course, I'm just saying the rust wrapper is with problem
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.
Can you please point me to where libsecp256k1
is consumed?
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.
libp2p and substrate, is it enough to convince you?
https://github.com/libp2p/rust-libp2p
https://github.com/paritytech/substrate/
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.
Even it is not widely used, there is no hurt if you use it for testing against signature
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.
And why we don't use C bindings?
The answer is:
rust-bitcoin/rust-secp256k1#163
That is to say, it'll break the test
let party_keys_vec = (0..n.clone()) | ||
.map(|i| Keys::create(i)) | ||
.collect::<Vec<Keys>>(); | ||
let (t, n) = (t as usize, n as usize); |
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.
is redefining absolutely necessary here? are they used into APIs that require usize
?
Maybe this PR should focus on changing the requirement of the APIs to use u16
rather than the consuming code in benches
?
e.g.
- https://github.com/kigawas/multi-party-ecdsa/blob/keygen-clippy/src/protocols/multi_party_ecdsa/gg_2018/party_i.rs#L56
- https://github.com/kigawas/multi-party-ecdsa/blob/keygen-clippy/src/protocols/multi_party_ecdsa/gg_2018/party_i.rs#L147
- https://github.com/kigawas/multi-party-ecdsa/blob/keygen-clippy/src/protocols/multi_party_ecdsa/gg_2018/party_i.rs#L161
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 just a handy redefinition to avoid lots of as usize below
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.
So it doesn't fix #72?
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.
should've already fixed
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.
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'll also fix other usize
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.
About party_index
, since secret shares (in curv) are taking usize, I'll just keep it here
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.
Thank you for your work. I added comments I'll be glad to discuss.
@kigawas is it possible to divide this PR into few smaller PRs? |
@omershlo
you can check it by commit |
…-ecdsa into keygen-clippy
assert_eq!(decom_vec.len(), params.share_count); | ||
assert_eq!(bc1_vec.len(), params.share_count); | ||
assert_eq!(decom_vec.len() as u16, params.share_count); | ||
assert_eq!(com_vec.len() as u16, params.share_count); |
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 don't think this rename is necessary.
if test_b_vec_and_com { | ||
Ok({ | ||
let gamma_sum = tail.fold(head.g_gamma_i, |acc, x| acc + x.g_gamma_i); | ||
gamma_sum * delta_inv |
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.
Please don't remove the R
or otherwise add a comment that this is R
@kigawas I see you changed the param file to params.json. In that case can you also provide such file in the repo (replacing the old params file) ? |
I finished my review. I approve once the comments above are resolved. |
Fix #72
Fix #74