Post
Topic
Board Development & Technical Discussion
Merits 24 from 3 users
Re: Why does secp256k1_fe_set_int enforce a <= 0x7FFF?
by
Pieter Wuille
on 23/07/2022, 15:43:07 UTC
⭐ Merited by ETFbitcoin (13) ,NotATether (10) ,PawGo (1)
Interesting question!

The reason for the restriction is simply to keep
Code:
secp256k1_fe_set_int
simple. Field elements are represented as 10 26-bit or 5 52-bit limbs internally, so restricting the function to only accept inputs that can be represented by a single limb means the function can just set all limbs to 0 and set the bottom one to the provided value.

Now in retrospect, it does seem that this function is rather pointless. It's currently only used for setting values to 0 or to 1 anymore. That used to be different; early on we e.g. didn't have a mechanism for constructing compile-time constants, and e.g. the B constant in the curve equation (y^2 = x^3 + B, with B=7 for secp256k1 proper) didn't exist until fairly recently.

I'm now considering adding a constant
Code:
secp256k1_fe
for 0 (a constant for 1 already exists), and removing the function. Thanks for the observation!