cairo_felt/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2
3#[allow(unused_imports)]
4#[macro_use]
5#[cfg(all(not(feature = "std"), feature = "alloc"))]
6pub extern crate alloc;
7
8#[cfg(not(feature = "lambdaworks-felt"))]
9mod bigint_felt;
10#[cfg(not(feature = "lambdaworks-felt"))]
11mod lib_bigint_felt;
12#[cfg(feature = "lambdaworks-felt")]
13mod lib_lambdaworks;
14
15use core::fmt;
16
17#[cfg(feature = "lambdaworks-felt")]
18pub use lib_lambdaworks::Felt252;
19
20#[cfg(not(feature = "lambdaworks-felt"))]
21pub use lib_bigint_felt::Felt252;
22
23pub const PRIME_STR: &str = "0x800000000000011000000000000000000000000000000000000000000000001"; // in decimal, this is equal to 3618502788666131213697322783095070105623107215331596699973092056135872020481
24pub const FIELD_HIGH: u128 = (1 << 123) + (17 << 64); // this is equal to 10633823966279327296825105735305134080
25pub const FIELD_LOW: u128 = 1;
26
27#[derive(Clone, Debug, PartialEq, Eq)]
28pub struct ParseFeltError;
29
30impl fmt::Display for ParseFeltError {
31    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
32        write!(f, "{ParseFeltError:?}")
33    }
34}
35
36#[cfg(any(feature = "arbitrary", test))]
37#[cfg_attr(feature = "lambdaworks-felt", path = "arbitrary_lambdaworks.rs")]
38#[cfg_attr(not(feature = "lambdaworks-felt"), path = "arbitrary_bigint_felt.rs")]
39/// [`proptest::arbitrary::Arbitrary`] implementation for [`Felt252`], and [`Strategy`] generating functions.
40///
41/// Not to be confused with [`arbitrary::Arbitrary`], which is also enabled by the _arbitrary_ feature.
42pub mod arbitrary;