Skip to content
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

Add no-std support #11

Merged
merged 10 commits into from
May 6, 2022
Merged

Add no-std support #11

merged 10 commits into from
May 6, 2022

Conversation

krnak
Copy link
Contributor

@krnak krnak commented Jan 19, 2022

Add support for no-std builds.

comments to this PR:

  • no code changed, except src/error.rs where I had to avoid usage of thiserror (crate has not no-std support)
  • module frost still depends on std
  • crate still depends on alloc because usage of Vec in VartimeMultiscalarMul implementations
  • tests/bincode.rs enabled only on std feature, because it depends on serde
  • serde enabled if std enabled, because serde-conditioned compilation for module messages is missing #9

@krnak
Copy link
Contributor Author

krnak commented Jan 19, 2022

I am working on alloc-independent version.

Copy link
Collaborator

@str4d str4d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK with cleanup suggestion.

src/lib.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@daira daira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@krnak
Copy link
Contributor Author

krnak commented Jan 25, 2022

cleaned up & rebased . but not ready to merge

[SOLVED]
I need your comments on these two issues:

  1. I would be a lot of work to make tests working in no-std (working with unstable no-std version of proptest, changing sources of randomness, etc.). May I just disable most of tests if std feature is off?

  2. If I condition batch module by new alloc feature flag, whole crate could be alloc independent. Unfortunately I have no idea how to conditionally disable VartimeMultiscalarMul trait bound for Sealed::Point, when alloc flag is off. VartimeMultiscalarMul is used only for batching and its implementation depend on Vec. My proposition is to add naive no-std implementation like:

    fn optional_multiscalar_mul<I, J>(scalars: I, points: J) -> Option<ExtendedPoint> where ... {
        #[cfg(feature = "alloc")]
        {...}
        #[cfg(not(feature = "alloc"))]
        scalars
            .into_iter() 
            .map(|c| c.borrow().clone())
            .zip(points.into_iter())
            .try_fold(ExtendedPoint::identity(), |acc, (s, p)| Some(acc + p? * s))
    }

Is the aforementioned approach fine? Or do you see any better approach?

@krnak krnak marked this pull request as draft February 5, 2022 11:41
@krnak
Copy link
Contributor Author

krnak commented Mar 16, 2022

I return to this PR. It's ready for a review and merge. @str4d @daira

Issues from the previous comment:

  1. I let tests to be std-dependent. I don't see any reason for testing in no-std environment. Furthermore this PR doesn't bring any new code, just compilation flags.
  2. I found a simple way (code) how to condition VartimeMultiscalarMul trait by alloc feature. So the crate supports pure no-std builds now.

@krnak krnak marked this pull request as ready for review March 16, 2022 09:35
@krnak krnak requested a review from str4d March 16, 2022 09:38
Copy link
Collaborator

@daira daira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

Copy link
Contributor

@conradoplg conradoplg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks! Just needs a small adjustment

Cargo.toml Show resolved Hide resolved
src/error.rs Show resolved Hide resolved
@codecov-commenter
Copy link

Codecov Report

Merging #11 (3caf57b) into main (0e912de) will decrease coverage by 0.10%.
The diff coverage is 71.42%.

@@            Coverage Diff             @@
##             main      #11      +/-   ##
==========================================
- Coverage   86.75%   86.65%   -0.11%     
==========================================
  Files          15       15              
  Lines        1148     1154       +6     
==========================================
+ Hits          996     1000       +4     
- Misses        152      154       +2     

Copy link
Contributor

@conradoplg conradoplg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed to 2021 edition to fix the resolver issue and solved conflicts.

src/error.rs Show resolved Hide resolved
Cargo.toml Show resolved Hide resolved
@conradoplg conradoplg merged commit ed11f44 into ZcashFoundation:main May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants