constraints.base#
Base classes for constraint evaluation.
ConstraintContext provides a uniform interface for constraint evaluation that works for both prover (returns arrays) and verifier (returns scalars). The same constraint code can be used in both contexts thanks to galois broadcasting.
- Example:
- def eval_constraint(ctx: ConstraintContext):
a = ctx.col(‘a’) b = ctx.col(‘b’) return a * b - ctx.challenge(‘alpha’)
# Works for prover (arrays) prover_result = eval_constraint(ProverConstraintContext(prover_data))
# Works for verifier (scalars) verifier_result = eval_constraint(VerifierConstraintContext(verifier_data))
Attributes#
Classes#
Uniform interface for constraint evaluation - works for prover and verifier. |
|
Prover implementation - returns polynomial arrays. |
|
Verifier implementation - returns scalar evaluations. |
|
Per-AIR constraint evaluation. Used by both prover and verifier. |
Functions#
|
Compress 2-column expression: ((col2*α + col1)*α + busid) + γ. |
Module Contents#
- constraints.base.compress_2col(busid: int, col1: primitives.field.FF3, col2: primitives.field.FF3, alpha: primitives.field.FF3, gamma: primitives.field.FF3, n: int | None = None) primitives.field.FF3[source]#
Compress 2-column expression: ((col2*α + col1)*α + busid) + γ.
- class constraints.base.ConstraintContext[source]#
Bases:
abc.ABCUniform interface for constraint evaluation - works for prover and verifier.
- abstractmethod col(name: str, index: int = 0) FF3Poly | primitives.field.FF3[source]#
Get column at current row.
- Args:
name: Column name index: Column index for multi-column polynomials (default 0)
- Returns:
Prover: array of values at all domain points Verifier: scalar evaluation at xi
- abstractmethod next_col(name: str, index: int = 0) FF3Poly | primitives.field.FF3[source]#
Get column at next row (offset +1).
- Args:
name: Column name index: Column index for multi-column polynomials (default 0)
- Returns:
Prover: array shifted by -1 (circular) Verifier: evaluation at xi * omega
- abstractmethod prev_col(name: str, index: int = 0) FF3Poly | primitives.field.FF3[source]#
Get column at previous row (offset -1).
- Args:
name: Column name index: Column index for multi-column polynomials (default 0)
- Returns:
Prover: array shifted by +1 (circular) Verifier: evaluation at xi * omega^(-1)
- abstractmethod const(name: str, index: int = 0) FF3Poly | primitives.field.FF3[source]#
Get constant polynomial at current row (converted to extension field).
- Args:
name: Constant name (e.g., ‘__L1__’ for Lagrange polynomial) index: Column index for AIRs with multiple constants sharing a name
- Returns:
Prover: array of constant values (as FF3 for arithmetic compatibility) Verifier: scalar evaluation at xi
- abstractmethod next_const(name: str, index: int = 0) FF3Poly | primitives.field.FF3[source]#
Get constant polynomial at next row (offset +1).
- Args:
name: Constant name index: Column index for AIRs with multiple constants sharing a name
- Returns:
Prover: array shifted by -1 (circular) Verifier: evaluation at xi * omega
- abstractmethod prev_const(name: str, index: int = 0) FF3Poly | primitives.field.FF3[source]#
Get constant polynomial at previous row (offset -1).
- Args:
name: Constant name index: Column index for AIRs with multiple constants sharing a name
- Returns:
Prover: array shifted by +1 (circular) Verifier: evaluation at xi * omega^(-1)
- abstractmethod challenge(name: str) primitives.field.FF3[source]#
Get Fiat-Shamir challenge (always scalar).
- Args:
name: Challenge name (e.g., ‘std_alpha’)
- Returns:
Scalar challenge value
- abstractmethod airgroup_value(index: int) primitives.field.FF3[source]#
Get airgroup value (accumulated result across AIR instances).
- Args:
index: Airgroup value index
- Returns:
Scalar airgroup value (FF3)
- class constraints.base.ProverConstraintContext(data: protocol.data.ProverData)[source]#
Bases:
ConstraintContextProver implementation - returns polynomial arrays.
The prover evaluates constraints at all domain points simultaneously, producing arrays of constraint evaluations.
- col(name: str, index: int = 0) FF3Poly[source]#
Get column at current row.
- Args:
name: Column name index: Column index for multi-column polynomials (default 0)
- Returns:
Prover: array of values at all domain points Verifier: scalar evaluation at xi
- next_col(name: str, index: int = 0) FF3Poly[source]#
Get column at next row (offset +1).
- Args:
name: Column name index: Column index for multi-column polynomials (default 0)
- Returns:
Prover: array shifted by -1 (circular) Verifier: evaluation at xi * omega
- prev_col(name: str, index: int = 0) FF3Poly[source]#
Get column at previous row (offset -1).
- Args:
name: Column name index: Column index for multi-column polynomials (default 0)
- Returns:
Prover: array shifted by +1 (circular) Verifier: evaluation at xi * omega^(-1)
- const(name: str, index: int = 0) FF3Poly[source]#
Get constant polynomial at current row (converted to extension field).
- Args:
name: Constant name (e.g., ‘__L1__’ for Lagrange polynomial) index: Column index for AIRs with multiple constants sharing a name
- Returns:
Prover: array of constant values (as FF3 for arithmetic compatibility) Verifier: scalar evaluation at xi
- next_const(name: str, index: int = 0) FF3Poly[source]#
Get constant polynomial at next row (offset +1).
- Args:
name: Constant name index: Column index for AIRs with multiple constants sharing a name
- Returns:
Prover: array shifted by -1 (circular) Verifier: evaluation at xi * omega
- prev_const(name: str, index: int = 0) FF3Poly[source]#
Get constant polynomial at previous row (offset -1).
- Args:
name: Constant name index: Column index for AIRs with multiple constants sharing a name
- Returns:
Prover: array shifted by +1 (circular) Verifier: evaluation at xi * omega^(-1)
- challenge(name: str) primitives.field.FF3[source]#
Get Fiat-Shamir challenge (always scalar).
- Args:
name: Challenge name (e.g., ‘std_alpha’)
- Returns:
Scalar challenge value
- airgroup_value(index: int) primitives.field.FF3[source]#
Get airgroup value (accumulated result across AIR instances).
- Args:
index: Airgroup value index
- Returns:
Scalar airgroup value (FF3)
- class constraints.base.VerifierConstraintContext(data: protocol.data.VerifierData)[source]#
Bases:
ConstraintContextVerifier implementation - returns scalar evaluations.
The verifier evaluates constraints at a single random point xi, checking that the constraint polynomial evaluates to zero.
- col(name: str, index: int = 0) primitives.field.FF3[source]#
Get column at current row.
- Args:
name: Column name index: Column index for multi-column polynomials (default 0)
- Returns:
Prover: array of values at all domain points Verifier: scalar evaluation at xi
- next_col(name: str, index: int = 0) primitives.field.FF3[source]#
Get column at next row (offset +1).
- Args:
name: Column name index: Column index for multi-column polynomials (default 0)
- Returns:
Prover: array shifted by -1 (circular) Verifier: evaluation at xi * omega
- prev_col(name: str, index: int = 0) primitives.field.FF3[source]#
Get column at previous row (offset -1).
- Args:
name: Column name index: Column index for multi-column polynomials (default 0)
- Returns:
Prover: array shifted by +1 (circular) Verifier: evaluation at xi * omega^(-1)
- const(name: str, index: int = 0) primitives.field.FF3[source]#
Get constant polynomial at current row (converted to extension field).
- Args:
name: Constant name (e.g., ‘__L1__’ for Lagrange polynomial) index: Column index for AIRs with multiple constants sharing a name
- Returns:
Prover: array of constant values (as FF3 for arithmetic compatibility) Verifier: scalar evaluation at xi
- next_const(name: str, index: int = 0) primitives.field.FF3[source]#
Get constant polynomial at next row (offset +1).
- Args:
name: Constant name index: Column index for AIRs with multiple constants sharing a name
- Returns:
Prover: array shifted by -1 (circular) Verifier: evaluation at xi * omega
- prev_const(name: str, index: int = 0) primitives.field.FF3[source]#
Get constant polynomial at previous row (offset -1).
- Args:
name: Constant name index: Column index for AIRs with multiple constants sharing a name
- Returns:
Prover: array shifted by +1 (circular) Verifier: evaluation at xi * omega^(-1)
- challenge(name: str) primitives.field.FF3[source]#
Get Fiat-Shamir challenge (always scalar).
- Args:
name: Challenge name (e.g., ‘std_alpha’)
- Returns:
Scalar challenge value
- airgroup_value(index: int) primitives.field.FF3[source]#
Get airgroup value (accumulated result across AIR instances).
- Args:
index: Airgroup value index
- Returns:
Scalar airgroup value (FF3)
- class constraints.base.ConstraintModule[source]#
Bases:
abc.ABCPer-AIR constraint evaluation. Used by both prover and verifier.
Each AIR (Algebraic Intermediate Representation) has its own constraint module that defines how constraints are evaluated. The same module works for both prover and verifier contexts.
- abstractmethod constraint_polynomial(ctx: ConstraintContext) FF3Poly | primitives.field.FF3[source]#
Evaluate all constraints combined into single polynomial.
- Args:
ctx: ConstraintContext providing access to columns, constants, challenges
- Returns:
Prover: array of constraint evaluations at all domain points Verifier: single constraint evaluation at xi