pub type AsmBuilder<F, EF> = Builder<AsmConfig<F, EF>>;
Expand description
A builder that compiles assembly code.
Aliased Type§
struct AsmBuilder<F, EF> {
pub operations: TracedVec<DslIr<AsmConfig<F, EF>>>,
pub flags: BuilderFlags,
pub is_sub_builder: bool,
/* private fields */
}
Fields§
§operations: TracedVec<DslIr<AsmConfig<F, EF>>>
§flags: BuilderFlags
§is_sub_builder: bool
Implementations§
Source§impl<F: PrimeField32 + TwoAdicField, EF: ExtensionField<F> + TwoAdicField> AsmBuilder<F, EF>
impl<F: PrimeField32 + TwoAdicField, EF: ExtensionField<F> + TwoAdicField> AsmBuilder<F, EF>
pub fn compile_isa(self) -> Program<F>
pub fn compile_isa_with_options(self, options: CompilerOptions) -> Program<F>
Source§impl<C: Config> Builder<C>
impl<C: Config> Builder<C>
Sourcepub fn num2bits_f(
&mut self,
num: Felt<C::F>,
num_bits: u32,
) -> Array<C, Var<C::N>>
pub fn num2bits_f( &mut self, num: Felt<C::F>, num_bits: u32, ) -> Array<C, Var<C::N>>
Converts a felt to bits. Will result in a failed assertion if num
has more than num_bits
bits. Only works for C::F = BabyBear
Sourcepub fn num2bits_f_circuit(&mut self, num: Felt<C::F>) -> Vec<Var<C::N>>
pub fn num2bits_f_circuit(&mut self, num: Felt<C::F>) -> Vec<Var<C::N>>
Converts a felt to bits inside a circuit.
Source§impl<C: Config> Builder<C>
impl<C: Config> Builder<C>
Sourcepub fn create_sub_builder(&self) -> Self
pub fn create_sub_builder(&self) -> Self
Creates a new builder with a given number of counts for each type.
Sourcepub fn trace_push(&mut self, op: DslIr<C>)
pub fn trace_push(&mut self, op: DslIr<C>)
Pushes an operation to the builder and records a trace if RUST_BACKTRACE=1.
Sourcepub fn eval<V: Variable<C>, E: Into<V::Expression>>(&mut self, expr: E) -> V
pub fn eval<V: Variable<C>, E: Into<V::Expression>>(&mut self, expr: E) -> V
Evaluates an expression and returns a variable.
Sourcepub fn eval_expr(&mut self, expr: impl Into<SymbolicVar<C::N>>) -> RVar<C::N>
pub fn eval_expr(&mut self, expr: impl Into<SymbolicVar<C::N>>) -> RVar<C::N>
Evaluates an expression and returns a right value.
Sourcepub fn constant<V: FromConstant<C>>(&mut self, value: V::Constant) -> V
pub fn constant<V: FromConstant<C>>(&mut self, value: V::Constant) -> V
Evaluates a constant expression and returns a variable.
Sourcepub fn assign<V: Variable<C>, E: Into<V::Expression>>(
&mut self,
dst: &V,
expr: E,
)
pub fn assign<V: Variable<C>, E: Into<V::Expression>>( &mut self, dst: &V, expr: E, )
Assigns an expression to a variable.
Sourcepub fn assert_nonzero(&mut self, u: &Usize<C::N>)
pub fn assert_nonzero(&mut self, u: &Usize<C::N>)
Asserts that a Usize is non-zero
Sourcepub fn assert_eq<V: Variable<C>>(
&mut self,
lhs: impl Into<V::Expression>,
rhs: impl Into<V::Expression>,
)
pub fn assert_eq<V: Variable<C>>( &mut self, lhs: impl Into<V::Expression>, rhs: impl Into<V::Expression>, )
Asserts that two expressions are equal.
Sourcepub fn assert_var_eq<LhsExpr: Into<SymbolicVar<C::N>>, RhsExpr: Into<SymbolicVar<C::N>>>(
&mut self,
lhs: LhsExpr,
rhs: RhsExpr,
)
pub fn assert_var_eq<LhsExpr: Into<SymbolicVar<C::N>>, RhsExpr: Into<SymbolicVar<C::N>>>( &mut self, lhs: LhsExpr, rhs: RhsExpr, )
Assert that two vars are equal.
Sourcepub fn assert_felt_eq<LhsExpr: Into<SymbolicFelt<C::F>>, RhsExpr: Into<SymbolicFelt<C::F>>>(
&mut self,
lhs: LhsExpr,
rhs: RhsExpr,
)
pub fn assert_felt_eq<LhsExpr: Into<SymbolicFelt<C::F>>, RhsExpr: Into<SymbolicFelt<C::F>>>( &mut self, lhs: LhsExpr, rhs: RhsExpr, )
Assert that two felts are equal.
Sourcepub fn assert_ext_eq<LhsExpr: Into<SymbolicExt<C::F, C::EF>>, RhsExpr: Into<SymbolicExt<C::F, C::EF>>>(
&mut self,
lhs: LhsExpr,
rhs: RhsExpr,
)
pub fn assert_ext_eq<LhsExpr: Into<SymbolicExt<C::F, C::EF>>, RhsExpr: Into<SymbolicExt<C::F, C::EF>>>( &mut self, lhs: LhsExpr, rhs: RhsExpr, )
Assert that two exts are equal.
pub fn assert_usize_eq<LhsExpr: Into<SymbolicVar<C::N>>, RhsExpr: Into<SymbolicVar<C::N>>>( &mut self, lhs: LhsExpr, rhs: RhsExpr, )
Sourcepub fn assert_var_array_eq(
&mut self,
lhs: &Array<C, Var<C::N>>,
rhs: &Array<C, Var<C::N>>,
)
pub fn assert_var_array_eq( &mut self, lhs: &Array<C, Var<C::N>>, rhs: &Array<C, Var<C::N>>, )
Assert that two arrays are equal.
Sourcepub fn if_eq<LhsExpr: Into<SymbolicVar<C::N>>, RhsExpr: Into<SymbolicVar<C::N>>>(
&mut self,
lhs: LhsExpr,
rhs: RhsExpr,
) -> IfBuilder<'_, C>
pub fn if_eq<LhsExpr: Into<SymbolicVar<C::N>>, RhsExpr: Into<SymbolicVar<C::N>>>( &mut self, lhs: LhsExpr, rhs: RhsExpr, ) -> IfBuilder<'_, C>
Evaluate a block of operations if two expressions are equal.
Sourcepub fn if_ne<LhsExpr: Into<SymbolicVar<C::N>>, RhsExpr: Into<SymbolicVar<C::N>>>(
&mut self,
lhs: LhsExpr,
rhs: RhsExpr,
) -> IfBuilder<'_, C>
pub fn if_ne<LhsExpr: Into<SymbolicVar<C::N>>, RhsExpr: Into<SymbolicVar<C::N>>>( &mut self, lhs: LhsExpr, rhs: RhsExpr, ) -> IfBuilder<'_, C>
Evaluate a block of operations if two expressions are not equal.
Sourcepub fn assert_less_than_slow_small_rhs<LhsExpr: Into<SymbolicVar<C::N>>, RhsExpr: Into<SymbolicVar<C::N>>>(
&mut self,
lhs: LhsExpr,
rhs: RhsExpr,
)
pub fn assert_less_than_slow_small_rhs<LhsExpr: Into<SymbolicVar<C::N>>, RhsExpr: Into<SymbolicVar<C::N>>>( &mut self, lhs: LhsExpr, rhs: RhsExpr, )
Asserts that lhs is less than rhs in time O(rhs).
Sourcepub fn assert_less_than_slow_bit_decomp(
&mut self,
lhs: Var<C::N>,
rhs: Var<C::N>,
)
pub fn assert_less_than_slow_bit_decomp( &mut self, lhs: Var<C::N>, rhs: Var<C::N>, )
Asserts that lhs is less than rhs in time O(log(lhs) + log(rhs)).
Only works for Felt == BabyBear and in the VM.
Uses bit decomposition hint, which has large constant factor overhead, so prefer Self::assert_less_than_slow_small_rhs when rhs is small.
Sourcepub fn range_check_var(&mut self, x: Var<C::N>, num_bits: usize)
pub fn range_check_var(&mut self, x: Var<C::N>, num_bits: usize)
asserts that x has at most num_bits bits
Sourcepub fn range(
&mut self,
start: impl Into<RVar<C::N>>,
end: impl Into<RVar<C::N>>,
) -> IteratorBuilder<'_, C>
pub fn range( &mut self, start: impl Into<RVar<C::N>>, end: impl Into<RVar<C::N>>, ) -> IteratorBuilder<'_, C>
Evaluate a block of operations over a range from start to end.
Sourcepub fn range_with_step(
&mut self,
start: impl Into<RVar<C::N>>,
end: impl Into<RVar<C::N>>,
step: C::N,
) -> IteratorBuilder<'_, C>
pub fn range_with_step( &mut self, start: impl Into<RVar<C::N>>, end: impl Into<RVar<C::N>>, step: C::N, ) -> IteratorBuilder<'_, C>
Evaluate a block of operations over a range from start to end with a custom step.
pub fn zip<'a>( &'a mut self, arrays: &'a [Box<dyn ArrayLike<C> + 'a>], ) -> IteratorBuilder<'a, C>
pub fn print_debug(&mut self, val: usize)
pub fn hint_var(&mut self) -> Var<C::N>
pub fn hint_felt(&mut self) -> Felt<C::F>
pub fn hint_ext(&mut self) -> Ext<C::F, C::EF>
Sourcepub fn hint_vars(&mut self) -> Array<C, Var<C::N>>
pub fn hint_vars(&mut self) -> Array<C, Var<C::N>>
Hint a vector of variables.
Writes the next element of the witness stream into memory and returns it.
Sourcepub fn hint_felts(&mut self) -> Array<C, Felt<C::F>>
pub fn hint_felts(&mut self) -> Array<C, Felt<C::F>>
Hint a vector of felts.
pub fn hint_felts_fixed( &mut self, len: impl Into<RVar<C::N>>, ) -> Array<C, Felt<C::F>>
Sourcepub fn hint_exts(&mut self) -> Array<C, Ext<C::F, C::EF>>
pub fn hint_exts(&mut self) -> Array<C, Ext<C::F, C::EF>>
Hint a vector of exts.
Emits two hint opcodes: the first for the number of exts, the second for the list of exts themselves.
Sourcepub fn hint_load(&mut self) -> Var<C::N>
pub fn hint_load(&mut self) -> Var<C::N>
Move data from input stream into hint space. Return an ID which can be used to load the data at runtime.
pub fn witness_var(&mut self) -> Var<C::N>
pub fn witness_felt(&mut self) -> Felt<C::F>
pub fn witness_ext(&mut self) -> Ext<C::F, C::EF>
pub fn witness_load(&mut self, witness_refs: Vec<WitnessRef>) -> Usize<C::N>
pub fn get_witness_refs(&self, id: Usize<C::N>) -> &[WitnessRef]
Sourcepub fn static_commit_public_value(&mut self, index: usize, val: Var<C::N>)
pub fn static_commit_public_value(&mut self, index: usize, val: Var<C::N>)
Commits a Var as public value. This value will be constrained when verified. This method should only be used in static mode.
Sourcepub fn commit_public_value(&mut self, val: Felt<C::F>)
pub fn commit_public_value(&mut self, val: Felt<C::F>)
Register and commits a felt as public value. This value will be constrained when verified.
Sourcepub fn commit_public_values(&mut self, vals: &Array<C, Felt<C::F>>)
pub fn commit_public_values(&mut self, vals: &Array<C, Felt<C::F>>)
Commits an array of felts in public values.
pub fn cycle_tracker_start(&mut self, name: &str)
pub fn cycle_tracker_end(&mut self, name: &str)
pub fn halt(&mut self)
Source§impl<C: Config> Builder<C>
impl<C: Config> Builder<C>
Sourcepub fn array<V: MemVariable<C>>(
&mut self,
len: impl Into<RVar<C::N>>,
) -> Array<C, V>
pub fn array<V: MemVariable<C>>( &mut self, len: impl Into<RVar<C::N>>, ) -> Array<C, V>
Initialize an array of fixed length len
. The entries will be uninitialized.
Sourcepub fn vec<V: MemVariable<C>>(&mut self, v: Vec<V>) -> Array<C, V>
pub fn vec<V: MemVariable<C>>(&mut self, v: Vec<V>) -> Array<C, V>
Creates an array from a vector.
Sourcepub fn uninit_fixed_array<V: Variable<C>>(&mut self, len: usize) -> Array<C, V>
pub fn uninit_fixed_array<V: Variable<C>>(&mut self, len: usize) -> Array<C, V>
Create an uninitialized Array::Fixed.
Sourcepub fn dyn_array<V: MemVariable<C>>(
&mut self,
len: impl Into<RVar<C::N>>,
) -> Array<C, V>
pub fn dyn_array<V: MemVariable<C>>( &mut self, len: impl Into<RVar<C::N>>, ) -> Array<C, V>
Creates a dynamic array for a length.
pub fn get<V: MemVariable<C>, I: Into<RVar<C::N>>>( &mut self, slice: &Array<C, V>, index: I, ) -> V
Sourcepub fn iter_ptr_get<V: MemVariable<C>>(
&mut self,
slice: &Array<C, V>,
ptr: RVar<C::N>,
) -> V
pub fn iter_ptr_get<V: MemVariable<C>>( &mut self, slice: &Array<C, V>, ptr: RVar<C::N>, ) -> V
Intended to be used with ptr
from zip
. Assumes that:
- if
slice
isArray::Fixed
, thenptr
is a constant index in [0, slice.len()). - if
slice
isArray::Dyn
, thenptr
is a variable iterator over the entries ofslice
.
In both cases, loads and returns the corresponding element of slice
.
Sourcepub fn iter_ptr_set<V: MemVariable<C>, Expr: Into<V::Expression>>(
&mut self,
slice: &Array<C, V>,
ptr: RVar<C::N>,
value: Expr,
)
pub fn iter_ptr_set<V: MemVariable<C>, Expr: Into<V::Expression>>( &mut self, slice: &Array<C, V>, ptr: RVar<C::N>, value: Expr, )
Intended to be used with ptr
from zip
. Assumes that:
- if
slice
isArray::Fixed
, thenptr
is a constant index in [0, slice.len()). - if
slice
isArray::Dyn
, thenptr
is a variable iterator over the entries ofslice
.
In both cases, stores the given value
at the corresponding element of slice
.
pub fn set<V: MemVariable<C>, I: Into<RVar<C::N>>, Expr: Into<V::Expression>>( &mut self, slice: &Array<C, V>, index: I, value: Expr, )
pub fn set_value<V: MemVariable<C>, I: Into<RVar<C::N>>>( &mut self, slice: &Array<C, V>, index: I, value: V, )
Source§impl<C: Config> Builder<C>
impl<C: Config> Builder<C>
Sourcepub fn poseidon2_permute(
&mut self,
array: &Array<C, Felt<C::F>>,
) -> Array<C, Felt<C::F>>
pub fn poseidon2_permute( &mut self, array: &Array<C, Felt<C::F>>, ) -> Array<C, Felt<C::F>>
Applies the Poseidon2 permutation to the given array.
Sourcepub fn poseidon2_permute_mut(&mut self, array: &Array<C, Felt<C::F>>)
pub fn poseidon2_permute_mut(&mut self, array: &Array<C, Felt<C::F>>)
Applies the Poseidon2 permutation to the given array.
Sourcepub fn poseidon2_compress(
&mut self,
left: &Array<C, Felt<C::F>>,
right: &Array<C, Felt<C::F>>,
) -> Array<C, Felt<C::F>>
pub fn poseidon2_compress( &mut self, left: &Array<C, Felt<C::F>>, right: &Array<C, Felt<C::F>>, ) -> Array<C, Felt<C::F>>
Applies the Poseidon2 compression function to the given array.
Sourcepub fn poseidon2_compress_x(
&mut self,
result: &Array<C, Felt<C::F>>,
left: &Array<C, Felt<C::F>>,
right: &Array<C, Felt<C::F>>,
)
pub fn poseidon2_compress_x( &mut self, result: &Array<C, Felt<C::F>>, left: &Array<C, Felt<C::F>>, right: &Array<C, Felt<C::F>>, )
Applies the Poseidon2 compression to the given array.
pub fn poseidon2_hash_x( &mut self, array: &Array<C, Array<C, Felt<C::F>>>, ) -> Array<C, Felt<C::F>>
pub fn poseidon2_hash_ext( &mut self, array: &Array<C, Array<C, Ext<C::F, C::EF>>>, ) -> Array<C, Felt<C::F>>
Source§impl<C: Config> Builder<C>
impl<C: Config> Builder<C>
Sourcepub fn alloc(&mut self, len: impl Into<RVar<C::N>>, size: usize) -> Ptr<C::N>
pub fn alloc(&mut self, len: impl Into<RVar<C::N>>, size: usize) -> Ptr<C::N>
Allocates an array on the heap.
Sourcepub fn load<V: MemVariable<C>>(
&mut self,
var: V,
ptr: Ptr<C::N>,
index: MemIndex<C::N>,
)
pub fn load<V: MemVariable<C>>( &mut self, var: V, ptr: Ptr<C::N>, index: MemIndex<C::N>, )
Loads a value from memory.
Sourcepub fn store<V: MemVariable<C>>(
&mut self,
ptr: Ptr<C::N>,
index: MemIndex<C::N>,
value: V,
)
pub fn store<V: MemVariable<C>>( &mut self, ptr: Ptr<C::N>, index: MemIndex<C::N>, value: V, )
Stores a value to memory.
pub fn load_heap_ptr(&mut self) -> Ptr<C::N>
pub fn store_heap_ptr(&mut self, ptr: Ptr<C::N>)
Source§impl<C: Config> Builder<C>
impl<C: Config> Builder<C>
Sourcepub fn generator(&mut self) -> Felt<C::F>
pub fn generator(&mut self) -> Felt<C::F>
The generator for the field.
Reference: openvm_stark_sdk::p3_baby_bear::BabyBear
Sourcepub fn select_v(
&mut self,
cond: Var<C::N>,
a: Var<C::N>,
b: Var<C::N>,
) -> Var<C::N>
pub fn select_v( &mut self, cond: Var<C::N>, a: Var<C::N>, b: Var<C::N>, ) -> Var<C::N>
Select a variable based on a condition.
Sourcepub fn select_f(
&mut self,
cond: Var<C::N>,
a: Felt<C::F>,
b: Felt<C::F>,
) -> Felt<C::F>
pub fn select_f( &mut self, cond: Var<C::N>, a: Felt<C::F>, b: Felt<C::F>, ) -> Felt<C::F>
Select a felt based on a condition.
Sourcepub fn select_ef(
&mut self,
cond: Var<C::N>,
a: Ext<C::F, C::EF>,
b: Ext<C::F, C::EF>,
) -> Ext<C::F, C::EF>
pub fn select_ef( &mut self, cond: Var<C::N>, a: Ext<C::F, C::EF>, b: Ext<C::F, C::EF>, ) -> Ext<C::F, C::EF>
Select an extension based on a condition.
Sourcepub fn exp_bits_big_endian<V>(
&mut self,
x: V,
power_bits: &Array<C, Var<C::N>>,
) -> Vwhere
V::Expression: FieldAlgebra,
V: Copy + Mul<Output = V::Expression> + Variable<C> + CanSelect<C>,
pub fn exp_bits_big_endian<V>(
&mut self,
x: V,
power_bits: &Array<C, Var<C::N>>,
) -> Vwhere
V::Expression: FieldAlgebra,
V: Copy + Mul<Output = V::Expression> + Variable<C> + CanSelect<C>,
Exponentiates a variable to a list of big endian bits with a given length.
Example: if power_bits = [1, 0, 1, 0], then the result should be x^8 * x^2 = x^10.
Sourcepub fn exp_power_of_2_v<V>(
&mut self,
base: impl Into<V::Expression>,
power_log: impl Into<RVar<C::N>>,
) -> V
pub fn exp_power_of_2_v<V>( &mut self, base: impl Into<V::Expression>, power_log: impl Into<RVar<C::N>>, ) -> V
Exponentiates a variable to a list of bits in little endian.
Sourcepub fn sll<V>(&mut self, base: impl Into<V::Expression>, shift: RVar<C::N>) -> V
pub fn sll<V>(&mut self, base: impl Into<V::Expression>, shift: RVar<C::N>) -> V
Multiplies base
by 2^{log_power}
.
Sourcepub fn ext_from_base_slice(&mut self, arr: &[Felt<C::F>]) -> Ext<C::F, C::EF>
pub fn ext_from_base_slice(&mut self, arr: &[Felt<C::F>]) -> Ext<C::F, C::EF>
Creates an ext from a slice of felts.
pub fn felts2ext(&mut self, felts: &[Felt<C::F>]) -> Ext<C::F, C::EF>
Sourcepub fn ext2felt(&mut self, value: Ext<C::F, C::EF>) -> Array<C, Felt<C::F>>
pub fn ext2felt(&mut self, value: Ext<C::F, C::EF>) -> Array<C, Felt<C::F>>
Converts an ext to a slice of felts.
Sourcepub fn ext2felt_circuit(&mut self, value: Ext<C::F, C::EF>) -> [Felt<C::F>; 4]
pub fn ext2felt_circuit(&mut self, value: Ext<C::F, C::EF>) -> [Felt<C::F>; 4]
Converts an ext to a slice of felts inside a circuit.
pub fn felt_reduce_circuit(&mut self, value: Felt<C::F>)
pub fn ext_reduce_circuit(&mut self, value: Ext<C::F, C::EF>)
Source§impl<C: Config> Builder<C>
impl<C: Config> Builder<C>
Sourcepub fn verify_batch_felt(
&mut self,
dimensions: &Array<C, Usize<C::F>>,
opened_values: &Array<C, Array<C, Felt<C::F>>>,
proof_id: Var<C::N>,
index_bits: &Array<C, Var<C::N>>,
commit: &Array<C, Felt<C::F>>,
)
pub fn verify_batch_felt( &mut self, dimensions: &Array<C, Usize<C::F>>, opened_values: &Array<C, Array<C, Felt<C::F>>>, proof_id: Var<C::N>, index_bits: &Array<C, Var<C::N>>, commit: &Array<C, Felt<C::F>>, )
- Requires
dimensions.len() == opened_values.len()
proof
is an array of arrays where inner arrays are of lengthCHUNK
commit.len() = CHUNK
Sourcepub fn verify_batch_ext(
&mut self,
dimensions: &Array<C, Usize<C::F>>,
opened_values: &Array<C, Array<C, Ext<C::F, C::EF>>>,
proof_id: Var<C::N>,
index_bits: &Array<C, Var<C::N>>,
commit: &Array<C, Felt<C::F>>,
)
pub fn verify_batch_ext( &mut self, dimensions: &Array<C, Usize<C::F>>, opened_values: &Array<C, Array<C, Ext<C::F, C::EF>>>, proof_id: Var<C::N>, index_bits: &Array<C, Var<C::N>>, commit: &Array<C, Felt<C::F>>, )
Version of Self::verify_batch_felt
where opened_values
are extension field elements.
- Requires
dimensions.len() == opened_values.len()
proof
is an array of arrays where inner arrays are of lengthCHUNK
commit.len() = CHUNK