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§

source

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.

source

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§

source

const SIZE_IN_FIELD_ELEMENTS: usize

The number of field elements that this type takes.

Required Methods§

source

fn to_cvars(&self) -> (Vec<FieldVar<F>>, Self::Auxiliary)

Returns the circuit variables (and auxiliary data) behind this type.

source

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).

source

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.

source

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!

source

fn value_to_field_elements( value: &Self::OutOfCircuit ) -> (Vec<F>, Self::Auxiliary)

Converts an out-of-circuit value

source

fn value_of_field_elements( fields: Vec<F>, aux: Self::Auxiliary ) -> Self::OutOfCircuit

Provided Methods§

source

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,

source

fn read<G>(&self, g: G) -> Self::OutOfCircuitwhere G: WitnessGeneration<F>,

Implementations on Foreign Types§

source§

impl<F, T1, T2> SnarkyType<F> for (T1, T2)where F: PrimeField, T1: SnarkyType<F>, T2: SnarkyType<F>,

§

type Auxiliary = (<T1 as SnarkyType<F>>::Auxiliary, <T2 as SnarkyType<F>>::Auxiliary)

§

type OutOfCircuit = (<T1 as SnarkyType<F>>::OutOfCircuit, <T2 as SnarkyType<F>>::OutOfCircuit)

source§

const SIZE_IN_FIELD_ELEMENTS: usize = _

source§

fn to_cvars(&self) -> (Vec<FieldVar<F>>, Self::Auxiliary)

source§

fn from_cvars_unsafe(cvars: Vec<FieldVar<F>>, aux: Self::Auxiliary) -> Self

source§

fn check( &self, cs: &mut RunState<F>, loc: Cow<'static, str> ) -> SnarkyResult<()>

source§

fn constraint_system_auxiliary() -> Self::Auxiliary

source§

fn value_to_field_elements( value: &Self::OutOfCircuit ) -> (Vec<F>, Self::Auxiliary)

source§

fn value_of_field_elements( fields: Vec<F>, aux: Self::Auxiliary ) -> Self::OutOfCircuit

source§

impl<F, T, const N: usize> SnarkyType<F> for [T; N]where F: PrimeField, T: SnarkyType<F>,

§

type Auxiliary = Vec<<T as SnarkyType<F>>::Auxiliary, Global>

§

type OutOfCircuit = [<T as SnarkyType<F>>::OutOfCircuit; N]

source§

const SIZE_IN_FIELD_ELEMENTS: usize = _

source§

fn to_cvars(&self) -> (Vec<FieldVar<F>>, Self::Auxiliary)

source§

fn from_cvars_unsafe(cvars: Vec<FieldVar<F>>, aux: Self::Auxiliary) -> Self

source§

fn check( &self, cs: &mut RunState<F>, loc: Cow<'static, str> ) -> SnarkyResult<()>

source§

fn constraint_system_auxiliary() -> Self::Auxiliary

source§

fn value_to_field_elements( value: &Self::OutOfCircuit ) -> (Vec<F>, Self::Auxiliary)

source§

fn value_of_field_elements( fields: Vec<F>, aux: Self::Auxiliary ) -> Self::OutOfCircuit

source§

impl<F> SnarkyType<F> for ()where F: PrimeField,

§

type Auxiliary = ()

§

type OutOfCircuit = ()

source§

const SIZE_IN_FIELD_ELEMENTS: usize = 0usize

source§

fn to_cvars(&self) -> (Vec<FieldVar<F>>, Self::Auxiliary)

source§

fn from_cvars_unsafe(_cvars: Vec<FieldVar<F>>, _aux: Self::Auxiliary) -> Self

source§

fn check( &self, _cs: &mut RunState<F>, _loc: Cow<'static, str> ) -> SnarkyResult<()>

source§

fn constraint_system_auxiliary() -> Self::Auxiliary

source§

fn value_to_field_elements( _value: &Self::OutOfCircuit ) -> (Vec<F>, Self::Auxiliary)

source§

fn value_of_field_elements( _fields: Vec<F>, _aux: Self::Auxiliary ) -> Self::OutOfCircuit

Implementors§

source§

impl<F> SnarkyType<F> for FieldVar<F>where F: PrimeField,

source§

impl<F> SnarkyType<F> for Boolean<F>where F: PrimeField,

source§

impl<F: PrimeField> SnarkyType<F> for FullChallenge<FieldVar<F>>