primitives.expression_bytecode.expressions_bin#
Expression binary parser.
Faithful translation from: - pil2-stark/src/starkpil/expressions_bin.hpp - pil2-stark/src/starkpil/expressions_bin.cpp
Parses compiled expression bytecode from expressions.bin files. The binary file contains: 1. Expression bytecode (operations and arguments) 2. Constraint bytecode (for debugging/verification) 3. Hints (for witness generation)
- Key types referenced by OpType:
Zi – inverse vanishing polynomial 1/Z_H(x) where Z_H(x) = x^N - 1 xDivXSubXi – x/(x - xi), precomputed quotient for FRI opening xi – challenge evaluation point (random point from Fiat-Shamir)
Attributes#
Classes#
Operation argument types. |
|
Parameters for a single expression. |
|
Global bytecode and constants. |
|
Hint field value. |
|
Hint field. |
|
Hint for witness generation. |
|
Binary file reader with little-endian decoding. |
|
Compiled expression database. |
Functions#
|
Convert string to OpType enum. |
Module Contents#
- class primitives.expression_bytecode.expressions_bin.OpType(*args, **kwds)[source]#
Bases:
enum.EnumOperation argument types.
Corresponds to C++ enum opType in stark_info.hpp (lines 30-49). These define the source/destination types for expression operands.
- primitives.expression_bytecode.expressions_bin.optype_from_string(s: str) OpType[source]#
Convert string to OpType enum.
- class primitives.expression_bytecode.expressions_bin.ParserParams[source]#
Parameters for a single expression.
Corresponds to C++ struct ParserParams in expressions_bin.hpp (lines 53-69).
- Attributes:
stage: Proof stage (0=custom, 1=trace, 2+=intermediate) exp_id: Expression ID in the expression database n_temp1: Number of scalar temporaries needed n_temp3: Number of field extension (dim=3) temporaries needed n_ops: Number of operations in this expression ops_offset: Offset into global ops array n_args: Number of arguments (8 per operation) args_offset: Offset into global args array first_row: First valid row for cyclic constraints last_row: Last valid row for cyclic constraints dest_dim: Destination dimension (1 or 3) dest_id: Destination identifier im_pol: Is intermediate polynomial line: Source code line (for debugging)
- class primitives.expression_bytecode.expressions_bin.ParserArgs[source]#
Global bytecode and constants.
Corresponds to C++ struct ParserArgs in expressions_bin.hpp (lines 71-77).
- Attributes:
- ops: Operation codes (uint8). Each value is 0-2:
0 = dim1 x dim1 -> dim1 (scalar operation) 1 = dim3 x dim1 -> dim3 (field extension x scalar) 2 = dim3 x dim3 -> dim3 (field extension x field extension)
- args: Operation arguments (uint16). 8 values per operation:
[0] = operation type (0=add, 1=sub, 2=mul, 3=sub_swap) [1] = destination temp index [2] = source A type (OpType value or temp buffer index) [3] = source A column/index [4] = source A stride index (for opening points) [5] = source B type [6] = source B column/index [7] = source B stride index
numbers: Literal constants (Goldilocks field elements as uint64) n_numbers: Number of literal constants
- class primitives.expression_bytecode.expressions_bin.HintFieldValue[source]#
Hint field value.
Corresponds to C++ struct HintFieldValue in expressions_bin.hpp (lines 30-39).
- class primitives.expression_bytecode.expressions_bin.HintField[source]#
Hint field.
Corresponds to C++ struct HintField in expressions_bin.hpp (lines 41-44).
- values: list[HintFieldValue] = [][source]#
- class primitives.expression_bytecode.expressions_bin.Hint[source]#
Hint for witness generation.
Corresponds to C++ struct Hint in expressions_bin.hpp (lines 47-51).
- class primitives.expression_bytecode.expressions_bin.BinFileReader(file_path: str)[source]#
Binary file reader with little-endian decoding.
Mimics C++ BinFileUtils::BinFile interface for reading.
Corresponds to C++ BinFile constructor in binfile_utils.cpp (lines 63-131).
- read_string() str[source]#
Read null-terminated string.
Corresponds to C++ BinFile::readString() which reads until null byte.
- class primitives.expression_bytecode.expressions_bin.ExpressionsBin[source]#
Compiled expression database.
Corresponds to C++ class ExpressionsBin in expressions_bin.hpp (lines 79-145).
This class loads and manages compiled expression bytecode from .bin files. The bytecode represents arithmetic constraint expressions compiled into a stack-based operation sequence.
- expressions_info: dict[int, ParserParams][source]#
- constraints_info_debug: list[ParserParams] = [][source]#
- classmethod from_file(file_path: str, global_bin: bool = False, verifier_bin: bool = False) ExpressionsBin[source]#
Load ExpressionsBin from binary file.
Corresponds to C++ constructor (lines 3-13 of expressions_bin.cpp).
- Args:
file_path: Path to .bin file global_bin: Load as global constraints binary verifier_bin: Load as verifier binary
- Returns:
Loaded ExpressionsBin instance
- get_expression(exp_id: int) ParserParams[source]#
Get expression parameters by ID.
- Args:
exp_id: Expression ID
- Returns:
ParserParams for the expression
- Raises:
KeyError: If expression ID not found
- get_hint_ids_by_name(name: str) list[int][source]#
Get hint indices by name.
Corresponds to C++ ExpressionsBin::getHintIdsByName() (lines 684-691 of expressions_bin.cpp).
- Args:
name: Hint name to search for
- Returns:
List of hint indices with matching name
- get_number_hint_ids_by_name(name: str) int[source]#
Get count of hints by name.
Corresponds to C++ ExpressionsBin::getNumberHintIdsByName() (lines 694-704 of expressions_bin.cpp).
- Args:
name: Hint name to search for
- Returns:
Number of hints with matching name
- get_hint_field(hint_id: int, field_name: str) HintField[source]#
Get a specific field from a hint by name.
- Args:
hint_id: Index into self.hints field_name: Name of field (e.g., “numerator”, “denominator”, “reference”)
- Returns:
HintField containing the field values
- Raises:
ValueError: If field not found in hint