diff --git a/book/src/user/wasm-port.md b/book/src/user/wasm-port.md index 97ad346b..97c56917 100644 --- a/book/src/user/wasm-port.md +++ b/book/src/user/wasm-port.md @@ -12,7 +12,7 @@ In the case of Zordle, this code is contained in [wasm.rs](https://github.com/na ### Prover -```rust +```rust,ignore #[wasm_bindgen] pub async fn prove_play(final_word: String, words_js: JsValue, params_ser: JsValue) -> JsValue { // Steps: @@ -34,7 +34,7 @@ The output is a `Vec` converted to a `JSValue` using Serde. This is later pa ### Verifier -```rust +```rust,ignore #[wasm_bindgen] pub fn verify_play(final_word: String, proof_js: JsValue, diffs_u64_js: JsValue, params_ser: JsValue) -> bool { // Steps: @@ -51,7 +51,7 @@ Similar to the prover, we take in input and output a boolean true/false indicati Additionally, both the prover and verifier functions input `params_ser`, a serialised form of the public parameters of the polynomial commitment scheme. These are passed in as input (instead of being regenerated in prove/verify functions) as a performance optimisation since these are constant based only on the circuit's value of `K`. We can store these seperately on a static web server and pass them in as input to the WASM. To generate the binary serialised form of these (seperately outside the WASM functions), you can run something like: -```rust +```rust,ignore fn write_params(K: u32) { let mut params_file = File::create("params.bin").unwrap(); let params: Params = Params::new(K); @@ -124,4 +124,4 @@ Often, you'll run into issues with your Rust code and see that the WASM executio ## Credits -This guide was written by [Nalin](https://twitter.com/nibnalin). Thanks additionally to [Uma](https://twitter.com/pumatheuma) and [Blaine](https://twitter.com/BlaineBublitz) for significant work on figuring out these steps. Feel free to reach out to me if you have trouble with any of these steps. \ No newline at end of file +This guide was written by [Nalin](https://twitter.com/nibnalin). Thanks additionally to [Uma](https://twitter.com/pumatheuma) and [Blaine](https://twitter.com/BlaineBublitz) for significant work on figuring out these steps. Feel free to reach out to me if you have trouble with any of these steps. diff --git a/halo2_gadgets/benches/poseidon.rs b/halo2_gadgets/benches/poseidon.rs index a25b7c21..9b80b560 100644 --- a/halo2_gadgets/benches/poseidon.rs +++ b/halo2_gadgets/benches/poseidon.rs @@ -131,7 +131,7 @@ impl Spec for MySpec<3, 2> { } fn sbox(val: Fp) -> Fp { - val.pow_vartime(&[5]) + val.pow_vartime([5]) } fn secure_mds() -> usize { @@ -153,7 +153,7 @@ impl Spec for MySpec<9, 8> { } fn sbox(val: Fp) -> Fp { - val.pow_vartime(&[5]) + val.pow_vartime([5]) } fn secure_mds() -> usize { @@ -175,7 +175,7 @@ impl Spec for MySpec<12, 11> { } fn sbox(val: Fp) -> Fp { - val.pow_vartime(&[5]) + val.pow_vartime([5]) } fn secure_mds() -> usize { diff --git a/halo2_gadgets/benches/sha256.rs b/halo2_gadgets/benches/sha256.rs index baf9c977..e289d390 100644 --- a/halo2_gadgets/benches/sha256.rs +++ b/halo2_gadgets/benches/sha256.rs @@ -79,18 +79,18 @@ fn bench(name: &str, k: u32, c: &mut Criterion) { // Initialize the polynomial commitment parameters let params_path = Path::new("./benches/sha256_assets/sha256_params"); - if File::open(¶ms_path).is_err() { + if File::open(params_path).is_err() { let params: Params = Params::new(k); let mut buf = Vec::new(); params.write(&mut buf).expect("Failed to write params"); - let mut file = File::create(¶ms_path).expect("Failed to create sha256_params"); + let mut file = File::create(params_path).expect("Failed to create sha256_params"); file.write_all(&buf[..]) .expect("Failed to write params to file"); } - let params_fs = File::open(¶ms_path).expect("couldn't load sha256_params"); + let params_fs = File::open(params_path).expect("couldn't load sha256_params"); let params: Params = Params::read::<_>(&mut BufReader::new(params_fs)).expect("Failed to read params"); @@ -117,16 +117,16 @@ fn bench(name: &str, k: u32, c: &mut Criterion) { // Create a proof let proof_path = Path::new("./benches/sha256_assets/sha256_proof"); - if File::open(&proof_path).is_err() { + if File::open(proof_path).is_err() { let mut transcript = Blake2bWrite::<_, _, Challenge255<_>>::init(vec![]); create_proof(¶ms, &pk, &[circuit], &[], OsRng, &mut transcript) .expect("proof generation should not fail"); let proof: Vec = transcript.finalize(); - let mut file = File::create(&proof_path).expect("Failed to create sha256_proof"); + let mut file = File::create(proof_path).expect("Failed to create sha256_proof"); file.write_all(&proof[..]).expect("Failed to write proof"); } - let mut proof_fs = File::open(&proof_path).expect("couldn't load sha256_proof"); + let mut proof_fs = File::open(proof_path).expect("couldn't load sha256_proof"); let mut proof = Vec::::new(); proof_fs .read_to_end(&mut proof) diff --git a/halo2_gadgets/src/ecc.rs b/halo2_gadgets/src/ecc.rs index 3cd2d87a..38fab0a4 100644 --- a/halo2_gadgets/src/ecc.rs +++ b/halo2_gadgets/src/ecc.rs @@ -437,14 +437,14 @@ impl + Clone + Debug + Eq> Point> { - chip: EccChip, inner: EccChip::X, } impl> X { /// Wraps the given x-coordinate (obtained directly from an instruction) in a gadget. pub fn from_inner(chip: EccChip, inner: EccChip::X) -> Self { - X { chip, inner } + let _ = chip; // unused + X { inner } } /// Returns the inner x-coordinate. diff --git a/halo2_gadgets/src/ecc/chip/mul_fixed.rs b/halo2_gadgets/src/ecc/chip/mul_fixed.rs index df456853..c1aa5c08 100644 --- a/halo2_gadgets/src/ecc/chip/mul_fixed.rs +++ b/halo2_gadgets/src/ecc/chip/mul_fixed.rs @@ -493,7 +493,7 @@ impl ScalarFixed { .by_vals() .take(FIXED_BASE_WINDOW_SIZE) .rev() - .fold(0, |acc, b| 2 * acc + if b { 1 } else { 0 }) + .fold(0, |acc, b| 2 * acc + usize::from(b)) }) }) .collect::>() diff --git a/halo2_gadgets/src/poseidon/pow5.rs b/halo2_gadgets/src/poseidon/pow5.rs index 9c98eb75..6c125ea6 100644 --- a/halo2_gadgets/src/poseidon/pow5.rs +++ b/halo2_gadgets/src/poseidon/pow5.rs @@ -33,7 +33,6 @@ pub struct Pow5Config { alpha: [u64; 4], round_constants: Vec<[F; WIDTH]>, m_reg: Mds, - m_inv: Mds, } /// A Poseidon chip using an $x^5$ S-Box. @@ -200,7 +199,6 @@ impl Pow5Chip { alpha, round_constants, m_reg, - m_inv, } } diff --git a/halo2_gadgets/src/poseidon/primitives/p128pow5t3.rs b/halo2_gadgets/src/poseidon/primitives/p128pow5t3.rs index dffa30bc..fe98517e 100644 --- a/halo2_gadgets/src/poseidon/primitives/p128pow5t3.rs +++ b/halo2_gadgets/src/poseidon/primitives/p128pow5t3.rs @@ -22,7 +22,7 @@ impl Spec for P128Pow5T3 { } fn sbox(val: Fp) -> Fp { - val.pow_vartime(&[5]) + val.pow_vartime([5]) } fn secure_mds() -> usize { @@ -48,7 +48,7 @@ impl Spec for P128Pow5T3 { } fn sbox(val: Fq) -> Fq { - val.pow_vartime(&[5]) + val.pow_vartime([5]) } fn secure_mds() -> usize { @@ -101,7 +101,7 @@ mod tests { } fn sbox(val: F) -> F { - val.pow_vartime(&[5]) + val.pow_vartime([5]) } fn secure_mds() -> usize { diff --git a/halo2_gadgets/src/sha256/table16/compression/compression_util.rs b/halo2_gadgets/src/sha256/table16/compression/compression_util.rs index cf4c366e..75f6e0b5 100644 --- a/halo2_gadgets/src/sha256/table16/compression/compression_util.rs +++ b/halo2_gadgets/src/sha256/table16/compression/compression_util.rs @@ -111,7 +111,7 @@ pub fn get_round_row(round_idx: RoundIdx) -> usize { RoundIdx::Init => 0, RoundIdx::Main(MainRoundIdx(idx)) => { assert!(idx < 64); - (idx as usize) * SUBREGION_MAIN_WORD + idx * SUBREGION_MAIN_WORD } } } @@ -783,7 +783,7 @@ impl CompressionConfig { || "h_prime_carry", a_9, row + 1, - || h_prime_carry.map(|value| pallas::Base::from(value as u64)), + || h_prime_carry.map(pallas::Base::from), )?; let h_prime: Value<[bool; 32]> = h_prime.map(|w| i2lebsp(w.into())); diff --git a/halo2_gadgets/src/sha256/table16/message_schedule/schedule_util.rs b/halo2_gadgets/src/sha256/table16/message_schedule/schedule_util.rs index 93f16430..e1e9ca4a 100644 --- a/halo2_gadgets/src/sha256/table16/message_schedule/schedule_util.rs +++ b/halo2_gadgets/src/sha256/table16/message_schedule/schedule_util.rs @@ -40,20 +40,17 @@ pub fn get_word_row(word_idx: usize) -> usize { if word_idx == 0 { 0 } else if (1..=13).contains(&word_idx) { - SUBREGION_0_ROWS + SUBREGION_1_WORD * (word_idx - 1) as usize + SUBREGION_0_ROWS + SUBREGION_1_WORD * (word_idx - 1) } else if (14..=48).contains(&word_idx) { SUBREGION_0_ROWS + SUBREGION_1_ROWS + SUBREGION_2_WORD * (word_idx - 14) + 1 } else if (49..=61).contains(&word_idx) { - SUBREGION_0_ROWS - + SUBREGION_1_ROWS - + SUBREGION_2_ROWS - + SUBREGION_3_WORD * (word_idx - 49) as usize + SUBREGION_0_ROWS + SUBREGION_1_ROWS + SUBREGION_2_ROWS + SUBREGION_3_WORD * (word_idx - 49) } else { SUBREGION_0_ROWS + SUBREGION_1_ROWS + SUBREGION_2_ROWS + SUBREGION_3_ROWS - + DECOMPOSE_0_ROWS * (word_idx - 62) as usize + + DECOMPOSE_0_ROWS * (word_idx - 62) } } diff --git a/halo2_gadgets/src/sha256/table16/message_schedule/subregion1.rs b/halo2_gadgets/src/sha256/table16/message_schedule/subregion1.rs index e30c32ee..8c4e003a 100644 --- a/halo2_gadgets/src/sha256/table16/message_schedule/subregion1.rs +++ b/halo2_gadgets/src/sha256/table16/message_schedule/subregion1.rs @@ -14,8 +14,8 @@ pub struct Subregion1Word { index: usize, a: AssignedBits<3>, b: AssignedBits<4>, - c: AssignedBits<11>, - d: AssignedBits<14>, + _c: AssignedBits<11>, + _d: AssignedBits<14>, spread_c: AssignedBits<22>, spread_d: AssignedBits<28>, } @@ -142,8 +142,8 @@ impl MessageScheduleConfig { index, a, b, - c: spread_c.dense, - d: spread_d.dense, + _c: spread_c.dense, + _d: spread_d.dense, spread_c: spread_c.spread, spread_d: spread_d.spread, }) diff --git a/halo2_gadgets/src/sha256/table16/message_schedule/subregion2.rs b/halo2_gadgets/src/sha256/table16/message_schedule/subregion2.rs index e5e25fae..0480d044 100644 --- a/halo2_gadgets/src/sha256/table16/message_schedule/subregion2.rs +++ b/halo2_gadgets/src/sha256/table16/message_schedule/subregion2.rs @@ -15,10 +15,10 @@ pub struct Subregion2Word { a: AssignedBits<3>, b: AssignedBits<4>, c: AssignedBits<3>, - d: AssignedBits<7>, + _d: AssignedBits<7>, e: AssignedBits<1>, f: AssignedBits<1>, - g: AssignedBits<13>, + _g: AssignedBits<13>, spread_d: AssignedBits<14>, spread_g: AssignedBits<26>, } @@ -261,7 +261,7 @@ impl MessageScheduleConfig { || format!("carry_{}", new_word_idx), a_9, get_word_row(new_word_idx - 16) + 1, - || carry.map(|carry| pallas::Base::from(carry as u64)), + || carry.map(pallas::Base::from), )?; let (word, halves) = self.assign_word_and_halves(region, word, new_word_idx)?; w.push(MessageWord(word)); @@ -342,10 +342,10 @@ impl MessageScheduleConfig { a, b: spread_b.dense, c, - d: spread_d.dense, + _d: spread_d.dense, e, f, - g: spread_g.dense, + _g: spread_g.dense, spread_d: spread_d.spread, spread_g: spread_g.spread, }) diff --git a/halo2_gadgets/src/sha256/table16/message_schedule/subregion3.rs b/halo2_gadgets/src/sha256/table16/message_schedule/subregion3.rs index 6ce3d290..ddb36ebf 100644 --- a/halo2_gadgets/src/sha256/table16/message_schedule/subregion3.rs +++ b/halo2_gadgets/src/sha256/table16/message_schedule/subregion3.rs @@ -177,7 +177,7 @@ impl MessageScheduleConfig { || format!("carry_{}", new_word_idx), a_9, get_word_row(new_word_idx - 16) + 1, - || carry.map(|carry| pallas::Base::from(carry as u64)), + || carry.map(pallas::Base::from), )?; let (word, halves) = self.assign_word_and_halves(region, word, new_word_idx)?; w.push(MessageWord(word)); diff --git a/halo2_gadgets/src/sha256/table16/spread_table.rs b/halo2_gadgets/src/sha256/table16/spread_table.rs index 891799eb..7342e6af 100644 --- a/halo2_gadgets/src/sha256/table16/spread_table.rs +++ b/halo2_gadgets/src/sha256/table16/spread_table.rs @@ -69,7 +69,7 @@ impl SpreadWord { /// A variable stored in advice columns corresponding to a row of [`SpreadTableConfig`]. #[derive(Clone, Debug)] pub(super) struct SpreadVar { - pub tag: Value, + pub _tag: Value, pub dense: AssignedBits, pub spread: AssignedBits, } @@ -98,7 +98,11 @@ impl SpreadVar { let spread = AssignedBits::::assign_bits(region, || "spread", cols.spread, row, spread_val)?; - Ok(SpreadVar { tag, dense, spread }) + Ok(SpreadVar { + _tag: tag, + dense, + spread, + }) } pub(super) fn without_lookup( @@ -129,7 +133,11 @@ impl SpreadVar { spread_val, )?; - Ok(SpreadVar { tag, dense, spread }) + Ok(SpreadVar { + _tag: tag, + dense, + spread, + }) } } diff --git a/halo2_gadgets/src/sha256/table16/util.rs b/halo2_gadgets/src/sha256/table16/util.rs index 6a790d37..628f0374 100644 --- a/halo2_gadgets/src/sha256/table16/util.rs +++ b/halo2_gadgets/src/sha256/table16/util.rs @@ -110,7 +110,7 @@ pub fn sum_with_carry(words: Vec<(Value, Value)>) -> (Value, Valu sum_lo.zip(sum_hi).map(|(lo, hi)| lo + (1 << 16) * hi) }; - let carry = sum.map(|sum| (sum >> 32) as u64); + let carry = sum.map(|sum| sum >> 32); let sum = sum.map(|sum| sum as u32); (sum, carry) diff --git a/halo2_gadgets/src/sinsemilla.rs b/halo2_gadgets/src/sinsemilla.rs index bb662d3f..11e4b24a 100644 --- a/halo2_gadgets/src/sinsemilla.rs +++ b/halo2_gadgets/src/sinsemilla.rs @@ -166,7 +166,6 @@ pub struct MessagePiece + Clone + Debug + Eq, { - chip: SinsemillaChip, inner: SinsemillaChip::MessagePiece, } @@ -199,7 +198,7 @@ where // Each message piece must have at most `floor(C::Base::CAPACITY / K)` words. // This ensures that the all-ones bitstring is canonical in the field. let piece_max_num_words = C::Base::CAPACITY as usize / K; - assert!(num_words <= piece_max_num_words as usize); + assert!(num_words <= piece_max_num_words); // Closure to parse a bitstring (little-endian) into a base field element. let to_base_field = |bits: &[Value]| -> Value { @@ -227,7 +226,7 @@ where num_words: usize, ) -> Result { let inner = chip.witness_message_piece(layouter, field_elem, num_words)?; - Ok(Self { chip, inner }) + Ok(Self { inner }) } /// Constructs a `MessagePiece` by concatenating a sequence of [`RangeConstrained`] diff --git a/halo2_proofs/CHANGELOG.md b/halo2_proofs/CHANGELOG.md index 12bdcee8..7ae956b4 100644 --- a/halo2_proofs/CHANGELOG.md +++ b/halo2_proofs/CHANGELOG.md @@ -6,6 +6,15 @@ and this project adheres to Rust's notion of [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +- The following structs now derive the `Eq` trait: + - `halo2_proofs::dev`: + - `failure::FailureLocation` + - `failure::VerifyFailure` + - `metadata::Gate` + - `metadata::Constraint` + - `metadata::Region` + - `halo2_proofs::poly::Rotation` + ### Added - `halo2_proofs::arithmetic::FftGroup` - `halo2_proofs::circuit::layouter`: diff --git a/halo2_proofs/src/arithmetic.rs b/halo2_proofs/src/arithmetic.rs index 6c2b2af5..2bc2ce17 100644 --- a/halo2_proofs/src/arithmetic.rs +++ b/halo2_proofs/src/arithmetic.rs @@ -195,7 +195,7 @@ pub fn best_fft>(a: &mut [G], omega: Scalar, let threads = multicore::current_num_threads(); let log_threads = log2_floor(threads); - let n = a.len() as usize; + let n = a.len(); assert_eq!(n, 1 << log_n); for k in 0..n { @@ -206,7 +206,7 @@ pub fn best_fft>(a: &mut [G], omega: Scalar, } // precompute twiddle factors - let twiddles: Vec<_> = (0..(n / 2) as usize) + let twiddles: Vec<_> = (0..(n / 2)) .scan(Scalar::one(), |w, _| { let tw = *w; *w *= ω @@ -216,7 +216,7 @@ pub fn best_fft>(a: &mut [G], omega: Scalar, if log_n <= log_threads { let mut chunk = 2_usize; - let mut twiddle_chunk = (n / 2) as usize; + let mut twiddle_chunk = n / 2; for _ in 0..log_n { a.chunks_mut(chunk).for_each(|coeffs| { let (left, right) = coeffs.split_at_mut(chunk / 2); @@ -339,9 +339,9 @@ where pub fn parallelize(v: &mut [T], f: F) { let n = v.len(); let num_threads = multicore::current_num_threads(); - let mut chunk = (n as usize) / num_threads; + let mut chunk = n / num_threads; if chunk < num_threads { - chunk = n as usize; + chunk = n; } multicore::scope(|scope| { @@ -374,7 +374,7 @@ pub fn lagrange_interpolate(points: &[F], evals: &[F]) -> Vec { assert_eq!(points.len(), evals.len()); if points.len() == 1 { // Constant polynomial - return vec![evals[0]]; + vec![evals[0]] } else { let mut denoms = Vec::with_capacity(points.len()); for (j, x_j) in points.iter().enumerate() { diff --git a/halo2_proofs/src/circuit/floor_planner/v1.rs b/halo2_proofs/src/circuit/floor_planner/v1.rs index b6f18215..fe24d10e 100644 --- a/halo2_proofs/src/circuit/floor_planner/v1.rs +++ b/halo2_proofs/src/circuit/floor_planner/v1.rs @@ -81,8 +81,8 @@ impl FloorPlanner for V1 { // - Determine how many rows our planned circuit will require. let first_unassigned_row = column_allocations - .iter() - .map(|(_, a)| a.unbounded_interval_start()) + .values() + .map(|a| a.unbounded_interval_start()) .max() .unwrap_or(0); diff --git a/halo2_proofs/src/dev/cost.rs b/halo2_proofs/src/dev/cost.rs index ceb20acb..7f82f1b2 100644 --- a/halo2_proofs/src/dev/cost.rs +++ b/halo2_proofs/src/dev/cost.rs @@ -21,6 +21,7 @@ use crate::{ }; /// Measures a circuit to determine its costs, and explain what contributes to them. +#[allow(dead_code)] #[derive(Debug)] pub struct CircuitCost> { /// Power-of-2 bound on the number of rows in the circuit. @@ -54,6 +55,7 @@ pub struct CircuitCost> { } /// Region implementation used by Layout +#[allow(dead_code)] #[derive(Debug)] pub(crate) struct LayoutRegion { /// The name of the region. Not required to be unique. diff --git a/halo2_proofs/src/dev/failure.rs b/halo2_proofs/src/dev/failure.rs index c08d1abe..c6c5aecf 100644 --- a/halo2_proofs/src/dev/failure.rs +++ b/halo2_proofs/src/dev/failure.rs @@ -16,7 +16,7 @@ use crate::{ mod emitter; /// The location within the circuit at which a particular [`VerifyFailure`] occurred. -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub enum FailureLocation { /// A location inside a region. InRegion { @@ -100,16 +100,14 @@ impl FailureLocation { }) .map(|(r_i, r)| FailureLocation::InRegion { region: (r_i, r.name.clone()).into(), - offset: failure_row as usize - r.rows.unwrap().0 as usize, - }) - .unwrap_or_else(|| FailureLocation::OutsideRegion { - row: failure_row as usize, + offset: failure_row - r.rows.unwrap().0, }) + .unwrap_or_else(|| FailureLocation::OutsideRegion { row: failure_row }) } } /// The reasons why a particular circuit is not satisfied. -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub enum VerifyFailure { /// A cell used in an active gate was not assigned to. CellNotAssigned { diff --git a/halo2_proofs/src/dev/graph/layout.rs b/halo2_proofs/src/dev/graph/layout.rs index 6cafd087..965e0683 100644 --- a/halo2_proofs/src/dev/graph/layout.rs +++ b/halo2_proofs/src/dev/graph/layout.rs @@ -178,7 +178,7 @@ impl CircuitLayout { root.draw(&Rectangle::new( [(0, 0), (total_columns, view_bottom)], - &BLACK, + BLACK, ))?; let draw_region = |root: &DrawingArea<_, _>, top_left, bottom_right| { @@ -194,7 +194,7 @@ impl CircuitLayout { [top_left, bottom_right], ShapeStyle::from(&GREEN.mix(0.2)).filled(), ))?; - root.draw(&Rectangle::new([top_left, bottom_right], &BLACK))?; + root.draw(&Rectangle::new([top_left, bottom_right], BLACK))?; Ok(()) }; diff --git a/halo2_proofs/src/dev/metadata.rs b/halo2_proofs/src/dev/metadata.rs index d7d2443e..9a47e3cb 100644 --- a/halo2_proofs/src/dev/metadata.rs +++ b/halo2_proofs/src/dev/metadata.rs @@ -83,7 +83,7 @@ impl fmt::Display for VirtualCell { } /// Metadata about a configured gate within a circuit. -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub struct Gate { /// The index of the active gate. These indices are assigned in the order in which /// `ConstraintSystem::create_gate` is called during `Circuit::configure`. @@ -106,7 +106,7 @@ impl From<(usize, &'static str)> for Gate { } /// Metadata about a configured constraint within a circuit. -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub struct Constraint { /// The gate containing the constraint. pub(super) gate: Gate, @@ -143,7 +143,7 @@ impl From<(Gate, usize, &'static str)> for Constraint { } /// Metadata about an assigned region within a circuit. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct Region { /// The index of the region. These indices are assigned in the order in which /// `Layouter::assign_region` is called during `Circuit::synthesize`. diff --git a/halo2_proofs/src/plonk/assigned.rs b/halo2_proofs/src/plonk/assigned.rs index 06b00b9d..27785ed4 100644 --- a/halo2_proofs/src/plonk/assigned.rs +++ b/halo2_proofs/src/plonk/assigned.rs @@ -612,7 +612,7 @@ mod proptests { // Ensure that: // - we have at least one value to apply unary operators to. // - we can apply every binary operator pairwise sequentially. - cmp::max(if num_unary > 0 { 1 } else { 0 }, num_binary + 1)), + cmp::max(usize::from(num_unary > 0), num_binary + 1)), operations in arb_operators(num_unary, num_binary).prop_shuffle(), ) -> (Vec>, Vec) { (values, operations) diff --git a/halo2_proofs/src/plonk/circuit/compress_selectors.rs b/halo2_proofs/src/plonk/circuit/compress_selectors.rs index c3a1485d..81dc27d2 100644 --- a/halo2_proofs/src/plonk/circuit/compress_selectors.rs +++ b/halo2_proofs/src/plonk/circuit/compress_selectors.rs @@ -70,33 +70,30 @@ where // All provided selectors of degree 0 are assumed to be either concrete // selectors or do not appear in a gate. Let's address these first. - selectors = selectors - .into_iter() - .filter(|selector| { - if selector.max_degree == 0 { - // This is a complex selector, or a selector that does not appear in any - // gate constraint. - let expression = allocate_fixed_column(); + selectors.retain(|selector| { + if selector.max_degree == 0 { + // This is a complex selector, or a selector that does not appear in any + // gate constraint. + let expression = allocate_fixed_column(); - let combination_assignment = selector - .activations - .iter() - .map(|b| if *b { F::one() } else { F::zero() }) - .collect::>(); - let combination_index = combination_assignments.len(); - combination_assignments.push(combination_assignment); - selector_assignments.push(SelectorAssignment { - selector: selector.selector, - combination_index, - expression, - }); + let combination_assignment = selector + .activations + .iter() + .map(|b| if *b { F::one() } else { F::zero() }) + .collect::>(); + let combination_index = combination_assignments.len(); + combination_assignments.push(combination_assignment); + selector_assignments.push(SelectorAssignment { + selector: selector.selector, + combination_index, + expression, + }); - false - } else { - true - } - }) - .collect(); + false + } else { + true + } + }); // All of the remaining `selectors` are simple. Let's try to combine them. // First, we compute the exclusion matrix that has (j, k) = true if selector diff --git a/halo2_proofs/src/plonk/lookup/prover.rs b/halo2_proofs/src/plonk/lookup/prover.rs index a29c6441..2b08bf14 100644 --- a/halo2_proofs/src/plonk/lookup/prover.rs +++ b/halo2_proofs/src/plonk/lookup/prover.rs @@ -613,7 +613,7 @@ fn permute_expression_pair( // Populate permuted table at unfilled rows with leftover table elements for (coeff, count) in leftover_table_map.iter() { for _ in 0..*count { - permuted_table_coeffs[repeated_input_rows.pop().unwrap() as usize] = *coeff; + permuted_table_coeffs[repeated_input_rows.pop().unwrap()] = *coeff; } } assert!(repeated_input_rows.is_empty()); diff --git a/halo2_proofs/src/plonk/permutation/prover.rs b/halo2_proofs/src/plonk/permutation/prover.rs index 84971173..2d792d60 100644 --- a/halo2_proofs/src/plonk/permutation/prover.rs +++ b/halo2_proofs/src/plonk/permutation/prover.rs @@ -128,7 +128,7 @@ impl Argument { Any::Instance => instance, }; parallelize(&mut modified_values, |modified_values, start| { - let mut deltaomega = deltaomega * &omega.pow_vartime(&[start as u64, 0, 0, 0]); + let mut deltaomega = deltaomega * &omega.pow_vartime([start as u64, 0, 0, 0]); for (modified_values, value) in modified_values .iter_mut() .zip(values[column.index()][start..].iter()) @@ -292,7 +292,7 @@ impl Committed { let mut right = poly::Ast::from(set.permutation_product_coset); let mut current_delta = *beta - * &(C::Scalar::DELTA.pow_vartime(&[(chunk_index * chunk_len) as u64])); + * &(C::Scalar::DELTA.pow_vartime([(chunk_index * chunk_len) as u64])); for values in columns.iter().map(|&column| match column.column_type() { Any::Advice => &advice_cosets[column.index()], Any::Fixed => &fixed_cosets[column.index()], diff --git a/halo2_proofs/src/plonk/permutation/verifier.rs b/halo2_proofs/src/plonk/permutation/verifier.rs index 001e1230..d3e8808c 100644 --- a/halo2_proofs/src/plonk/permutation/verifier.rs +++ b/halo2_proofs/src/plonk/permutation/verifier.rs @@ -179,7 +179,7 @@ impl Evaluated { let mut right = set.permutation_product_eval; let mut current_delta = (*beta * &*x) - * &(C::Scalar::DELTA.pow_vartime(&[(chunk_index * chunk_len) as u64])); + * &(C::Scalar::DELTA.pow_vartime([(chunk_index * chunk_len) as u64])); for eval in columns.iter().map(|&column| match column.column_type() { Any::Advice => { advice_evals[vk.cs.get_any_query_index(column, Rotation::cur())] diff --git a/halo2_proofs/src/plonk/prover.rs b/halo2_proofs/src/plonk/prover.rs index 209d75c0..304244e8 100644 --- a/halo2_proofs/src/plonk/prover.rs +++ b/halo2_proofs/src/plonk/prover.rs @@ -596,7 +596,7 @@ pub fn create_proof< )?; let x: ChallengeX<_> = transcript.squeeze_challenge_scalar(); - let xn = x.pow(&[params.n as u64, 0, 0, 0]); + let xn = x.pow(&[params.n, 0, 0, 0]); // Compute and hash instance evals for each circuit instance for instance in instance.iter() { diff --git a/halo2_proofs/src/plonk/verifier.rs b/halo2_proofs/src/plonk/verifier.rs index 6bb2c0a6..98916cbb 100644 --- a/halo2_proofs/src/plonk/verifier.rs +++ b/halo2_proofs/src/plonk/verifier.rs @@ -203,7 +203,7 @@ pub fn verify_proof< // commitments open to the correct values. let vanishing = { // x^n - let xn = x.pow(&[params.n as u64, 0, 0, 0]); + let xn = x.pow(&[params.n, 0, 0, 0]); let blinding_factors = vk.cs.blinding_factors(); let l_evals = vk diff --git a/halo2_proofs/src/poly.rs b/halo2_proofs/src/poly.rs index 81c0525e..95170a06 100644 --- a/halo2_proofs/src/poly.rs +++ b/halo2_proofs/src/poly.rs @@ -304,7 +304,7 @@ impl Mul for Polynomial { /// Describes the relative rotation of a vector. Negative numbers represent /// reverse (leftmost) rotations and positive numbers represent forward (rightmost) /// rotations. Zero represents no rotation. -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] pub struct Rotation(pub i32); impl Rotation { diff --git a/halo2_proofs/src/poly/commitment.rs b/halo2_proofs/src/poly/commitment.rs index 06283f9b..80c8b093 100644 --- a/halo2_proofs/src/poly/commitment.rs +++ b/halo2_proofs/src/poly/commitment.rs @@ -82,7 +82,7 @@ impl Params { } let mut g_lagrange_projective = g_projective; best_fft(&mut g_lagrange_projective, alpha_inv, k); - let minv = C::Scalar::TWO_INV.pow_vartime(&[k as u64, 0, 0, 0]); + let minv = C::Scalar::TWO_INV.pow_vartime([k as u64, 0, 0, 0]); parallelize(&mut g_lagrange_projective, |g, _| { for g in g.iter_mut() { *g *= minv; diff --git a/halo2_proofs/src/poly/domain.rs b/halo2_proofs/src/poly/domain.rs index d83ce78e..9e0398b7 100644 --- a/halo2_proofs/src/poly/domain.rs +++ b/halo2_proofs/src/poly/domain.rs @@ -85,8 +85,8 @@ impl EvaluationDomain { { // Compute the evaluations of t(X) = X^n - 1 in the coset evaluation domain. // We don't have to compute all of them, because it will repeat. - let orig = F::ZETA.pow_vartime(&[n as u64, 0, 0, 0]); - let step = extended_omega.pow_vartime(&[n as u64, 0, 0, 0]); + let orig = F::ZETA.pow_vartime([n, 0, 0, 0]); + let step = extended_omega.pow_vartime([n, 0, 0, 0]); let mut cur = orig; loop { t_evaluations.push(cur); @@ -404,11 +404,11 @@ impl EvaluationDomain { pub fn rotate_omega(&self, value: F, rotation: Rotation) -> F { let mut point = value; if rotation.0 >= 0 { - point *= &self.get_omega().pow_vartime(&[rotation.0 as u64]); + point *= &self.get_omega().pow_vartime([rotation.0 as u64]); } else { point *= &self .get_omega_inv() - .pow_vartime(&[(rotation.0 as i64).unsigned_abs()]); + .pow_vartime([(rotation.0 as i64).unsigned_abs()]); } point } diff --git a/halo2_proofs/src/poly/evaluator.rs b/halo2_proofs/src/poly/evaluator.rs index 8f2b2014..04f509d3 100644 --- a/halo2_proofs/src/poly/evaluator.rs +++ b/halo2_proofs/src/poly/evaluator.rs @@ -540,7 +540,7 @@ impl BasisOps for LagrangeCoeff { let omega = domain.get_omega(); let start = chunk_size * chunk_index; (0..cmp::min(chunk_size, poly_len - start)) - .scan(omega.pow_vartime(&[start as u64]) * scalar, |acc, _| { + .scan(omega.pow_vartime([start as u64]) * scalar, |acc, _| { let ret = *acc; *acc *= omega; Some(ret) @@ -585,7 +585,7 @@ impl BasisOps for ExtendedLagrangeCoeff { let start = chunk_size * chunk_index; (0..cmp::min(chunk_size, poly_len - start)) .scan( - omega.pow_vartime(&[start as u64]) * F::ZETA * scalar, + omega.pow_vartime([start as u64]) * F::ZETA * scalar, |acc, _| { let ret = *acc; *acc *= omega;