Skip to content

Commit e3cd679

Browse files
committed
Eliminate all side-effects from VERIFY_CHECK() usage.
The side-effects make review somewhat harder because 99.9% of the time the macro usage has no sideeffects, so they're easily ignored. The main motivation for avoiding the side effects is so that the macro can be completely stubbed out for branch coverage analysis otherwise all the unreachable verify code gets counted against coverage.
1 parent b30fc85 commit e3cd679

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

src/ecdsa_impl.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,16 @@ static int secp256k1_ecdsa_sig_recover(const secp256k1_ecmult_context *ctx, cons
260260
secp256k1_gej xj;
261261
secp256k1_scalar rn, u1, u2;
262262
secp256k1_gej qj;
263+
int r;
263264

264265
if (secp256k1_scalar_is_zero(sigr) || secp256k1_scalar_is_zero(sigs)) {
265266
return 0;
266267
}
267268

268269
secp256k1_scalar_get_b32(brx, sigr);
269-
VERIFY_CHECK(secp256k1_fe_set_b32(&fx, brx)); /* brx comes from a scalar, so is less than the order; certainly less than p */
270+
r = secp256k1_fe_set_b32(&fx, brx);
271+
(void)r;
272+
VERIFY_CHECK(r); /* brx comes from a scalar, so is less than the order; certainly less than p */
270273
if (recid & 2) {
271274
if (secp256k1_fe_cmp_var(&fx, &secp256k1_ecdsa_const_p_minus_order) >= 0) {
272275
return 0;

src/ecmult_gen_impl.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,13 @@ static void secp256k1_ecmult_gen_context_build(secp256k1_ecmult_gen_context *ctx
4040
static const unsigned char nums_b32[33] = "The scalar for this x is unknown";
4141
secp256k1_fe nums_x;
4242
secp256k1_ge nums_ge;
43-
VERIFY_CHECK(secp256k1_fe_set_b32(&nums_x, nums_b32));
44-
VERIFY_CHECK(secp256k1_ge_set_xo_var(&nums_ge, &nums_x, 0));
43+
int r;
44+
r = secp256k1_fe_set_b32(&nums_x, nums_b32);
45+
(void)r;
46+
VERIFY_CHECK(r);
47+
r = secp256k1_ge_set_xo_var(&nums_ge, &nums_x, 0);
48+
(void)r;
49+
VERIFY_CHECK(r);
4550
secp256k1_gej_set_ge(&nums_gej, &nums_ge);
4651
/* Add G to make the bits in x uniformly distributed. */
4752
secp256k1_gej_add_ge_var(&nums_gej, &nums_gej, &secp256k1_ge_const_g, NULL);

src/field_impl.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,17 @@ static void secp256k1_fe_inv_var(secp256k1_fe *r, const secp256k1_fe *a) {
224224
0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFC,0x2F
225225
};
226226
unsigned char b[32];
227+
int res;
227228
secp256k1_fe c = *a;
228229
secp256k1_fe_normalize_var(&c);
229230
secp256k1_fe_get_b32(b, &c);
230231
secp256k1_num_set_bin(&n, b, 32);
231232
secp256k1_num_set_bin(&m, prime, 32);
232233
secp256k1_num_mod_inverse(&n, &n, &m);
233234
secp256k1_num_get_bin(b, 32, &n);
234-
VERIFY_CHECK(secp256k1_fe_set_b32(r, b));
235+
res = secp256k1_fe_set_b32(r, b);
236+
(void)res;
237+
VERIFY_CHECK(res);
235238
/* Verify the result is the (unique) valid inverse using non-GMP code. */
236239
secp256k1_fe_mul(&c, &c, r);
237240
secp256k1_fe_add(&c, &negone);

src/num_gmp_impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static void secp256k1_num_add_abs(secp256k1_num *r, const secp256k1_num *a, cons
7070

7171
static void secp256k1_num_sub_abs(secp256k1_num *r, const secp256k1_num *a, const secp256k1_num *b) {
7272
mp_limb_t c = mpn_sub(r->data, a->data, a->limbs, b->data, b->limbs);
73+
(void)c;
7374
VERIFY_CHECK(c == 0);
7475
r->limbs = a->limbs;
7576
while (r->limbs > 1 && r->data[r->limbs-1]==0) {
@@ -125,6 +126,7 @@ static void secp256k1_num_mod_inverse(secp256k1_num *r, const secp256k1_num *a,
125126
}
126127
sn = NUM_LIMBS+1;
127128
gn = mpn_gcdext(g, r->data, &sn, u, m->limbs, v, m->limbs);
129+
(void)gn;
128130
VERIFY_CHECK(gn == 1);
129131
VERIFY_CHECK(g[0] == 1);
130132
r->neg = a->neg ^ m->neg;

0 commit comments

Comments
 (0)