Index Mathematics Conjectures nbv lettuce Widgets

static_eval!

Evaluate a block at compile time, treating every variable as static. Static evaluation

static_eval! { ... }

Runs the block in a separate VM in which every variable is static: let definitions become statics, multiplications are computed directly and no constraints or witness entries are created. The block's final expression is the result. Use it to compute tables and other constants with the same functions you would use on witness values, e.g. the ML-DSA verifier computes its public matrices this way.

The block sees copies of the static variables of the enclosing scope (read only) and none of its witness variables. Function calls inside the block are evaluated statically as well. See static evaluation.

Arguments

None, only a block.

Returns

The static value of the block's final expression, or a tuple if it ends with a tuple. A block without a final expression returns the empty tuple and logs a warning. It is an expression-form precompile.

Constraints

None. Inside the block, precompiles that create constraints (for example constrain_eq! and constrain_mul!) do nothing, and wtns! returns its input unchanged.

Example

(let x)
static k = 3
static table = static_eval! {
  let mut t[4]
  loop! 4, i {
    t[i] = k * i * i
  }
  t
}
x * table
(let x)
static y = static_eval! {
  x * x
}
y

Notes

Witness variables of the enclosing scope are not visible inside the block, as the second example shows. Functions that rely on hint precompiles which require a witness input, such as to_bits_unconstrained! (and so to_bits_exact), fail inside static_eval!.

Used in the standard library

bdlop/bdlop_lattice, dilithium/mldsa/mldsa44_verify_static, milli/mldsa/mldsa_reduce, mldsa/mldsa_mulmod_static