halo2_ecc/bigint/
big_is_zero.rsuse super::{OverflowInteger, ProperCrtUint, ProperUint};
use halo2_base::{gates::GateInstructions, utils::ScalarField, AssignedValue, Context};
pub fn positive<F: ScalarField>(
gate: &impl GateInstructions<F>,
ctx: &mut Context<F>,
a: OverflowInteger<F>,
) -> AssignedValue<F> {
let k = a.limbs.len();
assert_ne!(k, 0);
assert!(a.max_limb_bits as u32 + k.ilog2() < F::CAPACITY);
let sum = gate.sum(ctx, a.limbs);
gate.is_zero(ctx, sum)
}
pub fn assign<F: ScalarField>(
gate: &impl GateInstructions<F>,
ctx: &mut Context<F>,
a: ProperUint<F>,
) -> AssignedValue<F> {
assert!(!a.0.is_empty());
let mut a_limbs = a.0.into_iter();
let mut partial = gate.is_zero(ctx, a_limbs.next().unwrap());
for a_limb in a_limbs {
let limb_is_zero = gate.is_zero(ctx, a_limb);
partial = gate.and(ctx, limb_is_zero, partial);
}
partial
}
pub fn crt<F: ScalarField>(
gate: &impl GateInstructions<F>,
ctx: &mut Context<F>,
a: ProperCrtUint<F>,
) -> AssignedValue<F> {
assign(gate, ctx, ProperUint(a.0.truncation.limbs))
}