-
Notifications
You must be signed in to change notification settings - Fork 88
refactor: swap Goldilocks re-export to the Felt type unified for off-chain and on-chain code
#819
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
Changes from 5 commits
ba5aa2b
1519870
2340896
d852c32
06d007b
c5ae258
0e06cae
d0a0ae6
2374a2b
9ab51d9
2adaca4
d973a9b
b818ccc
f3f7bda
81f9ce6
a08abee
ad0c03f
ea183ce
2d67e4c
21199a3
04f5af6
a897b5b
daab99c
f3e1a5a
440b59e
59dadc1
7e5a2cb
12a70dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| [package] | ||
| authors.workspace = true | ||
| categories.workspace = true | ||
| description = "A unified field element type for on-chain and off-chain Miden Rust code" | ||
| documentation = "https://docs.rs/miden-field" | ||
| edition.workspace = true | ||
| keywords.workspace = true | ||
| license.workspace = true | ||
| name = "miden-field" | ||
| readme = "../README.md" | ||
|
bobbinth marked this conversation as resolved.
Outdated
|
||
| repository.workspace = true | ||
| rust-version.workspace = true | ||
| version.workspace = true | ||
|
|
||
| [lib] | ||
| crate-type = ["rlib"] | ||
|
|
||
| # dependendies for off-chain target | ||
| [target.'cfg(not(all(target_family = "wasm", miden)))'.dependencies] | ||
| miden-serde-utils = { workspace = true } | ||
| num-bigint = { default-features = false, version = "0.4" } | ||
| p3-challenger = { default-features = false, version = "0.4.2" } | ||
| p3-field = { default-features = false, version = "0.4.2" } | ||
| p3-goldilocks = { default-features = false, version = "0.4.2" } | ||
| paste = { version = "1.0.15" } | ||
| proptest = { default-features = false, features = ["alloc"], optional = true, version = "1.7" } | ||
| rand = { default-features = false, features = ["small_rng"], version = "0.9.0" } | ||
| serde = { default-features = false, features = ["derive"], version = "1.0" } | ||
|
|
||
| # dependendies for on-chain target | ||
| [dependencies] | ||
| thiserror = { default-features = false, version = "2.0" } | ||
|
bobbinth marked this conversation as resolved.
Outdated
|
||
|
|
||
| [features] | ||
| default = [] | ||
| testing = ["dep:proptest"] | ||
|
|
||
| [dev-dependencies] | ||
| rand = { default-features = false, version = "0.9" } | ||
| rstest = { version = "0.26" } | ||
|
bobbinth marked this conversation as resolved.
Outdated
|
||
|
|
||
| [lints] | ||
| workspace = true | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| use std::env; | ||
|
|
||
| fn main() { | ||
| println!("cargo::rerun-if-env-changed=MIDENC_TARGET_IS_MIDEN_VM"); | ||
| println!("cargo::rustc-check-cfg=cfg(miden)"); | ||
|
|
||
| // `cargo-miden` compiles Rust to Wasm which will then be compiled to Miden VM code by `midenc`. | ||
| // When targeting a "real" Wasm runtime (e.g. `wasm32-unknown-unknown` for a web SDK), we want a | ||
| // regular felt representation instead. | ||
| if env::var_os("MIDENC_TARGET_IS_MIDEN_VM").is_some() { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: This accepts any value (even empty string) for
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! Thanks! Done in 7e5a2cb |
||
| println!("cargo::rustc-cfg=miden"); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| //! A unified `Felt` for Miden Rust code. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure adding tests for For native implementation, I think the main thing we'd be testing is that we didn't mix up delegated function calls. Maybe there is a way to add a couple of tests which would run all (most?) operations on some random elements and make sure we get the same result for
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The For native implementation, the only thing worth testing is that we're delegating properly to the underlying |
||
| //! | ||
| //! This crate provides a single `Felt` type that can be used in both: | ||
| //! - On-chain (Wasm + `miden`): `Felt` is backed by a Miden VM felt via compiler intrinsics. | ||
| //! - Off-chain (native / non-Miden Wasm): `Felt` is backed by Plonky3's Goldilocks field element. | ||
|
|
||
| #![no_std] | ||
| #![deny(warnings)] | ||
|
|
||
| extern crate alloc; | ||
|
|
||
| #[cfg(all(target_family = "wasm", miden))] | ||
| mod wasm_miden; | ||
| #[cfg(all(target_family = "wasm", miden))] | ||
| pub use wasm_miden::Felt; | ||
|
|
||
| #[cfg(not(all(target_family = "wasm", miden)))] | ||
| mod native; | ||
| #[cfg(not(all(target_family = "wasm", miden)))] | ||
| pub use native::Felt; | ||
|
|
||
| pub mod utils; | ||
|
|
||
| pub mod word; | ||
|
|
||
| pub use word::{Word, WordError}; | ||
Uh oh!
There was an error while loading. Please reload this page.