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

improve: add some macros to generate big testing suite of fields #131

Conversation

duguorong009
Copy link
Contributor

Description

  • Create some macros to generate the big testing suites for all of fields in the lib

Related issues

Changes

  • Add the field_testing_suite macro for tests of fields
  • Create new macros for testing
  • Replace the functions used for testing, with new macros

@duguorong009 duguorong009 marked this pull request as ready for review January 25, 2024 17:03
Copy link
Contributor

@davidnevadoc davidnevadoc left a comment

Choose a reason for hiding this comment

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

That -700 lines is really good to see! 👍
I have given the PR a pass and it looks good so far. I've left a couple of suggestions.
Will approve it as I check the parts that I'm missing.
Nice work :)

macro_rules! random_multiplication_tests {
($f: ident, $rng: expr) => {
let _message = format!("multiplication {}", stringify!($f));
let start = start_timer!(|| _message);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these timers are quite unnecessary so I suggest removing them form all tests.
We can get rid of the ark-std dev-dependency as well.

Copy link
Contributor Author

@duguorong009 duguorong009 Jan 29, 2024

Choose a reason for hiding this comment

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

Remove the unnecessary timers in b549998

Regarding the ark-std dep, it is used in several places.
For example, it is for feature print-trace, msm testing, and bn256::Fr benchmarking
I think we should keep ark-std dep because of these usages.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, you're right, I forgot about those. Let's keep it then.

#[macro_export]
macro_rules! field_testing_suite {
($field: ident, "field_arithmetic") => {
macro_rules! random_multiplication_tests {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason for having these inner macros?
The outer macro is really nice, but I think these ones could be normal functions and the code would be simpler. I've made a suggestion here: davidnevadoc@a81fe26

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done f54b70c

Copy link
Member

@CPerezz CPerezz left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for this good work! 👍

Comment on lines +502 to +505
0x3c208c16d87cfd47,
0x97816a916871ca8d,
0xb85045b68181585d,
0x30644e72e131a029,
Copy link
Member

Choose a reason for hiding this comment

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

Can we comment how we obtained this? Or from where?

Copy link
Contributor Author

@duguorong009 duguorong009 Feb 2, 2024

Choose a reason for hiding this comment

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

@CPerezz
I add the comment regarding this frobenius power param in 4b5ba0c .
Pls check & gimme the comments.

Comment on lines +558 to +563
[
0x3c208c16d87cfd47,
0x97816a916871ca8d,
0xb85045b68181585d,
0x30644e72e131a029,
]
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Comment on lines +597 to +602
[
0x3c208c16d87cfd47,
0x97816a916871ca8d,
0xb85045b68181585d,
0x30644e72e131a029,
]
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Comment on lines +558 to +564
0x9ffffcd300000001,
0xa2a7e8c30006b945,
0xe4a7a5fe8fadffd6,
0x443f9a5cda8a6c7b,
0xa803ca76f439266f,
0x0130e0000d7f70e4,
0x2400000000002400,
Copy link
Member

Choose a reason for hiding this comment

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

ditto.

Comment on lines +585 to +591
0x9ffffcd300000001,
0xa2a7e8c30006b945,
0xe4a7a5fe8fadffd6,
0x443f9a5cda8a6c7b,
0xa803ca76f439266f,
0x0130e0000d7f70e4,
0x2400000000002400,
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Comment on lines +670 to +678
[
0x9ffffcd300000001,
0xa2a7e8c30006b945,
0xe4a7a5fe8fadffd6,
0x443f9a5cda8a6c7b,
0xa803ca76f439266f,
0x0130e0000d7f70e4,
0x2400000000002400,
]
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor

@davidnevadoc davidnevadoc left a comment

Choose a reason for hiding this comment

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

Nice work, LGTM!

Copy link
Member

@adria0 adria0 left a comment

Choose a reason for hiding this comment

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

Amazing refactor! :)

is assert_eq!(Fr::DELTA, GENERATOR.pow([1u64 << Fr::S])) implemented? I only see it for MULTIPLICATIVE_GENERATOR

crate::field_testing_suite!(Fq, "conversion");
crate::field_testing_suite!(Fq, "serialization");
crate::field_testing_suite!(Fq, "quadratic_residue");
// crate::field_testing_suite!(Fq, "bits");
Copy link
Member

Choose a reason for hiding this comment

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

Leftover?

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, I forgot it. 😅
Thanks for picking! @adria0
Remove it in 91a3f9e.

@duguorong009
Copy link
Contributor Author

Amazing refactor! :)

is assert_eq!(Fr::DELTA, GENERATOR.pow([1u64 << Fr::S])) implemented? I only see it for MULTIPLICATIVE_GENERATOR

I get rid of this test on purpose.
The reason is that the MULTIPLICATIVE_GENERATOR is, in essence, the GENERATOR.
You can check it here.
https://github.com/privacy-scaling-explorations/halo2curves/blob/main/src/bn256/fr.rs#L263

@duguorong009 duguorong009 added this pull request to the merge queue Feb 5, 2024
Merged via the queue into privacy-scaling-explorations:main with commit f96f7f9 Feb 5, 2024
11 checks passed
@CPerezz CPerezz mentioned this pull request Feb 8, 2024
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.

4 participants