feat: felt creation from bytes is infallible #16
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Expose 4 ways to create a field element from arbitrary bytes:
from_bytes_be
/from_bytes_le
: take exactly 32 bytes and interpret them as a big/little endian number of 256 bits and then build a field element from it, modulo STARK prime (in whatever representationStark252PrimeField
uses, currently Montgomery);from_bytes_be_slice
/from_bytes_le_slice
: take any number of bytes and interpret them as a big/little endian number modulo STARK prime by decomposing into 256 bits integers and multiplying by the appropriate factors.Pull Request type
What is the current behavior?
Current behavior mimics that of
lambdaworks
, where depending on the length of the slice passed tofrom_bytes_xe
(wherex
is eitherb
orl
) one of the following happens:P
;P
.What is the new behavior?
Now the functionality is divided in two:
∑Di*2^i
whereDi
is the i-th "digit" of 512 bits units. This should be exactly equivalent to the following code (for little endian):Does this introduce a breaking change?
Yes. The signature of the
from_bytes_xe
functions change, they no longer return an error.