Skip to content

Conversation

siv2r
Copy link
Owner

@siv2r siv2r commented Jul 23, 2022

For debugging CI tests

siv2r added 30 commits May 16, 2022 15:23
- `schnorrsig_batch_context_create`
- `schnorrsig_batch_context_destroy`
- simple test that calls both create and destroy (failing)
destroying the scratch space when its alloc_size > 0 leads to an error
secp256k1_context obj is used for its error_callback function
In future, batch_context_create and batch_context_destroy will be
moved to src/ directory. Only batch_context_add_*, batch_context_verify
will be present in the schnorrsig module
batch_context_create and batch_context_destroy function are compiled
by default.

src/batch_impl: contains create and destroy function definition.

This implementation is very similar to src/scratch_impl.h
added initial example where the batch context is created and destroyed.
added batch_context_verify to the schnorrsig module
batch_ctx->rounds keeps track of number of times the scratch space was
erased by batch_add_* function. This occurs when user's inputs exceed
batch object capacity (specified during creation).
This func will be update to include the following:
[ ] randomizer generation (currently assume to be 1)
[ ] run transparent verification if batch object is full
…orrsig

batch_context_verify:
- moved this API from module/schnorrsig/main_impl.h to secp256k1.c
- hence this API will be available even if the user doesn't enable schnorrsig module

batch_context_add_schnorrsig:
- moved this API from module/schnorrsig/main_impl.h to module/schnorrsig/batch_add_impl.h
- required since this api needs the `schnorrsig_challenge` func defined in schnorrsig/main_impl.h
- hence batch_impl.h will be included after schnorrsig/main_impl.h in the secp256k1.c file
for each term added by the user, twice the number of points (and scalars)
will be added to the scratch space. One term (schnorrsig or tweak) contains:
- R, P for schnorrsig
- Q, P for tweak check
…ignment

currently the code uses `scalar_cmov` to set a scalar to the scratch space.
This can be done using `batch_ctx->scalars[i] = ai` instead since we are
not required to use constant function during verification
…on scratch

let's use the following notation:
    - len(user_terms) = number of terms added by the user to the batch object
    - len(scratch_terms) = number of points (or scalars) present on batch objects's scratch space

Previously `batch_ctx->len` was used to represent `len(user_terms)` since I assumed that
`len(scratch_terms) = 2 * len(user_terms)` is always true.
    - if user adds schnorrsig, R and P will be added to scratch
    - if user adds tweak checks, Q and P will be added to scratch

This approach will fail if the batch objects is required to verify `e*P ?= s*G`. In this case,
`len(scratch_term) = len(user_term)` since only P will be added to batch objects scratch space
`rounds` was used to track the number of times the scratch space was
cleared by batch_context_add_* for transparent verification. It will
also tell the number of terms the user entered (rounds*capacity + len).

Keeping track of this data was not worth it since the user could always
have a counter to for total number of terms entered. It also made the
`batch_verify` function look messy. Hence, decided to remove `rounds` memeber.

The side effect of removing this data memeber is setting `batch_ctx->result = 1`
during creation since we alwasy need to `&&` with `batch_ctx->result` during
verification.
If the user calls `batch_add_schnorrsig` while the batch context's scratch
space is full (i.e, batch_ctx->len = batch_ctx->capacity). The previously
allocated points and scalars will be erased to allow adding new points
and scalars (to scratch space).
this part of batch_create does performs the same operation as
`secp256k1_batch_scratch_alloc`, so calling that func instead
Adds xonly pubkey tweak check data to the batch context.
This function's algorithm is based on `secp256k1_xonly_pubkey_tweak_add_check`.
Batch context's secp256k1_sha256 object will be initialized with the tag "BIP0340/batch"
- removed `init` from the randomizer function name
- removed `tweaked_buf[33]` from `secp256k1_batch_xonlypub_randomizer`
- update documentation of `batch_context_add_*` functions
libsecp's CI tests required a newline to be present at the end of every file
- rename `n_terms` to `max_terms`
- add `static` keyword for internal function definition
- add `ARG_CHECK(batch_ctx != NULL)`
siv2r and others added 19 commits July 9, 2022 17:26
Previously:
- `batch_add_schnorrsig` API was exposed through `include/secp256k1_schnorrsig.h`.
- `batch_add_xonlypub_tweak_check` API was exposed through `include/secp256k1_extrakeys.h`.
-  These APIs also had an `#ifdef` guard to check if user enable the batch module.

