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

Derive macro MontConfig panics if any other attribute is applied #704

Closed
aleasims opened this issue Nov 21, 2023 · 2 comments · Fixed by #747
Closed

Derive macro MontConfig panics if any other attribute is applied #704

aleasims opened this issue Nov 21, 2023 · 2 comments · Fixed by #747
Labels
T-bug Type: bug

Comments

@aleasims
Copy link
Contributor

When I'm trying to apply any additional attributes to structure with #[derive(MontConfig)], it results in a panic:

error: proc-macro derive panicked
 --> /root/proj/arkworks-curves/pallas/src/fields/fq.rs:4:10
  |
4 | #[derive(MontConfig)]
  |          ^^^^^^^^^^
  |
  = help: message: attribute modulus should be a string

E.g in case I want my config structure depend on some feature, I can't compile something like:

#[derive(MontConfig)]
#[modulus = "28948022309329048855892746252171976963363056481941560715954676764349967630337"]
#[generator = "5"]
#[cfg(feature = "some_feature_name")]
pub struct FqConfig;

As far as I understood, the problem is in ark_ff_macros::fetch_attr function, which rejects any meta except syn::Meta::NameValue. That's why attribute #[cfg(feature = "some_feature_name")] leads to a panic.

Is there any reason, why you disallow other attributes for MontConfig structures?

@mmagician
Copy link
Member

You're right, this is a potentially desirable feature. I'm not aware of any way of doing directly what you're proposing.
I can offer a simple workaround though:

#[cfg(feature = "feature1")]
pub use fp::FqConfig;

#[cfg(feature = "feautre1")]
mod fp {
    use ark_ff::fields::{Fp384, MontBackend, MontConfig};

    #[derive(MontConfig)]
    #[modulus = "28948022309329048855892746252171976963363056481941560715954676764349967630337"]
    #[generator = "5"]
    pub struct FqConfig;
}

#[cfg(feature = "feature2")]
pub use fp::{Fq, FqConfig};

#[cfg(feature = "feature2")]
mod fp {...}

I hope this helps!

@mmagician mmagician added the T-bug Type: bug label Jan 11, 2024
aleasims added a commit to aleasims/algebra that referenced this issue Jan 11, 2024
Previously fetching function was panicing on every different attribute.
Now it simply skips attributes of different format.  As a result, it is possible
now to apply other attributes when defining strucutre with MontConfig.
Original issue is arkworks-rs#704
aleasims added a commit to aleasims/algebra that referenced this issue Jan 11, 2024
@aleasims
Copy link
Contributor Author

@mmagician Thanks for your answer!

I've come up with a possible fix for this issue, including changes in ark-ff-macros. Hope that will close this issue.

github-merge-queue bot pushed a commit that referenced this issue Jan 11, 2024
* Fix fetching attributes in MontConfig macro

Previously fetching function was panicing on every different attribute.
Now it simply skips attributes of different format.  As a result, it is possible
now to apply other attributes when defining strucutre with MontConfig.
Original issue is #704

* Update CHANGELOG after fixing bug #704
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants