Struct kimchi::snarky::runner::RunState

source ·
pub struct RunState<F>where
    F: PrimeField,{
    pub system: Option<SnarkyConstraintSystem<F>>,
    pub eval_constraints: bool,
    pub num_public_inputs: usize,
    pub next_var: usize,
    pub has_witness: bool,
    pub as_prover: bool,
    /* private fields */
}
Expand description

The state used when compiling a circuit in snarky, or used in witness generation as well.

Fields§

§system: Option<SnarkyConstraintSystem<F>>

The constraint system used to build the circuit. If not set, the constraint system is not built.

§eval_constraints: bool

If set, the witness generation will check if the constraints are satisfied. This is useful to simulate running the circuit and return an error if an assertion fails.

§num_public_inputs: usize

The size of the public input part. This contains the public output as well.

§next_var: usize

A counter used to track variables (this includes public inputs) as they’re being created.

§has_witness: bool

Indication that we’re running the witness generation. This does not necessarily mean that constraints are not created, as we can do both at the same time.

§as_prover: bool

Indication that we’re running in prover mode. In this mode, we do not want to create constraints.

Implementations§

source§

impl<F> RunState<F>where F: PrimeField,

source

pub fn new<Curve: KimchiCurve<ScalarField = F>>( public_input_size: usize, public_output_size: usize, with_system: bool ) -> Self

Creates a new Self based on the size of the public input, and the size of the public output. If with_system is set it will create a SnarkyConstraintSystem in order to compile a new circuit.

source

pub fn read_var_idx(&self, idx: usize) -> F

Used internaly to evaluate variables. Can panic if used with a wrong index.

source

pub fn public_input<T: SnarkyType<F>>(&self) -> T

Returns the public input snarky variable.

source

pub fn alloc_var(&mut self) -> FieldVar<F>

Allocates a new var representing a private input.

source

pub fn store_field_elt(&mut self, x: F) -> FieldVar<F>

Stores a field element as an unconstrained private input.

source

pub fn compute<T, FUNC>( &mut self, loc: Cow<'static, str>, to_compute_value: FUNC ) -> SnarkyResult<T>where T: SnarkyType<F>, FUNC: FnOnce(&dyn WitnessGeneration<F>) -> T::OutOfCircuit,

Creates a new non-deterministic variable associated to a value type (SnarkyType), and a closure that can compute it when in witness generation mode.

source

pub fn assert_r1cs( &mut self, label: Option<Cow<'static, str>>, loc: Cow<'static, str>, a: FieldVar<F>, b: FieldVar<F>, c: FieldVar<F> ) -> SnarkyResult<()>

Creates a constraint for assert_eq!(a * b, c).

source

pub fn assert_eq( &mut self, label: Option<Cow<'static, str>>, loc: Cow<'static, str>, x: FieldVar<F>, y: FieldVar<F> ) -> SnarkyResult<()>

Creates a constraint for assert_eq!(x, y);

source

pub fn add_constraint( &mut self, constraint: Constraint<F>, label: Option<Cow<'static, str>>, loc: Cow<'static, str> ) -> SnarkyResult<()>

Adds a list of Constraint to the circuit.

source

pub fn if_( &mut self, loc: Cow<'static, str>, b: Boolean<F>, then_: FieldVar<F>, else_: FieldVar<F> ) -> SnarkyResult<FieldVar<F>>

Adds a constraint that returns then_ if b is true, else_ otherwise. Equivalent to if b { then_ } else { else_ }.

source

pub fn get_private_inputs(&self) -> Vec<F>

Getter for the OCaml side.

source

pub fn add_label(&mut self, label: Cow<'static, str>)

This adds a label in the stack of labels. Every error from now one will contain this label, until the label is popped (via Self::pop_label).

source

pub fn pop_label(&mut self)

This removes a label from any error that could come up from now on. Normally used shortly after Self::add_label.

source

pub fn with_label<FUNC, T>( &mut self, label: Option<Cow<'static, str>>, closure: FUNC ) -> Twhere FUNC: FnOnce(&mut Self) -> T,

A wrapper around code that needs to be labeled (for better errors).

source

pub fn error(&self, error: SnarkyError) -> RealSnarkyError

Creates an RealSnarkyError using the current context.

source

pub fn runtime_error(&self, error: SnarkyRuntimeError) -> Box<RealSnarkyError>

Creates a runtime error.

source

pub fn compilation_error( &self, error: SnarkyCompilationError ) -> Box<RealSnarkyError>

Crates a compilation error.

source

pub fn generate_witness_init( &mut self, public_input: Vec<F> ) -> SnarkyResult<()>

source

pub fn generate_witness(&mut self) -> Witness<F>

Returns the public output generated after running the circuit, and the witness of the execution trace.

source

pub fn poseidon( &mut self, loc: Cow<'static, str>, preimage: (FieldVar<F>, FieldVar<F>) ) -> (FieldVar<F>, FieldVar<F>)

source

pub fn range_check( &mut self, loc: Cow<'static, str>, v0: FieldVar<F>, v1: FieldVar<F>, v2: FieldVar<F> ) -> SnarkyResult<()>

constrains the 3 provided values to fit in 88 bits

Trait Implementations§

source§

impl<F> Debug for RunState<F>where F: PrimeField + Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<F> WitnessGeneration<F> for RunState<F>where F: PrimeField,

source§

fn read_var(&self, var: &FieldVar<F>) -> F

Allows the caller to obtain the value behind a circuit variable.
source§

fn constraints_counter(&self) -> usize

Auto Trait Implementations§

§

impl<F> RefUnwindSafe for RunState<F>where F: RefUnwindSafe,

§

impl<F> Send for RunState<F>

§

impl<F> Sync for RunState<F>

§

impl<F> Unpin for RunState<F>where F: Unpin,

§

impl<F> UnwindSafe for RunState<F>where F: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V