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

no-std support broken in 0.5.0 #71

Closed
tomaka opened this issue May 26, 2021 · 16 comments · Fixed by #75
Closed

no-std support broken in 0.5.0 #71

tomaka opened this issue May 26, 2021 · 16 comments · Fixed by #75

Comments

@tomaka
Copy link

tomaka commented May 26, 2021

This issue has the same title as #68, but the problem isn't the same.

As of version 0.5.0/core-0.2.0, recently published on crates.io, compiling with default-feature = false leads to compilation errors in the core:

error[E0412]: cannot find type `Vec` in this scope
  --> /home/pierre/.cargo/registry/src/github.com-1ecc6299db9ec823/libsecp256k1-core-0.2.0/src/ecmult.rs:19:19
   |
19 |     let mut prej: Vec<Jacobian> = Vec::with_capacity(pre.len());
   |                   ^^^ not found in this scope
   |
help: consider importing one of these items
   |
1  | use alloc::vec::Vec;
   |
1  | use crate::ecmult::vec::Vec;
   |

error[E0433]: failed to resolve: use of undeclared type `Vec`
  --> /home/pierre/.cargo/registry/src/github.com-1ecc6299db9ec823/libsecp256k1-core-0.2.0/src/ecmult.rs:19:35
   |
19 |     let mut prej: Vec<Jacobian> = Vec::with_capacity(pre.len());
   |                                   ^^^ not found in this scope
   |
help: consider importing one of these items
   |
1  | use alloc::vec::Vec;
   |
1  | use crate::ecmult::vec::Vec;
   |

error[E0412]: cannot find type `Vec` in this scope
  --> /home/pierre/.cargo/registry/src/github.com-1ecc6299db9ec823/libsecp256k1-core-0.2.0/src/ecmult.rs:23:19
   |
23 |     let mut prea: Vec<Affine> = Vec::with_capacity(pre.len());
   |                   ^^^ not found in this scope
   |
help: consider importing one of these items
   |
1  | use alloc::vec::Vec;
   |
1  | use crate::ecmult::vec::Vec;
   |

error[E0433]: failed to resolve: use of undeclared type `Vec`
  --> /home/pierre/.cargo/registry/src/github.com-1ecc6299db9ec823/libsecp256k1-core-0.2.0/src/ecmult.rs:23:33
   |
23 |     let mut prea: Vec<Affine> = Vec::with_capacity(pre.len());
   |                                 ^^^ not found in this scope
   |
help: consider importing one of these items
   |
1  | use alloc::vec::Vec;
   |
1  | use crate::ecmult::vec::Vec;
   |

error[E0412]: cannot find type `Vec` in this scope
  --> /home/pierre/.cargo/registry/src/github.com-1ecc6299db9ec823/libsecp256k1-core-0.2.0/src/ecmult.rs:27:17
   |
27 |     let mut zr: Vec<Field> = Vec::with_capacity(pre.len());
   |                 ^^^ not found in this scope
   |
help: consider importing one of these items
   |
1  | use alloc::vec::Vec;
   |
1  | use crate::ecmult::vec::Vec;
   |

error[E0433]: failed to resolve: use of undeclared type `Vec`
  --> /home/pierre/.cargo/registry/src/github.com-1ecc6299db9ec823/libsecp256k1-core-0.2.0/src/ecmult.rs:27:30
   |
27 |     let mut zr: Vec<Field> = Vec::with_capacity(pre.len());
   |                              ^^^ not found in this scope
   |
help: consider importing one of these items
   |
1  | use alloc::vec::Vec;
   |
1  | use crate::ecmult::vec::Vec;
   |

error[E0412]: cannot find type `Box` in this scope
  --> /home/pierre/.cargo/registry/src/github.com-1ecc6299db9ec823/libsecp256k1-core-0.2.0/src/ecmult.rs:62:27
   |
