Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/halo2_gadgets/src/sinsemilla/chip/hash_to_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn assign_hash_rounds(
len,
|row| round(row).map(|round| round.lambda_1),
)?;
region.assign_advice_batch(
region.assign_advice_batch_with_previous_denominator(
|_| "lambda_2",
double_and_add.lambda_2,
offset,
Expand All @@ -124,7 +124,7 @@ fn assign_hash_rounds(
)?;

// Only the final accumulator cell is referenced after assignment.
region.assign_advice_batch(
region.assign_advice_batch_with_previous_denominator_squared(
|_| "x_a",
double_and_add.x_a,
offset + 1,
Expand Down
57 changes: 57 additions & 0 deletions crates/halo2_proofs/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,63 @@ impl<'r, F: Field> Region<'r, F> {
)
}

/// Assigns rational advice whose denominators equal the corresponding
/// denominators in the immediately preceding batch.
///
/// This is equivalent to [`Self::assign_advice_batch`] when the hint is
/// correct. Proving backends may derive the denominators from the batch
/// relationship.
pub fn assign_advice_batch_with_previous_denominator<'v, V, A, AR>(
&'v mut self,
annotation: A,
column: Column<Advice>,
offset: usize,
len: usize,
mut to: V,
) -> Result<(), Error>
where
V: FnMut(usize) -> Value<Assigned<F>> + 'v,
A: Fn(usize) -> AR + 'v,
AR: Into<String>,
{
self.region.assign_advice_batch_with_previous_denominator(
&|index| annotation(index).into(),
column,
offset,
len,
&mut to,
)
}

/// Assigns rational advice whose denominators are the squares of the
/// corresponding denominators in the immediately preceding batch.
///
/// This is equivalent to [`Self::assign_advice_batch`] when the hint is
/// correct. Proving backends may derive the denominators from the batch
/// relationship.
pub fn assign_advice_batch_with_previous_denominator_squared<'v, V, A, AR>(
&'v mut self,
annotation: A,
column: Column<Advice>,
offset: usize,
len: usize,
mut to: V,
) -> Result<(), Error>
where
V: FnMut(usize) -> Value<Assigned<F>> + 'v,
A: Fn(usize) -> AR + 'v,
AR: Into<String>,
{
self.region
.assign_advice_batch_with_previous_denominator_squared(
&|index| annotation(index).into(),
column,
offset,
len,
&mut to,
)
}

/// Assigns a constant value to the column `advice` at `offset` within this region.
///
/// The constant value will be assigned to a cell within one of the fixed columns
Expand Down
42 changes: 42 additions & 0 deletions crates/halo2_proofs/src/circuit/floor_planner/single_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,48 @@ impl<'r, 'a, F: Field, CS: Assignment<F> + 'a> RegionLayouter<F>
.assign_advice_batch(annotation, column, offset, len, to)
}

fn assign_advice_batch_with_previous_denominator<'v>(
&'v mut self,
annotation: &'v (dyn Fn(usize) -> String + 'v),
column: Column<Advice>,
offset: usize,
len: usize,
to: &'v mut (dyn FnMut(usize) -> Value<Assigned<F>> + 'v),
) -> Result<(), Error> {
if len == 0 {
return Ok(());
}

let offset = self.layouter.regions[*self.region_index]
.checked_add(offset)
.ok_or(Error::BoundsFailure)?;
self.layouter
.cs
.assign_advice_batch_with_previous_denominator(annotation, column, offset, len, to)
}

fn assign_advice_batch_with_previous_denominator_squared<'v>(
&'v mut self,
annotation: &'v (dyn Fn(usize) -> String + 'v),
column: Column<Advice>,
offset: usize,
len: usize,
to: &'v mut (dyn FnMut(usize) -> Value<Assigned<F>> + 'v),
) -> Result<(), Error> {
if len == 0 {
return Ok(());
}

let offset = self.layouter.regions[*self.region_index]
.checked_add(offset)
.ok_or(Error::BoundsFailure)?;
self.layouter
.cs
.assign_advice_batch_with_previous_denominator_squared(
annotation, column, offset, len, to,
)
}

fn assign_advice_from_constant<'v>(
&'v mut self,
annotation: &'v (dyn Fn() -> String + 'v),
Expand Down
42 changes: 42 additions & 0 deletions crates/halo2_proofs/src/circuit/floor_planner/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,48 @@ impl<'r, 'a, F: Field, CS: Assignment<F> + 'a> RegionLayouter<F> for V1Region<'r
.assign_advice_batch(annotation, column, offset, len, to)
}

