Skip to content

Domain Tag Generation Macros #45

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

Open
bhgomes opened this issue Dec 9, 2022 · 0 comments
Open

Domain Tag Generation Macros #45

bhgomes opened this issue Dec 9, 2022 · 0 comments
Labels
A-macros Area: Issues and PRs related to Rust Macros

Comments

@bhgomes
Copy link
Member

bhgomes commented Dec 9, 2022

When building domain tags we usually use a trait like this:

/// Domain Tag
pub trait DomainTag<T>
where
    T: ParameterFieldType,
{
    /// Generates domain tag as a constant parameter.
    fn domain_tag() -> T::ParameterField;
}

and then build custom domain tags with code like this (from manta-rs):

/// Utxo Commitment Scheme Domain Tag
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct UtxoCommitmentSchemeDomainTag;

impl poseidon::hash::DomainTag<Poseidon5> for UtxoCommitmentSchemeDomainTag {
    #[inline]
    fn domain_tag() -> <Poseidon5 as ParameterFieldType>::ParameterField {
        todo!()
    }
}

impl<COM> Constant<COM> for UtxoCommitmentSchemeDomainTag {
    type Type = Self;

    #[inline]
    fn new_constant(this: &Self::Type, compiler: &mut COM) -> Self {
        let _ = (this, compiler);
        Self
    }
}

We should be able to simplify this to a generic domain tag type:

/// Domain Tag Parameter
#[component]
pub type DomainTagParameter;

/// Domain Tag
pub trait DomainTag<T>
where
    T: DomainTagParameterType,
{
    /// Generates a domain tag.
    fn domain_tag() -> T::DomainTagParameterType;
}

so that an implementation looks like this:

/// Utxo Commitment Scheme Domain Tag
#[domain_tag(Poseidon5)]
pub struct UtxoCommitmentSchemeDomainTag;
@bhgomes bhgomes added the A-macros Area: Issues and PRs related to Rust Macros label Dec 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: Issues and PRs related to Rust Macros
Development

No branches or pull requests

1 participant