-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use starknet-types-core
Felt
#1408
Conversation
.github/workflows/rust.yml
Outdated
cargo llvm-cov nextest --lcov --output-path lcov-${{ matrix.target }}-${{ matrix.special_features }}.info \ | ||
cargo llvm-cov nextest --lcov --output-path lcov-${{ matrix.target }}.info \ | ||
--partition count:${PARTITION}/4 \ | ||
--workspace --features "cairo-1-hints, test_utils, ${{ matrix.special_features }}" | ||
--workspace --features "cairo-1-hints, test_utils" | ||
;; | ||
'test-no_std') | ||
cargo llvm-cov nextest --lcov --output-path lcov-${{ matrix.target }}-${{ matrix.special_features }}.info \ | ||
cargo llvm-cov nextest --lcov --output-path lcov-${{ matrix.target }}.info \ | ||
--partition count:${PARTITION}/4 \ | ||
--workspace --no-default-features --features "${{ matrix.special_features }}" | ||
--workspace --no-default-features | ||
;; | ||
'test-wasm') | ||
# NOTE: release mode is needed to avoid "too many locals" error | ||
wasm-pack test --release --node vm --no-default-features --features "${{ matrix.special_features }}" | ||
wasm-pack test --release --node vm --no-default-features |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should restore this, as we added the "extensive-hints" feature recently and it should be tested
pub fn felt_to_biguint(felt: crate::Felt252) -> BigUint { | ||
let big_digits = felt | ||
.to_le_digits() | ||
.into_iter() | ||
.flat_map(|limb| [limb as u32, (limb >> 32) as u32]) | ||
.collect(); | ||
BigUint::new(big_digits) | ||
} | ||
|
||
pub fn felt_to_bigint(felt: crate::Felt252) -> BigInt { | ||
felt_to_biguint(felt).to_bigint().unwrap() | ||
} | ||
|
||
pub fn biguint_to_felt(biguint: &BigUint) -> Result<crate::Felt252, MathError> { | ||
// TODO This funtions should return a Felt252 instead of a Result | ||
Ok(crate::Felt252::from_bytes_le_slice(&biguint.to_bytes_le())) | ||
} | ||
|
||
pub fn bigint_to_felt(bigint: &BigInt) -> Result<crate::Felt252, MathError> { | ||
let (sign, bytes) = bigint | ||
.mod_floor(&CAIRO_PRIME.to_bigint().unwrap()) | ||
.to_bytes_le(); | ||
let felt = crate::Felt252::from_bytes_le_slice(&bytes); | ||
if sign == Sign::Minus { | ||
Ok(felt.neg()) | ||
} else { | ||
Ok(felt) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new version of starknet-core-types
implements conversions between Felt & biguint/bigint so we can use those and remove these functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest we leave them and refactor later. This PR has been lingering for a while and this limbo is getting in the way of some downstream devs too.
🔥 |
Replace
cairo-felt
crate withstarknet-types-core
Change the
Felt252
struct implemented in thecairo-felt
crate with one fromstarknet-types-core