62 |     pub fn new_boxed() -> Box<Self> {
   |                           ^^^ not found in this scope
   |
help: consider importing one of these items
   |
1  | use alloc::prelude::v1::Box;
   |
1  | use crate::ecmult::vec::Box;
   |

error[E0433]: failed to resolve: use of undeclared type `Box`
  --> /home/pierre/.cargo/registry/src/github.com-1ecc6299db9ec823/libsecp256k1-core-0.2.0/src/ecmult.rs:69:28
   |
69 |             let mut this = Box::from_raw(ptr);
   |                            ^^^ not found in this scope
   |
help: consider importing one of these items
   |
1  | use alloc::prelude::v1::Box;
   |
1  | use crate::ecmult::vec::Box;
   |

error[E0412]: cannot find type `Vec` in this scope
  --> /home/pierre/.cargo/registry/src/github.com-1ecc6299db9ec823/libsecp256k1-core-0.2.0/src/ecmult.rs:88:43
   |
88 | pub fn set_all_gej_var(a: &[Jacobian]) -> Vec<Affine> {
   |                                           ^^^ not found in this scope
   |
help: consider importing one of these items
   |
1  | use alloc::vec::Vec;
   |
1  | use crate::ecmult::vec::Vec;
   |

error[E0412]: cannot find type `Vec` in this scope
  --> /home/pierre/.cargo/registry/src/github.com-1ecc6299db9ec823/libsecp256k1-core-0.2.0/src/ecmult.rs:89:17
   |
89 |     let mut az: Vec<Field> = Vec::with_capacity(a.len());
   |                 ^^^ not found in this scope
   |
help: consider importing one of these items
   |
1  | use alloc::vec::Vec;
   |
1  | use crate::ecmult::vec::Vec;
   |

error[E0433]: failed to resolve: use of undeclared type `Vec`
  --> /home/pierre/.cargo/registry/src/github.com-1ecc6299db9ec823/libsecp256k1-core-0.2.0/src/ecmult.rs:89:30
   |
89 |     let mut az: Vec<Field> = Vec::with_capacity(a.len());
   |                              ^^^ not found in this scope
   |
help: consider importing one of these items
   |
1  | use alloc::vec::Vec;
   |
1  | use crate::ecmult::vec::Vec;
   |

error[E0412]: cannot find type `Vec` in this scope
  --> /home/pierre/.cargo/registry/src/github.com-1ecc6299db9ec823/libsecp256k1-core-0.2.0/src/ecmult.rs:95:14
   |
95 |     let azi: Vec<Field> = inv_all_var(&az);
   |              ^^^ not found in this scope
   |
help: consider importing one of these items
   |
1  | use alloc::vec::Vec;
   |
1  | use crate::ecmult::vec::Vec;
   |

error[E0412]: cannot find type `Vec` in this scope
   --> /home/pierre/.cargo/registry/src/github.com-1ecc6299db9ec823/libsecp256k1-core-0.2.0/src/ecmult.rs:114:41
    |
114 | pub fn inv_all_var(fields: &[Field]) -> Vec<Field> {
    |                                         ^^^ not found in this scope
    |
help: consider importing one of these items
    |
1   | use alloc::vec::Vec;
    |
1   | use crate::ecmult::vec::Vec;
    |

error[E0433]: failed to resolve: use of undeclared type `Vec`
   --> /home/pierre/.cargo/registry/src/github.com-1ecc6299db9ec823/libsecp256k1-core-0.2.0/src/ecmult.rs:116:16
    |
116 |         return Vec::new();
    |                ^^^ not found in this scope
    |
help: consider importing one of these items
    |
1   | use alloc::vec::Vec;
    |
1   | use crate::ecmult::vec::Vec;
    |

error[E0433]: failed to resolve: use of undeclared type `Vec`
   --> /home/pierre/.cargo/registry/src/github.com-1ecc6299db9ec823/libsecp256k1-core-0.2.0/src/ecmult.rs:119:19
    |
119 |     let mut ret = Vec::with_capacity(fields.len());
    |                   ^^^ not found in this scope
    |
help: consider importing one of these items
    |
1   | use alloc::vec::Vec;
    |
1   | use crate::ecmult::vec::Vec;
    |

error[E0412]: cannot find type `Box` in this scope
   --> /home/pierre/.cargo/registry/src/github.com-1ecc6299db9ec823/libsecp256k1-core-0.2.0/src/ecmult.rs:187:27
    |
187 |     pub fn new_boxed() -> Box<Self> {
    |                           ^^^ not found in this scope
    |
help: consider importing one of these items
    |
1   | use alloc::prelude::v1::Box;
    |
1   | use crate::ecmult::vec::Box;
    |

error[E0433]: failed to resolve: use of undeclared type `Box`
   --> /home/pierre/.cargo/registry/src/github.com-1ecc6299db9ec823/libsecp256k1-core-0.2.0/src/ecmult.rs:194:28
    |
194 |             let mut this = Box::from_raw(ptr);
    |                            ^^^ not found in this scope
    |
help: consider importing one of these items
    |
1   | use alloc::prelude::v1::Box;
    |
1   | use crate::ecmult::vec::Box;
    |

error[E0412]: cannot find type `Vec` in this scope
   --> /home/pierre/.cargo/registry/src/github.com-1ecc6299db9ec823/libsecp256k1-core-0.2.0/src/ecmult.rs:226:24
    |
226 |         let mut precj: Vec<Jacobian> = Vec::with_capacity(1024);
    |                        ^^^ not found in this scope
    |
help: consider importing one of these items
    |
1   | use alloc::vec::Vec;
    |
1   | use crate::ecmult::vec::Vec;
    |

error[E0433]: failed to resolve: use of undeclared type `Vec`
   --> /home/pierre/.cargo/registry/src/github.com-1ecc6299db9ec823/libsecp256k1-core-0.2.0/src/ecmult.rs:226:40
    |
226 |         let mut precj: Vec<Jacobian> = Vec::with_capacity(1024);
    |                                        ^^^ not found in this scope
    |
help: consider importing one of these items
    |
1   | use alloc::vec::Vec;
    |
1   | use crate::ecmult::vec::Vec;
    |

error: aborting due to 19 previous errors

Some errors have detailed explanations: E0412, E0433.
For more information about an error, try `rustc --explain E0412`.
error: could not compile `libsecp256k1-core`

To reproduce, just add libsecp256k1 = { version = "0.5.0", default-features = false } as a dependency to a project.

@fredfortier
Copy link

Same issue here. Here's what cargo nono says:

libsecp256k1: FAILURE
  - Did not find a #![no_std] attribute or a simple conditional attribute like #[cfg_attr(not(feature = "std"), no_std)] in the crate source. Crate most likely doesn't support no_std without changes.
log: FAILURE

@tomusdrw
Copy link

bump

@trevor-crypto
Copy link
Contributor

trevor-crypto commented Jul 14, 2021

Doing some investigation because I would like to move this forward as well.

I believe the issue came from the changes in #41 which make use of allocation (Vec and Box)

Would like to know what everyone else thinks. At first glance, it does not seem possible to feature-gate behind feature = "std" because the functions are used in the generators used in build.rs

Related: #46

@trevor-crypto
Copy link
Contributor

trevor-crypto commented Jul 20, 2021

#75 should resolve this issue, which is in 0.6.0

@samkirton
Copy link

I am experiencing this issue in 0.6.0 with:

libsecp256k1 = { version="0.6.0", default-features=false, features=["static-context"] }

std duplicate method exceptions are thrown noting:

the lang item is first defined in crate `std` (which `libsecp256k1_core` depends on)

@trevor-crypto
Copy link
Contributor

@samkirton that's strange...I just tried again with static-context and could not reproduce this. Do you have another crate in your dependencies that is possibly enabling std for libsecp256k1_core?

@samkirton
Copy link

The only other dependencies I have are:

rand = { version="0.7.3", optional = true }
sha2 = { version="0.9.5", default-features=false }

[features]
signing = ["rand", "libsecp256k1/hmac"]

where rand is turned on only for the signing feature

@trevor-crypto
Copy link
Contributor

@samkirton I still can't reproduce your exact error message above, but I can reproduce a similar one when I use rand as you have in your dependencies. You might need to turn off default-features for rand if you're using no_std when the signing feature is enabled.

@samkirton
Copy link

samkirton commented Aug 23, 2021

Signing requires hmac, which requires std, so rand is only ever used for std builds. I will try and disable default features on rand though just incase optional = true isn't working as I expected it to

@trevor-crypto
Copy link
Contributor

Signing requires hmac, which requires std, so rand is only ever used for std builds.

Oh right, sorry.

@fredfortier
Copy link

@trevor-crypto I just tried to upgrade to 0.6.0 from 0.3.5 and getting std dependencies again. I guess it's expected based on your note above:

Signing requires hmac, which requires std, so rand is only ever used for std builds.

Does this mean that this crate no longer support signing with no_std? There must be a no_std version of hmac because 0.3.5 is depending on one.

@fredfortier
Copy link

fredfortier commented Aug 25, 2021

I tried using the blank_with_context variants thinking that the static-context feature may have been the problem but it's not.

This dependency alone pulls in the std:

libsecp256k1 = { version = "0.6.0", default-features = false, features = [
    "hmac"
] }

It would be great (or rather necessary) to have no_std signing feature like in earlier versions. My only known option is to downgrade to 0.3.5 which I'll have to patch because some of its dependencies are no longer on crates_io.

trevor-crypto added a commit to trevor-crypto/libsecp256k1 that referenced this issue Aug 25, 2021
- Turn off default features for core in gen and genmult
- Use serde-json-core (no_std support) in dev-dependencies

Relates to paritytech#71
@trevor-crypto
Copy link
Contributor

@fredfortier I submitted a PR. If you'd like you can test it out on my branch or wait for it to come into develop

@fredfortier
Copy link

I'm confused about this issue as well because cargo nono check gives the dependency above (with only the hmac feature) a clear report, but the compiler gives an std error when I use it. I'll try your branch.

@fredfortier
Copy link

You did it @trevor-crypto . Your branch referenced above is now working for me when compiling to my no_std target.

sorpaas pushed a commit that referenced this issue Sep 13, 2021
* Fix no_std builds attempt 2

- Turn off default features for core in gen and genmult
- Use serde-json-core (no_std support) in dev-dependencies

Relates to #71

* Use resolver="2"

Allows us to use serde_json in dev-dependencies and compile for no_std:

https://blog.rust-lang.org/2021/03/25/Rust-1.51.0.html#cargos-new-feature-resolver

* revert unnecessary changes
@sorpaas
Copy link
Member

sorpaas commented Sep 15, 2021

This should be fixed now. Let me know if the error still exists.

@sorpaas sorpaas closed this as completed Sep 15, 2021
trevor-crypto added a commit to monacohq/libsecp256k1 that referenced this issue May 31, 2022
* Fix no_std builds attempt 2

- Turn off default features for core in gen and genmult
- Use serde-json-core (no_std support) in dev-dependencies

Relates to paritytech#71

* Use resolver="2"

Allows us to use serde_json in dev-dependencies and compile for no_std:

https://blog.rust-lang.org/2021/03/25/Rust-1.51.0.html#cargos-new-feature-resolver

* revert unnecessary changes
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 a pull request may close this issue.

6 participants