Post
Topic
Board Development & Technical Discussion
Merits 3 from 2 users
Topic OP
[libsecp256k1] secp256k1_fe_set_b32_mod doesn't actually reduce anything
by
Coding Enthusiast
on 26/11/2023, 13:36:41 UTC
⭐ Merited by ETFbitcoin (2) ,vapourminer (1)
I'm going through libsecp256k1 and noticed a new change which is strange.

secp256k1_fe_set_b32_mod method name and comment suggest that it reduces the value mod p and the result is supposed to be r ≡ a (mod p)
https://github.com/bitcoin-core/secp256k1/blob/c1b4966410a81162bf9404ec84e69a85e1e23469/src/field.h#L192

But looking at the implementations they don't actually perform any reduction. It's just a simple conversion from byte[] to uint[] in radix 26 or 52.
For example:
https://github.com/bitcoin-core/secp256k1/blob/c1b4966410a81162bf9404ec84e69a85e1e23469/src/field_10x26_impl.h#L293

How the method is called(?):
https://github.com/bitcoin-core/secp256k1/blob/c1b4966410a81162bf9404ec84e69a85e1e23469/src/field_impl.h#L258

The behavior of the method and where it is used doesn't seem to have changed
https://github.com/bitcoin-core/secp256k1/commit/5b32602295ff7ad9e1973f96b8ee8344b82f4af0#diff-6e0cae0111d7c054ba27f22399eb4a2ac6c9788ee97da7f9fc5948c63dcf882c
However this "assumption" that the secp256k1_fe_set_b32_mod reduces the result has.

Am I missing something or is this a mistake?