Skip to content

Commit 81951ac

Browse files
committed
Make fe_is_zero side-effect free
1 parent 26de4df commit 81951ac

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/field_10x26_impl.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,9 @@ SECP256K1_INLINE static void secp256k1_fe_set_int(secp256k1_fe *r, int a) {
275275

276276
SECP256K1_INLINE static int secp256k1_fe_is_zero(const secp256k1_fe *a) {
277277
const uint32_t *t = a->n;
278-
#ifdef VERIFY
279-
VERIFY_CHECK(a->normalized);
280-
secp256k1_fe_verify(a);
281-
#endif
278+
/* No secp256k1_fe_verify is needed here, because if all limbs are 0,
279+
* the representation is always valid. This also allows using this function
280+
* inside VERIFY_CHECK conditions itself without side effects. */
282281
return (t[0] | t[1] | t[2] | t[3] | t[4] | t[5] | t[6] | t[7] | t[8] | t[9]) == 0;
283282
}
284283

src/field_5x52_impl.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,9 @@ SECP256K1_INLINE static void secp256k1_fe_set_int(secp256k1_fe *r, int a) {
238238

239239
SECP256K1_INLINE static int secp256k1_fe_is_zero(const secp256k1_fe *a) {
240240
const uint64_t *t = a->n;
241-
#ifdef VERIFY
242-
VERIFY_CHECK(a->normalized);
243-
secp256k1_fe_verify(a);
244-
#endif
241+
/* No secp256k1_fe_verify is needed here, because if all limbs are 0,
242+
* the representation is always valid. This also allows using this function
243+
* inside VERIFY_CHECK conditions itself without side effects. */
245244
return (t[0] | t[1] | t[2] | t[3] | t[4]) == 0;
246245
}
247246

0 commit comments

Comments
 (0)