fn assign_advice_batch_with_previous_denominator<'v>(
&'v mut self,
annotation: &'v (dyn Fn(usize) -> String + 'v),
column: Column<Advice>,
offset: usize,
len: usize,
to: &'v mut (dyn FnMut(usize) -> Value<Assigned<F>> + 'v),
) -> Result<(), Error> {
if len == 0 {
return Ok(());
}

let offset = self.plan.regions[*self.region_index]
.checked_add(offset)
.ok_or(Error::BoundsFailure)?;
self.plan
.cs
.assign_advice_batch_with_previous_denominator(annotation, column, offset, len, to)
}

fn assign_advice_batch_with_previous_denominator_squared<'v>(
&'v mut self,
annotation: &'v (dyn Fn(usize) -> String + 'v),
column: Column<Advice>,
offset: usize,
len: usize,
to: &'v mut (dyn FnMut(usize) -> Value<Assigned<F>> + 'v),
) -> Result<(), Error> {
if len == 0 {
return Ok(());
}

let offset = self.plan.regions[*self.region_index]
.checked_add(offset)
.ok_or(Error::BoundsFailure)?;
self.plan
.cs
.assign_advice_batch_with_previous_denominator_squared(
annotation, column, offset, len, to,
)
}

fn assign_advice_from_constant<'v>(
&'v mut self,
annotation: &'v (dyn Fn() -> String + 'v),
Expand Down
24 changes: 24 additions & 0 deletions crates/halo2_proofs/src/circuit/layouter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,30 @@ pub trait RegionLayouter<F: Field>: fmt::Debug {
Ok(())
}

/// Assigns rational advice with an untrusted previous-batch equality hint.
fn assign_advice_batch_with_previous_denominator<'v>(
&'v mut self,
annotation: &'v (dyn Fn(usize) -> String + 'v),
column: Column<Advice>,
offset: usize,
len: usize,
to: &'v mut (dyn FnMut(usize) -> Value<Assigned<F>> + 'v),
) -> Result<(), Error> {
self.assign_advice_batch(annotation, column, offset, len, to)
}

/// Assigns rational advice with an untrusted previous-batch square hint.
fn assign_advice_batch_with_previous_denominator_squared<'v>(
&'v mut self,
annotation: &'v (dyn Fn(usize) -> String + 'v),
column: Column<Advice>,
offset: usize,
len: usize,
to: &'v mut (dyn FnMut(usize) -> Value<Assigned<F>> + 'v),
) -> Result<(), Error> {
self.assign_advice_batch(annotation, column, offset, len, to)
}

/// Assigns a constant value to the column `advice` at `offset` within this region.
///
/// The constant value will be assigned to a cell within one of the fixed columns
Expand Down
44 changes: 44 additions & 0 deletions crates/halo2_proofs/src/plonk/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,50 @@ pub trait Assignment<F: Field> {
Ok(())
}

/// Assigns rational advice whose denominators equal the corresponding
/// denominators in the immediately preceding batch.
///
/// Backends may derive the denominators from this untrusted relationship
/// hint. An incorrect hint can cause synthesis or constraint verification
/// to fail.
fn assign_advice_batch_with_previous_denominator<V, A, AR>(
&mut self,
annotation: A,
column: Column<Advice>,
row: usize,
len: usize,
to: V,
) -> Result<(), Error>
where
V: FnMut(usize) -> Value<Assigned<F>>,
A: Fn(usize) -> AR,
AR: Into<String>,
{
self.assign_advice_batch(annotation, column, row, len, to)
}

/// Assigns rational advice whose denominators are the squares of the
/// corresponding denominators in the immediately preceding batch.
///
/// Backends may derive the denominators from this untrusted relationship
/// hint. An incorrect hint can cause synthesis or constraint verification
/// to fail.
fn assign_advice_batch_with_previous_denominator_squared<V, A, AR>(
&mut self,
annotation: A,
column: Column<Advice>,
row: usize,
len: usize,
to: V,
) -> Result<(), Error>
where
V: FnMut(usize) -> Value<Assigned<F>>,
A: Fn(usize) -> AR,
AR: Into<String>,
{
self.assign_advice_batch(annotation, column, row, len, to)
}

/// Assign a fixed value
fn assign_fixed<V, VR, A, AR>(
&mut self,
Expand Down
Loading
Loading