Skip to content

Commit c2688f8

Browse files
committed
redefine VERIFY_CHECK to empty in production (non-VERIFY) mode
As suggested in issue #1381, this will make things simpler and improve code readability, as we don't need to force omitting of evaluations on a case-by-case basis anymore and hence can remove lots of `#ifdef VERIFY`/`#endif` lines (see next commit). Plus, VERIFY_CHECK behaves now identical in both non-VERIFY and coverage mode, making the latter not special anymore and hopefully decreasing maintenance burden. The idea of "side-effect safety" is given up. Note that at two places in the ellswift module void-casts of return values have to be inserted for non-VERIFY builds, in order to avoid "variable ... set but not used [-Wunused-but-set-variable]" warnings.
1 parent 5814d84 commit c2688f8

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/modules/ellswift/main_impl.h

+8
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,11 @@ static int secp256k1_ellswift_xswiftec_inv_var(secp256k1_fe *t, const secp256k1_
272272
secp256k1_fe_negate(&q, &q, 1); /* q = -s*(4*(u^3+7)+3*u^2*s) */
273273
if (!secp256k1_fe_is_square_var(&q)) return 0;
274274
ret = secp256k1_fe_sqrt(&r, &q); /* r = sqrt(-s*(4*(u^3+7)+3*u^2*s)) */
275+
#ifdef VERIFY
275276
VERIFY_CHECK(ret);
277+
#else
278+
(void)ret;
279+
#endif
276280

277281
/* If (c & 1) = 1 and r = 0, fail. */
278282
if (EXPECT((c & 1) && secp256k1_fe_normalizes_to_zero_var(&r), 0)) return 0;
@@ -417,7 +421,11 @@ int secp256k1_ellswift_encode(const secp256k1_context *ctx, unsigned char *ell64
417421
* BIP340 tagged hash with tag "secp256k1_ellswift_encode". */
418422
secp256k1_ellswift_sha256_init_encode(&hash);
419423
ser_ret = secp256k1_eckey_pubkey_serialize(&p, p64, &ser_size, 1);
424+
#ifdef VERIFY
420425
VERIFY_CHECK(ser_ret && ser_size == 33);
426+
#else
427+
(void)ser_ret;
428+
#endif
421429
secp256k1_sha256_write(&hash, p64, sizeof(p64));
422430
secp256k1_sha256_write(&hash, rnd32, 32);
423431

src/util.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,12 @@ static const secp256k1_callback default_error_callback = {
132132
} while(0)
133133
#endif
134134

135-
/* Like assert(), but when VERIFY is defined, and side-effect safe. */
136-
#if defined(COVERAGE)
137-
#define VERIFY_CHECK(check)
138-
#define VERIFY_SETUP(stmt)
139-
#elif defined(VERIFY)
135+
/* Like assert(), but when VERIFY is defined. */
136+
#if defined(VERIFY)
140137
#define VERIFY_CHECK CHECK
141138
#define VERIFY_SETUP(stmt) do { stmt; } while(0)
142139
#else
143-
#define VERIFY_CHECK(cond) do { (void)(cond); } while(0)
140+
#define VERIFY_CHECK(cond)
144141
#define VERIFY_SETUP(stmt)
145142
#endif
146143

0 commit comments

Comments
 (0)