-
Notifications
You must be signed in to change notification settings - Fork 1
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
[WAR-489] DKG test mockup using Fp and sample tracing #21
Conversation
merolish
commented
Aug 19, 2024
•
edited
Loading
edited
- DKG example in /examples
- At the moment, some Fp debug tracing
Clippy, fmt, and test fix ser! |
…into mike/dkg-tests
…into mike/dkg-tests
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 should move this to /examples and make it compile, as discussed, resolve lint issues and make it satisfy CI.
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.
left some light comments on the dkg stuff
Cargo.toml
Outdated
tracing = "0.1.40" | ||
confy = "0.6.1" | ||
rand = "0.9.0-alpha.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 rand explicitly imported? We should be using crypto_bigint::rand_core
for all things rng
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.
That's a leftover from when I was generating regular ints, will remove.
examples/dkg.rs
Outdated
while values.len() < count { | ||
let value = | ||
<Fp as FieldExtensionTrait<1, 1>>::rand(&mut OsRng) % Fp::from(max) + Fp::from(min); | ||
values.insert(value.value()); |
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.
Was there still the issue of adding the Eq
trait to Fp
?
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.
Yes...here I'm using U256s. Let me try that out.
examples/dkg.rs
Outdated
values.into_iter().map(Fp::new).collect() | ||
} | ||
|
||
#[allow(dead_code)] |
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.
how come this is dead? is it just clippy being silly?
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 will complain if there is any unused field. I can remove/comment out for the purpose of this test. In a distributed system they'd end up being used, hence having them.
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.
Glad to do whatever would be most illustrative.
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.
it's fine to leave it in, but it may be worth adding a comment stating this so it doesn't seem like we're just having code here for its own sake but for our future compatibility with the code we will eventually write for infra
src/fields/fp.rs
Outdated
@@ -374,33 +374,45 @@ macro_rules! define_finite_prime_field { | |||
if other.is_zero() { | |||
return Self::from(0u64); | |||
} | |||
let (mut _q, mut _r) = self | |||
let (mut _q, mut _r) = dbg!(self |
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 should be using the tracing::debug! macro here. We should not be wrapping the production code in the debug macro itself imo.
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.e. we should print debug statements of the values via tracing::debug, but such that they don't end up in the production build.
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.
Got it. My understanding was that dbg! worked in the same way, will opt for using tracing by default everywhere.
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.
Meant to request changes.
…into mike/dkg-tests
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.
Only one minor thing to change but overall it seems to be nice; good tracing in the mission critical stuff, and done in a way that doesn't seem to me to introduce branching => SCAs.
DKG also looks very nice too. I think that what's going to happen eventually when I make the thresholding signatures is that I'll make a general polynomial struct that the both the DKG and threshold BLS can use, so this will likely change a little but is an excellent self-contained cut. Great stuff!
src/fields/fp.rs
Outdated
@@ -133,7 +133,8 @@ macro_rules! define_finite_prime_field { | |||
|
|||
//special struct for const-time arithmetic on montgomery form integers mod p | |||
type $output = crypto_bigint::modular::ConstMontyForm<$mod_struct, { $mod_struct::LIMBS }>; | |||
#[derive(Clone, Debug, Copy)] //to be used in const contexts | |||
#[derive(Clone, Copy)] //to be used in const contexts | |||
#[derive(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.
consildate into one line please
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.
Ah, yes, I separated because of the const context comment. I can clarify that to just refer to clone/copy.
But please run fmt and clippy, forgot to mention! |
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.
small typos to fix; but otherwise lgtm! great work
src/pairing.rs
Outdated
@@ -130,6 +131,7 @@ impl MillerLoopResult { | |||
let mut z5 = f.0[1].0[2]; | |||
// Line 9 | |||
let (t0, t1) = fp4_square(z0, z1); | |||
tracing::debug!(?t0, ?t1, "MillerLoopResult::cyclotonic_squared"); |
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.
typos here and in line 144, should be "cyclotomic" with an "m", not "cyclotonic"
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.
Oops.
src/pairing.rs
Outdated
@@ -139,6 +141,7 @@ impl MillerLoopResult { | |||
|
|||
let (mut t0, t1) = fp4_square(z2, z3); | |||
let (t2, t3) = fp4_square(z4, z5); | |||
tracing::debug!(?t0, ?t1, ?t2, ?t3, "MillerLoopResult::cyclotonic_squared"); |
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.
see above comment
…into mike/dkg-tests