Skip to content

Follow-ups to making all tables fully static#1042

Merged
real-or-random merged 14 commits into
bitcoin-core:masterfrom
sipa:202112_precdotc2
Dec 20, 2021
Merged

Follow-ups to making all tables fully static#1042
real-or-random merged 14 commits into
bitcoin-core:masterfrom
sipa:202112_precdotc2

Conversation

@sipa

@sipa sipa commented Dec 17, 2021

Copy link
Copy Markdown
Contributor

This PR implements a number of changes to follow up after merging #988:

  • Naming consistency:
    • All precomputed table files now have name precomputed_*.*
    • All source files related to the creation of the precomputed table files have name precompute_*.*.
    • All source files related to the computation of tables (whether they go in precomputed files or not) have name *_compute_table.*.
  • Make the tables for exhaustive tests be computed at runtime rather than compile time (this was already the case for ecmult_gen, but not ecmult). This is a preparation for the next point, as the alternative would be to have separate precomputed libraries for the exhaustive tests and other binaries.
  • Moves the actual tables to separate precomputed_*.c files, which are compiled only once as part of a new libsecp256k1_precomputed.la, included where relevant. The corresponding precomputed_*.h file are normal source files.

Retry of #1041.

@sipa sipa force-pushed the 202112_precdotc2 branch 5 times, most recently from fd2a2a6 to 7e2eb52 Compare December 17, 2021 21:25

@real-or-random real-or-random left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK mod nits

Comment thread src/precompute_ecmult.c Outdated
Comment thread src/tests_exhaustive.c
Comment on lines +393 to +396
/* Recreate the ecmult{,_gen} tables using the right generator (as selected via EXHAUSTIVE_TEST_ORDER) */
secp256k1_ecmult_gen_create_prec_table(&secp256k1_ecmult_gen_prec_table[0][0], &secp256k1_ge_const_g, ECMULT_GEN_PREC_BITS);
secp256k1_ecmult_compute_two_tables(secp256k1_pre_g, secp256k1_pre_g_128, WINDOW_G, &secp256k1_ge_const_g);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just for curiosity: I haven't read the tests in detail now but is there a simple reason why the exhaustive tests worked with the wrong ecmult tables but not with the wrong ecmult_gen tables? The existence of known-output tests?

nit: no need to add a second newline here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The existing ecmult tables (from #956) contain separate tables for the exhaustive test case. So they're not using wrong tables.

The problem is that this approach isn't really compatible with the separately-compiled .c file with tables, unless there is a separately-compiled module for (each) exhaustive test generator. So instead I'm modifying the code to use the same approach for ecmult as ecmult_gen does since #988.

@real-or-random

Copy link
Copy Markdown
Contributor

I think so far it was in theory possible to use libsecp by just including the secp256k1.c file, i.e., by including the source instead of linking binaries. I assume this is not a use case we care about (and I don't expect anyone to do this) but I would like to draw attention to this.

@sipa

sipa commented Dec 18, 2021

Copy link
Copy Markdown
Contributor Author

@real-or-random Good to point that out, but I don't think it's really a concern. I think we should preserve (and improve) the ability to build without a complex build/config system around it, but whether that involves building one or two modules isn't the end of the world. If there is actual desire for that, it wouldn't be hard to make src/precomputed_ecmult_{,gen_}.h include the corresponding .c file.

@jonasnick jonasnick left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

otherwise looks good

Comment thread src/ecmult_compute_table.h

@jonasnick jonasnick left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK e05da9e

@real-or-random

Copy link
Copy Markdown
Contributor

ACK e05da9e

@hebasto

hebasto commented Mar 13, 2023

Copy link
Copy Markdown
Member

@sipa

During reviewing of the current master branch, I've noticed that extern "C" {...} guarded by #ifdef __cplusplus were added to non-public headers in the commit e05da9e "Fix c++ build".

But I cannot see any scenario where those headers, i.e., src/precomputed_ecmult.h and src/precomputed_ecmult_gen.h, are processed by a C++ compiler.

FWIW, no issues are observed when compiling Bitcoin Core after removal of extern "C" {...} from the mentioned headers.

Did I miss something?

@real-or-random

Copy link
Copy Markdown
Contributor

But I cannot see any scenario where those headers, i.e., src/precomputed_ecmult.h and src/precomputed_ecmult_gen.h, are processed by a C++ compiler.

I haven't checked, but maybe those will would be relevant when compiling the precomputed compilation unit with a C compiler but the rest with a C++ compiler? But why should anyone do this? ping @sipa

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.

5 participants