mirror of https://github.com/zcash/halo2.git
Return AssignedCell from circuit::Region::assign_* APIs.
This commit is contained in:
parent
4aabf7c1ca
commit
36183bd01a
|
@ -93,7 +93,7 @@ pub struct Cell {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An assigned cell.
|
/// An assigned cell.
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct AssignedCell<V: Clone + Into<Assigned<F>>, F: Field> {
|
pub struct AssignedCell<V: Clone + Into<Assigned<F>>, F: Field> {
|
||||||
value: Option<V>,
|
value: Option<V>,
|
||||||
cell: Cell,
|
cell: Cell,
|
||||||
|
@ -132,16 +132,12 @@ impl<V: Clone + Into<Assigned<F>>, F: Field> AssignedCell<V, F> {
|
||||||
AR: Into<String>,
|
AR: Into<String>,
|
||||||
{
|
{
|
||||||
let value = self.value();
|
let value = self.value();
|
||||||
let cell = region.assign_advice(annotation, column, offset, || {
|
let assigned_cell = region.assign_advice(annotation, column, offset, || {
|
||||||
value.clone().ok_or(Error::Synthesis)
|
value.clone().ok_or(Error::Synthesis)
|
||||||
})?;
|
})?;
|
||||||
region.constrain_equal(cell, self.cell())?;
|
region.constrain_equal(assigned_cell.cell(), self.cell())?;
|
||||||
|
|
||||||
Ok(AssignedCell {
|
Ok(assigned_cell)
|
||||||
value,
|
|
||||||
cell,
|
|
||||||
_marker: PhantomData,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,16 +188,27 @@ impl<'r, F: Field> Region<'r, F> {
|
||||||
column: Column<Advice>,
|
column: Column<Advice>,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
mut to: V,
|
mut to: V,
|
||||||
) -> Result<Cell, Error>
|
) -> Result<AssignedCell<VR, F>, Error>
|
||||||
where
|
where
|
||||||
V: FnMut() -> Result<VR, Error> + 'v,
|
V: FnMut() -> Result<VR, Error> + 'v,
|
||||||
VR: Into<Assigned<F>>,
|
VR: Clone + Into<Assigned<F>>,
|
||||||
A: Fn() -> AR,
|
A: Fn() -> AR,
|
||||||
AR: Into<String>,
|
AR: Into<String>,
|
||||||
{
|
{
|
||||||
|
let mut value = None;
|
||||||
|
let cell =
|
||||||
self.region
|
self.region
|
||||||
.assign_advice(&|| annotation().into(), column, offset, &mut || {
|
.assign_advice(&|| annotation().into(), column, offset, &mut || {
|
||||||
to().map(|v| v.into())
|
let v = to()?;
|
||||||
|
let value_f = v.clone().into();
|
||||||
|
value = Some(v);
|
||||||
|
Ok(value_f)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(AssignedCell {
|
||||||
|
value,
|
||||||
|
cell,
|
||||||
|
_marker: PhantomData,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,18 +224,24 @@ impl<'r, F: Field> Region<'r, F> {
|
||||||
column: Column<Advice>,
|
column: Column<Advice>,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
constant: VR,
|
constant: VR,
|
||||||
) -> Result<Cell, Error>
|
) -> Result<AssignedCell<VR, F>, Error>
|
||||||
where
|
where
|
||||||
VR: Into<Assigned<F>>,
|
VR: Clone + Into<Assigned<F>>,
|
||||||
A: Fn() -> AR,
|
A: Fn() -> AR,
|
||||||
AR: Into<String>,
|
AR: Into<String>,
|
||||||
{
|
{
|
||||||
self.region.assign_advice_from_constant(
|
let cell = self.region.assign_advice_from_constant(
|
||||||
&|| annotation().into(),
|
&|| annotation().into(),
|
||||||
column,
|
column,
|
||||||
offset,
|
offset,
|
||||||
constant.into(),
|
constant.clone().into(),
|
||||||
)
|
)?;
|
||||||
|
|
||||||
|
Ok(AssignedCell {
|
||||||
|
value: Some(constant),
|
||||||
|
cell,
|
||||||
|
_marker: PhantomData,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Assign the value of the instance column's cell at absolute location
|
/// Assign the value of the instance column's cell at absolute location
|
||||||
|
@ -242,18 +255,24 @@ impl<'r, F: Field> Region<'r, F> {
|
||||||
row: usize,
|
row: usize,
|
||||||
advice: Column<Advice>,
|
advice: Column<Advice>,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
) -> Result<(Cell, Option<F>), Error>
|
) -> Result<AssignedCell<F, F>, Error>
|
||||||
where
|
where
|
||||||
A: Fn() -> AR,
|
A: Fn() -> AR,
|
||||||
AR: Into<String>,
|
AR: Into<String>,
|
||||||
{
|
{
|
||||||
self.region.assign_advice_from_instance(
|
let (cell, value) = self.region.assign_advice_from_instance(
|
||||||
&|| annotation().into(),
|
&|| annotation().into(),
|
||||||
instance,
|
instance,
|
||||||
row,
|
row,
|
||||||
advice,
|
advice,
|
||||||
offset,
|
offset,
|
||||||
)
|
)?;
|
||||||
|
|
||||||
|
Ok(AssignedCell {
|
||||||
|
value,
|
||||||
|
cell,
|
||||||
|
_marker: PhantomData,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Assign a fixed value.
|
/// Assign a fixed value.
|
||||||
|
@ -265,16 +284,27 @@ impl<'r, F: Field> Region<'r, F> {
|
||||||
column: Column<Fixed>,
|
column: Column<Fixed>,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
mut to: V,
|
mut to: V,
|
||||||
) -> Result<Cell, Error>
|
) -> Result<AssignedCell<VR, F>, Error>
|
||||||
where
|
where
|
||||||
V: FnMut() -> Result<VR, Error> + 'v,
|
V: FnMut() -> Result<VR, Error> + 'v,
|
||||||
VR: Into<Assigned<F>>,
|
VR: Clone + Into<Assigned<F>>,
|
||||||
A: Fn() -> AR,
|
A: Fn() -> AR,
|
||||||
AR: Into<String>,
|
AR: Into<String>,
|
||||||
{
|
{
|
||||||
|
let mut value = None;
|
||||||
|
let cell =
|
||||||
self.region
|
self.region
|
||||||
.assign_fixed(&|| annotation().into(), column, offset, &mut || {
|
.assign_fixed(&|| annotation().into(), column, offset, &mut || {
|
||||||
to().map(|v| v.into())
|
let v = to()?;
|
||||||
|
let value_f = v.clone().into();
|
||||||
|
value = Some(v);
|
||||||
|
Ok(value_f)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(AssignedCell {
|
||||||
|
value,
|
||||||
|
cell,
|
||||||
|
_marker: PhantomData,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue