mirror of https://github.com/zcash/halo2.git
Replace `gadget::utilities::copy` with `AssignedCell::copy_advice`
Also replaces other copy-advice implementations that weren't using `copy`.
This commit is contained in:
parent
3079800f42
commit
65a89f099b
|
@ -50,7 +50,7 @@ use gadget::{
|
||||||
},
|
},
|
||||||
note_commit::NoteCommitConfig,
|
note_commit::NoteCommitConfig,
|
||||||
},
|
},
|
||||||
utilities::{copy, CellValue, UtilitiesInstructions},
|
utilities::{CellValue, UtilitiesInstructions},
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
@ -501,20 +501,8 @@ impl plonk::Circuit<pallas::Base> for Circuit {
|
||||||
|mut region| {
|
|mut region| {
|
||||||
config.q_add.enable(&mut region, 0)?;
|
config.q_add.enable(&mut region, 0)?;
|
||||||
|
|
||||||
copy(
|
hash_old.copy_advice(|| "copy hash_old", &mut region, config.advices[7], 0)?;
|
||||||
&mut region,
|
psi_old.copy_advice(|| "copy psi_old", &mut region, config.advices[8], 0)?;
|
||||||
|| "copy hash_old",
|
|
||||||
config.advices[7],
|
|
||||||
0,
|
|
||||||
&hash_old,
|
|
||||||
)?;
|
|
||||||
copy(
|
|
||||||
&mut region,
|
|
||||||
|| "copy psi_old",
|
|
||||||
config.advices[8],
|
|
||||||
0,
|
|
||||||
&psi_old,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
let scalar_val = hash_old
|
let scalar_val = hash_old
|
||||||
.value()
|
.value()
|
||||||
|
@ -691,19 +679,13 @@ impl plonk::Circuit<pallas::Base> for Circuit {
|
||||||
layouter.assign_region(
|
layouter.assign_region(
|
||||||
|| "v_old - v_new = magnitude * sign",
|
|| "v_old - v_new = magnitude * sign",
|
||||||
|mut region| {
|
|mut region| {
|
||||||
copy(&mut region, || "v_old", config.advices[0], 0, &v_old)?;
|
v_old.copy_advice(|| "v_old", &mut region, config.advices[0], 0)?;
|
||||||
copy(&mut region, || "v_new", config.advices[1], 0, &v_new)?;
|
v_new.copy_advice(|| "v_new", &mut region, config.advices[1], 0)?;
|
||||||
let (magnitude, sign) = v_net.clone();
|
let (magnitude, sign) = v_net.clone();
|
||||||
copy(
|
magnitude.copy_advice(|| "v_net magnitude", &mut region, config.advices[2], 0)?;
|
||||||
&mut region,
|
sign.copy_advice(|| "v_net sign", &mut region, config.advices[3], 0)?;
|
||||||
|| "v_net magnitude",
|
|
||||||
config.advices[2],
|
|
||||||
0,
|
|
||||||
&magnitude,
|
|
||||||
)?;
|
|
||||||
copy(&mut region, || "v_net sign", config.advices[3], 0, &sign)?;
|
|
||||||
|
|
||||||
copy(&mut region, || "anchor", config.advices[4], 0, &anchor)?;
|
anchor.copy_advice(|| "anchor", &mut region, config.advices[4], 0)?;
|
||||||
region.assign_advice_from_instance(
|
region.assign_advice_from_instance(
|
||||||
|| "pub input anchor",
|
|| "pub input anchor",
|
||||||
config.primary,
|
config.primary,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use super::EccInstructions;
|
use super::EccInstructions;
|
||||||
use crate::{
|
use crate::{
|
||||||
circuit::gadget::utilities::{
|
circuit::gadget::utilities::{
|
||||||
copy, lookup_range_check::LookupRangeCheckConfig, CellValue, UtilitiesInstructions,
|
lookup_range_check::LookupRangeCheckConfig, CellValue, UtilitiesInstructions,
|
||||||
},
|
},
|
||||||
constants::{self, NullifierK, OrchardFixedBasesFull, ValueCommitV},
|
constants::{self, NullifierK, OrchardFixedBasesFull, ValueCommitV},
|
||||||
primitives::sinsemilla,
|
primitives::sinsemilla,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::array;
|
use std::array;
|
||||||
|
|
||||||
use super::{copy, EccPoint};
|
use super::EccPoint;
|
||||||
use ff::{BatchInvert, Field};
|
use ff::{BatchInvert, Field};
|
||||||
use halo2::{
|
use halo2::{
|
||||||
circuit::Region,
|
circuit::Region,
|
||||||
|
@ -223,12 +223,12 @@ impl Config {
|
||||||
self.q_add.enable(region, offset)?;
|
self.q_add.enable(region, offset)?;
|
||||||
|
|
||||||
// Copy point `p` into `x_p`, `y_p` columns
|
// Copy point `p` into `x_p`, `y_p` columns
|
||||||
copy(region, || "x_p", self.x_p, offset, &p.x)?;
|
p.x.copy_advice(|| "x_p", region, self.x_p, offset)?;
|
||||||
copy(region, || "y_p", self.y_p, offset, &p.y)?;
|
p.y.copy_advice(|| "y_p", region, self.y_p, offset)?;
|
||||||
|
|
||||||
// Copy point `q` into `x_qr`, `y_qr` columns
|
// Copy point `q` into `x_qr`, `y_qr` columns
|
||||||
copy(region, || "x_q", self.x_qr, offset, &q.x)?;
|
q.x.copy_advice(|| "x_q", region, self.x_qr, offset)?;
|
||||||
copy(region, || "y_q", self.y_qr, offset, &q.y)?;
|
q.y.copy_advice(|| "y_q", region, self.y_qr, offset)?;
|
||||||
|
|
||||||
let (x_p, y_p) = (p.x.value(), p.y.value());
|
let (x_p, y_p) = (p.x.value(), p.y.value());
|
||||||
let (x_q, y_q) = (q.x.value(), q.y.value());
|
let (x_q, y_q) = (q.x.value(), q.y.value());
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::{array, collections::HashSet};
|
use std::{array, collections::HashSet};
|
||||||
|
|
||||||
use super::{copy, NonIdentityEccPoint};
|
use super::NonIdentityEccPoint;
|
||||||
use ff::Field;
|
use ff::Field;
|
||||||
use group::Curve;
|
use group::Curve;
|
||||||
use halo2::{
|
use halo2::{
|
||||||
|
@ -111,12 +111,12 @@ impl Config {
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
|
|
||||||
// Copy point `p` into `x_p`, `y_p` columns
|
// Copy point `p` into `x_p`, `y_p` columns
|
||||||
copy(region, || "x_p", self.x_p, offset, &p.x)?;
|
p.x.copy_advice(|| "x_p", region, self.x_p, offset)?;
|
||||||
copy(region, || "y_p", self.y_p, offset, &p.y)?;
|
p.y.copy_advice(|| "y_p", region, self.y_p, offset)?;
|
||||||
|
|
||||||
// Copy point `q` into `x_qr`, `y_qr` columns
|
// Copy point `q` into `x_qr`, `y_qr` columns
|
||||||
copy(region, || "x_q", self.x_qr, offset, &q.x)?;
|
q.x.copy_advice(|| "x_q", region, self.x_qr, offset)?;
|
||||||
copy(region, || "y_q", self.y_qr, offset, &q.y)?;
|
q.y.copy_advice(|| "y_q", region, self.y_qr, offset)?;
|
||||||
|
|
||||||
// Compute the sum `P + Q = R`
|
// Compute the sum `P + Q = R`
|
||||||
let r = {
|
let r = {
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
use super::{add, CellValue, EccPoint, NonIdentityEccPoint};
|
use super::{add, CellValue, EccPoint, NonIdentityEccPoint};
|
||||||
use crate::{
|
use crate::{
|
||||||
circuit::gadget::utilities::{
|
circuit::gadget::utilities::{bool_check, lookup_range_check::LookupRangeCheckConfig, ternary},
|
||||||
bool_check, copy, lookup_range_check::LookupRangeCheckConfig, ternary,
|
|
||||||
},
|
|
||||||
constants::T_Q,
|
constants::T_Q,
|
||||||
primitives::sinsemilla,
|
primitives::sinsemilla,
|
||||||
};
|
};
|
||||||
|
@ -342,20 +340,10 @@ impl Config {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Copy in `base_x`, `base_y` to use in the LSB gate
|
// Copy in `base_x`, `base_y` to use in the LSB gate
|
||||||
copy(
|
base.x()
|
||||||
region,
|
.copy_advice(|| "copy base_x", region, self.add_config.x_p, offset + 1)?;
|
||||||
|| "copy base_x",
|
base.y()
|
||||||
self.add_config.x_p,
|
.copy_advice(|| "copy base_y", region, self.add_config.y_p, offset + 1)?;
|
||||||
offset + 1,
|
|
||||||
&base.x(),
|
|
||||||
)?;
|
|
||||||
copy(
|
|
||||||
region,
|
|
||||||
|| "copy base_y",
|
|
||||||
self.add_config.y_p,
|
|
||||||
offset + 1,
|
|
||||||
&base.y(),
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// If `lsb` is 0, return `Acc + (-P)`. If `lsb` is 1, simply return `Acc + 0`.
|
// If `lsb` is 0, return `Acc + (-P)`. If `lsb` is 1, simply return `Acc + 0`.
|
||||||
let x = if let Some(lsb) = lsb {
|
let x = if let Some(lsb) = lsb {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use super::super::{add, copy, EccPoint};
|
use super::super::{add, EccPoint};
|
||||||
use super::{COMPLETE_RANGE, X, Y, Z};
|
use super::{COMPLETE_RANGE, X, Y, Z};
|
||||||
use crate::circuit::gadget::utilities::{bool_check, ternary};
|
use crate::circuit::gadget::utilities::{bool_check, ternary};
|
||||||
|
|
||||||
|
@ -110,12 +110,11 @@ impl Config {
|
||||||
|
|
||||||
// Copy running sum `z` from incomplete addition
|
// Copy running sum `z` from incomplete addition
|
||||||
let mut z = {
|
let mut z = {
|
||||||
let z = copy(
|
let z = z.copy_advice(
|
||||||
region,
|
|
||||||
|| "Copy `z` running sum from incomplete addition",
|
|| "Copy `z` running sum from incomplete addition",
|
||||||
|
region,
|
||||||
self.z_complete,
|
self.z_complete,
|
||||||
offset,
|
offset,
|
||||||
&z,
|
|
||||||
)?;
|
)?;
|
||||||
Z(z)
|
Z(z)
|
||||||
};
|
};
|
||||||
|
@ -152,12 +151,11 @@ impl Config {
|
||||||
|
|
||||||
// Assign `y_p` for complete addition.
|
// Assign `y_p` for complete addition.
|
||||||
let y_p = {
|
let y_p = {
|
||||||
let base_y = copy(
|
let base_y = base.y.copy_advice(
|
||||||
region,
|
|
||||||
|| "Copy `base.y`",
|
|| "Copy `base.y`",
|
||||||
|
region,
|
||||||
self.z_complete,
|
self.z_complete,
|
||||||
row + offset + 1,
|
row + offset + 1,
|
||||||
&base.y,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// If the bit is set, use `y`; if the bit is not set, use `-y`
|
// If the bit is set, use `y`; if the bit is not set, use `-y`
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use super::super::{copy, NonIdentityEccPoint};
|
use super::super::NonIdentityEccPoint;
|
||||||
use super::{X, Y, Z};
|
use super::{X, Y, Z};
|
||||||
use crate::circuit::gadget::utilities::bool_check;
|
use crate::circuit::gadget::utilities::bool_check;
|
||||||
use ff::Field;
|
use ff::Field;
|
||||||
|
@ -223,11 +223,15 @@ impl<const NUM_BITS: usize> Config<NUM_BITS> {
|
||||||
// Initialise double-and-add
|
// Initialise double-and-add
|
||||||
let (mut x_a, mut y_a, mut z) = {
|
let (mut x_a, mut y_a, mut z) = {
|
||||||
// Initialise the running `z` sum for the scalar bits.
|
// Initialise the running `z` sum for the scalar bits.
|
||||||
let z = copy(region, || "starting z", self.z, offset, &acc.2)?;
|
let z = acc.2.copy_advice(|| "starting z", region, self.z, offset)?;
|
||||||
|
|
||||||
// Initialise acc
|
// Initialise acc
|
||||||
let x_a = copy(region, || "starting x_a", self.x_a, offset + 1, &acc.0)?;
|
let x_a = acc
|
||||||
let y_a = copy(region, || "starting y_a", self.lambda1, offset, &acc.1)?;
|
.0
|
||||||
|
.copy_advice(|| "starting x_a", region, self.x_a, offset + 1)?;
|
||||||
|
let y_a = acc
|
||||||
|
.1
|
||||||
|
.copy_advice(|| "starting y_a", region, self.lambda1, offset)?;
|
||||||
|
|
||||||
(x_a, y_a.value().cloned(), z)
|
(x_a, y_a.value().cloned(), z)
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use super::super::{copy, CellValue};
|
use super::super::CellValue;
|
||||||
use super::Z;
|
use super::Z;
|
||||||
use crate::{
|
use crate::{
|
||||||
circuit::gadget::utilities::lookup_range_check::LookupRangeCheckConfig, constants::T_Q,
|
circuit::gadget::utilities::lookup_range_check::LookupRangeCheckConfig, constants::T_Q,
|
||||||
|
@ -140,16 +140,10 @@ impl Config {
|
||||||
self.q_mul_overflow.enable(&mut region, offset + 1)?;
|
self.q_mul_overflow.enable(&mut region, offset + 1)?;
|
||||||
|
|
||||||
// Copy `z_0`
|
// Copy `z_0`
|
||||||
copy(&mut region, || "copy z_0", self.advices[0], offset, &*zs[0])?;
|
zs[0].copy_advice(|| "copy z_0", &mut region, self.advices[0], offset)?;
|
||||||
|
|
||||||
// Copy `z_130`
|
// Copy `z_130`
|
||||||
copy(
|
zs[130].copy_advice(|| "copy z_130", &mut region, self.advices[0], offset + 1)?;
|
||||||
&mut region,
|
|
||||||
|| "copy z_130",
|
|
||||||
self.advices[0],
|
|
||||||
offset + 1,
|
|
||||||
&*zs[130],
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// Witness η = inv0(z_130), where inv0(x) = 0 if x = 0, 1/x otherwise
|
// Witness η = inv0(z_130), where inv0(x) = 0 if x = 0, 1/x otherwise
|
||||||
{
|
{
|
||||||
|
@ -169,34 +163,26 @@ impl Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy `k_254` = z_254
|
// Copy `k_254` = z_254
|
||||||
copy(
|
zs[254].copy_advice(|| "copy k_254", &mut region, self.advices[1], offset)?;
|
||||||
&mut region,
|
|
||||||
|| "copy k_254",
|
|
||||||
self.advices[1],
|
|
||||||
offset,
|
|
||||||
&*zs[254],
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// Copy original alpha
|
// Copy original alpha
|
||||||
copy(
|
alpha.copy_advice(
|
||||||
&mut region,
|
|
||||||
|| "copy original alpha",
|
|| "copy original alpha",
|
||||||
|
&mut region,
|
||||||
self.advices[1],
|
self.advices[1],
|
||||||
offset + 1,
|
offset + 1,
|
||||||
&alpha,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Copy weighted sum of the decomposition of s = alpha + k_254 ⋅ 2^130.
|
// Copy weighted sum of the decomposition of s = alpha + k_254 ⋅ 2^130.
|
||||||
copy(
|
s_minus_lo_130.copy_advice(
|
||||||
&mut region,
|
|
||||||
|| "copy s_minus_lo_130",
|
|| "copy s_minus_lo_130",
|
||||||
|
&mut region,
|
||||||
self.advices[1],
|
self.advices[1],
|
||||||
offset + 2,
|
offset + 2,
|
||||||
&s_minus_lo_130,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Copy witnessed s to check that it was properly derived from alpha and k_254.
|
// Copy witnessed s to check that it was properly derived from alpha and k_254.
|
||||||
copy(&mut region, || "copy s", self.advices[2], offset + 1, &s)?;
|
s.copy_advice(|| "copy s", &mut region, self.advices[2], offset + 1)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
|
|
|
@ -3,7 +3,7 @@ use super::H_BASE;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
circuit::gadget::utilities::{
|
circuit::gadget::utilities::{
|
||||||
bitrange_subset, copy, lookup_range_check::LookupRangeCheckConfig, range_check, CellValue,
|
bitrange_subset, lookup_range_check::LookupRangeCheckConfig, range_check, CellValue,
|
||||||
},
|
},
|
||||||
constants::{self, T_P},
|
constants::{self, T_P},
|
||||||
primitives::sinsemilla,
|
primitives::sinsemilla,
|
||||||
|
@ -290,21 +290,14 @@ impl Config {
|
||||||
let offset = 0;
|
let offset = 0;
|
||||||
|
|
||||||
// Copy α
|
// Copy α
|
||||||
copy(
|
alpha.copy_advice(|| "Copy α", &mut region, self.canon_advices[0], offset)?;
|
||||||
&mut region,
|
|
||||||
|| "Copy α",
|
|
||||||
self.canon_advices[0],
|
|
||||||
offset,
|
|
||||||
&alpha,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// z_84_alpha = the top three bits of alpha.
|
// z_84_alpha = the top three bits of alpha.
|
||||||
copy(
|
z_84_alpha.copy_advice(
|
||||||
&mut region,
|
|
||||||
|| "Copy z_84_alpha",
|
|| "Copy z_84_alpha",
|
||||||
|
&mut region,
|
||||||
self.canon_advices[2],
|
self.canon_advices[2],
|
||||||
offset,
|
offset,
|
||||||
&z_84_alpha,
|
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,12 +306,11 @@ impl Config {
|
||||||
let offset = 1;
|
let offset = 1;
|
||||||
// Copy alpha_0_prime = alpha_0 + 2^130 - t_p.
|
// Copy alpha_0_prime = alpha_0 + 2^130 - t_p.
|
||||||
// We constrain this in the custom gate to be derived correctly.
|
// We constrain this in the custom gate to be derived correctly.
|
||||||
copy(
|
alpha_0_prime.copy_advice(
|
||||||
&mut region,
|
|
||||||
|| "Copy α_0 + 2^130 - t_p",
|
|| "Copy α_0 + 2^130 - t_p",
|
||||||
|
&mut region,
|
||||||
self.canon_advices[0],
|
self.canon_advices[0],
|
||||||
offset,
|
offset,
|
||||||
&alpha_0_prime,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Decompose α into three pieces,
|
// Decompose α into three pieces,
|
||||||
|
@ -347,30 +339,27 @@ impl Config {
|
||||||
{
|
{
|
||||||
let offset = 2;
|
let offset = 2;
|
||||||
// Copy z_13_alpha_0_prime
|
// Copy z_13_alpha_0_prime
|
||||||
copy(
|
z_13_alpha_0_prime.copy_advice(
|
||||||
&mut region,
|
|
||||||
|| "Copy z_13_alpha_0_prime",
|
|| "Copy z_13_alpha_0_prime",
|
||||||
|
&mut region,
|
||||||
self.canon_advices[0],
|
self.canon_advices[0],
|
||||||
offset,
|
offset,
|
||||||
&z_13_alpha_0_prime,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Copy z_44_alpha
|
// Copy z_44_alpha
|
||||||
copy(
|
z_44_alpha.copy_advice(
|
||||||
&mut region,
|
|
||||||
|| "Copy z_44_alpha",
|
|| "Copy z_44_alpha",
|
||||||
|
&mut region,
|
||||||
self.canon_advices[1],
|
self.canon_advices[1],
|
||||||
offset,
|
offset,
|
||||||
&z_44_alpha,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Copy z_43_alpha
|
// Copy z_43_alpha
|
||||||
copy(
|
z_43_alpha.copy_advice(
|
||||||
&mut region,
|
|
||||||
|| "Copy z_43_alpha",
|
|| "Copy z_43_alpha",
|
||||||
|
&mut region,
|
||||||
self.canon_advices[2],
|
self.canon_advices[2],
|
||||||
offset,
|
offset,
|
||||||
&z_43_alpha,
|
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ use std::{array, convert::TryInto};
|
||||||
|
|
||||||
use super::super::{EccPoint, EccScalarFixedShort};
|
use super::super::{EccPoint, EccScalarFixedShort};
|
||||||
use crate::{
|
use crate::{
|
||||||
circuit::gadget::utilities::{bool_check, copy, CellValue},
|
circuit::gadget::utilities::{bool_check, CellValue},
|
||||||
constants::{ValueCommitV, L_VALUE, NUM_WINDOWS_SHORT},
|
constants::{ValueCommitV, L_VALUE, NUM_WINDOWS_SHORT},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -138,25 +138,18 @@ impl Config {
|
||||||
let offset = offset + 1;
|
let offset = offset + 1;
|
||||||
|
|
||||||
// Copy sign to `window` column
|
// Copy sign to `window` column
|
||||||
let sign = copy(
|
let sign = scalar.sign.copy_advice(
|
||||||
&mut region,
|
|
||||||
|| "sign",
|
|| "sign",
|
||||||
|
&mut region,
|
||||||
self.super_config.window,
|
self.super_config.window,
|
||||||
offset,
|
offset,
|
||||||
&scalar.sign,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Copy last window to `u` column.
|
// Copy last window to `u` column.
|
||||||
// (Although the last window is not a `u` value; we are copying it into the `u`
|
// (Although the last window is not a `u` value; we are copying it into the `u`
|
||||||
// column because there is an available cell there.)
|
// column because there is an available cell there.)
|
||||||
let z_21 = scalar.running_sum[21].clone();
|
let z_21 = scalar.running_sum[21].clone();
|
||||||
copy(
|
z_21.copy_advice(|| "last_window", &mut region, self.super_config.u, offset)?;
|
||||||
&mut region,
|
|
||||||
|| "last_window",
|
|
||||||
self.super_config.u,
|
|
||||||
offset,
|
|
||||||
&z_21,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// Conditionally negate `y`-coordinate
|
// Conditionally negate `y`-coordinate
|
||||||
let y_val = if let Some(sign) = sign.value() {
|
let y_val = if let Some(sign) = sign.value() {
|
||||||
|
|
|
@ -320,15 +320,15 @@ impl<F: FieldExt, S: Spec<F, WIDTH, RATE>, const WIDTH: usize, const RATE: usize
|
||||||
|
|
||||||
// Load the initial state into this region.
|
// Load the initial state into this region.
|
||||||
let load_state_word = |i: usize| {
|
let load_state_word = |i: usize| {
|
||||||
let value = initial_state[i].0.value().cloned();
|
initial_state[i]
|
||||||
let var = region.assign_advice(
|
.0
|
||||||
|| format!("load state_{}", i),
|
.copy_advice(
|
||||||
config.state[i],
|
|| format!("load state_{}", i),
|
||||||
0,
|
&mut region,
|
||||||
|| value.ok_or(Error::Synthesis),
|
config.state[i],
|
||||||
)?;
|
0,
|
||||||
region.constrain_equal(initial_state[i].0.cell(), var.cell())?;
|
)
|
||||||
Ok(StateWord(var))
|
.map(StateWord)
|
||||||
};
|
};
|
||||||
let initial_state: Result<Vec<_>, Error> =
|
let initial_state: Result<Vec<_>, Error> =
|
||||||
(0..WIDTH).map(load_state_word).collect();
|
(0..WIDTH).map(load_state_word).collect();
|
||||||
|
@ -338,28 +338,24 @@ impl<F: FieldExt, S: Spec<F, WIDTH, RATE>, const WIDTH: usize, const RATE: usize
|
||||||
|
|
||||||
// Load the input and padding into this region.
|
// Load the input and padding into this region.
|
||||||
let load_input_word = |i: usize| {
|
let load_input_word = |i: usize| {
|
||||||
let (constraint_var, value) = match (input[i].clone(), padding_values[i]) {
|
let constraint_var = match (input[i].clone(), padding_values[i]) {
|
||||||
(Some(word), None) => (word.0.cell(), word.0.value().cloned()),
|
(Some(word), None) => word.0,
|
||||||
(None, Some(padding_value)) => {
|
(None, Some(padding_value)) => region.assign_fixed(
|
||||||
let padding_var = region.assign_fixed(
|
|| format!("load pad_{}", i),
|
||||||
|| format!("load pad_{}", i),
|
config.rc_b[i],
|
||||||
config.rc_b[i],
|
1,
|
||||||
1,
|
|| Ok(padding_value),
|
||||||
|| Ok(padding_value),
|
)?,
|
||||||
)?;
|
|
||||||
(padding_var.cell(), Some(padding_value))
|
|
||||||
}
|
|
||||||
_ => panic!("Input and padding don't match"),
|
_ => panic!("Input and padding don't match"),
|
||||||
};
|
};
|
||||||
let var = region.assign_advice(
|
constraint_var
|
||||||
|| format!("load input_{}", i),
|
.copy_advice(
|
||||||
config.state[i],
|
|| format!("load input_{}", i),
|
||||||
1,
|
&mut region,
|
||||||
|| value.ok_or(Error::Synthesis),
|
config.state[i],
|
||||||
)?;
|
1,
|
||||||
region.constrain_equal(constraint_var, var.cell())?;
|
)
|
||||||
|
.map(StateWord)
|
||||||
Ok(StateWord(var))
|
|
||||||
};
|
};
|
||||||
let input: Result<Vec<_>, Error> = (0..RATE).map(load_input_word).collect();
|
let input: Result<Vec<_>, Error> = (0..RATE).map(load_input_word).collect();
|
||||||
let input = input?;
|
let input = input?;
|
||||||
|
@ -538,15 +534,10 @@ impl<F: FieldExt, const WIDTH: usize> Pow5State<F, WIDTH> {
|
||||||
initial_state: &State<StateWord<F>, WIDTH>,
|
initial_state: &State<StateWord<F>, WIDTH>,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let load_state_word = |i: usize| {
|
let load_state_word = |i: usize| {
|
||||||
let value = initial_state[i].0.value().cloned();
|
initial_state[i]
|
||||||
let var = region.assign_advice(
|
.0
|
||||||
|| format!("load state_{}", i),
|
.copy_advice(|| format!("load state_{}", i), region, config.state[i], 0)
|
||||||
config.state[i],
|
.map(StateWord)
|
||||||
0,
|
|
||||||
|| value.ok_or(Error::Synthesis),
|
|
||||||
)?;
|
|
||||||
region.constrain_equal(initial_state[i].0.cell(), var.cell())?;
|
|
||||||
Ok(StateWord(var))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let state: Result<Vec<_>, _> = (0..WIDTH).map(load_state_word).collect();
|
let state: Result<Vec<_>, _> = (0..WIDTH).map(load_state_word).collect();
|
||||||
|
|
|
@ -261,14 +261,13 @@ impl SinsemillaChip {
|
||||||
let mut zs = Vec::with_capacity(piece.num_words() + 1);
|
let mut zs = Vec::with_capacity(piece.num_words() + 1);
|
||||||
|
|
||||||
// Copy message and initialize running sum `z` to decompose message in-circuit
|
// Copy message and initialize running sum `z` to decompose message in-circuit
|
||||||
let cell = region.assign_advice(
|
let initial_z = piece.cell_value().copy_advice(
|
||||||
|| "z_0 (copy of message piece)",
|
|| "z_0 (copy of message piece)",
|
||||||
|
region,
|
||||||
config.bits,
|
config.bits,
|
||||||
offset,
|
offset,
|
||||||
|| piece.field_elem().ok_or(Error::Synthesis),
|
|
||||||
)?;
|
)?;
|
||||||
region.constrain_equal(piece.cell(), cell.cell())?;
|
zs.push(initial_z);
|
||||||
zs.push(cell);
|
|
||||||
|
|
||||||
// Assign cumulative sum such that for 0 <= i < n,
|
// Assign cumulative sum such that for 0 <= i < n,
|
||||||
// z_i = 2^K * z_{i + 1} + m_{i + 1}
|
// z_i = 2^K * z_{i + 1} + m_{i + 1}
|
||||||
|
|
|
@ -8,7 +8,7 @@ use pasta_curves::{arithmetic::FieldExt, pallas};
|
||||||
use crate::{
|
use crate::{
|
||||||
circuit::gadget::{
|
circuit::gadget::{
|
||||||
ecc::{chip::EccChip, X},
|
ecc::{chip::EccChip, X},
|
||||||
utilities::{bitrange_subset, bool_check, copy, CellValue},
|
utilities::{bitrange_subset, bool_check, CellValue},
|
||||||
},
|
},
|
||||||
constants::T_P,
|
constants::T_P,
|
||||||
};
|
};
|
||||||
|
@ -474,28 +474,24 @@ impl CommitIvkConfig {
|
||||||
{
|
{
|
||||||
let offset = 0;
|
let offset = 0;
|
||||||
// Copy in `ak`
|
// Copy in `ak`
|
||||||
copy(
|
gate_cells
|
||||||
&mut region,
|
.ak
|
||||||
|| "ak",
|
.copy_advice(|| "ak", &mut region, self.advices[0], offset)?;
|
||||||
self.advices[0],
|
|
||||||
offset,
|
|
||||||
&gate_cells.ak,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// Copy in `a`
|
// Copy in `a`
|
||||||
copy(&mut region, || "a", self.advices[1], offset, &gate_cells.a)?;
|
gate_cells
|
||||||
|
.a
|
||||||
|
.copy_advice(|| "a", &mut region, self.advices[1], offset)?;
|
||||||
|
|
||||||
// Copy in `b`
|
// Copy in `b`
|
||||||
copy(&mut region, || "b", self.advices[2], offset, &gate_cells.b)?;
|
gate_cells
|
||||||
|
.b
|
||||||
|
.copy_advice(|| "b", &mut region, self.advices[2], offset)?;
|
||||||
|
|
||||||
// Copy in `b_0`
|
// Copy in `b_0`
|
||||||
copy(
|
gate_cells
|
||||||
&mut region,
|
.b_0
|
||||||
|| "b_0",
|
.copy_advice(|| "b_0", &mut region, self.advices[3], offset)?;
|
||||||
self.advices[3],
|
|
||||||
offset,
|
|
||||||
&gate_cells.b_0,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// Witness `b_1`
|
// Witness `b_1`
|
||||||
region.assign_advice(
|
region.assign_advice(
|
||||||
|
@ -506,39 +502,32 @@ impl CommitIvkConfig {
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Copy in `b_2`
|
// Copy in `b_2`
|
||||||
copy(
|
gate_cells
|
||||||
&mut region,
|
.b_2
|
||||||
|| "b_2",
|
.copy_advice(|| "b_2", &mut region, self.advices[5], offset)?;
|
||||||
self.advices[5],
|
|
||||||
offset,
|
|
||||||
&gate_cells.b_2,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// Copy in z13_a
|
// Copy in z13_a
|
||||||
copy(
|
gate_cells.z13_a.copy_advice(
|
||||||
&mut region,
|
|
||||||
|| "z13_a",
|
|| "z13_a",
|
||||||
|
&mut region,
|
||||||
self.advices[6],
|
self.advices[6],
|
||||||
offset,
|
offset,
|
||||||
&gate_cells.z13_a,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Copy in a_prime
|
// Copy in a_prime
|
||||||
copy(
|
gate_cells.a_prime.copy_advice(
|
||||||
&mut region,
|
|
||||||
|| "a_prime",
|
|| "a_prime",
|
||||||
|
&mut region,
|
||||||
self.advices[7],
|
self.advices[7],
|
||||||
offset,
|
offset,
|
||||||
&gate_cells.a_prime,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Copy in z13_a_prime
|
// Copy in z13_a_prime
|
||||||
copy(
|
gate_cells.z13_a_prime.copy_advice(
|
||||||
&mut region,
|
|
||||||
|| "z13_a_prime",
|
|| "z13_a_prime",
|
||||||
|
&mut region,
|
||||||
self.advices[8],
|
self.advices[8],
|
||||||
offset,
|
offset,
|
||||||
&gate_cells.z13_a_prime,
|
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -547,28 +536,24 @@ impl CommitIvkConfig {
|
||||||
let offset = 1;
|
let offset = 1;
|
||||||
|
|
||||||
// Copy in `nk`
|
// Copy in `nk`
|
||||||
copy(
|
gate_cells
|
||||||
&mut region,
|
.nk
|
||||||
|| "nk",
|
.copy_advice(|| "nk", &mut region, self.advices[0], offset)?;
|
||||||
self.advices[0],
|
|
||||||
offset,
|
|
||||||
&gate_cells.nk,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// Copy in `c`
|
// Copy in `c`
|
||||||
copy(&mut region, || "c", self.advices[1], offset, &gate_cells.c)?;
|
gate_cells
|
||||||
|
.c
|
||||||
|
.copy_advice(|| "c", &mut region, self.advices[1], offset)?;
|
||||||
|
|
||||||
// Copy in `d`
|
// Copy in `d`
|
||||||
copy(&mut region, || "d", self.advices[2], offset, &gate_cells.d)?;
|
gate_cells
|
||||||
|
.d
|
||||||
|
.copy_advice(|| "d", &mut region, self.advices[2], offset)?;
|
||||||
|
|
||||||
// Copy in `d_0`
|
// Copy in `d_0`
|
||||||
copy(
|
gate_cells
|
||||||
&mut region,
|
.d_0
|
||||||
|| "d_0",
|
.copy_advice(|| "d_0", &mut region, self.advices[3], offset)?;
|
||||||
self.advices[3],
|
|
||||||
offset,
|
|
||||||
&gate_cells.d_0,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// Witness `d_1`
|
// Witness `d_1`
|
||||||
region.assign_advice(
|
region.assign_advice(
|
||||||
|
@ -579,30 +564,27 @@ impl CommitIvkConfig {
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Copy in z13_c
|
// Copy in z13_c
|
||||||
copy(
|
gate_cells.z13_c.copy_advice(
|
||||||
&mut region,
|
|
||||||
|| "z13_c",
|
|| "z13_c",
|
||||||
|
&mut region,
|
||||||
self.advices[6],
|
self.advices[6],
|
||||||
offset,
|
offset,
|
||||||
&gate_cells.z13_c,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Copy in b2_c_prime
|
// Copy in b2_c_prime
|
||||||
copy(
|
gate_cells.b2_c_prime.copy_advice(
|
||||||
&mut region,
|
|
||||||
|| "b2_c_prime",
|
|| "b2_c_prime",
|
||||||
|
&mut region,
|
||||||
self.advices[7],
|
self.advices[7],
|
||||||
offset,
|
offset,
|
||||||
&gate_cells.b2_c_prime,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Copy in z14_b2_c_prime
|
// Copy in z14_b2_c_prime
|
||||||
copy(
|
gate_cells.z14_b2_c_prime.copy_advice(
|
||||||
&mut region,
|
|
||||||
|| "z14_b2_c_prime",
|
|| "z14_b2_c_prime",
|
||||||
|
&mut region,
|
||||||
self.advices[8],
|
self.advices[8],
|
||||||
offset,
|
offset,
|
||||||
&gate_cells.z14_b2_c_prime,
|
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ use crate::{
|
||||||
circuit::gadget::utilities::{
|
circuit::gadget::utilities::{
|
||||||
bitrange_subset,
|
bitrange_subset,
|
||||||
cond_swap::{CondSwapChip, CondSwapConfig, CondSwapInstructions},
|
cond_swap::{CondSwapChip, CondSwapConfig, CondSwapInstructions},
|
||||||
copy, CellValue, UtilitiesInstructions,
|
CellValue, UtilitiesInstructions,
|
||||||
},
|
},
|
||||||
constants::{L_ORCHARD_BASE, MERKLE_DEPTH_ORCHARD},
|
constants::{L_ORCHARD_BASE, MERKLE_DEPTH_ORCHARD},
|
||||||
primitives::sinsemilla,
|
primitives::sinsemilla,
|
||||||
|
@ -287,43 +287,28 @@ impl MerkleInstructions<pallas::Affine, MERKLE_DEPTH_ORCHARD, { sinsemilla::K },
|
||||||
|
|
||||||
// Offset 0
|
// Offset 0
|
||||||
// Copy and assign `a` at the correct position.
|
// Copy and assign `a` at the correct position.
|
||||||
copy(
|
a.cell_value()
|
||||||
&mut region,
|
.copy_advice(|| "copy a", &mut region, config.advices[0], 0)?;
|
||||||
|| "copy a",
|
|
||||||
config.advices[0],
|
|
||||||
0,
|
|
||||||
&a.cell_value(),
|
|
||||||
)?;
|
|
||||||
// Copy and assign `b` at the correct position.
|
// Copy and assign `b` at the correct position.
|
||||||
copy(
|
b.cell_value()
|
||||||
&mut region,
|
.copy_advice(|| "copy b", &mut region, config.advices[1], 0)?;
|
||||||
|| "copy b",
|
|
||||||
config.advices[1],
|
|
||||||
0,
|
|
||||||
&b.cell_value(),
|
|
||||||
)?;
|
|
||||||
// Copy and assign `c` at the correct position.
|
// Copy and assign `c` at the correct position.
|
||||||
copy(
|
c.cell_value()
|
||||||
&mut region,
|
.copy_advice(|| "copy c", &mut region, config.advices[2], 0)?;
|
||||||
|| "copy c",
|
|
||||||
config.advices[2],
|
|
||||||
0,
|
|
||||||
&c.cell_value(),
|
|
||||||
)?;
|
|
||||||
// Copy and assign the left node at the correct position.
|
// Copy and assign the left node at the correct position.
|
||||||
copy(&mut region, || "left", config.advices[3], 0, &left)?;
|
left.copy_advice(|| "left", &mut region, config.advices[3], 0)?;
|
||||||
// Copy and assign the right node at the correct position.
|
// Copy and assign the right node at the correct position.
|
||||||
copy(&mut region, || "right", config.advices[4], 0, &right)?;
|
right.copy_advice(|| "right", &mut region, config.advices[4], 0)?;
|
||||||
|
|
||||||
// Offset 1
|
// Offset 1
|
||||||
// Copy and assign z_1 of SinsemillaHash(a) = a_1
|
// Copy and assign z_1 of SinsemillaHash(a) = a_1
|
||||||
copy(&mut region, || "z1_a", config.advices[0], 1, &z1_a)?;
|
z1_a.copy_advice(|| "z1_a", &mut region, config.advices[0], 1)?;
|
||||||
// Copy and assign z_1 of SinsemillaHash(b) = b_1
|
// Copy and assign z_1 of SinsemillaHash(b) = b_1
|
||||||
copy(&mut region, || "z1_b", config.advices[1], 1, &z1_b)?;
|
z1_b.copy_advice(|| "z1_b", &mut region, config.advices[1], 1)?;
|
||||||
// Copy `b_1`, which has been constrained to be a 5-bit value
|
// Copy `b_1`, which has been constrained to be a 5-bit value
|
||||||
copy(&mut region, || "b_1", config.advices[2], 1, &b_1)?;
|
b_1.copy_advice(|| "b_1", &mut region, config.advices[2], 1)?;
|
||||||
// Copy `b_2`, which has been constrained to be a 5-bit value
|
// Copy `b_2`, which has been constrained to be a 5-bit value
|
||||||
copy(&mut region, || "b_2", config.advices[3], 1, &b_2)?;
|
b_2.copy_advice(|| "b_2", &mut region, config.advices[3], 1)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
|
|
|
@ -11,7 +11,7 @@ use crate::{
|
||||||
chip::{EccChip, NonIdentityEccPoint},
|
chip::{EccChip, NonIdentityEccPoint},
|
||||||
Point,
|
Point,
|
||||||
},
|
},
|
||||||
utilities::{bitrange_subset, bool_check, copy, CellValue},
|
utilities::{bitrange_subset, bool_check, CellValue},
|
||||||
},
|
},
|
||||||
constants::T_P,
|
constants::T_P,
|
||||||
};
|
};
|
||||||
|
@ -1041,7 +1041,7 @@ impl NoteCommitConfig {
|
||||||
let offset = 0;
|
let offset = 0;
|
||||||
|
|
||||||
// Copy y.
|
// Copy y.
|
||||||
copy(&mut region, || "copy y", self.advices[5], offset, &y)?;
|
y.copy_advice(|| "copy y", &mut region, self.advices[5], offset)?;
|
||||||
// Witness LSB.
|
// Witness LSB.
|
||||||
let lsb = region.assign_advice(
|
let lsb = region.assign_advice(
|
||||||
|| "witness LSB",
|
|| "witness LSB",
|
||||||
|
@ -1050,9 +1050,9 @@ impl NoteCommitConfig {
|
||||||
|| lsb.ok_or(Error::Synthesis),
|
|| lsb.ok_or(Error::Synthesis),
|
||||||
)?;
|
)?;
|
||||||
// Witness k_0.
|
// Witness k_0.
|
||||||
copy(&mut region, || "copy k_0", self.advices[7], offset, &k_0)?;
|
k_0.copy_advice(|| "copy k_0", &mut region, self.advices[7], offset)?;
|
||||||
// Copy k_2.
|
// Copy k_2.
|
||||||
copy(&mut region, || "copy k_2", self.advices[8], offset, &k_2)?;
|
k_2.copy_advice(|| "copy k_2", &mut region, self.advices[8], offset)?;
|
||||||
// Witness k_3.
|
// Witness k_3.
|
||||||
region.assign_advice(
|
region.assign_advice(
|
||||||
|| "witness k_3",
|
|| "witness k_3",
|
||||||
|
@ -1069,32 +1069,19 @@ impl NoteCommitConfig {
|
||||||
let offset = 1;
|
let offset = 1;
|
||||||
|
|
||||||
// Copy j.
|
// Copy j.
|
||||||
copy(&mut region, || "copy j", self.advices[5], offset, &j)?;
|
j.copy_advice(|| "copy j", &mut region, self.advices[5], offset)?;
|
||||||
// Copy z1_j.
|
// Copy z1_j.
|
||||||
copy(&mut region, || "copy z1_j", self.advices[6], offset, &z1_j)?;
|
z1_j.copy_advice(|| "copy z1_j", &mut region, self.advices[6], offset)?;
|
||||||
// Copy z13_j.
|
// Copy z13_j.
|
||||||
copy(
|
z13_j.copy_advice(|| "copy z13_j", &mut region, self.advices[7], offset)?;
|
||||||
&mut region,
|
|
||||||
|| "copy z13_j",
|
|
||||||
self.advices[7],
|
|
||||||
offset,
|
|
||||||
&z13_j,
|
|
||||||
)?;
|
|
||||||
// Copy j_prime.
|
// Copy j_prime.
|
||||||
copy(
|
j_prime.copy_advice(|| "copy j_prime", &mut region, self.advices[8], offset)?;
|
||||||
&mut region,
|
|
||||||
|| "copy j_prime",
|
|
||||||
self.advices[8],
|
|
||||||
offset,
|
|
||||||
&j_prime,
|
|
||||||
)?;
|
|
||||||
// Copy z13_j_prime.
|
// Copy z13_j_prime.
|
||||||
copy(
|
z13_j_prime.copy_advice(
|
||||||
&mut region,
|
|
||||||
|| "copy z13_j_prime",
|
|| "copy z13_j_prime",
|
||||||
|
&mut region,
|
||||||
self.advices[9],
|
self.advices[9],
|
||||||
offset,
|
offset,
|
||||||
&z13_j_prime,
|
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1123,8 +1110,10 @@ impl NoteCommitConfig {
|
||||||
|mut region| {
|
|mut region| {
|
||||||
self.q_notecommit_b.enable(&mut region, 0)?;
|
self.q_notecommit_b.enable(&mut region, 0)?;
|
||||||
|
|
||||||
copy(&mut region, || "b", col_l, 0, &gate_cells.b)?;
|
gate_cells.b.copy_advice(|| "b", &mut region, col_l, 0)?;
|
||||||
copy(&mut region, || "b_0", col_m, 0, &gate_cells.b_0)?;
|
gate_cells
|
||||||
|
.b_0
|
||||||
|
.copy_advice(|| "b_0", &mut region, col_m, 0)?;
|
||||||
let b_1 = region.assign_advice(
|
let b_1 = region.assign_advice(
|
||||||
|| "b_1",
|
|| "b_1",
|
||||||
col_r,
|
col_r,
|
||||||
|
@ -1132,8 +1121,12 @@ impl NoteCommitConfig {
|
||||||
|| gate_cells.b_1.ok_or(Error::Synthesis),
|
|| gate_cells.b_1.ok_or(Error::Synthesis),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
copy(&mut region, || "b_2", col_m, 1, &gate_cells.b_2)?;
|
gate_cells
|
||||||
copy(&mut region, || "b_3", col_r, 1, &gate_cells.b_3)?;
|
.b_2
|
||||||
|
.copy_advice(|| "b_2", &mut region, col_m, 1)?;
|
||||||
|
gate_cells
|
||||||
|
.b_3
|
||||||
|
.copy_advice(|| "b_3", &mut region, col_r, 1)?;
|
||||||
|
|
||||||
Ok(b_1)
|
Ok(b_1)
|
||||||
},
|
},
|
||||||
|
@ -1148,17 +1141,23 @@ impl NoteCommitConfig {
|
||||||
|mut region| {
|
|mut region| {
|
||||||
self.q_notecommit_d.enable(&mut region, 0)?;
|
self.q_notecommit_d.enable(&mut region, 0)?;
|
||||||
|
|
||||||
copy(&mut region, || "d", col_l, 0, &gate_cells.d)?;
|
gate_cells.d.copy_advice(|| "d", &mut region, col_l, 0)?;
|
||||||
let d_0 = region.assign_advice(
|
let d_0 = region.assign_advice(
|
||||||
|| "d_0",
|
|| "d_0",
|
||||||
col_m,
|
col_m,
|
||||||
0,
|
0,
|
||||||
|| gate_cells.d_0.ok_or(Error::Synthesis),
|
|| gate_cells.d_0.ok_or(Error::Synthesis),
|
||||||
)?;
|
)?;
|
||||||
copy(&mut region, || "d_1", col_r, 0, &gate_cells.d_1)?;
|
gate_cells
|
||||||
|
.d_1
|
||||||
|
.copy_advice(|| "d_1", &mut region, col_r, 0)?;
|
||||||
|
|
||||||
copy(&mut region, || "d_2", col_m, 1, &gate_cells.d_2)?;
|
gate_cells
|
||||||
copy(&mut region, || "d_3 = z1_d", col_r, 1, &gate_cells.z1_d)?;
|
.d_2
|
||||||
|
.copy_advice(|| "d_2", &mut region, col_m, 1)?;
|
||||||
|
gate_cells
|
||||||
|
.z1_d
|
||||||
|
.copy_advice(|| "d_3 = z1_d", &mut region, col_r, 1)?;
|
||||||
|
|
||||||
Ok(d_0)
|
Ok(d_0)
|
||||||
},
|
},
|
||||||
|
@ -1172,9 +1171,13 @@ impl NoteCommitConfig {
|
||||||
|mut region| {
|
|mut region| {
|
||||||
self.q_notecommit_e.enable(&mut region, 0)?;
|
self.q_notecommit_e.enable(&mut region, 0)?;
|
||||||
|
|
||||||
copy(&mut region, || "e", col_l, 0, &gate_cells.e)?;
|
gate_cells.e.copy_advice(|| "e", &mut region, col_l, 0)?;
|
||||||
copy(&mut region, || "e_0", col_m, 0, &gate_cells.e_0)?;
|
gate_cells
|
||||||
copy(&mut region, || "e_1", col_r, 0, &gate_cells.e_1)?;
|
.e_0
|
||||||
|
.copy_advice(|| "e_0", &mut region, col_m, 0)?;
|
||||||
|
gate_cells
|
||||||
|
.e_1
|
||||||
|
.copy_advice(|| "e_1", &mut region, col_r, 0)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
|
@ -1189,7 +1192,7 @@ impl NoteCommitConfig {
|
||||||
|mut region| {
|
|mut region| {
|
||||||
self.q_notecommit_g.enable(&mut region, 0)?;
|
self.q_notecommit_g.enable(&mut region, 0)?;
|
||||||
|
|
||||||
copy(&mut region, || "g", col_l, 0, &gate_cells.g)?;
|
gate_cells.g.copy_advice(|| "g", &mut region, col_l, 0)?;
|
||||||
let g_0 = region.assign_advice(
|
let g_0 = region.assign_advice(
|
||||||
|| "g_0",
|
|| "g_0",
|
||||||
col_m,
|
col_m,
|
||||||
|
@ -1197,8 +1200,12 @@ impl NoteCommitConfig {
|
||||||
|| gate_cells.g_0.ok_or(Error::Synthesis),
|
|| gate_cells.g_0.ok_or(Error::Synthesis),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
copy(&mut region, || "g_1", col_l, 1, &gate_cells.g_1)?;
|
gate_cells
|
||||||
copy(&mut region, || "g_2 = z1_g", col_m, 1, &gate_cells.z1_g)?;
|
.g_1
|
||||||
|
.copy_advice(|| "g_1", &mut region, col_l, 1)?;
|
||||||
|
gate_cells
|
||||||
|
.z1_g
|
||||||
|
.copy_advice(|| "g_2 = z1_g", &mut region, col_m, 1)?;
|
||||||
|
|
||||||
Ok(g_0)
|
Ok(g_0)
|
||||||
},
|
},
|
||||||
|
@ -1212,8 +1219,10 @@ impl NoteCommitConfig {
|
||||||
|mut region| {
|
|mut region| {
|
||||||
self.q_notecommit_h.enable(&mut region, 0)?;
|
self.q_notecommit_h.enable(&mut region, 0)?;
|
||||||
|
|
||||||
copy(&mut region, || "h", col_l, 0, &gate_cells.h)?;
|
gate_cells.h.copy_advice(|| "h", &mut region, col_l, 0)?;
|
||||||
copy(&mut region, || "h_0", col_m, 0, &gate_cells.h_0)?;
|
gate_cells
|
||||||
|
.h_0
|
||||||
|
.copy_advice(|| "h_0", &mut region, col_m, 0)?;
|
||||||
let h_1 = region.assign_advice(
|
let h_1 = region.assign_advice(
|
||||||
|| "h_1",
|
|| "h_1",
|
||||||
col_r,
|
col_r,
|
||||||
|
@ -1232,22 +1241,26 @@ impl NoteCommitConfig {
|
||||||
layouter.assign_region(
|
layouter.assign_region(
|
||||||
|| "NoteCommit input g_d",
|
|| "NoteCommit input g_d",
|
||||||
|mut region| {
|
|mut region| {
|
||||||
copy(&mut region, || "gd_x", col_l, 0, &gate_cells.gd_x)?;
|
gate_cells
|
||||||
|
.gd_x
|
||||||
|
.copy_advice(|| "gd_x", &mut region, col_l, 0)?;
|
||||||
|
|
||||||
copy(&mut region, || "b_0", col_m, 0, &gate_cells.b_0)?;
|
gate_cells
|
||||||
copy(&mut region, || "b_1", col_m, 1, &b_1)?;
|
.b_0
|
||||||
|
.copy_advice(|| "b_0", &mut region, col_m, 0)?;
|
||||||
|
b_1.copy_advice(|| "b_1", &mut region, col_m, 1)?;
|
||||||
|
|
||||||
copy(&mut region, || "a", col_r, 0, &gate_cells.a)?;
|
gate_cells.a.copy_advice(|| "a", &mut region, col_r, 0)?;
|
||||||
copy(&mut region, || "a_prime", col_r, 1, &gate_cells.a_prime)?;
|
gate_cells
|
||||||
|
.a_prime
|
||||||
|
.copy_advice(|| "a_prime", &mut region, col_r, 1)?;
|
||||||
|
|
||||||
copy(&mut region, || "z13_a", col_z, 0, &gate_cells.z13_a)?;
|
gate_cells
|
||||||
copy(
|
.z13_a
|
||||||
&mut region,
|
.copy_advice(|| "z13_a", &mut region, col_z, 0)?;
|
||||||
|| "z13_a_prime",
|
gate_cells
|
||||||
col_z,
|
.z13_a_prime
|
||||||
1,
|
.copy_advice(|| "z13_a_prime", &mut region, col_z, 1)?;
|
||||||
&gate_cells.z13_a_prime,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
self.q_notecommit_g_d.enable(&mut region, 0)
|
self.q_notecommit_g_d.enable(&mut region, 0)
|
||||||
},
|
},
|
||||||
|
@ -1260,27 +1273,28 @@ impl NoteCommitConfig {
|
||||||
layouter.assign_region(
|
layouter.assign_region(
|
||||||
|| "NoteCommit input pk_d",
|
|| "NoteCommit input pk_d",
|
||||||
|mut region| {
|
|mut region| {
|
||||||
copy(&mut region, || "pkd_x", col_l, 0, &gate_cells.pkd_x)?;
|
gate_cells
|
||||||
|
.pkd_x
|
||||||
|
.copy_advice(|| "pkd_x", &mut region, col_l, 0)?;
|
||||||
|
|
||||||
copy(&mut region, || "b_3", col_m, 0, &gate_cells.b_3)?;
|
gate_cells
|
||||||
copy(&mut region, || "d_0", col_m, 1, &d_0)?;
|
.b_3
|
||||||
|
.copy_advice(|| "b_3", &mut region, col_m, 0)?;
|
||||||
|
d_0.copy_advice(|| "d_0", &mut region, col_m, 1)?;
|
||||||
|
|
||||||
copy(&mut region, || "c", col_r, 0, &gate_cells.c)?;
|
gate_cells.c.copy_advice(|| "c", &mut region, col_r, 0)?;
|
||||||
copy(
|
gate_cells
|
||||||
&mut region,
|
.b3_c_prime
|
||||||
|| "b3_c_prime",
|
.copy_advice(|| "b3_c_prime", &mut region, col_r, 1)?;
|
||||||
col_r,
|
|
||||||
1,
|
|
||||||
&gate_cells.b3_c_prime,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
copy(&mut region, || "z13_c", col_z, 0, &gate_cells.z13_c)?;
|
gate_cells
|
||||||
copy(
|
.z13_c
|
||||||
&mut region,
|
.copy_advice(|| "z13_c", &mut region, col_z, 0)?;
|
||||||
|
gate_cells.z14_b3_c_prime.copy_advice(
|
||||||
|| "z14_b3_c_prime",
|
|| "z14_b3_c_prime",
|
||||||
|
&mut region,
|
||||||
col_z,
|
col_z,
|
||||||
1,
|
1,
|
||||||
&gate_cells.z14_b3_c_prime,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.q_notecommit_pk_d.enable(&mut region, 0)
|
self.q_notecommit_pk_d.enable(&mut region, 0)
|
||||||
|
@ -1291,10 +1305,18 @@ impl NoteCommitConfig {
|
||||||
layouter.assign_region(
|
layouter.assign_region(
|
||||||
|| "NoteCommit input value",
|
|| "NoteCommit input value",
|
||||||
|mut region| {
|
|mut region| {
|
||||||
copy(&mut region, || "value", col_l, 0, &gate_cells.value)?;
|
gate_cells
|
||||||
copy(&mut region, || "d_2", col_m, 0, &gate_cells.d_2)?;
|
.value
|
||||||
copy(&mut region, || "d3 = z1_d", col_r, 0, &gate_cells.z1_d)?;
|
.copy_advice(|| "value", &mut region, col_l, 0)?;
|
||||||
copy(&mut region, || "e_0", col_z, 0, &gate_cells.e_0)?;
|
gate_cells
|
||||||
|
.d_2
|
||||||
|
.copy_advice(|| "d_2", &mut region, col_m, 0)?;
|
||||||
|
gate_cells
|
||||||
|
.z1_d
|
||||||
|
.copy_advice(|| "d3 = z1_d", &mut region, col_r, 0)?;
|
||||||
|
gate_cells
|
||||||
|
.e_0
|
||||||
|
.copy_advice(|| "e_0", &mut region, col_z, 0)?;
|
||||||
|
|
||||||
self.q_notecommit_value.enable(&mut region, 0)
|
self.q_notecommit_value.enable(&mut region, 0)
|
||||||
},
|
},
|
||||||
|
@ -1307,27 +1329,28 @@ impl NoteCommitConfig {
|
||||||
layouter.assign_region(
|
layouter.assign_region(
|
||||||
|| "NoteCommit input rho",
|
|| "NoteCommit input rho",
|
||||||
|mut region| {
|
|mut region| {
|
||||||
copy(&mut region, || "rho", col_l, 0, &gate_cells.rho)?;
|
gate_cells
|
||||||
|
.rho
|
||||||
|
.copy_advice(|| "rho", &mut region, col_l, 0)?;
|
||||||
|
|
||||||
copy(&mut region, || "e_1", col_m, 0, &gate_cells.e_1)?;
|
gate_cells
|
||||||
copy(&mut region, || "g_0", col_m, 1, &g_0)?;
|
.e_1
|
||||||
|
.copy_advice(|| "e_1", &mut region, col_m, 0)?;
|
||||||
|
g_0.copy_advice(|| "g_0", &mut region, col_m, 1)?;
|
||||||
|
|
||||||
copy(&mut region, || "f", col_r, 0, &gate_cells.f)?;
|
gate_cells.f.copy_advice(|| "f", &mut region, col_r, 0)?;
|
||||||
copy(
|
gate_cells
|
||||||
&mut region,
|
.e1_f_prime
|
||||||
|| "e1_f_prime",
|
.copy_advice(|| "e1_f_prime", &mut region, col_r, 1)?;
|
||||||
col_r,
|
|
||||||
1,
|
|
||||||
&gate_cells.e1_f_prime,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
copy(&mut region, || "z13_f", col_z, 0, &gate_cells.z13_f)?;
|
gate_cells
|
||||||
copy(
|
.z13_f
|
||||||
&mut region,
|
.copy_advice(|| "z13_f", &mut region, col_z, 0)?;
|
||||||
|
gate_cells.z14_e1_f_prime.copy_advice(
|
||||||
|| "z14_e1_f_prime",
|
|| "z14_e1_f_prime",
|
||||||
|
&mut region,
|
||||||
col_z,
|
col_z,
|
||||||
1,
|
1,
|
||||||
&gate_cells.z14_e1_f_prime,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.q_notecommit_rho.enable(&mut region, 0)
|
self.q_notecommit_rho.enable(&mut region, 0)
|
||||||
|
@ -1341,28 +1364,33 @@ impl NoteCommitConfig {
|
||||||
layouter.assign_region(
|
layouter.assign_region(
|
||||||
|| "NoteCommit input psi",
|
|| "NoteCommit input psi",
|
||||||
|mut region| {
|
|mut region| {
|
||||||
copy(&mut region, || "psi", col_l, 0, &gate_cells.psi)?;
|
gate_cells
|
||||||
copy(&mut region, || "h_0", col_l, 1, &gate_cells.h_0)?;
|
.psi
|
||||||
|
.copy_advice(|| "psi", &mut region, col_l, 0)?;
|
||||||
|
gate_cells
|
||||||
|
.h_0
|
||||||
|
.copy_advice(|| "h_0", &mut region, col_l, 1)?;
|
||||||
|
|
||||||
copy(&mut region, || "g_1", col_m, 0, &gate_cells.g_1)?;
|
gate_cells
|
||||||
copy(&mut region, || "h_1", col_m, 1, &h_1)?;
|
.g_1
|
||||||
|
.copy_advice(|| "g_1", &mut region, col_m, 0)?;
|
||||||
|
h_1.copy_advice(|| "h_1", &mut region, col_m, 1)?;
|
||||||
|
|
||||||
copy(&mut region, || "g_2 = z1_g", col_r, 0, &gate_cells.z1_g)?;
|
gate_cells
|
||||||
copy(
|
.z1_g
|
||||||
&mut region,
|
.copy_advice(|| "g_2 = z1_g", &mut region, col_r, 0)?;
|
||||||
|| "g1_g2_prime",
|
gate_cells
|
||||||
col_r,
|
.g1_g2_prime
|
||||||
1,
|
.copy_advice(|| "g1_g2_prime", &mut region, col_r, 1)?;
|
||||||
&gate_cells.g1_g2_prime,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
copy(&mut region, || "z13_g", col_z, 0, &gate_cells.z13_g)?;
|
gate_cells
|
||||||
copy(
|
.z13_g
|
||||||
&mut region,
|
.copy_advice(|| "z13_g", &mut region, col_z, 0)?;
|
||||||
|
gate_cells.z13_g1_g2_prime.copy_advice(
|
||||||
|| "z13_g1_g2_prime",
|
|| "z13_g1_g2_prime",
|
||||||
|
&mut region,
|
||||||
col_z,
|
col_z,
|
||||||
1,
|
1,
|
||||||
&gate_cells.z13_g1_g2_prime,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.q_notecommit_psi.enable(&mut region, 0)
|
self.q_notecommit_psi.enable(&mut region, 0)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use ff::PrimeFieldBits;
|
use ff::PrimeFieldBits;
|
||||||
use halo2::{
|
use halo2::{
|
||||||
circuit::{AssignedCell, Cell, Layouter, Region},
|
circuit::{AssignedCell, Cell, Layouter},
|
||||||
plonk::{Advice, Column, Error, Expression},
|
plonk::{Advice, Column, Error, Expression},
|
||||||
};
|
};
|
||||||
use pasta_curves::arithmetic::FieldExt;
|
use pasta_curves::arithmetic::FieldExt;
|
||||||
|
@ -62,29 +62,6 @@ pub trait UtilitiesInstructions<F: FieldExt> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Assigns a cell at a specific offset within the given region, constraining it
|
|
||||||
/// to the same value as another cell (which may be in any region).
|
|
||||||
///
|
|
||||||
/// Returns an error if either `column` or `copy` is not in a column that was passed to
|
|
||||||
/// [`ConstraintSystem::enable_equality`] during circuit configuration.
|
|
||||||
///
|
|
||||||
/// [`ConstraintSystem::enable_equality`]: halo2::plonk::ConstraintSystem::enable_equality
|
|
||||||
pub fn copy<A, AR, F: FieldExt>(
|
|
||||||
region: &mut Region<'_, F>,
|
|
||||||
annotation: A,
|
|
||||||
column: Column<Advice>,
|
|
||||||
offset: usize,
|
|
||||||
copy: &CellValue<F>,
|
|
||||||
) -> Result<CellValue<F>, Error>
|
|
||||||
where
|
|
||||||
A: Fn() -> AR,
|
|
||||||
AR: Into<String>,
|
|
||||||
{
|
|
||||||
// Temporarily implement `copy()` in terms of `AssignedCell::copy_advice`.
|
|
||||||
// We will remove this in a subsequent commit.
|
|
||||||
copy.copy_advice(annotation, region, column, offset)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn transpose_option_array<T: Copy + std::fmt::Debug, const LEN: usize>(
|
pub(crate) fn transpose_option_array<T: Copy + std::fmt::Debug, const LEN: usize>(
|
||||||
option_array: Option<[T; LEN]>,
|
option_array: Option<[T; LEN]>,
|
||||||
) -> [Option<T>; LEN] {
|
) -> [Option<T>; LEN] {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use super::{bool_check, copy, ternary, CellValue, UtilitiesInstructions};
|
use super::{bool_check, ternary, CellValue, UtilitiesInstructions};
|
||||||
use halo2::{
|
use halo2::{
|
||||||
circuit::{Chip, Layouter},
|
circuit::{Chip, Layouter},
|
||||||
plonk::{Advice, Column, ConstraintSystem, Error, Selector},
|
plonk::{Advice, Column, ConstraintSystem, Error, Selector},
|
||||||
|
@ -73,7 +73,7 @@ impl<F: FieldExt> CondSwapInstructions<F> for CondSwapChip<F> {
|
||||||
config.q_swap.enable(&mut region, 0)?;
|
config.q_swap.enable(&mut region, 0)?;
|
||||||
|
|
||||||
// Copy in `a` value
|
// Copy in `a` value
|
||||||
let a = copy(&mut region, || "copy a", config.a, 0, &pair.0)?;
|
let a = pair.0.copy_advice(|| "copy a", &mut region, config.a, 0)?;
|
||||||
|
|
||||||
// Witness `b` value
|
// Witness `b` value
|
||||||
let b = region.assign_advice(
|
let b = region.assign_advice(
|
||||||
|
|
|
@ -29,7 +29,7 @@ use halo2::{
|
||||||
poly::Rotation,
|
poly::Rotation,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{copy, range_check, CellValue};
|
use super::{range_check, CellValue};
|
||||||
use crate::constants::util::decompose_word;
|
use crate::constants::util::decompose_word;
|
||||||
use pasta_curves::arithmetic::FieldExt;
|
use pasta_curves::arithmetic::FieldExt;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
@ -127,7 +127,7 @@ impl<F: FieldExt + PrimeFieldBits, const WINDOW_NUM_BITS: usize>
|
||||||
word_num_bits: usize,
|
word_num_bits: usize,
|
||||||
num_windows: usize,
|
num_windows: usize,
|
||||||
) -> Result<RunningSum<F>, Error> {
|
) -> Result<RunningSum<F>, Error> {
|
||||||
let z_0 = copy(region, || "copy z_0 = alpha", self.z, offset, &alpha)?;
|
let z_0 = alpha.copy_advice(|| "copy z_0 = alpha", region, self.z, offset)?;
|
||||||
self.decompose(region, offset, z_0, strict, word_num_bits, num_windows)
|
self.decompose(region, offset, z_0, strict, word_num_bits, num_windows)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -151,7 +151,7 @@ impl<F: FieldExt + PrimeFieldBits, const K: usize> LookupRangeCheckConfig<F, K>
|
||||||
|| format!("{:?} words range check", num_words),
|
|| format!("{:?} words range check", num_words),
|
||||||
|mut region| {
|
|mut region| {
|
||||||
// Copy `element` and initialize running sum `z_0 = element` to decompose it.
|
// Copy `element` and initialize running sum `z_0 = element` to decompose it.
|
||||||
let z_0 = copy(&mut region, || "z_0", self.running_sum, 0, &element)?;
|
let z_0 = element.copy_advice(|| "z_0", &mut region, self.running_sum, 0)?;
|
||||||
self.range_check(&mut region, z_0, num_words, strict)
|
self.range_check(&mut region, z_0, num_words, strict)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -278,7 +278,8 @@ impl<F: FieldExt + PrimeFieldBits, const K: usize> LookupRangeCheckConfig<F, K>
|
||||||
|| format!("Range check {:?} bits", num_bits),
|
|| format!("Range check {:?} bits", num_bits),
|
||||||
|mut region| {
|
|mut region| {
|
||||||
// Copy `element` to use in the k-bit lookup.
|
// Copy `element` to use in the k-bit lookup.
|
||||||
let element = copy(&mut region, || "element", self.running_sum, 0, &element)?;
|
let element =
|
||||||
|
element.copy_advice(|| "element", &mut region, self.running_sum, 0)?;
|
||||||
|
|
||||||
self.short_range_check(&mut region, element, num_bits)
|
self.short_range_check(&mut region, element, num_bits)
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue