mirror of https://github.com/zcash/halo2.git
halo2_gadgets: Remove usage of `array::IntoIter::new`
Rust 2021 implements `IntoIterator` for arrays directly, instead of only references to arrays. https://doc.rust-lang.org/edition-guide/rust-2021/IntoIterator-for-arrays.html
This commit is contained in:
parent
f830c6f7fb
commit
e3f1bf68db
|
@ -1,5 +1,3 @@
|
|||
use std::array;
|
||||
|
||||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
|
||||
use ff::Field;
|
||||
use halo2_gadgets::primitives::{
|
||||
|
@ -39,7 +37,7 @@ fn bench_primitives(c: &mut Criterion) {
|
|||
// - 510 bits for Commit^ivk
|
||||
// - 520 bits for MerkleCRH
|
||||
// - 1086 bits for NoteCommit
|
||||
for size in array::IntoIter::new([510, 520, 1086]) {
|
||||
for size in [510, 520, 1086] {
|
||||
group.bench_function(BenchmarkId::new("hash-to-point", size), |b| {
|
||||
b.iter(|| hasher.hash_to_point(bits[..size].iter().cloned()))
|
||||
});
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use std::array;
|
||||
|
||||
use super::EccPoint;
|
||||
use ff::{BatchInvert, Field};
|
||||
use halo2_proofs::{
|
||||
|
@ -71,7 +69,7 @@ impl Config {
|
|||
}
|
||||
|
||||
pub(crate) fn advice_columns(&self) -> HashSet<Column<Advice>> {
|
||||
core::array::IntoIter::new([
|
||||
[
|
||||
self.x_p,
|
||||
self.y_p,
|
||||
self.x_qr,
|
||||
|
@ -81,12 +79,13 @@ impl Config {
|
|||
self.beta,
|
||||
self.gamma,
|
||||
self.delta,
|
||||
])
|
||||
]
|
||||
.into_iter()
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub(crate) fn output_columns(&self) -> HashSet<Column<Advice>> {
|
||||
core::array::IntoIter::new([self.x_qr, self.y_qr]).collect()
|
||||
[self.x_qr, self.y_qr].into_iter().collect()
|
||||
}
|
||||
|
||||
fn create_gate(&self, meta: &mut ConstraintSystem<pallas::Base>) {
|
||||
|
@ -206,10 +205,10 @@ impl Config {
|
|||
|
||||
Constraints::with_selector(
|
||||
q_add,
|
||||
array::IntoIter::new([
|
||||
[
|
||||
poly1, poly2, poly3, poly4, poly5, poly6, poly7, poly8, poly9, poly10, poly11,
|
||||
poly12,
|
||||
]),
|
||||
],
|
||||
)
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::{array, collections::HashSet};
|
||||
use std::collections::HashSet;
|
||||
|
||||
use super::NonIdentityEccPoint;
|
||||
use ff::Field;
|
||||
|
@ -50,7 +50,9 @@ impl Config {
|
|||
}
|
||||
|
||||
pub(crate) fn advice_columns(&self) -> HashSet<Column<Advice>> {
|
||||
core::array::IntoIter::new([self.x_p, self.y_p, self.x_qr, self.y_qr]).collect()
|
||||
[self.x_p, self.y_p, self.x_qr, self.y_qr]
|
||||
.into_iter()
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn create_gate(&self, meta: &mut ConstraintSystem<pallas::Base>) {
|
||||
|
@ -74,10 +76,7 @@ impl Config {
|
|||
// (y_r + y_q)(x_p − x_q) − (y_p − y_q)(x_q − x_r) = 0
|
||||
let poly2 = (y_r + y_q.clone()) * (x_p - x_q.clone()) - (y_p - y_q) * (x_q - x_r);
|
||||
|
||||
Constraints::with_selector(
|
||||
q_add_incomplete,
|
||||
array::IntoIter::new([("x_r", poly1), ("y_r", poly2)]),
|
||||
)
|
||||
Constraints::with_selector(q_add_incomplete, [("x_r", poly1), ("y_r", poly2)])
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -153,11 +153,11 @@ impl Config {
|
|||
|
||||
Constraints::with_selector(
|
||||
q_mul_lsb,
|
||||
std::array::IntoIter::new([
|
||||
[
|
||||
("bool_check", bool_check),
|
||||
("lsb_x", lsb_x),
|
||||
("lsb_y", lsb_y),
|
||||
]),
|
||||
],
|
||||
)
|
||||
});
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ impl Config {
|
|||
|
||||
Constraints::with_selector(
|
||||
q_mul_decompose_var,
|
||||
std::array::IntoIter::new([("bool_check", bool_check), ("y_switch", y_switch)]),
|
||||
[("bool_check", bool_check), ("y_switch", y_switch)],
|
||||
)
|
||||
},
|
||||
);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::{array, convert::TryInto};
|
||||
use std::convert::TryInto;
|
||||
|
||||
use super::super::{EccPoint, EccScalarFixedShort, FixedPoints, L_SCALAR_SHORT, NUM_WINDOWS_SHORT};
|
||||
use crate::{ecc::chip::MagnitudeSign, utilities::bool_check};
|
||||
|
@ -59,12 +59,12 @@ impl<Fixed: FixedPoints<pallas::Affine>> Config<Fixed> {
|
|||
|
||||
Constraints::with_selector(
|
||||
q_mul_fixed_short,
|
||||
array::IntoIter::new([
|
||||
[
|
||||
("last_window_check", last_window_check),
|
||||
("sign_check", sign_check),
|
||||
("y_check", y_check),
|
||||
("negation_check", negation_check),
|
||||
]),
|
||||
],
|
||||
)
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use std::array;
|
||||
|
||||
use super::{EccPoint, NonIdentityEccPoint};
|
||||
|
||||
use group::prime::PrimeCurveAffine;
|
||||
|
@ -68,10 +66,10 @@ impl Config {
|
|||
// of the form `q_point * (x * curve_eqn)`, but this was implemented without
|
||||
// parentheses, and thus evaluates as `(q_point * x) * curve_eqn`, which is
|
||||
// structurally different in the pinned verifying key.
|
||||
array::IntoIter::new([
|
||||
[
|
||||
("x == 0 v on_curve", q_point.clone() * x * curve_eqn(meta)),
|
||||
("y == 0 v on_curve", q_point * y * curve_eqn(meta)),
|
||||
])
|
||||
]
|
||||
});
|
||||
|
||||
meta.create_gate("witness non-identity point", |meta| {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
//! Gadget and chips for the Poseidon algebraic hash function.
|
||||
|
||||
use std::array;
|
||||
use std::convert::TryInto;
|
||||
use std::fmt;
|
||||
use std::marker::PhantomData;
|
||||
|
@ -283,7 +282,8 @@ impl<
|
|||
mut layouter: impl Layouter<F>,
|
||||
message: [AssignedCell<F, F>; L],
|
||||
) -> Result<AssignedCell<F, F>, Error> {
|
||||
for (i, value) in array::IntoIter::new(message)
|
||||
for (i, value) in message
|
||||
.into_iter()
|
||||
.map(PaddedWord::Message)
|
||||
.chain(<ConstantLength<L> as Domain<F, RATE>>::padding(L).map(PaddedWord::Padding))
|
||||
.enumerate()
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
//! The Poseidon algebraic hash function.
|
||||
|
||||
use std::array;
|
||||
use std::convert::TryInto;
|
||||
use std::fmt;
|
||||
use std::iter;
|
||||
|
@ -363,8 +362,9 @@ impl<F: FieldExt, S: Spec<F, T, RATE>, const T: usize, const RATE: usize, const
|
|||
{
|
||||
/// Hashes the given input.
|
||||
pub fn hash(mut self, message: [F; L]) -> F {
|
||||
for value in
|
||||
array::IntoIter::new(message).chain(<ConstantLength<L> as Domain<F, RATE>>::padding(L))
|
||||
for value in message
|
||||
.into_iter()
|
||||
.chain(<ConstantLength<L> as Domain<F, RATE>>::padding(L))
|
||||
{
|
||||
self.sponge.absorb(value);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use super::super::{util::*, Gate};
|
||||
use halo2_proofs::{
|
||||
arithmetic::FieldExt,
|
||||
plonk::{Constraints, Expression},
|
||||
plonk::{Constraint, Constraints, Expression},
|
||||
};
|
||||
use std::{array, marker::PhantomData};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
pub struct CompressionGate<F: FieldExt>(PhantomData<F>);
|
||||
|
||||
|
@ -426,23 +426,19 @@ impl<F: FieldExt> CompressionGate<F> {
|
|||
lo_3: Expression<F>,
|
||||
hi_3: Expression<F>,
|
||||
word_3: Expression<F>,
|
||||
) -> Constraints<
|
||||
F,
|
||||
(&'static str, Expression<F>),
|
||||
impl Iterator<Item = (&'static str, Expression<F>)>,
|
||||
> {
|
||||
) -> impl IntoIterator<Item = Constraint<F>> {
|
||||
let check_lo_hi = |lo: Expression<F>, hi: Expression<F>, word: Expression<F>| {
|
||||
lo + hi * F::from(1 << 16) - word
|
||||
};
|
||||
|
||||
Constraints::with_selector(
|
||||
s_digest,
|
||||
array::IntoIter::new([
|
||||
[
|
||||
("check_lo_hi_0", check_lo_hi(lo_0, hi_0, word_0)),
|
||||
("check_lo_hi_1", check_lo_hi(lo_1, hi_1, word_1)),
|
||||
("check_lo_hi_2", check_lo_hi(lo_2, hi_2, word_2)),
|
||||
("check_lo_hi_3", check_lo_hi(lo_3, hi_3, word_3)),
|
||||
]),
|
||||
],
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use super::super::Gate;
|
||||
use halo2_proofs::{arithmetic::FieldExt, plonk::Expression};
|
||||
use std::{array, marker::PhantomData};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
pub struct ScheduleGate<F: FieldExt>(PhantomData<F>);
|
||||
|
||||
|
@ -29,7 +29,8 @@ impl<F: FieldExt> ScheduleGate<F> {
|
|||
+ (word * (-F::one()));
|
||||
let carry_check = Gate::range_check(carry, 0, 3);
|
||||
|
||||
array::IntoIter::new([("word_check", word_check), ("carry_check", carry_check)])
|
||||
[("word_check", word_check), ("carry_check", carry_check)]
|
||||
.into_iter()
|
||||
.map(move |(name, poly)| (name, s_word.clone() * poly))
|
||||
}
|
||||
|
||||
|
@ -65,11 +66,12 @@ impl<F: FieldExt> ScheduleGate<F> {
|
|||
let range_check_tag_c = Gate::range_check(tag_c, 0, 2);
|
||||
let range_check_tag_d = Gate::range_check(tag_d, 0, 4);
|
||||
|
||||
array::IntoIter::new([
|
||||
[
|
||||
("decompose_check", decompose_check),
|
||||
("range_check_tag_c", range_check_tag_c),
|
||||
("range_check_tag_d", range_check_tag_d),
|
||||
])
|
||||
]
|
||||
.into_iter()
|
||||
.map(move |(name, poly)| (name, s_decompose_1.clone() * poly))
|
||||
}
|
||||
|
||||
|
@ -101,11 +103,12 @@ impl<F: FieldExt> ScheduleGate<F> {
|
|||
let range_check_tag_d = Gate::range_check(tag_d, 0, 0);
|
||||
let range_check_tag_g = Gate::range_check(tag_g, 0, 3);
|
||||
|
||||
array::IntoIter::new([
|
||||
[
|
||||
("decompose_check", decompose_check),
|
||||
("range_check_tag_g", range_check_tag_g),
|
||||
("range_check_tag_d", range_check_tag_d),
|
||||
])
|
||||
]
|
||||
.into_iter()
|
||||
.map(move |(name, poly)| (name, s_decompose_2.clone() * poly))
|
||||
}
|
||||
|
||||
|
@ -130,11 +133,12 @@ impl<F: FieldExt> ScheduleGate<F> {
|
|||
let range_check_tag_a = Gate::range_check(tag_a, 0, 1);
|
||||
let range_check_tag_d = Gate::range_check(tag_d, 0, 3);
|
||||
|
||||
array::IntoIter::new([
|
||||
[
|
||||
("decompose_check", decompose_check),
|
||||
("range_check_tag_a", range_check_tag_a),
|
||||
("range_check_tag_d", range_check_tag_d),
|
||||
])
|
||||
]
|
||||
.into_iter()
|
||||
.map(move |(name, poly)| (name, s_decompose_3.clone() * poly))
|
||||
}
|
||||
|
||||
|
|
|
@ -259,10 +259,7 @@ where
|
|||
lhs - rhs
|
||||
};
|
||||
|
||||
Constraints::with_selector(
|
||||
q_s1,
|
||||
std::array::IntoIter::new([("Secant line", secant_line), ("y check", y_check)]),
|
||||
)
|
||||
Constraints::with_selector(q_s1, [("Secant line", secant_line), ("y check", y_check)])
|
||||
});
|
||||
|
||||
config
|
||||
|
|
|
@ -25,7 +25,6 @@ use crate::{
|
|||
},
|
||||
};
|
||||
use group::ff::PrimeField;
|
||||
use std::array;
|
||||
|
||||
/// Configuration for the `MerkleChip` implementation.
|
||||
#[derive(Clone, Debug)]
|
||||
|
@ -165,12 +164,12 @@ where
|
|||
|
||||
Constraints::with_selector(
|
||||
q_decompose,
|
||||
array::IntoIter::new([
|
||||
[
|
||||
("l_check", l_check),
|
||||
("left_check", left_check),
|
||||
("right_check", right_check),
|
||||
("b1_b2_check", b1_b2_check),
|
||||
]),
|
||||
],
|
||||
)
|
||||
});
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use halo2_proofs::{
|
|||
plonk::{Advice, Column, Error, Expression},
|
||||
};
|
||||
use pasta_curves::arithmetic::FieldExt;
|
||||
use std::{array, ops::Range};
|
||||
use std::ops::Range;
|
||||
|
||||
pub mod cond_swap;
|
||||
pub mod decompose_running_sum;
|
||||
|
@ -64,7 +64,7 @@ pub(crate) fn transpose_option_array<T: Copy + std::fmt::Debug, const LEN: usize
|
|||
) -> [Option<T>; LEN] {
|
||||
let mut ret = [None; LEN];
|
||||
if let Some(arr) = option_array {
|
||||
for (entry, value) in ret.iter_mut().zip(array::IntoIter::new(arr)) {
|
||||
for (entry, value) in ret.iter_mut().zip(arr) {
|
||||
*entry = Some(value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use halo2_proofs::{
|
|||
poly::Rotation,
|
||||
};
|
||||
use pasta_curves::arithmetic::FieldExt;
|
||||
use std::{array, marker::PhantomData};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
/// Instructions for a conditional swap gadget.
|
||||
pub trait CondSwapInstructions<F: FieldExt>: UtilitiesInstructions<F> {
|
||||
|
@ -191,11 +191,11 @@ impl<F: FieldExt> CondSwapChip<F> {
|
|||
|
||||
Constraints::with_selector(
|
||||
q_swap,
|
||||
array::IntoIter::new([
|
||||
[
|
||||
("a check", a_check),
|
||||
("b check", b_check),
|
||||
("swap is bool", bool_check),
|
||||
]),
|
||||
],
|
||||
)
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue