pub struct Values<'a, F> { /* private fields */ }Expand description
A view of the values assigned so far during prover-mode construction.
A view is passed to witness init closures, which read the values of
earlier vars with Var::value. This is how a prover supplies values
that are cheaper to verify than to compute with circuit operations, such
as inverses: compute the value natively, then constrain it with
assertions.
Closures receiving a view must not call back into the Context, for
example by creating new vars: doing so deadlocks.
§Example
use commonware_cryptography::zk::circuit::{build_with_values, Var};
use commonware_math::{
algebra::{Field, Ring},
test::F,
};
let (valued, _) = build_with_values(|ctx| {
let x = Var::witness(ctx, |_| F::from(3u64));
// The prover computes the inverse natively...
let inv = Var::witness(ctx, {
let x = x.clone();
move |v| x.value(v).inv()
});
// ...and the circuit checks it with a single multiplication.
(x * &inv).assert_eq(&Var::one());
Vec::new()
});
assert!(valued.is_satisfied());Trait Implementations§
Auto Trait Implementations§
impl<'a, F> Freeze for Values<'a, F>
impl<'a, F> RefUnwindSafe for Values<'a, F>where
F: RefUnwindSafe,
impl<'a, F> Send for Values<'a, F>where
F: Sync,
impl<'a, F> Sync for Values<'a, F>where
F: Sync,
impl<'a, F> Unpin for Values<'a, F>
impl<'a, F> UnsafeUnpin for Values<'a, F>
impl<'a, F> UnwindSafe for Values<'a, F>where
F: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more