Trait kimchi::snarky::snarky_type::SnarkyType
source · pub trait SnarkyType<F>: Debug + Sizedwhere
F: PrimeField,{
type Auxiliary;
type OutOfCircuit;
const SIZE_IN_FIELD_ELEMENTS: usize;
// Required methods
fn to_cvars(&self) -> (Vec<FieldVar<F>>, Self::Auxiliary);
fn from_cvars_unsafe(cvars: Vec<FieldVar<F>>, aux: Self::Auxiliary) -> Self;
fn check(
&self,
cs: &mut RunState<F>,
loc: Cow<'static, str>
) -> SnarkyResult<()>;
fn constraint_system_auxiliary() -> Self::Auxiliary;
fn value_to_field_elements(
value: &Self::OutOfCircuit
) -> (Vec<F>, Self::Auxiliary);
fn value_of_field_elements(
fields: Vec<F>,
aux: Self::Auxiliary
) -> Self::OutOfCircuit;
// Provided methods
fn compute<FUNC>(
cs: &mut RunState<F>,
loc: Cow<'static, str>,
to_compute_value: FUNC
) -> SnarkyResult<Self>
where FUNC: Fn(&dyn WitnessGeneration<F>) -> Self::OutOfCircuit { ... }
fn read<G>(&self, g: G) -> Self::OutOfCircuit
where G: WitnessGeneration<F> { ... }
}
Expand description
A snarky type is a type that can be used in a circuit. It references an equivalent “out-of-circuit” type that one can use outside of the circuit. (For example, to construct private or public inputs, or a public output, to the circuit.)
Required Associated Types§
sourcetype Auxiliary
type Auxiliary
Some ‘out-of-circuit’ data, which is carried as part of Self. This data isn’t encoded as CVars in the circuit, since the data may be large (e.g. a sparse merkle tree), or may only be used by witness computations / for debugging.
sourcetype OutOfCircuit
type OutOfCircuit
The equivalent “out-of-circuit” type. For example, the super::boolean::Boolean snarky type has an out-of-circuit type of bool.
Required Associated Constants§
sourceconst SIZE_IN_FIELD_ELEMENTS: usize
const SIZE_IN_FIELD_ELEMENTS: usize
The number of field elements that this type takes.
Required Methods§
sourcefn to_cvars(&self) -> (Vec<FieldVar<F>>, Self::Auxiliary)
fn to_cvars(&self) -> (Vec<FieldVar<F>>, Self::Auxiliary)
Returns the circuit variables (and auxiliary data) behind this type.
sourcefn from_cvars_unsafe(cvars: Vec<FieldVar<F>>, aux: Self::Auxiliary) -> Self
fn from_cvars_unsafe(cvars: Vec<FieldVar<F>>, aux: Self::Auxiliary) -> Self
Creates a new instance of this type from the given circuit variables (And some auxiliary data).
sourcefn check(
&self,
cs: &mut RunState<F>,
loc: Cow<'static, str>
) -> SnarkyResult<()>
fn check( &self, cs: &mut RunState<F>, loc: Cow<'static, str> ) -> SnarkyResult<()>
Checks that the circuit variables behind this type are valid. For some definition of valid. For example, a Boolean snarky type would check that the field element representing it is either 0 or 1. The function does this by adding constraints to your constraint system.
sourcefn constraint_system_auxiliary() -> Self::Auxiliary
fn constraint_system_auxiliary() -> Self::Auxiliary
The “default” value of Self::Auxiliary. This is passed to Self::from_cvars_unsafe when we are not generating a witness, since we have no candidate value to get the auxiliary data from. Note that we use an explicit value here rather than Auxiliary: Default, since the default value for the type may not match the default value we actually want to pass!
sourcefn value_to_field_elements(
value: &Self::OutOfCircuit
) -> (Vec<F>, Self::Auxiliary)
fn value_to_field_elements( value: &Self::OutOfCircuit ) -> (Vec<F>, Self::Auxiliary)
Converts an out-of-circuit value