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,
impl<F> RunState<F>where F: PrimeField,
sourcepub fn new<Curve: KimchiCurve<ScalarField = F>>(
public_input_size: usize,
public_output_size: usize,
with_system: bool
) -> Self
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.
sourcepub fn read_var_idx(&self, idx: usize) -> F
pub fn read_var_idx(&self, idx: usize) -> F
Used internaly to evaluate variables. Can panic if used with a wrong index.
sourcepub fn public_input<T: SnarkyType<F>>(&self) -> T
pub fn public_input<T: SnarkyType<F>>(&self) -> T
Returns the public input snarky variable.
sourcepub fn store_field_elt(&mut self, x: F) -> FieldVar<F>
pub fn store_field_elt(&mut self, x: F) -> FieldVar<F>
Stores a field element as an unconstrained private input.
sourcepub 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,
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.
sourcepub fn assert_r1cs(
&mut self,
label: Option<Cow<'static, str>>,
loc: Cow<'static, str>,
a: FieldVar<F>,
b: FieldVar<F>,
c: FieldVar<F>
) -> SnarkyResult<()>
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)
.
sourcepub fn assert_eq(
&mut self,
label: Option<Cow<'static, str>>,
loc: Cow<'static, str>,
x: FieldVar<F>,
y: FieldVar<F>
) -> SnarkyResult<()>
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)
;
sourcepub fn add_constraint(
&mut self,
constraint: Constraint<F>,
label: Option<Cow<'static, str>>,
loc: Cow<'static, str>
) -> SnarkyResult<()>
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.
sourcepub fn if_(
&mut self,
loc: Cow<'static, str>,
b: Boolean<F>,
then_: FieldVar<F>,
else_: FieldVar<F>
) -> SnarkyResult<FieldVar<F>>
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_ }
.
sourcepub fn get_private_inputs(&self) -> Vec<F>
pub fn get_private_inputs(&self) -> Vec<F>
Getter for the OCaml side.
sourcepub fn add_label(&mut self, label: Cow<'static, str>)
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).
sourcepub fn pop_label(&mut self)
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.
sourcepub fn with_label<FUNC, T>(
&mut self,
label: Option<Cow<'static, str>>,
closure: FUNC
) -> Twhere
FUNC: FnOnce(&mut Self) -> T,
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).
sourcepub fn error(&self, error: SnarkyError) -> RealSnarkyError
pub fn error(&self, error: SnarkyError) -> RealSnarkyError
Creates an RealSnarkyError using the current context.
sourcepub fn runtime_error(&self, error: SnarkyRuntimeError) -> Box<RealSnarkyError>
pub fn runtime_error(&self, error: SnarkyRuntimeError) -> Box<RealSnarkyError>
Creates a runtime error.
sourcepub fn compilation_error(
&self,
error: SnarkyCompilationError
) -> Box<RealSnarkyError>
pub fn compilation_error( &self, error: SnarkyCompilationError ) -> Box<RealSnarkyError>
Crates a compilation error.
pub fn generate_witness_init( &mut self, public_input: Vec<F> ) -> SnarkyResult<()>
sourcepub fn generate_witness(&mut self) -> Witness<F>
pub fn generate_witness(&mut self) -> Witness<F>
Returns the public output generated after running the circuit, and the witness of the execution trace.
pub fn poseidon( &mut self, loc: Cow<'static, str>, preimage: (FieldVar<F>, FieldVar<F>) ) -> (FieldVar<F>, FieldVar<F>)
sourcepub fn range_check(
&mut self,
loc: Cow<'static, str>,
v0: FieldVar<F>,
v1: FieldVar<F>,
v2: FieldVar<F>
) -> SnarkyResult<()>
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