-
Notifications
You must be signed in to change notification settings - Fork 41
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
helper for unsafe code #722
Conversation
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.
clippy found more than 10 potential problems in the proposed changes. Check the Files changed tab for more details.
7ec5fd0
to
1c914fd
Compare
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.
A first round of comments. Tomorrow I'll look into the unsafe_helpers module.
mithril-stm/src/multi_sig.rs
Outdated
// use blst::{ | ||
// blst_fp12, blst_fp12_finalverify, blst_p1_affine_generator, blst_p2_affine_generator, | ||
// BLST_ERROR, | ||
// }; |
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.
leftover?
mithril-stm/src/multi_sig.rs
Outdated
use blst::{ | ||
blst_p1, blst_p1_affine, blst_p1_compress, blst_p1_from_affine, blst_p1_to_affine, | ||
blst_p1_uncompress, blst_p2, blst_p2_affine, blst_p2_from_affine, blst_p2_to_affine, | ||
blst_scalar, p1_affines, p2_affines, | ||
blst_scalar, p1_affines, p2_affines, BLST_ERROR, | ||
}; |
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't any of these imports be moved to the unsafe_helpers module?
mithril-stm/src/multi_sig.rs
Outdated
bytes | ||
} | ||
|
||
pub(crate) fn uncompress_p1(bytes: &[u8]) -> blst_p1 { |
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.
We could do a length check for the input. if it's not 48 bytes, return error. I also thought of using an array, [u8; 48]
, but that might complicate the function call, and it's not necessary.
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.
Meaning the output of the function should be aResult<blst_p1, ()>
rather than a point (where ()
should be some error type that we have in the lib).
mithril-stm/src/multi_sig.rs
Outdated
unsafe { | ||
let mut point = blst_p1_affine::default(); | ||
let mut out = blst_p1::default(); | ||
blst_p1_uncompress(&mut point, bytes.as_ptr()); |
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 returns a BLST_ERROR
. It should not be ignored.
mithril-stm/src/multi_sig.rs
Outdated
} | ||
} | ||
|
||
pub(crate) fn p2_affine_to_vk(grouped_vks: &p2_affines, scalars: &[u8]) -> BlstVk { |
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 signature is very confusing. It's name p2_affine_to_vk
but you give as input &p2_affines
and &[u8]
, and you output a BlstVk
. This function should already take as input the result of &grouped_vks.mult(scalars, 128)
, or have a different name (if possible, I'd suggest the former).
mithril-stm/src/multi_sig.rs
Outdated
} | ||
} | ||
|
||
pub(crate) fn p1_affine_to_sig(grouped_sigs: &p1_affines, scalars: &[u8]) -> BlstSig { |
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 comment as for p2_affine_to_vk
function
Co-authored-by: Iñigo Querejeta Azurmendi <31273774+iquerejeta@users.noreply.github.com>
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.
Looks good 👍 just minor comment to revert one comment I said in the previous round, didn't realise it would require us to copy secret data.
mithril-stm/src/multi_sig.rs
Outdated
// blst_p1_affine, blst_p1_compress, blst_p1_from_affine, blst_p1_to_affine, | ||
// blst_p1_uncompress, blst_p2, blst_p2_affine, blst_p2_from_affine, blst_p2_to_affine, | ||
// blst_scalar, p1_affines, p2_affines, BLST_ERROR, |
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.
leftover
blst_scalar, blst_sk_to_pk_in_g1, | ||
}; | ||
|
||
pub(crate) fn verify_pairing(vk: &VerificationKey, pop: &ProofOfPossession) -> bool { |
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 would include a little description of what this function does, as one could get confused. I would describe the relation that it is checking, i.e. e(g1, mvk) = e(k2, g2)
.
mithril-stm/src/multi_sig.rs
Outdated
|
||
pub(crate) fn scalar_to_pk_in_g1(sk: &SigningKey) -> blst_p1 { | ||
unsafe { | ||
let sk_scalar = std::mem::transmute::<BlstSk, blst_scalar>(sk.0.clone()); |
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 like the fact that we have to clone the secret key here. I know I said about consistency in my previous comment, but it is true that this means that the value of the secret key needs to be cloned. I did not think about that. I'd rather revert to the previous state, where we transmute the pointers so that we don't have to clone secret data.
Content
This PR includes the helper functions that store all usage of unsafe code in
multi_sig.rs
.Pre-submit checklist
Issue(s)
Closes #690