Placing an `#ifdef` guard in an include file forces the user to define `ENABLE_MODULE_BATCH`
macro while compling their C program. Hence, the `batch_add_` APIs are exposed through a
new header file without any `#ifdef`. Now, the user can simply the any libsecp's header file
without worrying about defining any macro (during compilation).
@siv2r siv2r closed this Jul 23, 2022
@siv2r siv2r reopened this Jul 23, 2022
@siv2r
Copy link
Owner Author

siv2r commented Jul 23, 2022

Fixed CI test issues

@siv2r siv2r closed this Jul 23, 2022
@siv2r siv2r deleted the debug-ci branch July 24, 2022 18:08
siv2r pushed a commit that referenced this pull request Jun 25, 2025
f87a358 cmake: Do not set `CTEST_TEST_TARGET_ALIAS` (Hennadii Stepanov)

Pull request description:

  An alias for the "test" target can be confusing for the downstream project.

  For instance, when integrating using `add_subdirectory(secp256k1 EXCLUDE_FROM_ALL)` (see hebasto/bitcoin#192), test binaries are not being built by default. But the `check` alias target is exposed to the downstream project build system, which in turn fails:
  ```
  $ make -C build check
  ...
  Unable to find executable: /home/hebasto/git/bitcoin/build/src/secp256k1/src/exhaustive_tests
  3/3 Test #3: exhaustive_tests .................***Not Run   0.00 sec

  0% tests passed, 3 tests failed out of 3

  Total Test time (real) =   0.03 sec

  The following tests FAILED:
    1 - noverify_tests (Not Run)
    2 - tests (Not Run)
    3 - exhaustive_tests (Not Run)
  Errors while running CTest
  ...
  ```

  This PR fixes this issue by deleting the `CTEST_TEST_TARGET_ALIAS` usage.

ACKs for top commit:
  real-or-random:
    utACK bitcoin-core@f87a358

Tree-SHA512: ccf3f30939cf1747471ea15260f7caa6dad3f510e5771245ecbfbef3cc0b0e7c8ac551519d0892bf2544c91467d8d67d2c6e6bc52f56c384b174b88bcf377d4a
siv2r pushed a commit that referenced this pull request Jun 25, 2025
… names

87384f5 cmake, test: Add `secp256k1_` prefix to test names (Hennadii Stepanov)

Pull request description:

  This PR improves regex matching options when using `ctest` in downstream projects, such as Bitcoin Core.

  For instance, a downstream project users can filter their tests like that:
  ```
  ctest --tests-regex "secp256k1"
  ```
  or
  ```
  ctest --exclude-regex "secp256k1"
  ```

  A `ctest` log with this PR:
  ```
  $ ctest --test-dir build -j 16
  Internal ctest changing into directory: /home/hebasto/git/secp256k1/secp256k1/build
  Test project /home/hebasto/git/secp256k1/secp256k1/build
      Start 1: secp256k1_noverify_tests
      Start 2: secp256k1_tests
      Start 3: secp256k1_exhaustive_tests
      Start 4: secp256k1_ecdsa_example
      Start 5: secp256k1_ecdh_example
      Start 6: secp256k1_schnorr_example
      Start 7: secp256k1_ellswift_example
      Start 8: secp256k1_musig_example
  1/8 Test #4: secp256k1_ecdsa_example ..........   Passed    0.00 sec
  2/8 Test #5: secp256k1_ecdh_example ...........   Passed    0.00 sec
  3/8 Test #6: secp256k1_schnorr_example ........   Passed    0.00 sec
  4/8 Test #7: secp256k1_ellswift_example .......   Passed    0.00 sec
  5/8 Test bitcoin-core#8: secp256k1_musig_example ..........   Passed    0.00 sec
  6/8 Test #3: secp256k1_exhaustive_tests .......   Passed    6.19 sec
  7/8 Test #1: secp256k1_noverify_tests .........   Passed   38.83 sec
  8/8 Test #2: secp256k1_tests ..................   Passed   91.66 sec

  100% tests passed, 0 tests failed out of 8

  Total Test time (real) =  91.67 sec
  ```

ACKs for top commit:
  theuni:
    utACK 87384f5
  real-or-random:
    utACK 87384f5

Tree-SHA512: d8e46558cf58c9c660544b7bdfed24c991eb3e120b6511aa3968f509190130e498749a3c4dbabc87a7f22f0aa0056c6bcd3fc6c44f5eb131588945d593546840
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