pub fn endomorphism_gadget(
    cs: ConstraintSystemRef<Fq>,
    point_var: &EdwardsAffineVar,
) -> Result<EdwardsAffineVar, SynthesisError> {
    let base = point_var.value()?.into_affine();
    let endor_point =
        <BandersnatchParameters as GLVParameters>::endomorphism(&base);
    let new_x_var = FqVar::new_witness(cs.clone(), || Ok(endor_point.x))?;
    let new_y_var = FqVar::new_witness(cs, || Ok(endor_point.y))?;

    let coeff_b_var =
        &FqVar::constant(<BandersnatchParameters as GLVParameters>::COEFF_B);
    let coeff_c_var =
        &FqVar::constant(<BandersnatchParameters as GLVParameters>::COEFF_C);

    let coeff_b_square_var = &FqVar::constant(
        <BandersnatchParameters as GLVParameters>::COEFF_B
            * <BandersnatchParameters as GLVParameters>::COEFF_B,
    );

    let x_var = &point_var.x;
    let y_var = &point_var.y;

    // xy = x * y
    let xy_var = x_var * y_var;
    // y_square = y^2
    let y_square_var = y_var * y_var;

    // f(y) = c(1-y^2)
    let f_y_var = coeff_c_var - coeff_c_var * &y_square_var;
    // g(y) = b(y^2 + b)
    let g_y_var = coeff_b_var * &y_square_var + coeff_b_square_var;
    // h(y) = y^2 - b
    let h_y_var = y_square_var - coeff_b_var;

    // x = f(y) / (xy)
    f_y_var.enforce_equal(&(&xy_var * &new_x_var))?;
    // y = g(y)/ h(y)
    g_y_var.enforce_equal(&(&h_y_var * &new_y_var))?;

    Ok(EdwardsAffineVar::new(new_x_var, new_y_var))
}
/// The circuit for computing the point endomorphism.
The circuit for computing the point endomorphism.
The circuit for computing the point endomorphism .
pub fn endomorphism_gadget(
    cs: ConstraintSystemRef<Fq>,
    point_var: &EdwardsAffineVar,
) -> Result<EdwardsAffineVar, SynthesisError> {
    let base = point_var.value()?.into_affine();
    let endor_point =
        <BandersnatchParameters as GLVParameters>::endomorphism(&base);
    let new_x_var = FqVar::new_witness(cs.clone(), || Ok(endor_point.x))?;
    let new_y_var = FqVar::new_witness(cs, || Ok(endor_point.y))?;
    let coeff_b_var =
        &FqVar::constant(<BandersnatchParameters as GLVParameters>::COEFF_B);
    let coeff_c_var =
        &FqVar::constant(<BandersnatchParameters as GLVParameters>::COEFF_C);
    let coeff_b_square_var = &FqVar::constant(
        <BandersnatchParameters as GLVParameters>::COEFF_B
            * <BandersnatchParameters as GLVParameters>::COEFF_B,
    );
    let x_var = &point_var.x;
    let y_var = &point_var.y;
    // xy = x * y
    let xy_var = x_var * y_var;
    // y_square = y^2
    let y_square_var = y_var * y_var;
    // f(y) = c(1-y^2)
    let f_y_var = coeff_c_var - coeff_c_var * &y_square_var;
    // g(y) = b(y^2 + b)
    let g_y_var = coeff_b_var * &y_square_var + coeff_b_square_var;
    // h(y) = y^2 - b
    let h_y_var = y_square_var - coeff_b_var;
    // x = f(y) / (xy)
    f_y_var.enforce_equal(&(&xy_var * &new_x_var))?;
    // y = g(y)/ h(y)
    g_y_var.enforce_equal(&(&h_y_var * &new_y_var))?;
    Ok(EdwardsAffineVar::new(new_x_var, new_y_var))
}
pub fn endomorphism_gadget ( cs : ConstraintSystemRef < Fq > , point_var : & EdwardsAffineVar , ) -> Result < EdwardsAffineVar , SynthesisError > { let base = point_var . value ( ) ? . into_affine ( ) ; let endor_point = < BandersnatchParameters as GLVParameters > :: endomorphism ( & base ) ; let new_x_var = FqVar :: new_witness ( cs . clone ( ) , | | Ok ( endor_point . x ) ) ? ; let new_y_var = FqVar :: new_witness ( cs , | | Ok ( endor_point . y ) ) ? ; let coeff_b_var = & FqVar :: constant ( < BandersnatchParameters as GLVParameters > :: COEFF_B ) ; let coeff_c_var = & FqVar :: constant ( < BandersnatchParameters as GLVParameters > :: COEFF_C ) ; let coeff_b_square_var = & FqVar :: constant ( < BandersnatchParameters as GLVParameters > :: COEFF_B * < BandersnatchParameters as GLVParameters > :: COEFF_B , ) ; let x_var = & point_var . x ; let y_var = & point_var . y ; // xy = x * y let xy_var = x_var * y_var ; // y_square = y^2 let y_square_var = y_var * y_var ; // f(y) = c(1-y^2) let f_y_var = coeff_c_var - coeff_c_var * & y_square_var ; // g(y) = b(y^2 + b) let g_y_var = coeff_b_var * & y_square_var + coeff_b_square_var ; // h(y) = y^2 - b let h_y_var = y_square_var - coeff_b_var ; // x = f(y) / (xy) f_y_var . enforce_equal ( & ( & xy_var * & new_x_var ) ) ? ; // y = g(y)/ h(y) g_y_var . enforce_equal ( & ( & h_y_var * & new_y_var ) ) ? ; Ok ( EdwardsAffineVar :: new ( new_x_var , new_y_var ) ) }
The circuit for computing the point endomorphism.
The circuit for computing the point endomorphism .
cs
ConstraintSystemRef<Fq>
point_var
&EdwardsAffineVar
cs
ConstraintSystemRef<Fq>
point_var
&EdwardsAffineVar