Skip to main content

Module layout

Module layout 

Source
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 most FR_BYTES_STORED (31) arbitrary bytes. Multi-chunk Bytes<N> values occupy ceil(N / 31) field elements (0 for Bytes<0>), emitted MSB-chunk-first in FAB ChunkOrder::MsbFirst and LSB-chunk-first in ZKIR v3 ChunkOrder::LsbFirst.
  • Uint byte widths: respects explicit alignment-bytes when present, otherwise derives the standard {1, 2, 4, 8, 16}-byte alignment width from maxval (or minimal byte width for wider bounds).
  • Foreign-field limb splits & -1 mod p rotation: two-atom foreign fields store (v - 1) mod p split 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 native Field slots (x, y).
    • Secp256k1Point / Secp256r1Point: 5 slots (x_lo, x_hi, y_lo, y_hi, native Field identity flag).
    • Curve25519Point: 4 slots (x_lo, x_hi, y_lo, y_hi; Edwards identity (0, 1) needs no flag).

Structs§

FieldLayout
Flattened FAB atom sequence and ZKIR field-element geometry for a TypeDescriptor.
ForeignFieldSplit
Two-atom limb split geometry for a foreign field element.

Enums§

AtomLayout
Single FAB alignment atom in the flattened representation of a type.
ChunkOrder
Ordering of 31-byte field-element chunks for multi-chunk Bytes<N> atoms.

Constants§

CURVE25519_BASE_MODULUS
Order of the Curve25519 base field (2^255 - 19).
CURVE25519_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.
SECP256K1_BASE_MODULUS
Order of the secp256k1 base field (2^256 - 2^32 - 977).
SECP256K1_SCALAR_MODULUS
Order of the secp256k1 scalar field.
SECP256R1_BASE_MODULUS
Order of the secp256r1 (P-256) base field (2^256 - 2^224 + 2^192 + 2^96 - 1).
SECP256R1_SCALAR_MODULUS
Order of the secp256r1 (P-256) scalar field.

Functions§

bytes_field_slots
Number of native field elements required to store byte_len raw 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 requested ChunkOrder.
field_chunks_to_bytes
Reassemble byte_len raw bytes from 32-byte little-endian field-element limbs ordered according to order.
foreign_field_modulus
Prime modulus of a non-native FieldType, or None for the native BLS12-381 Field.
foreign_field_split
Two-atom limb split for a foreign FieldType, or None for single-atom fields (Field, JubjubScalar).
join_foreign_limbs
Reassemble little-endian (low_le, high_le) foreign-field limb bytes and undo the -1 mod p rotation.
reorder_chunks
Reorder a slice of field-element chunks belonging to a single Bytes<N> atom between ChunkOrder::MsbFirst and ChunkOrder::LsbFirst.
rotate_foreign_from_wire
Undo the ZKIR/FAB -1 mod p rotation on a two-atom foreign field element (p - 1 -> 0, w -> w + 1). Returns None if field_type is not a two-atom foreign field or wire >= p.
rotate_foreign_to_wire
Apply the ZKIR/FAB -1 mod p rotation to a two-atom foreign field element (0 -> p - 1, v -> v - 1). Returns None if field_type is not a two-atom foreign field or value >= p.
split_foreign_limbs
Rotate a foreign field element by -1 mod p and split it into its fixed-width little-endian (low_bytes, high_bytes) limbs ([24, 8] or [26, 7]).
uint_byte_width
Compute the FAB Bytes atom width for a Uint { maxval, alignment_bytes }.