From 2f06a78cb14c6767a134de3c1a6374d7f3f5346c Mon Sep 17 00:00:00 2001 From: wborgeaud Date: Fri, 25 Jun 2021 16:53:11 +0200 Subject: [PATCH] Simplify exp_u64 --- src/gadgets/arithmetic.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/gadgets/arithmetic.rs b/src/gadgets/arithmetic.rs index 73455797..bda70624 100644 --- a/src/gadgets/arithmetic.rs +++ b/src/gadgets/arithmetic.rs @@ -176,16 +176,8 @@ impl, const D: usize> CircuitBuilder { /// Exponentiate `base` to the power of a known `exponent`. // TODO: Test pub fn exp_u64(&mut self, base: Target, exponent: u64) -> Target { - let mut current = base; - let mut product = self.one(); - - for j in 0..bits_u64(exponent as u64) { - if (exponent >> j & 1) != 0 { - product = self.mul(product, current); - } - current = self.square(current); - } - product + let base_ext = self.convert_to_ext(base); + self.exp_u64_extension(base_ext, exponent).0[0] } /// Computes `q = x / y` by witnessing `q` and requiring that `q * y = x`. This can be unsafe in