Skip to content
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

Merged
merged 19 commits into from
Aug 21, 2024
Merged

Conversation

merolish
Copy link
Contributor

@merolish merolish commented Aug 19, 2024

  • DKG example in /examples
  • At the moment, some Fp debug tracing

Copy link

linear bot commented Aug 19, 2024

WAR-489 DKG tests

@0xAlcibiades 0xAlcibiades marked this pull request as ready for review August 19, 2024 17:34
@0xAlcibiades
Copy link
Member

Clippy, fmt, and test fix ser!

Copy link
Member

@0xAlcibiades 0xAlcibiades left a 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.

Copy link
Collaborator

@trbritt trbritt left a 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 Show resolved Hide resolved
Cargo.toml Outdated
tracing = "0.1.40"
confy = "0.6.1"
rand = "0.9.0-alpha.2"
Copy link
Collaborator

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

Copy link
Contributor Author

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 Show resolved Hide resolved
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());
Copy link
Collaborator

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?

Copy link
Contributor Author

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)]
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

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

examples/dkg.rs Show resolved Hide resolved
examples/dkg.rs Outdated Show resolved Hide resolved
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
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

@0xAlcibiades 0xAlcibiades left a 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.

@merolish merolish changed the title [WAR-489] DKG test mockup using Fp [WAR-489] DKG test mockup using Fp and sample tracing Aug 21, 2024
Copy link
Collaborator

@trbritt trbritt left a 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)]
Copy link
Collaborator

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

Copy link
Contributor Author

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.

@trbritt
Copy link
Collaborator

trbritt commented Aug 21, 2024

But please run fmt and clippy, forgot to mention!

Copy link
Collaborator

@trbritt trbritt left a 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");
Copy link
Collaborator

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"

Copy link
Contributor Author

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");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above comment

@merolish merolish merged commit b36d074 into main Aug 21, 2024
15 checks passed
@merolish merolish deleted the mike/dkg-tests branch August 21, 2024 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants