8000 Incremental clang-tidy fixes by dtebbs · Pull Request #213 · clearmatics/zeth · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Incremental clang-tidy fixes #213

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

Merged
merged 19 commits into from
May 28, 2020
Merged

Conversation

dtebbs
Copy link
Contributor
@dtebbs dtebbs commented May 7, 2020

Related to #212. Proposal for a subset of warnings to enable for now. Many of the disabled warnings are worth addressing, but may be better done later.

@dtebbs dtebbs changed the base branch from master to tooling-improvement May 7, 2020 14:11
@@ -406,7 +406,7 @@ int main(int argc, char **argv)

#ifdef DEBUG
// Run only if the flag is set
if (jr1cs_file != "") {
if (jr1cs_file.empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this fixed by the tool? It should be !jr1cs_file.empty()

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 my mistake. Thanks.

@dtebbs dtebbs changed the base branch from tooling-improvement to develop May 11, 2020 14:31
@dtebbs dtebbs force-pushed the clang-tidy-incremental-fixes branch 9 times, most recently from 1c80995 to 063f1e3 Compare May 18, 2020 15:00
@dtebbs dtebbs force-pushed the clang-tidy-incremental-fixes branch 6 times, most recently from be2e753 to a30c182 Compare May 20, 2020 11:58
@dtebbs dtebbs changed the title WIP: incremental clang-tidy fixes Incremental clang-tidy fixes May 20, 2020
@dtebbs dtebbs requested a review from AntoineRondelet May 20, 2020 11:58
@dtebbs dtebbs force-pushed the clang-tidy-incremental-fixes branch from a30c182 to 0df760a Compare May 21, 2020 13:26
-modernize-use-auto
-modernize-use-auto,
-modernize-use-trailing-return-type,
-readability-magic-numbers,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we use "magic numbers" in many places? I like this check actually

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In general it's pretty good, but picks up a few bits of test data and some numbers in expressions (masking expressions, etc) which don't really warrant a whole separate constant. It would be nice if it was a tiny bit less sensitive, so we may want to revisit in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, thanks

-readability-magic-numbers,
-readability-implicit-bool-conversion,
-modernize-return-braced-init-list,
-readability-named-parameter,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we use functions with unnamed arguments?

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, in the case of unused parameters we remove the name to stop the compiler complaining.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yes right...

-misc-unused-parameters,
-readability-redundant-member-init,
-modernize-deprecated-headers,
-readability-identifier-naming,
Copy link
Contributor

Choose a reason for hiding this comment

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

I can see that you have disabled many checks here, which is fine (if we can't do otherwise for now). I think it would be nice to add a few lines about why each check has been disabled (as I started to do above) in order to make it crystal clear that we have a reason to remove the checks.

Eg. If we have a lot of magic numbers (in the tests for eg) we can add a line to say "-readability-magic-numbers is removed because we have a lot of magic numbers in the tests [...]". Likewise, I imagine that you removed readability-implicit-bool-conversion because of the boolean vectors we use in the hash implementation, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added some comments about the disabled checks.

// mode. See: Section 2.8 https://blake2.net/blake2.pdf Table 2
std::array<std::array<bool, BLAKE2s_word_size>, 8> parameter_block = {
// mode. See: Section 2.8 https://blake2.net/blake2.pdf Table 2. Note, byte
// endianness has been swapped to avoid doing this repeatedly at runtime.
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean by "to avoid doing this repeatedly at runtime"?

Copy link
Contributor Author
@dtebbs dtebbs May 27, 2020

Choose a reason for hiding this comment

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

Previously, these constants were endian-swappd before being used (see the .tcc file), and this swap was happening for every invocation of generate_r1cs_witness for every instance of the gadget. Those constants did not seem to be used anywhere else, so the byte swapping seemed unnecessary.

What do you mean by "to avoid doing this repeatedly at runtime"?

It refers to the byte swapping. After this change, it's swapped in the static data, so it doesn't have to be done many times when running the proof gen. (I also put the comment for anyone looking at the reference above, in case they see a discrepency in the order).

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yes, I see. The parameter block structure was taken from Table 2. https://blake2.net/blake2.pdf and since blake processed byte strings as little endian the endianness needed to be switched.
Yes that's fine to switch the endianness directly in the parameter block definition. This is what is done in the RFC (see section 2.5 https://tools.ietf.org/html/rfc7693#page-5)

/// "Construct" `bits` types from hexadecimal strings
bits384 bits384_from_hex(const std::string &hex_str);
template<typename FieldT>
void fill_variable_array(
Copy link
Contributor

Choose a reaso 9E7A n for hiding this comment

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

I would add a comment:

/// Pours the content of the *this - the calling bits object - in the variable "var_array" passed to the funcion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks

#
# -readability-implicit-bool-conversion
# We use implicit bool conversion for specifying many constants in terms of
# `0` and `1`. (TODO: it may be a good idea to enable this to fix implicit
Copy link
Contributor

Choose a reason for hiding this comment

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

We can enable this check bu we will need to add a lot of NOLINT comments to disable the checks when we use pb_variable_arrays of booleans (like in blake/sha). This is what I did on #212

@AntoineRondelet AntoineRondelet merged commit d1e4ed3 into develop May 28, 2020
@AntoineRondelet AntoineRondelet deleted the clang-tidy-incremental-fixes branch July 28, 2020 17:53
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.

2 participants
0