Skip to content

Commit

Permalink
Add ensure_no_std build to CI (#1232)
Browse files Browse the repository at this point in the history
* Add ensure_no_std build to CI

* Add print to test

* Install wasm32 target for no-std testing

* Fix: added option in wrong job

* Try another breaking change

* Remove "alloc" feature in Cargo.toml

* Also add compilation with the 'alloc' option

* Add cairo-vm to ensure_no_std deps

* Remove alloc feature

* Fix (WIP)

* comment vm (not no_std ready); use nightly toolchain

* add Timothée num-prime fork and fix no-std support

* run cargo fmt

* fix clippy; add original num_prime for tests; ignore unused FloatCore

* fix typo on unused_variables instead imports

* remove prime computations for non default primality test config

* Split implementation of is_prime into std/no_std

* Remove unused import

* Change some constants

* Update dir name

* Fix errors

* Use modpow, and increase time of bench

* Merge smoke and smoke-no_std

* Use mul instead of pow

---------

Co-authored-by: João Carvalho <joao.carvalho@tripleoak.pt>
  • Loading branch information
MegaRedHand and João Carvalho authored Jun 15, 2023
1 parent e876253 commit 8a72ddc
Show file tree
Hide file tree
Showing 7 changed files with 859 additions and 848 deletions.
17 changes: 12 additions & 5 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
name: Run Lints
runs-on: ubuntu-22.04
steps:
- name: Install Rust 1.69.0
- name: Install Rust
uses: dtolnay/rust-toolchain@1.69.0
with:
components: rustfmt, clippy
Expand Down Expand Up @@ -114,8 +114,11 @@ jobs:
name: Make sure all builds work
runs-on: ubuntu-22.04
steps:
- name: Install Rust 1.69.0
- name: Install Rust
uses: dtolnay/rust-toolchain@1.69.0
with:
targets: wasm32-unknown-unknown

- name: Set up cargo cache
uses: Swatinem/rust-cache@v2
- name: Install cargo-all-features
Expand Down Expand Up @@ -154,9 +157,13 @@ jobs:
cairo_programs/**/*.json
key: cairo_1_test_contracts-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}

- name: Check
- name: Check all features
run: cargo check-all-features --workspace --all-targets

- name: Check no-std
run: |
cd ensure-no_std
cargo build --release
tests:
needs: build-programs
Expand All @@ -168,7 +175,7 @@ jobs:
name: Run tests
runs-on: ubuntu-22.04
steps:
- name: Install Rust 1.69.0
- name: Install Rust
uses: dtolnay/rust-toolchain@1.69.0
with:
components: llvm-tools-preview
Expand Down Expand Up @@ -237,7 +244,7 @@ jobs:
name: Build release binary for comparisons
runs-on: ubuntu-22.04
steps:
- name: Install Rust 1.69.0
- name: Install Rust
uses: dtolnay/rust-toolchain@1.69.0
- name: Set up cargo cache
uses: Swatinem/rust-cache@v2
Expand Down
20 changes: 13 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
[workspace]
members = ["cairo-vm-cli", "felt", "vm", "hint_accountant", "./deps/parse-hyperlinks"]
members = [
"cairo-vm-cli",
"felt",
"vm",
"hint_accountant",
"./deps/parse-hyperlinks",
]
exclude = ["ensure-no_std"]

[workspace.dependencies]
mimalloc = { version = "0.1.29", default-features = false }
num-bigint = { version = "0.4", features = [
num-bigint = { version = "0.4", default-features = false, features = [
"serde",
"rand",
], default-features = false }
] }
rand = { version = "0.8.3", features = ["small_rng"], default-features = false }
num-traits = { version = "0.2", default-features = false }
num-integer = { version = "0.1.45", default-features = false }
Expand Down Expand Up @@ -39,7 +45,7 @@ keccak = { version = "0.1.2", default-features = false }
hashbrown = { version = "0.13.2", features = ["serde"] }
anyhow = { version = "1.0.69", default-features = false }
thiserror = { version = "1.0.32", default-features = false }
thiserror-no-std = "2.0.2"
thiserror-no-std = { version = "2.0.2", default-features = false }

