halo2_ecc/bigint/
big_is_equal.rs

1use super::ProperUint;
2use halo2_base::{gates::GateInstructions, utils::ScalarField, AssignedValue, Context};
3use itertools::Itertools;
4
5/// Given [`ProperUint`]s `a` and `b` with the same number of limbs,
6/// returns whether `a == b`.
7///
8/// # Assumptions:
9/// * `a, b` have the same number of limbs.
10/// * The number of limbs is nonzero.
11pub fn assign<F: ScalarField>(
12    gate: &impl GateInstructions<F>,
13    ctx: &mut Context<F>,
14    a: impl Into<ProperUint<F>>,
15    b: impl Into<ProperUint<F>>,
16) -> AssignedValue<F> {
17    let a = a.into();
18    let b = b.into();
19    debug_assert!(!a.0.is_empty());
20
21    let mut a_limbs = a.0.into_iter();
22    let mut b_limbs = b.0.into_iter();
23    let mut partial = gate.is_equal(ctx, a_limbs.next().unwrap(), b_limbs.next().unwrap());
24    for (a_limb, b_limb) in a_limbs.zip_eq(b_limbs) {
25        let eq_limb = gate.is_equal(ctx, a_limb, b_limb);
26        partial = gate.and(ctx, eq_limb, partial);
27    }
28    partial
29}