Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions crates/core/executor/src/syscalls/precompiles/fptower/fp2_mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,18 @@ impl<P: FpOpField> Syscall for Fp2MulSyscall<P> {
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);
Expand Down