Skip to content

Commit 302939c

Browse files
AbdelStarktdelabro
authored andcommitted
feat: introduce no_std support for ff and crypto
1 parent 2f2928b commit 302939c

File tree

23 files changed

+247
-91
lines changed

23 files changed

+247
-91
lines changed

Cargo.lock

Lines changed: 40 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,7 @@ url = "2.2.2"
4848
[features]
4949
default = ["bigdecimal"]
5050
bigdecimal = ["starknet-core/bigdecimal"]
51-
no_unknown_fields = ["starknet-core/no_unknown_fields", "starknet-providers/no_unknown_fields"]
51+
no_unknown_fields = [
52+
"starknet-core/no_unknown_fields",
53+
"starknet-providers/no_unknown_fields",
54+
]

starknet-core/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ all-features = true
1717

1818
[dependencies]
1919
starknet-crypto = { version = "0.2.0", path = "../starknet-crypto" }
20-
starknet-ff = { version = "0.2.0", path = "../starknet-ff", default-features = false }
20+
starknet-ff = { version = "0.2.0", path = "../starknet-ff" }
2121
base64 = "0.13.0"
2222
ethereum-types = "0.12.1"
2323
flate2 = "1.0.24"
@@ -37,7 +37,7 @@ wasm-bindgen-test = "0.3.29"
3737

3838
[features]
3939
default = ["bigdecimal"]
40-
bigdecimal = ["starknet-ff/bigdecimal"]
40+
bigdecimal = ["starknet-ff/bigdecimal", "starknet-crypto/bigdecimal"]
4141
no_unknown_fields = []
4242

4343
[[bench]]

starknet-crypto-codegen/Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ keywords = ["ethereum", "starknet", "web3"]
1616
proc-macro = true
1717

1818
[dependencies]
19-
starknet-curve = { version = "0.1.0", path = "../starknet-curve" }
20-
starknet-ff = { version = "0.2.0", path = "../starknet-ff" }
21-
syn = "1.0.96"
19+
starknet-curve = { version = "0.1.0", path = "../starknet-curve", default-features = false }
20+
starknet-ff = { version = "0.2.0", path = "../starknet-ff", default-features = false }
21+
syn = { version = "1.0.96", default-features = false }
22+
23+
[features]
24+
default = ["std"]
25+
std = ["starknet-ff/std", "starknet-curve/std"]
26+
alloc = ["starknet-ff/alloc", "starknet-curve/alloc"]

starknet-crypto/Cargo.toml

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,37 @@ Low-level cryptography utilities for Starknet
1313
keywords = ["ethereum", "starknet", "web3"]
1414

1515
[dependencies]
16-
starknet-crypto-codegen = { version = "0.1.0", path = "../starknet-crypto-codegen" }
17-
starknet-curve = { version = "0.1.0", path = "../starknet-curve" }
18-
starknet-ff = { version = "0.2.0", path = "../starknet-ff" }
19-
crypto-bigint = "0.4.9"
20-
hmac = "0.12.1"
21-
num-bigint = "0.4.3"
22-
num-integer = "0.1.44"
23-
num-traits = "0.2.14"
24-
rfc6979 = "0.3.1"
25-
sha2 = "0.10.6"
26-
thiserror = "1.0.30"
27-
zeroize = "1.5.0"
28-
hex = "0.4.3"
16+
starknet-crypto-codegen = { version = "0.1.0", path = "../starknet-crypto-codegen", default-features = false }
17+
starknet-curve = { version = "0.1.0", path = "../starknet-curve", default-features = false }
18+
starknet-ff = { version = "0.2.0", path = "../starknet-ff", default-features = false }
19+
crypto-bigint = { version = "0.4.9", default-features = false }
20+
hmac = { version = "0.12.1", default-features = false }
21+
num-bigint = { version = "0.4.3", default-features = false }
22+
num-integer = { version = "0.1.44", default-features = false }
23+
num-traits = { version = "0.2.14", default-features = false }
24+
rfc6979 = { version = "0.3.1", default-features = false }
25+
sha2 = { version = "0.10.6", default-features = false }
26+
zeroize = { version = "1.5.0", default-features = false }
27+
hex = { version = "0.4.3", default-features = false }
28+
hashbrown = { version = "0.13.2", default-features = false }
29+
thiserror-no-std = "2.0.2"
30+
31+
[features]
32+
default = ["std"]
33+
std = [
34+
"starknet-ff/std",
35+
"starknet-curve/std",
36+
"starknet-crypto-codegen/std",
37+
"thiserror-no-std/std",
38+
"hex/std",
39+
]
40+
alloc = [
41+
"starknet-ff/alloc",
42+
"starknet-curve/alloc",
43+
"starknet-crypto-codegen/alloc",
44+
"hex/alloc",
45+
]
46+
bigdecimal = ["starknet-curve/bigdecimal", "starknet-ff/bigdecimal"]
2947

