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

Is ParametersVar necessary? #36

Open
tsunrise opened this issue Apr 2, 2021 · 3 comments
Open

Is ParametersVar necessary? #36

tsunrise opened this issue Apr 2, 2021 · 3 comments
Labels
D-medium Difficulty: medium P-low Priority: low T-design Type: discuss API design and/or research T-refactor Type: cleanup/refactor

Comments

@tsunrise
Copy link
Member

tsunrise commented Apr 2, 2021

pub trait FixedLengthCRHGadget<H: FixedLengthCRH, ConstraintF: Field>: Sized {
type OutputVar: EqGadget<ConstraintF>
+ ToBytesGadget<ConstraintF>
+ CondSelectGadget<ConstraintF>
+ AllocVar<H::Output, ConstraintF>
+ R1CSVar<ConstraintF>
+ Debug
+ Clone
+ Sized;
type ParametersVar: AllocVar<H::Parameters, ConstraintF> + Clone;
fn evaluate(
parameters: &Self::ParametersVar,
input: &[UInt8<ConstraintF>],
) -> Result<Self::OutputVar, SynthesisError>;
}

Is there any circumstance where user compute CRH parameters in circuit? Computing ParametersVar requires extra constraints so it should be better to allow an option to use native CRH parameters instead.

Relevant discussions: #30 (comment)

@weikengchen
Copy link
Member

Based on what I know, the ParametersVar has always been a trivial copy of Parameters in our current implementations, so it does not add any new constraints?

It would still be helpful to separate them since it opens the opportunity for one-time precomputation for some parameters in case we want to verify CRH inside the circuits, though none of our current constructions need this...

@Pratyush
Copy link
Member

Pratyush commented Apr 4, 2021

Hmm generally we always invoke alloc_constant on these CRH parameters, so it never actually costs any constraints. That being said, we should evaluate How the code would change if we replaced ParametersVar with just Parameters in, say, PedersenCRH

@weikengchen
Copy link
Member

weikengchen commented Apr 9, 2021

In PedersenCRH it seems that this change would be trivial since the current ParametersVar simply invokes Parameters.

#[derive(Derivative)]
#[derivative(Clone(bound = "C: ProjectiveCurve, GG: CurveVar<C, ConstraintF<C>>"))]
pub struct CRHParametersVar<C: ProjectiveCurve, GG: CurveVar<C, ConstraintF<C>>>
where
    for<'a> &'a GG: GroupOpsBounds<'a, C, GG>,
{
    params: Parameters<C>,
    #[doc(hidden)]
    _group_g: PhantomData<GG>,
}

If this does not create new constraints, we could come back to this issue later, like when we do a refactoring of CRH in the future.

@Pratyush Pratyush added D-medium Difficulty: medium P-low Priority: low T-design Type: discuss API design and/or research T-refactor Type: cleanup/refactor labels Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
D-medium Difficulty: medium P-low Priority: low T-design Type: discuss API design and/or research T-refactor Type: cleanup/refactor
Projects
None yet
Development

No branches or pull requests

3 participants