Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Sep 9, 2024
1 parent 9879fed commit 87f7c33
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion crates/utils/src/crypto/modexp/arith.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ mod tests {
mod_inv, monsq, monpro, compute_r_mod_n, in_place_shl, in_place_shr, big_wrapping_pow,
big_wrapping_mul, big_sq, borrowing_sub, shifted_carrying_mul
};
use utils::crypto::modexp::mpnat::tests::{mp_nat_to_u128};
use utils::crypto::modexp::mpnat::{mp_nat_to_u128};
use utils::crypto::modexp::mpnat::{
MPNat, MPNatTrait, WORD_MAX, DOUBLE_WORD_MAX, BASE, Word, WORD_BYTES
};
Expand Down
31 changes: 16 additions & 15 deletions crates/utils/src/crypto/modexp/mpnat.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -679,30 +679,31 @@ pub impl MPNatTraitImpl of MPNatTrait {
}
}

pub fn mp_nat_to_u128(ref x: MPNat) -> u128 {
let result = x.digits.to_le_bytes();
let mut i: usize = 0;
loop {
if i == result.len() {
break;
};

i += 1;
};
result.from_le_bytes_partial().expect('mpnat_to_u128')
}

#[cfg(test)]
mod tests {
use alexandria_data_structures::vec::Felt252VecImpl;
use alexandria_data_structures::vec::VecTrait;
use utils::crypto::modexp::mpnat::{MPNat, MPNatTrait};
use utils::helpers::{Felt252VecTrait, ToBytes, FromBytes};
use utils::crypto::modexp::mpnat::MPNatTrait;
use utils::helpers::ToBytes;
use utils::math::{Bitshift, WrappingBitshift};
use super::mp_nat_to_u128;

// the tests are taken from
// [aurora-engine](https://github.com/aurora-is-near/aurora-engine/blob/1213f2c7c035aa523601fced8f75bef61b4728ab/engine-modexp/src/mpnat.rs#L825)

pub fn mp_nat_to_u128(ref x: MPNat) -> u128 {
let result = x.digits.to_le_bytes();
let mut i: usize = 0;
loop {
if i == result.len() {
break;
};

i += 1;
};
result.from_le_bytes_partial().expect('mpnat_to_u128')
}

fn check_modpow_even(base: u128, exp: u128, modulus: u128, expected: u128) {
let mut x = MPNatTrait::from_big_endian(base.to_be_bytes());
let mut m = MPNatTrait::from_big_endian(modulus.to_be_bytes());
Expand Down

0 comments on commit 87f7c33

Please sign in to comment.