diff --git a/src/circuit.rs b/src/circuit.rs index 7d6c8b69..df53bcb4 100644 --- a/src/circuit.rs +++ b/src/circuit.rs @@ -50,7 +50,7 @@ use gadget::{ }, note_commit::NoteCommitConfig, }, - utilities::{copy, CellValue, UtilitiesInstructions}, + utilities::{CellValue, UtilitiesInstructions}, }; use std::convert::TryInto; @@ -501,20 +501,8 @@ impl plonk::Circuit for Circuit { |mut region| { config.q_add.enable(&mut region, 0)?; - copy( - &mut region, - || "copy hash_old", - config.advices[7], - 0, - &hash_old, - )?; - copy( - &mut region, - || "copy psi_old", - config.advices[8], - 0, - &psi_old, - )?; + hash_old.copy_advice(|| "copy hash_old", &mut region, config.advices[7], 0)?; + psi_old.copy_advice(|| "copy psi_old", &mut region, config.advices[8], 0)?; let scalar_val = hash_old .value() @@ -691,19 +679,13 @@ impl plonk::Circuit for Circuit { layouter.assign_region( || "v_old - v_new = magnitude * sign", |mut region| { - copy(&mut region, || "v_old", config.advices[0], 0, &v_old)?; - copy(&mut region, || "v_new", config.advices[1], 0, &v_new)?; + v_old.copy_advice(|| "v_old", &mut region, config.advices[0], 0)?; + v_new.copy_advice(|| "v_new", &mut region, config.advices[1], 0)?; let (magnitude, sign) = v_net.clone(); - copy( - &mut region, - || "v_net magnitude", - config.advices[2], - 0, - &magnitude, - )?; - copy(&mut region, || "v_net sign", config.advices[3], 0, &sign)?; + magnitude.copy_advice(|| "v_net magnitude", &mut region, config.advices[2], 0)?; + sign.copy_advice(|| "v_net sign", &mut region, config.advices[3], 0)?; - copy(&mut region, || "anchor", config.advices[4], 0, &anchor)?; + anchor.copy_advice(|| "anchor", &mut region, config.advices[4], 0)?; region.assign_advice_from_instance( || "pub input anchor", config.primary, diff --git a/src/circuit/gadget/ecc/chip.rs b/src/circuit/gadget/ecc/chip.rs index d50bf98a..82062240 100644 --- a/src/circuit/gadget/ecc/chip.rs +++ b/src/circuit/gadget/ecc/chip.rs @@ -1,7 +1,7 @@ use super::EccInstructions; use crate::{ circuit::gadget::utilities::{ - copy, lookup_range_check::LookupRangeCheckConfig, CellValue, UtilitiesInstructions, + lookup_range_check::LookupRangeCheckConfig, CellValue, UtilitiesInstructions, }, constants::{self, NullifierK, OrchardFixedBasesFull, ValueCommitV}, primitives::sinsemilla, diff --git a/src/circuit/gadget/ecc/chip/add.rs b/src/circuit/gadget/ecc/chip/add.rs index aec2f615..1db13c52 100644 --- a/src/circuit/gadget/ecc/chip/add.rs +++ b/src/circuit/gadget/ecc/chip/add.rs @@ -1,6 +1,6 @@ use std::array; -use super::{copy, EccPoint}; +use super::EccPoint; use ff::{BatchInvert, Field}; use halo2::{ circuit::Region, @@ -223,12 +223,12 @@ impl Config { self.q_add.enable(region, offset)?; // Copy point `p` into `x_p`, `y_p` columns - copy(region, || "x_p", self.x_p, offset, &p.x)?; - copy(region, || "y_p", self.y_p, offset, &p.y)?; + p.x.copy_advice(|| "x_p", region, self.x_p, offset)?; + p.y.copy_advice(|| "y_p", region, self.y_p, offset)?; // Copy point `q` into `x_qr`, `y_qr` columns - copy(region, || "x_q", self.x_qr, offset, &q.x)?; - copy(region, || "y_q", self.y_qr, offset, &q.y)?; + q.x.copy_advice(|| "x_q", region, self.x_qr, offset)?; + q.y.copy_advice(|| "y_q", region, self.y_qr, offset)?; let (x_p, y_p) = (p.x.value(), p.y.value()); let (x_q, y_q) = (q.x.value(), q.y.value()); diff --git a/src/circuit/gadget/ecc/chip/add_incomplete.rs b/src/circuit/gadget/ecc/chip/add_incomplete.rs index d466056d..da98461a 100644 --- a/src/circuit/gadget/ecc/chip/add_incomplete.rs +++ b/src/circuit/gadget/ecc/chip/add_incomplete.rs @@ -1,6 +1,6 @@ use std::{array, collections::HashSet}; -use super::{copy, NonIdentityEccPoint}; +use super::NonIdentityEccPoint; use ff::Field; use group::Curve; use halo2::{ @@ -111,12 +111,12 @@ impl Config { .transpose()?; // Copy point `p` into `x_p`, `y_p` columns - copy(region, || "x_p", self.x_p, offset, &p.x)?; - copy(region, || "y_p", self.y_p, offset, &p.y)?; + p.x.copy_advice(|| "x_p", region, self.x_p, offset)?; + p.y.copy_advice(|| "y_p", region, self.y_p, offset)?; // Copy point `q` into `x_qr`, `y_qr` columns - copy(region, || "x_q", self.x_qr, offset, &q.x)?; - copy(region, || "y_q", self.y_qr, offset, &q.y)?; + q.x.copy_advice(|| "x_q", region, self.x_qr, offset)?; + q.y.copy_advice(|| "y_q", region, self.y_qr, offset)?; // Compute the sum `P + Q = R` let r = { diff --git a/src/circuit/gadget/ecc/chip/mul.rs b/src/circuit/gadget/ecc/chip/mul.rs index f0cebf11..05c93a51 100644 --- a/src/circuit/gadget/ecc/chip/mul.rs +++ b/src/circuit/gadget/ecc/chip/mul.rs @@ -1,8 +1,6 @@ use super::{add, CellValue, EccPoint, NonIdentityEccPoint}; use crate::{ - circuit::gadget::utilities::{ - bool_check, copy, lookup_range_check::LookupRangeCheckConfig, ternary, - }, + circuit::gadget::utilities::{bool_check, lookup_range_check::LookupRangeCheckConfig, ternary}, constants::T_Q, primitives::sinsemilla, }; @@ -342,20 +340,10 @@ impl Config { }; // Copy in `base_x`, `base_y` to use in the LSB gate - copy( - region, - || "copy base_x", - self.add_config.x_p, - offset + 1, - &base.x(), - )?; - copy( - region, - || "copy base_y", - self.add_config.y_p, - offset + 1, - &base.y(), - )?; + base.x() + .copy_advice(|| "copy base_x", region, self.add_config.x_p, offset + 1)?; + base.y() + .copy_advice(|| "copy base_y", region, self.add_config.y_p, offset + 1)?; // If `lsb` is 0, return `Acc + (-P)`. If `lsb` is 1, simply return `Acc + 0`. let x = if let Some(lsb) = lsb { diff --git a/src/circuit/gadget/ecc/chip/mul/complete.rs b/src/circuit/gadget/ecc/chip/mul/complete.rs index ba260b0f..d8bbe625 100644 --- a/src/circuit/gadget/ecc/chip/mul/complete.rs +++ b/src/circuit/gadget/ecc/chip/mul/complete.rs @@ -1,4 +1,4 @@ -use super::super::{add, copy, EccPoint}; +use super::super::{add, EccPoint}; use super::{COMPLETE_RANGE, X, Y, Z}; use crate::circuit::gadget::utilities::{bool_check, ternary}; @@ -110,12 +110,11 @@ impl Config { // Copy running sum `z` from incomplete addition let mut z = { - let z = copy( - region, + let z = z.copy_advice( || "Copy `z` running sum from incomplete addition", + region, self.z_complete, offset, - &z, )?; Z(z) }; @@ -152,12 +151,11 @@ impl Config { // Assign `y_p` for complete addition. let y_p = { - let base_y = copy( - region, + let base_y = base.y.copy_advice( || "Copy `base.y`", + region, self.z_complete, row + offset + 1, - &base.y, )?; // If the bit is set, use `y`; if the bit is not set, use `-y` diff --git a/src/circuit/gadget/ecc/chip/mul/incomplete.rs b/src/circuit/gadget/ecc/chip/mul/incomplete.rs index ac16c2fa..766026da 100644 --- a/src/circuit/gadget/ecc/chip/mul/incomplete.rs +++ b/src/circuit/gadget/ecc/chip/mul/incomplete.rs @@ -1,4 +1,4 @@ -use super::super::{copy, NonIdentityEccPoint}; +use super::super::NonIdentityEccPoint; use super::{X, Y, Z}; use crate::circuit::gadget::utilities::bool_check; use ff::Field; @@ -223,11 +223,15 @@ impl Config { // Initialise double-and-add let (mut x_a, mut y_a, mut z) = { // 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 - let x_a = copy(region, || "starting x_a", self.x_a, offset + 1, &acc.0)?; - let y_a = copy(region, || "starting y_a", self.lambda1, offset, &acc.1)?; + let x_a = acc + .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) }; diff --git a/src/circuit/gadget/ecc/chip/mul/overflow.rs b/src/circuit/gadget/ecc/chip/mul/overflow.rs index 8f78e6ee..d007a772 100644 --- a/src/circuit/gadget/ecc/chip/mul/overflow.rs +++ b/src/circuit/gadget/ecc/chip/mul/overflow.rs @@ -1,4 +1,4 @@ -use super::super::{copy, CellValue}; +use super::super::CellValue; use super::Z; use crate::{ 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)?; // 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( - &mut region, - || "copy z_130", - self.advices[0], - offset + 1, - &*zs[130], - )?; + zs[130].copy_advice(|| "copy z_130", &mut region, self.advices[0], offset + 1)?; // 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( - &mut region, - || "copy k_254", - self.advices[1], - offset, - &*zs[254], - )?; + zs[254].copy_advice(|| "copy k_254", &mut region, self.advices[1], offset)?; // Copy original alpha - copy( - &mut region, + alpha.copy_advice( || "copy original alpha", + &mut region, self.advices[1], offset + 1, - &alpha, )?; // Copy weighted sum of the decomposition of s = alpha + k_254 ⋅ 2^130. - copy( - &mut region, + s_minus_lo_130.copy_advice( || "copy s_minus_lo_130", + &mut region, self.advices[1], offset + 2, - &s_minus_lo_130, )?; // 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(()) }, diff --git a/src/circuit/gadget/ecc/chip/mul_fixed/base_field_elem.rs b/src/circuit/gadget/ecc/chip/mul_fixed/base_field_elem.rs index dc421e53..fb5de1f2 100644 --- a/src/circuit/gadget/ecc/chip/mul_fixed/base_field_elem.rs +++ b/src/circuit/gadget/ecc/chip/mul_fixed/base_field_elem.rs @@ -3,7 +3,7 @@ use super::H_BASE; use crate::{ 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}, primitives::sinsemilla, @@ -290,21 +290,14 @@ impl Config { let offset = 0; // Copy α - copy( - &mut region, - || "Copy α", - self.canon_advices[0], - offset, - &alpha, - )?; + alpha.copy_advice(|| "Copy α", &mut region, self.canon_advices[0], offset)?; // z_84_alpha = the top three bits of alpha. - copy( - &mut region, + z_84_alpha.copy_advice( || "Copy z_84_alpha", + &mut region, self.canon_advices[2], offset, - &z_84_alpha, )?; } @@ -313,12 +306,11 @@ impl Config { let offset = 1; // Copy alpha_0_prime = alpha_0 + 2^130 - t_p. // We constrain this in the custom gate to be derived correctly. - copy( - &mut region, + alpha_0_prime.copy_advice( || "Copy α_0 + 2^130 - t_p", + &mut region, self.canon_advices[0], offset, - &alpha_0_prime, )?; // Decompose α into three pieces, @@ -347,30 +339,27 @@ impl Config { { let offset = 2; // Copy z_13_alpha_0_prime - copy( - &mut region, + z_13_alpha_0_prime.copy_advice( || "Copy z_13_alpha_0_prime", + &mut region, self.canon_advices[0], offset, - &z_13_alpha_0_prime, )?; // Copy z_44_alpha - copy( - &mut region, + z_44_alpha.copy_advice( || "Copy z_44_alpha", + &mut region, self.canon_advices[1], offset, - &z_44_alpha, )?; // Copy z_43_alpha - copy( - &mut region, + z_43_alpha.copy_advice( || "Copy z_43_alpha", + &mut region, self.canon_advices[2], offset, - &z_43_alpha, )?; } diff --git a/src/circuit/gadget/ecc/chip/mul_fixed/short.rs b/src/circuit/gadget/ecc/chip/mul_fixed/short.rs index b630ed58..ad20316a 100644 --- a/src/circuit/gadget/ecc/chip/mul_fixed/short.rs +++ b/src/circuit/gadget/ecc/chip/mul_fixed/short.rs @@ -2,7 +2,7 @@ use std::{array, convert::TryInto}; use super::super::{EccPoint, EccScalarFixedShort}; use crate::{ - circuit::gadget::utilities::{bool_check, copy, CellValue}, + circuit::gadget::utilities::{bool_check, CellValue}, constants::{ValueCommitV, L_VALUE, NUM_WINDOWS_SHORT}, }; @@ -138,25 +138,18 @@ impl Config { let offset = offset + 1; // Copy sign to `window` column - let sign = copy( - &mut region, + let sign = scalar.sign.copy_advice( || "sign", + &mut region, self.super_config.window, offset, - &scalar.sign, )?; // Copy last window to `u` column. // (Although the last window is not a `u` value; we are copying it into the `u` // column because there is an available cell there.) let z_21 = scalar.running_sum[21].clone(); - copy( - &mut region, - || "last_window", - self.super_config.u, - offset, - &z_21, - )?; + z_21.copy_advice(|| "last_window", &mut region, self.super_config.u, offset)?; // Conditionally negate `y`-coordinate let y_val = if let Some(sign) = sign.value() { diff --git a/src/circuit/gadget/poseidon/pow5.rs b/src/circuit/gadget/poseidon/pow5.rs index 27101b46..de6d4aa6 100644 --- a/src/circuit/gadget/poseidon/pow5.rs +++ b/src/circuit/gadget/poseidon/pow5.rs @@ -320,15 +320,15 @@ impl, const WIDTH: usize, const RATE: usize // Load the initial state into this region. let load_state_word = |i: usize| { - let value = initial_state[i].0.value().cloned(); - let var = region.assign_advice( - || format!("load state_{}", i), - config.state[i], - 0, - || value.ok_or(Error::Synthesis), - )?; - region.constrain_equal(initial_state[i].0.cell(), var.cell())?; - Ok(StateWord(var)) + initial_state[i] + .0 + .copy_advice( + || format!("load state_{}", i), + &mut region, + config.state[i], + 0, + ) + .map(StateWord) }; let initial_state: Result, Error> = (0..WIDTH).map(load_state_word).collect(); @@ -338,28 +338,24 @@ impl, const WIDTH: usize, const RATE: usize // Load the input and padding into this region. let load_input_word = |i: usize| { - let (constraint_var, value) = match (input[i].clone(), padding_values[i]) { - (Some(word), None) => (word.0.cell(), word.0.value().cloned()), - (None, Some(padding_value)) => { - let padding_var = region.assign_fixed( - || format!("load pad_{}", i), - config.rc_b[i], - 1, - || Ok(padding_value), - )?; - (padding_var.cell(), Some(padding_value)) - } + let constraint_var = match (input[i].clone(), padding_values[i]) { + (Some(word), None) => word.0, + (None, Some(padding_value)) => region.assign_fixed( + || format!("load pad_{}", i), + config.rc_b[i], + 1, + || Ok(padding_value), + )?, _ => panic!("Input and padding don't match"), }; - let var = region.assign_advice( - || format!("load input_{}", i), - config.state[i], - 1, - || value.ok_or(Error::Synthesis), - )?; - region.constrain_equal(constraint_var, var.cell())?; - - Ok(StateWord(var)) + constraint_var + .copy_advice( + || format!("load input_{}", i), + &mut region, + config.state[i], + 1, + ) + .map(StateWord) }; let input: Result, Error> = (0..RATE).map(load_input_word).collect(); let input = input?; @@ -538,15 +534,10 @@ impl Pow5State { initial_state: &State, WIDTH>, ) -> Result { let load_state_word = |i: usize| { - let value = initial_state[i].0.value().cloned(); - let var = region.assign_advice( - || format!("load state_{}", i), - config.state[i], - 0, - || value.ok_or(Error::Synthesis), - )?; - region.constrain_equal(initial_state[i].0.cell(), var.cell())?; - Ok(StateWord(var)) + initial_state[i] + .0 + .copy_advice(|| format!("load state_{}", i), region, config.state[i], 0) + .map(StateWord) }; let state: Result, _> = (0..WIDTH).map(load_state_word).collect(); diff --git a/src/circuit/gadget/sinsemilla/chip/hash_to_point.rs b/src/circuit/gadget/sinsemilla/chip/hash_to_point.rs index f78996df..67ed9268 100644 --- a/src/circuit/gadget/sinsemilla/chip/hash_to_point.rs +++ b/src/circuit/gadget/sinsemilla/chip/hash_to_point.rs @@ -261,14 +261,13 @@ impl SinsemillaChip { let mut zs = Vec::with_capacity(piece.num_words() + 1); // 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)", + region, config.bits, offset, - || piece.field_elem().ok_or(Error::Synthesis), )?; - region.constrain_equal(piece.cell(), cell.cell())?; - zs.push(cell); + zs.push(initial_z); // Assign cumulative sum such that for 0 <= i < n, // z_i = 2^K * z_{i + 1} + m_{i + 1} diff --git a/src/circuit/gadget/sinsemilla/commit_ivk.rs b/src/circuit/gadget/sinsemilla/commit_ivk.rs index a10f8c0c..5606966b 100644 --- a/src/circuit/gadget/sinsemilla/commit_ivk.rs +++ b/src/circuit/gadget/sinsemilla/commit_ivk.rs @@ -8,7 +8,7 @@ use pasta_curves::{arithmetic::FieldExt, pallas}; use crate::{ circuit::gadget::{ ecc::{chip::EccChip, X}, - utilities::{bitrange_subset, bool_check, copy, CellValue}, + utilities::{bitrange_subset, bool_check, CellValue}, }, constants::T_P, }; @@ -474,28 +474,24 @@ impl CommitIvkConfig { { let offset = 0; // Copy in `ak` - copy( - &mut region, - || "ak", - self.advices[0], - offset, - &gate_cells.ak, - )?; + gate_cells + .ak + .copy_advice(|| "ak", &mut region, self.advices[0], offset)?; // 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(&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( - &mut region, - || "b_0", - self.advices[3], - offset, - &gate_cells.b_0, - )?; + gate_cells + .b_0 + .copy_advice(|| "b_0", &mut region, self.advices[3], offset)?; // Witness `b_1` region.assign_advice( @@ -506,39 +502,32 @@ impl CommitIvkConfig { )?; // Copy in `b_2` - copy( - &mut region, - || "b_2", - self.advices[5], - offset, - &gate_cells.b_2, - )?; + gate_cells + .b_2 + .copy_advice(|| "b_2", &mut region, self.advices[5], offset)?; // Copy in z13_a - copy( - &mut region, + gate_cells.z13_a.copy_advice( || "z13_a", + &mut region, self.advices[6], offset, - &gate_cells.z13_a, )?; // Copy in a_prime - copy( - &mut region, + gate_cells.a_prime.copy_advice( || "a_prime", + &mut region, self.advices[7], offset, - &gate_cells.a_prime, )?; // Copy in z13_a_prime - copy( - &mut region, + gate_cells.z13_a_prime.copy_advice( || "z13_a_prime", + &mut region, self.advices[8], offset, - &gate_cells.z13_a_prime, )?; } @@ -547,28 +536,24 @@ impl CommitIvkConfig { let offset = 1; // Copy in `nk` - copy( - &mut region, - || "nk", - self.advices[0], - offset, - &gate_cells.nk, - )?; + gate_cells + .nk + .copy_advice(|| "nk", &mut region, self.advices[0], offset)?; // 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(&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( - &mut region, - || "d_0", - self.advices[3], - offset, - &gate_cells.d_0, - )?; + gate_cells + .d_0 + .copy_advice(|| "d_0", &mut region, self.advices[3], offset)?; // Witness `d_1` region.assign_advice( @@ -579,30 +564,27 @@ impl CommitIvkConfig { )?; // Copy in z13_c - copy( - &mut region, + gate_cells.z13_c.copy_advice( || "z13_c", + &mut region, self.advices[6], offset, - &gate_cells.z13_c, )?; // Copy in b2_c_prime - copy( - &mut region, + gate_cells.b2_c_prime.copy_advice( || "b2_c_prime", + &mut region, self.advices[7], offset, - &gate_cells.b2_c_prime, )?; // Copy in z14_b2_c_prime - copy( - &mut region, + gate_cells.z14_b2_c_prime.copy_advice( || "z14_b2_c_prime", + &mut region, self.advices[8], offset, - &gate_cells.z14_b2_c_prime, )?; } diff --git a/src/circuit/gadget/sinsemilla/merkle/chip.rs b/src/circuit/gadget/sinsemilla/merkle/chip.rs index 310a7ae2..50722d47 100644 --- a/src/circuit/gadget/sinsemilla/merkle/chip.rs +++ b/src/circuit/gadget/sinsemilla/merkle/chip.rs @@ -15,7 +15,7 @@ use crate::{ circuit::gadget::utilities::{ bitrange_subset, cond_swap::{CondSwapChip, CondSwapConfig, CondSwapInstructions}, - copy, CellValue, UtilitiesInstructions, + CellValue, UtilitiesInstructions, }, constants::{L_ORCHARD_BASE, MERKLE_DEPTH_ORCHARD}, primitives::sinsemilla, @@ -287,43 +287,28 @@ impl MerkleInstructions { } } -/// 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( - region: &mut Region<'_, F>, - annotation: A, - column: Column, - offset: usize, - copy: &CellValue, -) -> Result, Error> -where - A: Fn() -> AR, - AR: Into, -{ - // 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( option_array: Option<[T; LEN]>, ) -> [Option; LEN] { diff --git a/src/circuit/gadget/utilities/cond_swap.rs b/src/circuit/gadget/utilities/cond_swap.rs index f3d3f1be..e372bb22 100644 --- a/src/circuit/gadget/utilities/cond_swap.rs +++ b/src/circuit/gadget/utilities/cond_swap.rs @@ -1,4 +1,4 @@ -use super::{bool_check, copy, ternary, CellValue, UtilitiesInstructions}; +use super::{bool_check, ternary, CellValue, UtilitiesInstructions}; use halo2::{ circuit::{Chip, Layouter}, plonk::{Advice, Column, ConstraintSystem, Error, Selector}, @@ -73,7 +73,7 @@ impl CondSwapInstructions for CondSwapChip { config.q_swap.enable(&mut region, 0)?; // 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 let b = region.assign_advice( diff --git a/src/circuit/gadget/utilities/decompose_running_sum.rs b/src/circuit/gadget/utilities/decompose_running_sum.rs index 75aa1376..e22d5adf 100644 --- a/src/circuit/gadget/utilities/decompose_running_sum.rs +++ b/src/circuit/gadget/utilities/decompose_running_sum.rs @@ -29,7 +29,7 @@ use halo2::{ poly::Rotation, }; -use super::{copy, range_check, CellValue}; +use super::{range_check, CellValue}; use crate::constants::util::decompose_word; use pasta_curves::arithmetic::FieldExt; use std::marker::PhantomData; @@ -127,7 +127,7 @@ impl word_num_bits: usize, num_windows: usize, ) -> Result, 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) } diff --git a/src/circuit/gadget/utilities/lookup_range_check.rs b/src/circuit/gadget/utilities/lookup_range_check.rs index 14f59dcb..54f9018b 100644 --- a/src/circuit/gadget/utilities/lookup_range_check.rs +++ b/src/circuit/gadget/utilities/lookup_range_check.rs @@ -151,7 +151,7 @@ impl LookupRangeCheckConfig || format!("{:?} words range check", num_words), |mut region| { // 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) }, ) @@ -278,7 +278,8 @@ impl LookupRangeCheckConfig || format!("Range check {:?} bits", num_bits), |mut region| { // 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) },