forked from lambdaclass/cairo-vm
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…ambdaclass#1281) * wip * Manually implement some common derives Also comment `from` impls for primitive numbers and (De)Serialize derives * Implement FromPrimitive * Implement ToPrimitive * Add BitAnd/Xor/Or implementations * Implement bit shift operators * Remove Signed implementation * Remove Integer impl * Impl Bounded * Impl from_str_radix * Add iter_u64_digits impl * Add Add impls * Add Sub impls * Patch arbitrary * Fix some warnings * Implement parse_bytes * Implement utility methods for tests * Fix test compilation errors * Add From impl for signed primitive nums * Impl From<BigInt> * Re-add bits fn * Impl Signed * Impl (De)Serialize * Fix compile errors and clippy suggestions * Pin cairo 1 compiler version * Reorder impls * Fix compile error * Fix various errors (tests pass!) * Remove to_bytes_be * Fix panicky from_bytes_be * Fix is_positive * Fix str conversions * Add documentation * Fix from_i64 accepting negative numbers * Use BigUint in from_bytes_be * Remove unneded field macro * Pin lambdaworks commit * Fix keccak * Fix from_i64 condition was reversed * Change Debug::fmt to return number in decimal * Appease clippy in felt crate * Silence clippy warning (for now) * Fix nostd error * Update lambdaworks to latest revision * Update rust version in CI * Change sqrt for lambdaworks' * Manually build BigDigits on to_biguint * Use a bigger number of iterations for square bench * Update lambdaworks-math revision * Fix sqrt tests and Shl/Shr impl (+add tests) * Update Cargo.lock * Appease clippy and fix Shr<usize> * Square input instead of using prop_assume * Revert the change to Shr * Appease clippy * Use bits instead of shl in range check * Remove `FeltBigInt` * Add lamdaworks-benchmarks.sh * Add lamdaworks-benchmarks.md * Update lamdaworks-benchmarks.md * Update commits * Update .md commits * Looooong benchmark * Remove bigbox clippy allow * Update lambdaworks to latest, and change AddAssign * Remove `-P` option in `xargs` In the measurements we got through `perf`, there were 3 to 4 times more page faults compared to base. This can be explained by the runner using swap memory because of the increase in memory usage. We can fix it by reducing the amount of processes ran in parallel by xargs (2 -> 1) * Change `to_(b|l)e_bytes` to not use lw primitives * Change comments in `Add<&Felt252> for u64` * Fix: wasn't indexing properly :P * Override default `div_mod_floor` impl for Felt252 * Disable swap memory before benchmarking * Reduce number of warmups and runs * Optimize `assert_le_felt` (used in math_integration_benchmark) * Use constant for zero() function * Extract division by constant * Use BigUint in assert_le_felt This part uses comparisons and integer division (that use `to_biguint`), so it's better to use `BigUints` directly. * Avoid calling `BigInt::abs` * Update changelog * Add tests for felt * Add TODO * Add other texts * Update lambdaworks to latest * Revert hyperfine arguments to main * Remove unneeded clones and into_owneds * Remove unneeded references and clones * Add BREAKING note to changelog * Make Felt252::one just copy a constant * Impl From<bool> for Felt252 * Change some uses of get_ref with get_mut_ref Using `get_ref` and later updating the variable with an `exec_scopes.insert_value(...)` causes two lookups in a hashmap, along with two creation of `String` from a slice. This change reduces it to just a single lookup and `String` creation. * Unify mem*_continue_* functions * Run benchmarks sequentially to avoid mem issues * Use div_mod_floor instead of div and mod * Use BigUint for non-modular calculations * Add TODO * Include both lib.rs * Fix lib_bigint_felt * Add test-lambdaworks-felt workflow * Fix failling example * Move extern crate import to lib.rs * Update changelog * Fix changelog * Fix example * Remove benchmark docs * Remove clone * Move crate-level attribute to lib.rs * Fix changelog * Remove blank line in toml * Use one line cfg directives * Remove reference * Restore clone * Fix doc test * Add `lambdaworks-felt` feature to vm crate * Add instructions to (de)activate the new feature * Use different matrix group for lambdaworks felt in CI * Move the sections a bit * Update lambdaworks-math version to 0.1.1 * Invert the part talking about features --------- Co-authored-by: Pedro Fontana <fontana.pedro93@gmail.com> Co-authored-by: Tomá <47506558+MegaRedHand@users.noreply.github.com> Co-authored-by: Mario Rugiero <mrugiero@gmail.com>
- Loading branch information
Showing
30 changed files
with
3,647 additions
and
1,819 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use lambdaworks_math::{field::element::FieldElement, unsigned_integer::element::UnsignedInteger}; | ||
use num_traits::Zero; | ||
use proptest::prelude::*; | ||
|
||
use crate::{Felt252, FIELD_HIGH, FIELD_LOW}; | ||
|
||
/// Returns a [`Strategy`] that generates any valid Felt252 | ||
fn any_felt252() -> impl Strategy<Value = Felt252> { | ||
(0..=FIELD_HIGH) | ||
// turn range into `impl Strategy` | ||
.prop_map(|x| x) | ||
// choose second 128-bit limb capped by first one | ||
.prop_flat_map(|high| { | ||
let low = if high == FIELD_HIGH { | ||
(0..FIELD_LOW).prop_map(|x| x).sboxed() | ||
} else { | ||
any::<u128>().sboxed() | ||
}; | ||
(Just(high), low) | ||
}) | ||
// turn (u128, u128) into limbs array and then into Felt252 | ||
.prop_map(|(high, low)| { | ||
let limbs = [ | ||
(high >> 64) as u64, | ||
(high & ((1 << 64) - 1)) as u64, | ||
(low >> 64) as u64, | ||
(low & ((1 << 64) - 1)) as u64, | ||
]; | ||
FieldElement::new(UnsignedInteger::from_limbs(limbs)) | ||
}) | ||
.prop_map(|value| Felt252 { value }) | ||
} | ||
|
||
/// Returns a [`Strategy`] that generates any nonzero Felt252 | ||
pub fn nonzero_felt252() -> impl Strategy<Value = Felt252> { | ||
any_felt252().prop_filter("is zero", |x| !x.is_zero()) | ||
} | ||
|
||
impl Arbitrary for Felt252 { | ||
type Parameters = (); | ||
|
||
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { | ||
any_felt252().sboxed() | ||
} | ||
|
||
type Strategy = SBoxedStrategy<Self>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.