Skip to content

Commit

Permalink
SQUASH ME: Fix silent merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
fjahr committed Nov 27, 2024
1 parent 4a0ea61 commit 69df387
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 126 deletions.
1 change: 1 addition & 0 deletions src/modules/batch/main_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ int secp256k1_batch_verify(const secp256k1_context *ctx, secp256k1_batch *batch)
}

if (batch->len > 0) {
/* TODO: check why this is reported as unused variable, probably because of the VERIFY_CHECK being optimized out */
int strauss_ret = secp256k1_ecmult_strauss_batch_internal(&ctx->error_callback, batch->data, &resj, batch->scalars, batch->points, &batch->sc_g, batch->len);
int mid_res = secp256k1_gej_is_infinity(&resj);

Expand Down
47 changes: 24 additions & 23 deletions src/modules/batch/tests_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ void test_batch_sha256_tagged(void) {
#define N_TWK_CHECKS 10
#define N_TERMS (N_TWK_CHECKS + 2*N_SIGS)
void test_batch_api(void) {
secp256k1_batch *batch_none;
secp256k1_batch *batch_sign;
secp256k1_batch *batch_vrfy;
secp256k1_batch *batch_both;
secp256k1_batch *batch_sttc;
unsigned char aux_rand16[32];
int ecount;

#ifdef ENABLE_MODULE_EXTRAKEYS
unsigned char sk[32];
Expand All @@ -62,39 +69,33 @@ void test_batch_api(void) {
secp256k1_context *sign = secp256k1_context_create(SECP256K1_CONTEXT_SIGN);
secp256k1_context *vrfy = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY);
secp256k1_context *both = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
secp256k1_context *sttc = secp256k1_context_clone(secp256k1_context_no_precomp);
secp256k1_batch *batch_none;
secp256k1_batch *batch_sign;
secp256k1_batch *batch_vrfy;
secp256k1_batch *batch_both;
secp256k1_batch *batch_sttc;
unsigned char aux_rand16[32];
int ecount;

secp256k1_context_set_error_callback(none, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_error_callback(sign, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_error_callback(vrfy, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_error_callback(both, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_error_callback(sttc, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_illegal_callback(none, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_illegal_callback(sign, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_illegal_callback(vrfy, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_illegal_callback(both, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_illegal_callback(sttc, counting_illegal_callback_fn, &ecount);
secp256k1_context *sttc = malloc(sizeof(*secp256k1_context_no_precomp));
memcpy(sttc, secp256k1_context_no_precomp, sizeof(secp256k1_context));

secp256k1_context_set_error_callback(none, counting_callback_fn, &ecount);
secp256k1_context_set_error_callback(sign, counting_callback_fn, &ecount);
secp256k1_context_set_error_callback(vrfy, counting_callback_fn, &ecount);
secp256k1_context_set_error_callback(both, counting_callback_fn, &ecount);
secp256k1_context_set_error_callback(sttc, counting_callback_fn, &ecount);
secp256k1_context_set_illegal_callback(none, counting_callback_fn, &ecount);
secp256k1_context_set_illegal_callback(sign, counting_callback_fn, &ecount);
secp256k1_context_set_illegal_callback(vrfy, counting_callback_fn, &ecount);
secp256k1_context_set_illegal_callback(both, counting_callback_fn, &ecount);
secp256k1_context_set_illegal_callback(sttc, counting_callback_fn, &ecount);

/* 16 byte auxiliary randomness */
secp256k1_testrand256(aux_rand16);
testrand256(aux_rand16);
memset(&aux_rand16[16], 0, 16);

#ifdef ENABLE_MODULE_EXTRAKEYS
/* generate keypair data */
secp256k1_testrand256(sk);
testrand256(sk);
CHECK(secp256k1_keypair_create(sign, &keypair, sk) == 1);
CHECK(secp256k1_keypair_xonly_pub(sign, &pk, NULL, &keypair) == 1);

/* generate N_TWK_CHECKS tweak check data (tweaked_pk, tweaked_pk_parity, tweak) */
for (i = 0; i < N_TWK_CHECKS; i++) {
secp256k1_testrand256(tweak[i]);
testrand256(tweak[i]);
CHECK(secp256k1_xonly_pubkey_tweak_add(vrfy, &tmp_pk, &pk, tweak[i]));
CHECK(secp256k1_xonly_pubkey_from_pubkey(vrfy, &tmp_xonly_pk, &tweaked_pk_parity[i], &tmp_pk));
CHECK(secp256k1_xonly_pubkey_serialize(vrfy, tweaked_pk[i], &tmp_xonly_pk));
Expand All @@ -105,7 +106,7 @@ void test_batch_api(void) {
#ifdef ENABLE_MODULE_SCHNORRSIG
/* generate N_SIGS schnorr verify data (msg, sig) */
for (i = 0; i < N_SIGS; i++) {
secp256k1_testrand256(msg[i]);
testrand256(msg[i]);
CHECK(secp256k1_schnorrsig_sign32(sign, sig[i], msg[i], &keypair, NULL) == 1);
CHECK(secp256k1_schnorrsig_verify(vrfy, sig[i], msg[i], sizeof(msg[i]), &pk));
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/extrakeys/batch_add_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ int secp256k1_batch_add_xonlypub_tweak_check(const secp256k1_context* ctx, secp2
return 0;
}

if (!secp256k1_fe_set_b32(&qx, tweaked_pubkey32)) {
if (!secp256k1_fe_set_b32_limit(&qx, tweaked_pubkey32)) {
return 0;
}

Expand Down
30 changes: 15 additions & 15 deletions src/modules/extrakeys/batch_add_tests_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void batch_xonlypub_tweak_randomizer_gen_bitflip(secp256k1_sha256 *sha, unsigned
secp256k1_sha256 sha_cpy;
sha_cpy = *sha;
secp256k1_batch_xonlypub_tweak_randomizer_gen(randomizers[0], &sha_cpy, args[0], args[1], args[2], args[3]);
secp256k1_testrand_flip(args[n_flip], n_bytes);
testrand_flip(args[n_flip], n_bytes);
sha_cpy = *sha;
secp256k1_batch_xonlypub_tweak_randomizer_gen(randomizers[1], &sha_cpy, args[0], args[1], args[2], args[3]);
CHECK(secp256k1_memcmp_var(randomizers[0], randomizers[1], 32) != 0);
Expand All @@ -35,11 +35,11 @@ void run_batch_xonlypub_tweak_randomizer_gen_tests(void) {
uint8_t temp_rand;

/* generate i-th tweak check data */
secp256k1_testrand256(tweaked_pk);
tweaked_pk_parity = (unsigned char) secp256k1_testrand_int(2);
secp256k1_testrand256(tweak);
secp256k1_testrand256(&internal_pk[1]);
temp_rand = secp256k1_testrand_int(2) + 2; /* randomly choose 2 or 3 */
testrand256(tweaked_pk);
tweaked_pk_parity = (unsigned char) testrand_int(2);
testrand256(tweak);
testrand256(&internal_pk[1]);
temp_rand = testrand_int(2) + 2; /* randomly choose 2 or 3 */
internal_pk[0] = (unsigned char)temp_rand;

/* check bitflip in any argument results in generates randomizers */
Expand All @@ -48,7 +48,7 @@ void run_batch_xonlypub_tweak_randomizer_gen_tests(void) {
args[2] = internal_pk;
args[3] = tweak;

for (j = 0; j < count; j++) {
for (j = 0; j < COUNT; j++) {
batch_xonlypub_tweak_randomizer_gen_bitflip(&sha, args, 0, 32);
batch_xonlypub_tweak_randomizer_gen_bitflip(&sha, args, 1, 1);
batch_xonlypub_tweak_randomizer_gen_bitflip(&sha, args, 2, 33);
Expand Down Expand Up @@ -86,21 +86,21 @@ void test_batch_add_xonlypub_tweak_api(void) {
secp256k1_batch *batch2 = secp256k1_batch_create(none, 1, NULL);
int ecount;

secp256k1_context_set_error_callback(none, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_error_callback(sign, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_error_callback(vrfy, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_illegal_callback(none, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_illegal_callback(sign, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_illegal_callback(vrfy, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_error_callback(none, counting_callback_fn, &ecount);
secp256k1_context_set_error_callback(sign, counting_callback_fn, &ecount);
secp256k1_context_set_error_callback(vrfy, counting_callback_fn, &ecount);
secp256k1_context_set_illegal_callback(none, counting_callback_fn, &ecount);
secp256k1_context_set_illegal_callback(sign, counting_callback_fn, &ecount);
secp256k1_context_set_illegal_callback(vrfy, counting_callback_fn, &ecount);

/** generate keypair data **/
secp256k1_testrand256(sk);
testrand256(sk);
CHECK(secp256k1_keypair_create(sign, &keypair, sk) == 1);
CHECK(secp256k1_keypair_xonly_pub(sign, &pk, NULL, &keypair) == 1);
memset(overflows, 0xFF, sizeof(overflows));

/** generate tweak check data (tweaked_pk, tweaked_pk_parity, tweak) **/
secp256k1_testrand256(tweak);
testrand256(tweak);
CHECK(secp256k1_xonly_pubkey_tweak_add(vrfy, &tmp_pk, &pk, tweak));
CHECK(secp256k1_xonly_pubkey_from_pubkey(vrfy, &tmp_xonly_pk, &tweaked_pk_parity, &tmp_pk));
CHECK(secp256k1_xonly_pubkey_serialize(vrfy, tweaked_pk, &tmp_xonly_pk));
Expand Down
2 changes: 1 addition & 1 deletion src/modules/schnorrsig/batch_add_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ int secp256k1_batch_add_schnorrsig(const secp256k1_context* ctx, secp256k1_batch
return 0;
}

if (!secp256k1_fe_set_b32(&rx, &sig64[0])) {
if (!secp256k1_fe_set_b32_limit(&rx, &sig64[0])) {
return 0;
}

Expand Down
Loading

0 comments on commit 69df387

Please sign in to comment.