Skip to content

Commit 27d0cef

Browse files
committed
Make fe_is_zero side-effect free
1 parent 4c3ba88 commit 27d0cef

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
@@ -274,10 +274,9 @@ SECP256K1_INLINE static void secp256k1_fe_set_int(secp256k1_fe *r, int a) {
274274

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

src/field_5x52_impl.h

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

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

0 commit comments

Comments
 (0)