3048
[dev-dependencies]
3149
criterion = { version = "0.4.0", default-features = false }

starknet-crypto/src/ecdsa.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use crate::{
77
fe_utils::{add_unbounded, bigint_mul_mod_floor, mod_inverse, mul_mod_floor},
88
FieldElement, SignError, VerifyError,
99
};
10-
use std::fmt;
10+
11+
use crate::stdlib::fmt;
1112

1213
const ELEMENT_UPPER_BOUND: FieldElement = FieldElement::from_mont([
1314
18446743986131435553,

starknet-crypto/src/error.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
use thiserror_no_std::Error;
2+
13
/// Errors when performing ECDSA [`sign`](fn.sign) operations
2-
#[derive(Debug, thiserror::Error)]
4+
#[derive(Debug, Error)]
35
pub enum SignError {
46
#[error("Invalid message hash")]
57
InvalidMessageHash,
@@ -8,7 +10,7 @@ pub enum SignError {
810
}
911

1012
/// Errors when performing ECDSA [`verify`](fn.verify) operations
11-
#[derive(Debug, thiserror::Error)]
13+
#[derive(Debug, Error)]
1214
pub enum VerifyError {
1315
#[error("Invalid message hash")]
1416
InvalidMessageHash,

starknet-crypto/src/fe_utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
use crate::stdlib::ops::{Add, Mul};
2+
13
use num_bigint::BigInt;
24
use num_integer::Integer;
35
use num_traits::{One, Zero};
4-
use std::ops::{Add, Mul};
56

67
use crate::FieldElement;
78

starknet-crypto/src/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
1+
#![cfg_attr(not(feature = "std"), no_std)]
12
#![doc = include_str!("../README.md")]
23

4+
#[cfg(feature = "std")]
5+
include!("./with_std.rs");
6+
7+
#[cfg(not(feature = "std"))]
8+
include!("./without_std.rs");
9+
10+
#[cfg(all(test, not(feature = "std"), feature = "alloc"))]
11+
include!("./with_alloc.rs");
12+
13+
pub mod stdlib {
14+
#[cfg(all(test, not(feature = "std"), feature = "alloc"))]
15+
pub use crate::with_alloc::*;
16+
#[cfg(feature = "std")]
17+
pub use crate::with_std::*;
18+
#[cfg(not(feature = "std"))]
19+
pub use crate::without_std::*;
20+
}
21+
322
mod ecdsa;
423
mod error;
524
mod fe_utils;

starknet-crypto/src/rfc6979.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ where
8080
#[cfg(test)]
8181
mod tests {
8282
use super::*;
83+
use crate::stdlib::string::String;
84+
use crate::stdlib::vec::Vec;
8385
use crate::test_utils::field_element_from_be_hex;
8486

8587
use serde::Deserialize;

starknet-crypto/src/with_alloc.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extern crate alloc;
2+
3+
pub mod with_alloc {
4+
pub use alloc::{string, vec};
5+
}

starknet-crypto/src/with_std.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pub mod with_std {
2+
pub use std::{fmt, ops, str};
3+
4+
#[cfg(test)]
5+
pub use std::{string, vec};
6+
}

starknet-crypto/src/without_std.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub mod without_std {
2+
pub use core::{fmt, ops, str};
3+
}

starknet-curve/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,10 @@ Stark curve
1313
keywords = ["ethereum", "starknet", "web3"]
1414

1515
[dependencies]
16-
starknet-ff = { version = "0.2.0", path = "../starknet-ff" }
16+
starknet-ff = { version = "0.2.0", path = "../starknet-ff", default-features = false }
17+
18+
[features]
19+
default = ["std"]
20+
std = ["starknet-ff/std"]
21+
alloc = ["starknet-ff/alloc"]
22+
bigdecimal = ["starknet-ff/bigdecimal"]

0 commit comments

Comments
 (0)