diff --git a/src/air/autogenerated.cairo b/src/air/autogenerated.cairo index a599bdb16..86ff3e232 100644 --- a/src/air/autogenerated.cairo +++ b/src/air/autogenerated.cairo @@ -1,5 +1,5 @@ use cairo_verifier::air::global_values::GlobalValues; -use cairo_verifier::common::felt252::{Felt252Div, pow}; +use cairo_verifier::common::math::{Felt252Div, pow}; fn eval_composition_polynomial_inner( mask_values: Array, diff --git a/src/air/composition.cairo b/src/air/composition.cairo index 2298c4970..e2c82dbae 100644 --- a/src/air/composition.cairo +++ b/src/air/composition.cairo @@ -7,7 +7,7 @@ use cairo_verifier::air::public_input::{PublicInput, PublicInputTrait}; use cairo_verifier::air::diluted::get_diluted_product; use cairo_verifier::air::pedersen::{eval_pedersen_x, eval_pedersen_y}; use cairo_verifier::air::autogenerated::eval_composition_polynomial_inner; -use cairo_verifier::common::felt252::{Felt252Div, Felt252PartialOrd, pow}; +use cairo_verifier::common::math::{Felt252Div, Felt252PartialOrd, pow}; const SHIFT_POINT_X: felt252 = 0x49ee3eba8c1600700ee1b87eb599f16716b0b1022947733551fde4050ca6804; const SHIFT_POINT_Y: felt252 = 0x3ca0cfe4b3bc6ddf346d49d06ea0ed34e621062c0e056c1d0405d266e10268a; diff --git a/src/air/diluted.cairo b/src/air/diluted.cairo index 9284b7502..1b95f232f 100644 --- a/src/air/diluted.cairo +++ b/src/air/diluted.cairo @@ -1,4 +1,4 @@ -use cairo_verifier::common::felt252::pow; +use cairo_verifier::common::math::pow; // The cumulative value is defined using the next recursive formula: // r_1 = 1, r_{j+1} = r_j * (1 + z * u_j) + alpha * u_j^2 diff --git a/src/air/public_input.cairo b/src/air/public_input.cairo index 91c4a3a09..789c3c192 100644 --- a/src/air/public_input.cairo +++ b/src/air/public_input.cairo @@ -1,7 +1,7 @@ use cairo_verifier::air::public_memory::{ Page, PageTrait, ContinuousPageHeader, get_continuous_pages_product }; -use cairo_verifier::common::felt252::{pow, Felt252PartialOrd, Felt252Div}; +use cairo_verifier::common::math::{pow, Felt252PartialOrd, Felt252Div}; #[derive(Drop)] struct SegmentInfo { diff --git a/src/common.cairo b/src/common.cairo index e20391b2a..cf165c02e 100644 --- a/src/common.cairo +++ b/src/common.cairo @@ -2,7 +2,6 @@ mod blake2s; mod flip_endianness; mod from_span; mod horner_eval; -mod felt252; mod array_append; mod math; mod array_print; diff --git a/src/common/felt252.cairo b/src/common/felt252.cairo deleted file mode 100644 index 7a0aeb619..000000000 --- a/src/common/felt252.cairo +++ /dev/null @@ -1,41 +0,0 @@ -fn pow(base: felt252, exp: felt252) -> felt252 { - if exp == 0 { - 1 - } else { - base * pow(base, exp - 1) - } -} - -impl Felt252Div of Div { - fn div(lhs: felt252, rhs: felt252) -> felt252 { - let lhs_u256: u256 = lhs.into(); - let rhs_u256: u256 = rhs.into(); - (lhs_u256 / rhs_u256).try_into().unwrap() - } -} - -impl Felt252PartialOrd of PartialOrd { - fn le(lhs: felt252, rhs: felt252) -> bool { - let lhs_u256: u256 = lhs.into(); - let rhs_u256: u256 = rhs.into(); - lhs <= rhs - } - - fn ge(lhs: felt252, rhs: felt252) -> bool { - let lhs_u256: u256 = lhs.into(); - let rhs_u256: u256 = rhs.into(); - lhs >= rhs - } - - fn lt(lhs: felt252, rhs: felt252) -> bool { - let lhs_u256: u256 = lhs.into(); - let rhs_u256: u256 = rhs.into(); - lhs < rhs - } - - fn gt(lhs: felt252, rhs: felt252) -> bool { - let lhs_u256: u256 = lhs.into(); - let rhs_u256: u256 = rhs.into(); - lhs > rhs - } -} diff --git a/src/common/math.cairo b/src/common/math.cairo index 978aacc95..5c9db3808 100644 --- a/src/common/math.cairo +++ b/src/common/math.cairo @@ -27,3 +27,37 @@ fn mul_inverse(x: felt252) -> felt252 { // a ^ (p - 2) is the multiplicative inverse of a modulo p. pow(x, STARK_PRIME_MINUS_TWO) } + +impl Felt252Div of Div { + fn div(lhs: felt252, rhs: felt252) -> felt252 { + let lhs_u256: u256 = lhs.into(); + let rhs_u256: u256 = rhs.into(); + (lhs_u256 / rhs_u256).try_into().unwrap() + } +} + +impl Felt252PartialOrd of PartialOrd { + fn le(lhs: felt252, rhs: felt252) -> bool { + let lhs_u256: u256 = lhs.into(); + let rhs_u256: u256 = rhs.into(); + lhs <= rhs + } + + fn ge(lhs: felt252, rhs: felt252) -> bool { + let lhs_u256: u256 = lhs.into(); + let rhs_u256: u256 = rhs.into(); + lhs >= rhs + } + + fn lt(lhs: felt252, rhs: felt252) -> bool { + let lhs_u256: u256 = lhs.into(); + let rhs_u256: u256 = rhs.into(); + lhs < rhs + } + + fn gt(lhs: felt252, rhs: felt252) -> bool { + let lhs_u256: u256 = lhs.into(); + let rhs_u256: u256 = rhs.into(); + lhs > rhs + } +}