Expand description
Pure, dependency-free single source of truth for FAB AlignedValue ↔ ZKIR v3
field-element layout.
This module encodes the canonical atom and field-element geometry for every
flat TypeDescriptor without depending on any ledger or proving crate:
Bytes<N>chunking: each native BLS12-381 scalar field element stores at mostFR_BYTES_STORED(31) arbitrary bytes. Multi-chunkBytes<N>values occupyceil(N / 31)field elements (0forBytes<0>), emitted MSB-chunk-first in FABChunkOrder::MsbFirstand LSB-chunk-first in ZKIR v3ChunkOrder::LsbFirst.Uintbyte widths: respects explicitalignment-byteswhen present, otherwise derives the standard{1, 2, 4, 8, 16}-byte alignment width frommaxval(or minimal byte width for wider bounds).- Foreign-field limb splits &
-1 mod protation: two-atom foreign fields store(v - 1) mod psplit into[24, 8]bytes (192-bit low limb) for secp256k1 / secp256r1 / Curve25519 base fields, and[26, 7]bytes (204-bit low limb) for Curve25519’s scalar field. - Curve points:
JubjubPoint: 2 nativeFieldslots (x,y).Secp256k1Point/Secp256r1Point: 5 slots (x_lo,x_hi,y_lo,y_hi, nativeFieldidentity flag).Curve25519Point: 4 slots (x_lo,x_hi,y_lo,y_hi; Edwards identity(0, 1)needs no flag).
Structs§
- Field
Layout - Flattened FAB atom sequence and ZKIR field-element geometry for a
TypeDescriptor. - Foreign
Field Split - Two-atom limb split geometry for a foreign field element.
Enums§
- Atom
Layout - Single FAB alignment atom in the flattened representation of a type.
- Chunk
Order - Ordering of 31-byte field-element chunks for multi-chunk
Bytes<N>atoms.
Constants§
- CURV
E25519_ BASE_ MODULUS - Order of the Curve25519 base field (
2^255 - 19). - CURV
E25519_ SCALAR_ MODULUS - Order of the Curve25519 prime-order scalar subgroup.
- FR_
BYTES - Canonical little-endian byte width of a native BLS12-381 scalar field element.
- FR_
BYTES_ STORED - Maximum number of arbitrary raw bytes that fit unconditionally inside one
native BLS12-381 scalar field element (
Fr). - JUBJUB_
SCALAR_ MODULUS - Order of the Jubjub scalar field.
- SECP256
K1_ BASE_ MODULUS - Order of the secp256k1 base field (
2^256 - 2^32 - 977). - SECP256
K1_ SCALAR_ MODULUS - Order of the secp256k1 scalar field.
- SECP256
R1_ BASE_ MODULUS - Order of the secp256r1 (P-256) base field (
2^256 - 2^224 + 2^192 + 2^96 - 1). - SECP256
R1_ SCALAR_ MODULUS - Order of the secp256r1 (P-256) scalar field.
Functions§
- bytes_
field_ slots - Number of native field elements required to store
byte_lenraw bytes. - bytes_
to_ field_ chunks - Split a raw byte buffer into 32-byte little-endian field-element limbs
(each carrying up to
FR_BYTES_STORED= 31 bytes) in the requestedChunkOrder. - field_
chunks_ to_ bytes - Reassemble
byte_lenraw bytes from 32-byte little-endian field-element limbs ordered according toorder. - foreign_
field_ modulus - Prime modulus of a non-native
FieldType, orNonefor the native BLS12-381Field. - foreign_
field_ split - Two-atom limb split for a foreign
FieldType, orNonefor single-atom fields (Field,JubjubScalar). - join_
foreign_ limbs - Reassemble little-endian
(low_le, high_le)foreign-field limb bytes and undo the-1 mod protation. - reorder_
chunks - Reorder a slice of field-element chunks belonging to a single
Bytes<N>atom betweenChunkOrder::MsbFirstandChunkOrder::LsbFirst. - rotate_
foreign_ from_ wire - Undo the ZKIR/FAB
-1 mod protation on a two-atom foreign field element (p - 1 -> 0,w -> w + 1). ReturnsNoneiffield_typeis not a two-atom foreign field orwire >= p. - rotate_
foreign_ to_ wire - Apply the ZKIR/FAB
-1 mod protation to a two-atom foreign field element (0 -> p - 1,v -> v - 1). ReturnsNoneiffield_typeis not a two-atom foreign field orvalue >= p. - split_
foreign_ limbs - Rotate a foreign field element by
-1 mod pand split it into its fixed-width little-endian(low_bytes, high_bytes)limbs ([24, 8]or[26, 7]). - uint_
byte_ width - Compute the FAB
Bytesatom width for aUint { maxval, alignment_bytes }.