Skip to content

Commit

Permalink
Merge bitcoin#628: Fix ability to compile tests without -DVERIFY.
Browse files Browse the repository at this point in the history
dcf3920 Fix ability to compile tests without -DVERIFY. (Gregory Maxwell)

Pull request description:

  Broken by 3f3964e.

  It's important that the tests are also run without -DVERIFY due to
   the possibility that side-effects of a VERIFY_CHECK fix a bug that
   would otherwise be detected.

  Use of the verify_check macro in tests isn't sufficient.

ACKs for commit dcf392:

Tree-SHA512: ff7ca0e89e33f845656a4d7d18c0195d1378b020d67f89e900b18cf3d702aa81dd91ffd05a98953a481b83e4247eaf0c484bea12eab020efb3c966a456e8129f
  • Loading branch information
gmaxwell committed May 29, 2019
2 parents ecc94ab + dcf3920 commit 1669bb2
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ void random_field_element_magnitude(secp256k1_fe *fe) {
secp256k1_fe_negate(&zero, &zero, 0);
secp256k1_fe_mul_int(&zero, n - 1);
secp256k1_fe_add(fe, &zero);
VERIFY_CHECK(fe->magnitude == n);
#ifdef VERIFY
CHECK(fe->magnitude == n);
#endif
}

void random_group_element_test(secp256k1_ge *ge) {
Expand Down Expand Up @@ -1819,24 +1821,32 @@ void run_field_misc(void) {
/* Test fe conditional move; z is not normalized here. */
q = x;
secp256k1_fe_cmov(&x, &z, 0);
VERIFY_CHECK(!x.normalized && x.magnitude == z.magnitude);
#ifdef VERIFY
CHECK(!x.normalized && x.magnitude == z.magnitude);
#endif
secp256k1_fe_cmov(&x, &x, 1);
CHECK(fe_memcmp(&x, &z) != 0);
CHECK(fe_memcmp(&x, &q) == 0);
secp256k1_fe_cmov(&q, &z, 1);
VERIFY_CHECK(!q.normalized && q.magnitude == z.magnitude);
#ifdef VERIFY
CHECK(!q.normalized && q.magnitude == z.magnitude);
#endif
CHECK(fe_memcmp(&q, &z) == 0);
secp256k1_fe_normalize_var(&x);
secp256k1_fe_normalize_var(&z);
CHECK(!secp256k1_fe_equal_var(&x, &z));
secp256k1_fe_normalize_var(&q);
secp256k1_fe_cmov(&q, &z, (i&1));
VERIFY_CHECK(q.normalized && q.magnitude == 1);
#ifdef VERIFY
CHECK(q.normalized && q.magnitude == 1);
#endif
for (j = 0; j < 6; j++) {
secp256k1_fe_negate(&z, &z, j+1);
secp256k1_fe_normalize_var(&q);
secp256k1_fe_cmov(&q, &z, (j&1));
VERIFY_CHECK(!q.normalized && q.magnitude == (j+2));
#ifdef VERIFY
CHECK(!q.normalized && q.magnitude == (j+2));
#endif
}
secp256k1_fe_normalize_var(&z);
/* Test storage conversion and conditional moves. */
Expand Down

0 comments on commit 1669bb2

Please sign in to comment.