Each field is written as 32 big-endian bytes and the chunks are concatenated. The field array [5, 42] becomes:
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5, // First field (32 bytes)
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,42] // Second field (32 bytes)
Privacy
The BN254 modulus is < 2^254, so every 32-byte chunk has its top bit at zero and the next bit biased. The output
is therefore distinguishable from uniform random bytes; take this into account when feeding it into anything that
assumes uniform randomness (e.g. ciphertexts meant to look random).
Encodes an array of fields as bytes.
Losslessly preserves any field value; use
try_decode_fields_from_bytesto recover the original fields.Encoding
Each field is written as 32 big-endian bytes and the chunks are concatenated. The field array
[5, 42]becomes:Privacy
The BN254 modulus is
< 2^254, so every 32-byte chunk has its top bit at zero and the next bit biased. The output is therefore distinguishable from uniform random bytes; take this into account when feeding it into anything that assumes uniform randomness (e.g. ciphertexts meant to look random).