From ad0eb3ccd1c011c0506ced8377f002b2842fd84a Mon Sep 17 00:00:00 2001 From: enitrat Date: Fri, 22 Nov 2024 00:26:32 +0800 Subject: [PATCH] add debug prints to locate long operations --- crates/evm/src/precompiles/modexp.cairo | 2 ++ crates/utils/src/crypto/modexp/lib.cairo | 4 ++++ crates/utils/src/crypto/modexp/mpnat.cairo | 11 ++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/evm/src/precompiles/modexp.cairo b/crates/evm/src/precompiles/modexp.cairo index d2b35b73e..4bf993da8 100644 --- a/crates/evm/src/precompiles/modexp.cairo +++ b/crates/evm/src/precompiles/modexp.cairo @@ -26,6 +26,7 @@ pub impl ModExp of Precompile { } fn exec(input: Span) -> Result<(u64, Span), EVMError> { + println!("Start: Executing Modexp Precompile"); // The format of input is: // // Where every length is a 32-byte left-padded integer representing the number of bytes @@ -98,6 +99,7 @@ pub impl ModExp of Precompile { let output = modexp(base, exponent, modulus); let return_data = output.pad_left_with_zeroes(mod_len); + println!("End: Executing Modexp Precompile"); Result::Ok((gas.into(), return_data)) } } diff --git a/crates/utils/src/crypto/modexp/lib.cairo b/crates/utils/src/crypto/modexp/lib.cairo index a904bf8af..0d0f707ec 100644 --- a/crates/utils/src/crypto/modexp/lib.cairo +++ b/crates/utils/src/crypto/modexp/lib.cairo @@ -7,13 +7,17 @@ use crate::felt_vec::{Felt252VecTrait}; /// Computes `(base ^ exp) % modulus`, where all values are given as big-endian /// encoded bytes. pub fn modexp(base: Span, exp: Span, modulus: Span) -> Span { + println!("Start: MPNAT::from_big_endian operation"); let mut x = MPNatTrait::from_big_endian(base); let mut m = MPNatTrait::from_big_endian(modulus); + println!("End: MPNAT::from_big_endian operation"); if m.digits.len == 1 && m.digits[0] == 0 { return [].span(); } + println!("Start: modpow operation"); let mut result = x.modpow(exp, ref m); + println!("End: modpow operation"); result.digits.to_be_bytes() } diff --git a/crates/utils/src/crypto/modexp/mpnat.cairo b/crates/utils/src/crypto/modexp/mpnat.cairo index 5f461837f..f04238306 100644 --- a/crates/utils/src/crypto/modexp/mpnat.cairo +++ b/crates/utils/src/crypto/modexp/mpnat.cairo @@ -384,9 +384,13 @@ pub impl MPNatTraitImpl of MPNatTrait { } if modulus.is_power_of_two() { // return + println!("Start: modpow_with_power_of_two operation"); return self.modpow_with_power_of_two(exp, ref modulus); + println!("End: modpow_with_power_of_two operation"); } else if modulus.is_odd() { + println!("Start: modpow_montgomery operation"); return self.modpow_montgomery(exp, ref modulus); + println!("End: modpow_montgomery operation"); } // If the modulus is not a power of two and not an odd number then @@ -457,13 +461,18 @@ pub impl MPNatTraitImpl of MPNatTrait { }; let mut base_copy = MPNat { digits: self.digits.duplicate(), }; + println!("Start: modpow_montgomery operation"); let mut x1 = base_copy.modpow_montgomery(exp, ref odd); + println!("End: modpow_montgomery operation"); + println!("Start: modpow_with_power_of_two operation"); let mut x2 = self.modpow_with_power_of_two(exp, ref power_of_two); + println!("End: modpow_with_power_of_two operation"); + println!("Start: koc_2017_inverse operation"); let mut odd_inv = Self::koc_2017_inverse( ref odd, trailing_zeros * WORD_BITS + additional_zero_bits ); - + println!("End: koc_2017_inverse operation"); let s = power_of_two.digits.len(); let mut scratch: Felt252Vec = Felt252VecImpl::new(); scratch.expand(s).unwrap();