diff --git a/crates/core/executor/src/syscalls/precompiles/fptower/fp2_mul.rs b/crates/core/executor/src/syscalls/precompiles/fptower/fp2_mul.rs index c3f87d35..8e8ba828 100644 --- a/crates/core/executor/src/syscalls/precompiles/fptower/fp2_mul.rs +++ b/crates/core/executor/src/syscalls/precompiles/fptower/fp2_mul.rs @@ -56,12 +56,18 @@ impl Syscall for Fp2MulSyscall

{ let bc1 = &BigUint::from_slice(bc1); let modulus = &BigUint::from_bytes_le(P::MODULUS); + // Pre-compute products to avoid redundant BigUint multiplications + let ac0_bc0 = (ac0 * bc0) % modulus; + let ac1_bc1 = (ac1 * bc1) % modulus; + let ac0_bc1 = (ac0 * bc1) % modulus; + let ac1_bc0 = (ac1 * bc0) % modulus; + #[allow(clippy::match_bool)] - let c0 = match (ac0 * bc0) % modulus < (ac1 * bc1) % modulus { - true => ((modulus + (ac0 * bc0) % modulus) - (ac1 * bc1) % modulus) % modulus, - false => ((ac0 * bc0) % modulus - (ac1 * bc1) % modulus) % modulus, + let c0 = match ac0_bc0 < ac1_bc1 { + true => ((modulus + &ac0_bc0) - &ac1_bc1) % modulus, + false => (&ac0_bc0 - &ac1_bc1) % modulus, }; - let c1 = ((ac0 * bc1) % modulus + (ac1 * bc0) % modulus) % modulus; + let c1 = (&ac0_bc1 + &ac1_bc0) % modulus; let mut result = c0.to_u32_digits(); result.resize(num_words / 2, 0);