Struct halo2_base::Context
source · [−]pub struct Context<F: ScalarField> {
pub context_id: usize,
pub advice: Vec<Assigned<F>>,
pub cells_to_lookup: Vec<AssignedValue<F>>,
pub zero_cell: Option<AssignedValue<F>>,
pub selector: Vec<bool>,
pub advice_equality_constraints: Vec<(ContextCell, ContextCell)>,
pub constant_equality_constraints: Vec<(F, ContextCell)>,
/* private fields */
}
Expand description
Represents a single thread of an execution trace.
- We keep the naming Context for historical reasons.
Fields
context_id: usize
Identifier to reference cells from this Context.
advice: Vec<Assigned<F>>
Single column of advice cells.
cells_to_lookup: Vec<AssignedValue<F>>
Vec tracking all cells that lookup is enabled for.
- When there is more than 1 advice column all
advice
cells will be copied to a single lookup enabled column to perform lookups.
zero_cell: Option<AssignedValue<F>>
Cell that represents the zero value as AssignedValue
selector: Vec<bool>
Vec representing the selector column of this Context accompanying each advice
column
- Assumed to have the same length as
advice
advice_equality_constraints: Vec<(ContextCell, ContextCell)>
A Vec tracking equality constraints between pairs of Context advice
cells.
Assumes both advice
cells are in the same Context.
constant_equality_constraints: Vec<(F, ContextCell)>
A Vec tracking pairs equality constraints between Fixed values and Context advice
cells.
Assumes the constant and advice
cell are in the same Context.
Implementations
sourceimpl<F: ScalarField> Context<F>
impl<F: ScalarField> Context<F>
sourcepub fn new(witness_gen_only: bool, context_id: usize) -> Self
pub fn new(witness_gen_only: bool, context_id: usize) -> 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.
sourcepub fn witness_gen_only(&self) -> bool
pub fn witness_gen_only(&self) -> bool
Returns the witness_gen_only
flag of the Context
sourcepub fn assign_cell(&mut self, input: impl Into<QuantumCell<F>>)
pub fn assign_cell(&mut self, input: impl Into<QuantumCell<F>>)
Pushes a QuantumCelladvice
column (Vec of advice cells) in this Context.
input
: the cell to be assigned.
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
is inputs[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_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
.
Trait Implementations
sourceimpl<F: Clone + ScalarField> Clone for Context<F>
impl<F: Clone + ScalarField> Clone for Context<F>
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> FmtForward for T
impl<T> FmtForward for T
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.fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
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.fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
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 morefn 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 morefn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
self
, then passes self.as_ref()
into the pipe function.fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> Rwhere
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> Rwhere
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
self
, then passes self.deref()
into the pipe function.impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Tap for T
impl<T> Tap for T
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
Borrow<B>
of a value. Read morefn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
BorrowMut<B>
of a value. Read morefn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
AsRef<R>
view of a value. Read morefn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
AsMut<R>
view of a value. Read morefn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
Deref::Target
of a value. Read morefn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
Deref::Target
of a value. Read morefn 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.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. Read morefn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
.tap_borrow()
only in debug builds, and is erased in release
builds. Read morefn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
.tap_borrow_mut()
only in debug builds, and is erased in release
builds. Read morefn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
.tap_ref()
only in debug builds, and is erased in release
builds. Read morefn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
.tap_ref_mut()
only in debug builds, and is erased in release
builds. Read more