Skip to content

Commit 382f405

Browse files
No std (#192)
* cargo.toml changes and started no_std support * importing alloc Vec and Box when no_std * alloc Vec and Box * halo2derive alloc imports * lazy_static spin_no_std feature * alloc imports fix * maybe_rayon * cfg std typo fix * fixed -> ln(), imports and to_raw_bytes is std only method * cargo.toml -> group optional deps * maybe_rayon::join * serde_arrays 0.2.0 for no_std support * using std with asm * core::arch::asm instead of std::arch::asm * chore: clean deps * bn256-table ci fix * derive_serde CI fix * No std ci (#1) * removed std from cargo.toml features in default, bn256-table and derive_serde * wip: fixing tests * run ci on no_std_ci for checks * typo fix * removed comment * removed ci_check branch from ci * Ci (#2) --------- Co-authored-by: David Nevado <[email protected]>
1 parent 3915335 commit 382f405

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+458
-167
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,29 @@ concurrency:
3434
cancel-in-progress: true
3535

3636
jobs:
37+
no_std:
38+
if: github.event.pull_request.draft == false
39+
name: no_std-compatibility
40+
runs-on: ubuntu-latest
41+
strategy:
42+
matrix:
43+
feature: [default, bn256-table, derive_serde, ""]
44+
steps:
45+
- uses: actions/checkout@v2
46+
- uses: actions-rs/toolchain@v1
47+
48+
- name: Download no_std target
49+
run: rustup target add thumbv7em-none-eabi
50+
51+
# Check if build passes on `thumbv7em-none-eabi` no_std target with and without specific features (default, bn256-table and derive_serde)
52+
- name: Build
53+
# Script that checks if feature is empty or script should be ran with feature
54+
run: |
55+
if [ -z "${{ matrix.feature }}" ]; then
56+
cargo build --release --target thumbv7em-none-eabi --no-default-features
57+
else
58+
cargo build --release --target thumbv7em-none-eabi --no-default-features --features ${{ matrix.feature }}
59+
fi
3760
compat:
3861
if: github.event.pull_request.draft == false
3962
name: Wasm-compatibility
@@ -119,7 +142,7 @@ jobs:
119142
- uses: actions/checkout@v4
120143
- name: Use typos with config file
121144
uses: crate-ci/typos@master
122-
with:
145+
with:
123146
config: .config/typos.toml
124147

125148
bench:

Cargo.toml

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,49 +11,60 @@ rust-version = "1.63.0"
1111

1212
[dev-dependencies]
1313
criterion = { version = "0.3", features = ["html_reports"] }
14-
rand_xorshift = "0.3"
1514
ark-std = { version = "0.3" }
1615
bincode = "1.3.3"
1716
serde_json = "1.0.105"
18-
hex = "0.4"
1917
rand_chacha = "0.3.1"
18+
rand_xorshift = "0.3"
2019
impls = "1"
20+
rand_core = { version = "0.6", features = ["getrandom"] }
21+
2122

2223
# Added to make sure we are able to build the lib in the CI.
2324
# Notice this will never be loaded for someone using this lib as dep.
2425
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies]
2526
getrandom = { version = "0.2", features = ["js"] }
2627

2728
[dependencies]
28-
halo2derive = {path = "derive", version="0.1.0"}
29-
subtle = "2.5"
29+
halo2derive = { path = "derive", version = "0.1.0", default-features = false }
3030
ff = { version = "0.13.0", default-features = false, features = ["std"] }
31-
group = "0.13.0"
32-
pairing = "0.23.0"
33-
static_assertions = "1.1.0"
34-
rand = "0.8"
31+
group = { version = "0.13.0", default-features = false }
32+
pairing = { version = "0.23.0", default-features = false }
33+
subtle = { version = "2.5", default-features = false }
34+
35+
static_assertions = { version = "1.1.0", default-features = false }
3536
rand_core = { version = "0.6", default-features = false }
36-
lazy_static = "1.4.0"
37-
num-bigint = "0.4.3"
38-
num-integer = "0.1.46"
39-
num-traits = "0.2"
40-
paste = "1.0.11"
37+
lazy_static = { version = "1.4.0", default-features = false, features = [
38+
"spin_no_std",
39+
] }
40+
num-bigint = { version = "0.4.3", default-features = false }
41+
num-integer = { version = "0.1.46", default-features = false }
42+
num-traits = { version = "0.2", default-features = false }
43+
paste = { version = "1.0.11", default-features = false }
44+
hex = { version = "0.4", optional = true, default-features = false, features = [
45+
"alloc",
46+
"serde",
47+
] }
48+
sha2 = { version = "0.10.8", default-features = false }
49+
digest = { version = "0.10.7", default-features = false }
50+
51+
plonky2_maybe_rayon = { version = "1.0.0", default-features = false }
52+
rayon = { version = "1.8", default-features = false, optional = true }
53+
54+
libm = { version = "0.2.11", default-features = false }
55+
4156
serde = { version = "1.0", default-features = false, optional = true }
42-
serde_arrays = { version = "0.1.0", optional = true }
43-
hex = { version = "0.4", optional = true, default-features = false, features = ["alloc", "serde"] }
44-
rayon = "1.8"
45-
unroll = "0.1.5"
46-
blake2 = "0.10.6"
47-
sha2 = "0.10.8"
48-
digest = "0.10.7"
57+
serde_arrays = { version = "0.2.0", optional = true }
4958

5059
[features]
5160
default = ["bits"]
52-
asm = ["halo2derive/asm"]
61+
asm = ["halo2derive/asm", "std"]
5362
bits = ["ff/bits"]
5463
bn256-table = []
5564
derive_serde = ["serde/derive", "serde_arrays", "hex"]
5665
print-trace = ["ark-std/print-trace"]
66+
std = ["rayon", "halo2derive/std", "plonky2_maybe_rayon/parallel"]
67+
5768

5869
[profile.bench]
5970
opt-level = 3
@@ -83,6 +94,7 @@ harness = false
8394
[[bench]]
8495
name = "msm"
8596
harness = false
97+
required-features = ["std"]
8698

8799
[[bench]]
88100
name = "pairing"

benches/curve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughpu
99
use ff::Field;
1010
use group::prime::PrimeCurveAffine;
1111
use halo2curves::{bn256::G1, CurveExt};
12-
use rand::SeedableRng;
12+
use rand_core::SeedableRng;
1313
use rand_xorshift::XorShiftRng;
1414

1515
fn bench_curve_ops<G: CurveExt>(c: &mut Criterion, name: &'static str) {

benches/fft.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::{ops::Range, time::SystemTime};
1818
use criterion::{BenchmarkId, Criterion};
1919
use group::ff::Field;
2020
use halo2curves::{bn256::Fr as Scalar, fft::best_fft};
21-
use rand::{RngCore, SeedableRng};
21+
use rand_core::{RngCore, SeedableRng};
2222
use rand_xorshift::XorShiftRng;
2323

2424
const RANGE: Range<u32> = 3..19;

benches/field_arith.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use halo2curves::{
1111
ff::Field,
1212
ff_ext::Legendre,
1313
};
14-
use rand::{RngCore, SeedableRng};
14+
use rand_core::{RngCore, SeedableRng};
1515
use rand_xorshift::XorShiftRng;
1616

1717
const SEED: [u8; 16] = [

benches/hash_to_curve.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
//!
66
//! cargo bench --bench hash_to_curve
77
8-
use std::iter;
8+
use core::iter;
99

1010
use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput};
1111
use halo2curves::{bn256::G1, CurveExt};
12-
use rand::SeedableRng;
13-
use rand_core::RngCore;
12+
use rand_core::{RngCore, SeedableRng};
1413
use rand_xorshift::XorShiftRng;
1514

1615
const SEED: [u8; 16] = [

benches/pairing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use ff::Field;
1010
use group::prime::PrimeCurveAffine;
1111
use halo2curves::bn256::Bn256;
1212
use pairing::Engine;
13-
use rand::SeedableRng;
13+
use rand_core::SeedableRng;
1414
use rand_xorshift::XorShiftRng;
1515

1616
const SEED: [u8; 16] = [

derive/Cargo.toml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ rust-version = "1.63.0"
1212
proc-macro = true
1313

1414
[dependencies]
15-
num-bigint = "0.4"
16-
num-integer = "0.1"
17-
num-traits = "0.2"
18-
proc-macro2 = "1.0"
19-
quote = "1.0"
20-
syn = {version = "1.0", features = ["full"]}
15+
num-bigint = { version = "0.4", default-features = false }
16+
num-integer = { version = "0.1", default-features = false }
17+
num-traits = { version = "0.2", default-features = false }
18+
proc-macro2 = { version = "1.0", default-features = false }
19+
quote = { version = "1.0", default-features = false }
20+
syn = { version = "1.0", features = ["full"] }
21+
2122

2223
[features]
23-
default = []
24+
default = ["std"]
2425
asm = []
26+
std = []

derive/src/field/arith.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#[cfg(not(feature = "std"))]
2+
extern crate alloc;
3+
#[cfg(not(feature = "std"))]
4+
use alloc::vec::Vec;
5+
16
use proc_macro2::TokenStream;
27
use quote::{format_ident as fmtid, quote};
38

derive/src/field/asm/limb4.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use proc_macro2::TokenStream;
22

33
pub(crate) fn impl_arith(field: &syn::Ident, inv: u64) -> TokenStream {
44
quote::quote! {
5-
use std::arch::asm;
5+
use core::arch::asm;
66
impl #field {
77
/// Doubles this field element.
88
#[inline]

0 commit comments

Comments
 (0)