pub struct Context<F: ScalarField> {
pub advice: Vec<Assigned<F>>,
pub selector: Vec<bool>,
pub copy_manager: SharedCopyConstraintManager<F>,
/* private fields */
}
Expand description
Fields§
§advice: Vec<Assigned<F>>
Single column of advice cells.
selector: Vec<bool>
Vec representing the selector column of this Context accompanying each advice
column
- Assumed to have the same length as
advice
copy_manager: SharedCopyConstraintManager<F>
Global shared thread-safe manager for all copy (equality) constraints between virtual advice, constants, and raw external Halo2 cells.
Implementations§
Source§impl<F: ScalarField> Context<F>
impl<F: ScalarField> Context<F>
Sourcepub fn witness_gen_only(&self) -> bool
pub fn witness_gen_only(&self) -> bool
Flag to determine whether only witness generation or proving and verification key generation is being performed.
- If witness gen is performed many operations can be skipped for optimization.
Sourcepub fn type_id(&self) -> &'static str
pub fn type_id(&self) -> &'static str
Identifier for what virtual region this context is in. Warning: the circuit writer must ensure that distinct virtual regions have distinct names as strings to prevent possible errors. We do not use std::any::TypeId because it is not stable across rust builds or dependencies.
Source§impl<F: ScalarField> Context<F>
impl<F: ScalarField> Context<F>
Sourcepub fn new(
witness_gen_only: bool,
phase: usize,
type_id: &'static str,
context_id: usize,
copy_manager: SharedCopyConstraintManager<F>,
) -> Self
pub fn new( witness_gen_only: bool, phase: usize, type_id: &'static str, context_id: usize, copy_manager: SharedCopyConstraintManager<F>, ) -> Self
Creates a new Context with the given context_id
and witness generation enabled/disabled by the witness_gen_only
flag.
witness_gen_only
: flag to determine whether public key generation or only witness generation is being performed.context_id
: identifier to reference advice cells from this Context later.
Warning: If you create your own Context
in a new virtual region not provided by our libraries, you must ensure that the type_id: &str
of the context is a globally unique identifier for the virtual region, distinct from the other type_id
strings used to identify other virtual regions. We suggest that you either include your crate name as a prefix in the type_id
or use module_path!
to generate a prefix.
In the future we will introduce a macro to check this uniqueness at compile time.
Sourcepub fn tag(&self) -> ContextTag
pub fn tag(&self) -> ContextTag
A unique tag that should identify this context across all virtual regions and phases.
Sourcepub fn assign_cell(&mut self, input: impl Into<QuantumCell<F>>)
pub fn assign_cell(&mut self, input: impl Into<QuantumCell<F>>)
Virtually assigns the input
within the current Context, with different handling depending on the QuantumCell variant.
Sourcepub fn last(&self) -> Option<AssignedValue<F>>
pub fn last(&self) -> Option<AssignedValue<F>>
Returns the AssignedValue of the last cell in the advice
column of Context or None if advice
is empty
Sourcepub fn get(&self, offset: isize) -> AssignedValue<F>
pub fn get(&self, offset: isize) -> AssignedValue<F>
Returns the AssignedValue of the cell at the given offset
in the advice
column of Context
offset
: the offset of the cell to be fetchedoffset
may be negative indexing from the end of the column (e.g.,-1
is the last cell)
- Assumes
offset
is a valid index inadvice
;0
<=offset
<advice.len()
(oradvice.len() + offset >= 0
ifoffset
is negative)
Sourcepub fn constrain_equal(&mut self, a: &AssignedValue<F>, b: &AssignedValue<F>)
pub fn constrain_equal(&mut self, a: &AssignedValue<F>, b: &AssignedValue<F>)
Creates an equality constraint between two advice
cells.
a
: the firstadvice
cell to be constrained equalb
: the secondadvice
cell to be constrained equal- Assumes both cells are
advice
cells
Sourcepub fn assign_region<Q>(
&mut self,
inputs: impl IntoIterator<Item = Q>,
gate_offsets: impl IntoIterator<Item = isize>,
)where
Q: Into<QuantumCell<F>>,
pub fn assign_region<Q>(
&mut self,
inputs: impl IntoIterator<Item = Q>,
gate_offsets: impl IntoIterator<Item = isize>,
)where
Q: Into<QuantumCell<F>>,
Pushes multiple advice cells to the advice
column of Context and enables them by enabling the corresponding selector specified in gate_offset
.
inputs
: Iterator that specifies the cells to be assignedgate_offsets
: specifies relative offset from current position to enable selector for the gate (e.g.,0
isinputs[0]
).offset
may be negative indexing from the end of the column (e.g.,-1
is the last previously assigned cell)
Sourcepub fn assign_region_last<Q>(
&mut self,
inputs: impl IntoIterator<Item = Q>,
gate_offsets: impl IntoIterator<Item = isize>,
) -> AssignedValue<F>where
Q: Into<QuantumCell<F>>,
pub fn assign_region_last<Q>(
&mut self,
inputs: impl IntoIterator<Item = Q>,
gate_offsets: impl IntoIterator<Item = isize>,
) -> AssignedValue<F>where
Q: Into<QuantumCell<F>>,
Pushes multiple advice cells to the advice
column of Context and enables them by enabling the corresponding selector specified in gate_offset
and returns the last assigned cell.
Assumes gate_offsets
is the same length as inputs
Returns the last assigned cell
inputs
: Iterator that specifies the cells to be assignedgate_offsets
: specifies indices to enable selector for the gate; assumegate_offsets
is sorted in increasing orderoffset
may be negative indexing from the end of the column (e.g.,-1
is the last cell)
Sourcepub fn assign_region_smart<Q>(
&mut self,
inputs: impl IntoIterator<Item = Q>,
gate_offsets: impl IntoIterator<Item = isize>,
equality_offsets: impl IntoIterator<Item = (isize, isize)>,
external_equality: impl IntoIterator<Item = (Option<ContextCell>, isize)>,
)where
Q: Into<QuantumCell<F>>,
pub fn assign_region_smart<Q>(
&mut self,
inputs: impl IntoIterator<Item = Q>,
gate_offsets: impl IntoIterator<Item = isize>,
equality_offsets: impl IntoIterator<Item = (isize, isize)>,
external_equality: impl IntoIterator<Item = (Option<ContextCell>, isize)>,
)where
Q: Into<QuantumCell<F>>,
Pushes multiple advice cells to the advice
column of Context and enables them by enabling the corresponding selector specified in gate_offset
.
Allows for the specification of equality constraints between cells at equality_offsets
within the advice
column and external advice cells specified in external_equality
(e.g, Fixed column).
gate_offsets
: specifies indices to enable selector for the gate;offset
may be negative indexing from the end of the column (e.g.,-1
is the last cell)
equality_offsets
: specifies pairs of indices to constrain equalityexternal_equality
: specifies an existing cell to constrain equality with the cell at a certain index
Sourcepub fn assign_witnesses(
&mut self,
witnesses: impl IntoIterator<Item = F>,
) -> Vec<AssignedValue<F>>
pub fn assign_witnesses( &mut self, witnesses: impl IntoIterator<Item = F>, ) -> Vec<AssignedValue<F>>
Assigns a region of witness cells in an iterator and returns a Vec of assigned cells.
witnesses
: Iterator that specifies the cells to be assigned
Sourcepub fn load_witness(&mut self, witness: F) -> AssignedValue<F>
pub fn load_witness(&mut self, witness: F) -> AssignedValue<F>
Assigns a witness value and returns the corresponding assigned cell.
witness
: the witness value to be assigned
Sourcepub fn load_constant(&mut self, c: F) -> AssignedValue<F>
pub fn load_constant(&mut self, c: F) -> AssignedValue<F>
Assigns a constant value and returns the corresponding assigned cell.
c
: the constant value to be assigned
Sourcepub fn load_constants(&mut self, c: &[F]) -> Vec<AssignedValue<F>>
pub fn load_constants(&mut self, c: &[F]) -> Vec<AssignedValue<F>>
Assigns a list of constant values and returns the corresponding assigned cells.
c
: the list of constant values to be assigned
Sourcepub fn load_zero(&mut self) -> AssignedValue<F>
pub fn load_zero(&mut self) -> AssignedValue<F>
Assigns the 0 value to a new cell or returns a previously assigned zero cell from zero_cell
.
Sourcepub fn debug_assert_false(&mut self)
pub fn debug_assert_false(&mut self)
Helper function for debugging using MockProver
. This adds a constraint that always fails.
The MockProver
will print out the row, column where it fails, so it serves as a debugging “break point”
so you can add to your code to search for where the actual constraint failure occurs.
Trait Implementations§
Auto Trait Implementations§
impl<F> Freeze for Context<F>where
F: Freeze,
impl<F> RefUnwindSafe for Context<F>where
F: RefUnwindSafe,
impl<F> Send for Context<F>
impl<F> Sync for Context<F>
impl<F> Unpin for Context<F>where
F: Unpin,
impl<F> UnwindSafe for Context<F>where
F: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.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>
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>
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 moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.