# This crate has only one function `take_until_unbalanced` that is
# very useful for our parsing purposes:
Expand All @@ -55,11 +61,11 @@ felt = { package = "cairo-felt", path = "./felt", version = "0.5.2", default-fea
bitvec = { version = "1", default-features = false, features = ["alloc"] }

# Dependencies for cairo-1-hints feature
cairo-lang-starknet = { version = "1.1.0"}
cairo-lang-casm = { version = "1.1.0"}
cairo-lang-starknet = { version = "1.1.0", default-features = false }
cairo-lang-casm = { version = "1.1.0", default-features = false }

# TODO: check these dependencies for wasm compatibility
ark-ff = { version = "0.4.0-alpha.7", default-features = false }
ark-ff = { version = "0.4.0-alpha.7", default-features = false }
ark-std = { version = "0.3.0", default-features = false }

[profile.release]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ func main{range_check_ptr: felt, bitwise_ptr: BitwiseBuiltin*}() {
let p = Uint384(18446744069414584321, 0, 0); // Goldilocks Prime
let x = Uint384(5, 0, 0);
let g = Uint384(7, 0, 0);
run_get_square(p, g, x, 100);
run_get_square(p, g, x, 1000);
return ();
}
4 changes: 3 additions & 1 deletion ensure-no_std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ version = "0.1.0"
edition = "2021"

[dependencies]
cairo-felt = { path = "../felt", default-features = false, features = ["alloc"] }
cairo-felt = { path = "../felt", default-features = false, features = [
"alloc",
] }
cairo-vm = { path = "../vm", default-features = false }

wee_alloc = "0.4.5"
Expand Down
69 changes: 38 additions & 31 deletions vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,60 +17,67 @@ std = [
"starknet-crypto/std",
"parse-hyperlinks/std",
"felt/std",
"num-prime",
]
cairo-1-hints = ["cairo-lang-starknet", "cairo-lang-casm", "ark-ff", "ark-std"]


# Note that these features are not retro-compatible with the cairo Python VM.
test_utils = ["skip_next_instruction_hint", "hooks"] # This feature will reference every test-oriented feature
test_utils = [
"skip_next_instruction_hint",
"hooks",
] # This feature will reference every test-oriented feature
skip_next_instruction_hint = []
hooks = []

[dependencies]
mimalloc = {workspace = true, optional = true}
num-bigint = {workspace = true}
rand = {workspace = true}
num-traits = {workspace = true}
num-integer = {workspace = true}
serde = {workspace = true}
serde_bytes = {workspace = true}
serde_json = {workspace = true}
hex = {workspace = true}
bincode = {workspace = true}
starknet-crypto = {workspace = true}
sha3 = {workspace = true}
rand_core = {workspace = true}
lazy_static = {workspace = true}
nom = {workspace = true}
sha2 = {workspace = true}
generic-array = {workspace = true}
keccak = {workspace = true}
hashbrown = {workspace = true}
anyhow = {workspace = true}
thiserror = {workspace = true}
thiserror-no-std = { workspace = true}
mimalloc = { workspace = true, optional = true }
num-bigint = { workspace = true }
rand = { workspace = true }
num-traits = { workspace = true }
num-integer = { workspace = true }
serde = { workspace = true }
serde_bytes = { workspace = true }
serde_json = { workspace = true }
hex = { workspace = true }
bincode = { workspace = true }
starknet-crypto = { workspace = true }
sha3 = { workspace = true }
rand_core = { workspace = true }
lazy_static = { workspace = true }
nom = { workspace = true }
sha2 = { workspace = true }
generic-array = { workspace = true }
keccak = { workspace = true }
hashbrown = { workspace = true }
anyhow = { workspace = true }
thiserror = { workspace = true }
thiserror-no-std = { workspace = true }

# only for std
num-prime = { version = "0.4.3", features = ["big-int"], optional = true }

# This crate has only one function `take_until_unbalanced` that is
# very useful for our parsing purposes:
# https://stackoverflow.com/questions/70630556/parse-allowing-nested-parentheses-in-nom
# There is a proposal for extending nom::delimited to use this function:
# https://github.com/Geal/nom/issues/1253
parse-hyperlinks = {workspace = true}
felt = {workspace = true}
bitvec = {workspace = true}
parse-hyperlinks = { workspace = true }
felt = { workspace = true }
bitvec = { workspace = true }

# Dependencies for cairo-1-hints feature
cairo-lang-starknet = {workspace = true, optional = true}
cairo-lang-casm = {workspace = true, optional = true}
cairo-lang-starknet = { workspace = true, optional = true }
cairo-lang-casm = { workspace = true, optional = true }

# TODO: check these dependencies for wasm compatibility
ark-ff = {workspace = true, optional = true}
ark-std = {workspace = true, optional = true}
ark-ff = { workspace = true, optional = true }
ark-std = { workspace = true, optional = true }

[dev-dependencies]
assert_matches = "1.5.0"
rstest = { version = "0.17.0", default-features = false }
num-prime = { version = "0.4.3", features = ["big-int"]}
num-prime = { version = "0.4.3", features = ["big-int"] }

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen-test = "0.3.34"
Expand Down
Loading

0 comments on commit 8a72ddc

Please sign in to comment.