Visibility fixes.

This commit is contained in:
therealyingtong 2022-01-28 23:38:22 +08:00
parent bb76d8c292
commit 7c7c281000
9 changed files with 80 additions and 26 deletions

View File

@ -130,7 +130,7 @@ impl<FixedPoints: super::FixedPoints<pallas::Affine>> Config<FixedPoints> {
fn running_sum_coords_gate(&self, meta: &mut ConstraintSystem<pallas::Base>) {
meta.create_gate("Running sum coordinates check", |meta| {
let q_mul_fixed_running_sum =
meta.query_selector(self.running_sum_config.q_range_check);
meta.query_selector(self.running_sum_config.q_range_check());
let z_cur = meta.query_advice(self.window, Rotation::cur());
let z_next = meta.query_advice(self.window, Rotation::next());

View File

@ -190,7 +190,7 @@ impl<Fixed: FixedPoints<pallas::Affine>> Config<Fixed> {
offset,
&(&scalar).into(),
base,
self.super_config.running_sum_config.q_range_check,
self.super_config.running_sum_config.q_range_check(),
)?;
Ok((scalar, acc, mul_b))

View File

@ -117,7 +117,7 @@ impl<Fixed: FixedPoints<pallas::Affine>> Config<Fixed> {
offset,
&(&scalar).into(),
base,
self.super_config.running_sum_config.q_range_check,
self.super_config.running_sum_config.q_range_check(),
)?;
Ok((scalar, acc, mul_b))

View File

@ -13,7 +13,7 @@ use crate::utilities::{
};
use std::iter;
pub(crate) mod chip;
pub mod chip;
/// SWU hash-to-curve personalization for the Merkle CRH generator
pub const MERKLE_CRH_PERSONALIZATION: &str = "z.cash:Orchard-MerkleCRH";
@ -58,12 +58,40 @@ pub struct MerklePath<
> where
MerkleChip: MerkleInstructions<C, PATH_LENGTH, K, MAX_WORDS> + Clone,
{
pub(crate) chip_1: MerkleChip,
pub(crate) chip_2: MerkleChip,
pub(crate) domain: MerkleChip::HashDomains,
pub(crate) leaf_pos: Option<u32>,
chip_1: MerkleChip,
chip_2: MerkleChip,
domain: MerkleChip::HashDomains,
leaf_pos: Option<u32>,
// The Merkle path is ordered from leaves to root.
pub(crate) path: Option<[C::Base; PATH_LENGTH]>,
path: Option<[C::Base; PATH_LENGTH]>,
}
impl<
C: CurveAffine,
MerkleChip,
const PATH_LENGTH: usize,
const K: usize,
const MAX_WORDS: usize,
> MerklePath<C, MerkleChip, PATH_LENGTH, K, MAX_WORDS>
where
MerkleChip: MerkleInstructions<C, PATH_LENGTH, K, MAX_WORDS> + Clone,
{
/// Constructs a [`MerklePath`].
pub fn construct(
chip_1: MerkleChip,
chip_2: MerkleChip,
domain: MerkleChip::HashDomains,
leaf_pos: Option<u32>,
path: Option<[C::Base; PATH_LENGTH]>,
) -> Self {
Self {
chip_1,
chip_2,
domain,
leaf_pos,
path,
}
}
}
#[allow(non_snake_case)]
@ -78,7 +106,7 @@ where
MerkleChip: MerkleInstructions<C, PATH_LENGTH, K, MAX_WORDS> + Clone,
{
/// Calculates the root of the tree containing the given leaf at this Merkle path.
pub(crate) fn calculate_root(
pub fn calculate_root(
&self,
mut layouter: impl Layouter<C::Base>,
leaf: MerkleChip::Var,
@ -253,7 +281,7 @@ pub mod tests {
let leaf = chip_1.load_private(
layouter.namespace(|| ""),
config.0.cond_swap_config.a,
config.0.cond_swap_config.a(),
self.leaf,
)?;

View File

@ -1,3 +1,5 @@
//! Chip implementing a Merkle hash using Sinsemilla as the hash function.
use halo2_proofs::{
circuit::{AssignedCell, Chip, Layouter},
plonk::{Advice, Column, ConstraintSystem, Error, Selector},
@ -25,6 +27,7 @@ use crate::{
use group::ff::PrimeField;
use std::array;
/// Configuration for the `MerkleChip` implementation.
#[derive(Clone, Debug)]
pub struct MerkleConfig<Hash, Commit, Fixed>
where
@ -38,6 +41,7 @@ where
pub(super) sinsemilla_config: SinsemillaConfig<Hash, Commit, Fixed>,
}
/// Chip implementing `MerkleInstructions`.
#[derive(Clone, Debug)]
pub struct MerkleChip<Hash, Commit, Fixed>
where
@ -72,6 +76,7 @@ where
F: FixedPoints<pallas::Affine>,
Commit: CommitDomains<pallas::Affine, F, Hash>,
{
/// Configures the [`MerkleChip`].
pub fn configure(
meta: &mut ConstraintSystem<pallas::Base>,
sinsemilla_config: SinsemillaConfig<Hash, Commit, F>,
@ -175,6 +180,7 @@ where
}
}
/// Constructs a [`MerkleChip`] given a [`MerkleConfig`].
pub fn construct(config: MerkleConfig<Hash, Commit, F>) -> Self {
MerkleChip { config }
}

View File

@ -8,9 +8,9 @@ use halo2_proofs::{
use pasta_curves::arithmetic::FieldExt;
use std::{array, ops::Range};
pub(crate) mod cond_swap;
pub(crate) mod decompose_running_sum;
pub(crate) mod lookup_range_check;
pub mod cond_swap;
pub mod decompose_running_sum;
pub mod lookup_range_check;
/// Trait for a variable in the circuit.
pub trait Var<F: FieldExt>: Clone + std::fmt::Debug + From<AssignedCell<F, F>> {

View File

@ -1,3 +1,5 @@
//! Gadget and chip for a conditional swap utility.
use super::{bool_check, ternary, UtilitiesInstructions};
use halo2_proofs::{
circuit::{AssignedCell, Chip, Layouter},
@ -7,6 +9,7 @@ use halo2_proofs::{
use pasta_curves::arithmetic::FieldExt;
use std::{array, marker::PhantomData};
/// Instructions for a conditional swap gadget.
pub trait CondSwapInstructions<F: FieldExt>: UtilitiesInstructions<F> {
#[allow(clippy::type_complexity)]
/// Given an input pair (a,b) and a `swap` boolean flag, returns
@ -42,14 +45,22 @@ impl<F: FieldExt> Chip<F> for CondSwapChip<F> {
}
}
/// Configuration for the [`CondSwapChip`].
#[derive(Clone, Debug)]
pub struct CondSwapConfig {
pub q_swap: Selector,
pub a: Column<Advice>,
pub b: Column<Advice>,
pub a_swapped: Column<Advice>,
pub b_swapped: Column<Advice>,
pub swap: Column<Advice>,
q_swap: Selector,
a: Column<Advice>,
b: Column<Advice>,
a_swapped: Column<Advice>,
b_swapped: Column<Advice>,
swap: Column<Advice>,
}
#[cfg(test)]
impl CondSwapConfig {
pub(crate) fn a(&self) -> Column<Advice> {
self.a
}
}
impl<F: FieldExt> UtilitiesInstructions<F> for CondSwapChip<F> {
@ -185,6 +196,7 @@ impl<F: FieldExt> CondSwapChip<F> {
config
}
/// Constructs a [`CondSwapChip`] given a [`CondSwapConfig`].
pub fn construct(config: CondSwapConfig) -> Self {
CondSwapChip {
config,

View File

@ -34,6 +34,7 @@ use pasta_curves::arithmetic::FieldExt;
use std::marker::PhantomData;
/// The running sum $[z_0, ..., z_W]$. If created in strict mode, $z_W = 0$.
#[derive(Debug)]
pub struct RunningSum<F: FieldExt + PrimeFieldBits>(Vec<AssignedCell<F, F>>);
impl<F: FieldExt + PrimeFieldBits> std::ops::Deref for RunningSum<F> {
type Target = Vec<AssignedCell<F, F>>;
@ -43,16 +44,22 @@ impl<F: FieldExt + PrimeFieldBits> std::ops::Deref for RunningSum<F> {
}
}
/// Configuration that provides methods for running sum decomposition.
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct RunningSumConfig<F: FieldExt + PrimeFieldBits, const WINDOW_NUM_BITS: usize> {
pub q_range_check: Selector,
pub z: Column<Advice>,
q_range_check: Selector,
z: Column<Advice>,
_marker: PhantomData<F>,
}
impl<F: FieldExt + PrimeFieldBits, const WINDOW_NUM_BITS: usize>
RunningSumConfig<F, WINDOW_NUM_BITS>
{
/// Returns the q_range_check selector of this [`RunningSumConfig`].
pub(crate) fn q_range_check(&self) -> Selector {
self.q_range_check
}
/// `perm` MUST include the advice column `z`.
///
/// # Panics

View File

@ -23,12 +23,13 @@ impl<F: FieldExt + PrimeFieldBits> std::ops::Deref for RunningSum<F> {
}
}
/// Configuration that provides methods for a lookup range check.
#[derive(Eq, PartialEq, Debug, Clone, Copy)]
pub struct LookupRangeCheckConfig<F: FieldExt + PrimeFieldBits, const K: usize> {
pub q_lookup: Selector,
pub q_running: Selector,
pub q_bitshift: Selector,
pub running_sum: Column<Advice>,
q_lookup: Selector,
q_running: Selector,
q_bitshift: Selector,
running_sum: Column<Advice>,
table_idx: TableColumn,
_marker: PhantomData<F>,
}