-
Notifications
You must be signed in to change notification settings - Fork 79
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
Draft
greenhat
wants to merge
5
commits into
main
Choose a base branch
from
greenhat-unified-felt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ba5aa2b
refactor: add `Felt` type unified for off-chain and on-chain code,
greenhat 1519870
refactor: move `Word` and derived types from `miden-crypto` to `miden…
greenhat 2340896
chore: add `make build_target_miden` task and `targe-miden` CI job in…
greenhat d852c32
fix: bring wasm+miden Felt API on par with native
greenhat 06d007b
fix: build `miden-field` for wasm+miden target
greenhat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| 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" } | ||
|
|
||
| [features] | ||
| default = [] | ||
| testing = ["dep:proptest"] | ||
|
|
||
| [dev-dependencies] | ||
| rand = { default-features = false, version = "0.9" } | ||
| rstest = { version = "0.26" } | ||
|
|
||
| [lints] | ||
| workspace = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() { | ||
| println!("cargo::rustc-cfg=miden"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| //! A unified `Felt` for Miden Rust code. | ||
| //! | ||
| //! 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}; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
miden-fieldcrate has no tests. Since this is cryptographic code used throughout the codebase, consider adding unit tests for both the native and WASM implementations to ensure correctness of field operations.