Skip to content
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

Merged
merged 118 commits into from
Dec 21, 2023
Merged

Use starknet-types-core Felt #1408

merged 118 commits into from
Dec 21, 2023

Conversation

pefontana
Copy link
Member

@pefontana pefontana commented Aug 24, 2023

Replace cairo-felt crate with starknet-types-core

Change the Felt252 struct implemented in the cairo-felt crate with one from starknet-types-core

edg-l
edg-l previously approved these changes Dec 21, 2023
Comment on lines 261 to 266
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
Copy link
Member

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

Comment on lines +54 to +82
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)
}
}
Copy link
Member

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

Copy link
Member

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.

Oppen
Oppen previously approved these changes Dec 21, 2023
@Oppen Oppen dismissed stale reviews from edg-l and themself via d186c10 December 21, 2023 19:36
fmoletta
fmoletta previously approved these changes Dec 21, 2023
Oppen
Oppen previously approved these changes Dec 21, 2023
@pefontana pefontana dismissed stale reviews from Oppen and fmoletta via 24fc563 December 21, 2023 21:03
@Oppen Oppen enabled auto-merge December 21, 2023 21:04
@pefontana pefontana changed the title Use standard felt Use starknet-types-core Felt Dec 21, 2023
@Oppen Oppen added this pull request to the merge queue Dec 21, 2023
Merged via the queue into main with commit fe72ee0 Dec 21, 2023
50 checks passed
@Oppen Oppen deleted the use-standard-felt branch December 21, 2023 21:56
@tdelabro
Copy link
Contributor

🔥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants