aztec-nr - noir_aztec::utils::conversion::bytes_as_fields

Function encode_bytes_as_fields

pub fn encode_bytes_as_fields<let N: u32>(bytes: [u8; N]) -> [Field; N / 31]

Encodes an array of bytes as fields.

Use decode_bytes_from_fields to recover the original bytes.

The bytes array length must be a multiple of 31. If padding is added, it will need to be manually removed after decoding.

Encoding

Each 31-byte chunk is interpreted as a big-endian integer and stored in a Field. For input [1, 10, 3, ..., 0] (31 bytes), the resulting Field is 1 * 256^30 + 10 * 256^29 + 3 * 256^28 + ... + 0.