Skip to content

Commit

Permalink
add outcome to lpc marshalling, todos #73
Browse files Browse the repository at this point in the history
update marshalling for proof-producer #73

Remove r1cs marshalling tests and example, update todos for zk #73

todo merkle proof

abstract method generate_assignments #73

Leave merkle_proof as it is #73

todo in tests

removed extended_integral_type

updating extended_integral_type #86

rm extended_integral_type from pairings #86

cleanup blueprint

wip removing r1cs

rm extended, change quotes

wip cleanup todos

wip

stale marshalling headers cleanup

Done with all todos in algebra

reworking type traits

wip [ci skip]

Formulae for converting a point from Edwards to Montgomery form

wip

wip type traits

cleanup

cleanup

wip

wip

refine params

cleanup [ci-skip]

wip

simplify field check

ppzk cleanup and marshalling fixes

changes to optional in pairings

mul by scalar fix

polish
  • Loading branch information
vo-nil committed Oct 23, 2024
1 parent 6572b08 commit cdf6ac2
Show file tree
Hide file tree
Showing 336 changed files with 1,320 additions and 52,507 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,12 @@

#include <nil/crypto3/algebra/pairing/pairing_policy.hpp>

#include <optional>

namespace nil {
namespace crypto3 {
namespace algebra {

// template<typename PairingCurveType>
// typename PairingCurveType::pairing::affine_ate_g1_precomp
// affine_ate_precompute_g1(const typename PairingCurveType::pairing::g1_type::value_type &P) {

// return PairingCurveType::pairing::affine_ate_precompute_g1(P);
// }

// template<typename PairingCurveType>
// typename PairingCurveType::pairing::affine_ate_g2_precomp
// affine_ate_precompute_g2(const typename PairingCurveType::pairing::g2_type::value_type &P) {

// return PairingCurveType::pairing::affine_ate_precompute_g2(P);
// }

// template<typename PairingCurveType>
// typename PairingCurveType::pairing::gt_type::value_type
// affine_ate_miller_loop(const typename PairingCurveType::pairing::affine_ate_g1_precomp &prec_P,
// const typename PairingCurveType::pairing::affine_ate_g2_precomp &prec_Q) {

// return PairingCurveType::pairing::affine_ate_miller_loop(prec_P, prec_Q);
// }

template<typename PairingCurveType, typename PairingPolicy = pairing::pairing_policy<PairingCurveType>>
typename PairingPolicy::g1_precomputed_type
precompute_g1(const typename PairingCurveType::template g1_type<>::value_type &P) {
Expand Down Expand Up @@ -89,7 +69,7 @@ namespace nil {
#endif

template<typename PairingCurveType, typename PairingPolicy = pairing::pairing_policy<PairingCurveType>>
typename PairingCurveType::gt_type::value_type
std::optional<typename PairingCurveType::gt_type::value_type>
pair_reduced(const typename PairingCurveType::template g1_type<>::value_type &v1,
const typename PairingCurveType::template g2_type<>::value_type &v2) {

Expand All @@ -111,7 +91,7 @@ namespace nil {
}

template<typename PairingCurveType, typename PairingPolicy = pairing::pairing_policy<PairingCurveType>>
typename PairingCurveType::gt_type::value_type
std::optional<typename PairingCurveType::gt_type::value_type>
final_exponentiation(const typename PairingCurveType::gt_type::value_type &elt) {

return PairingPolicy::final_exponentiation::process(elt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ namespace nil {
using base_field_type = typename alt_bn128_types<254>::base_field_type;
using scalar_field_type = typename alt_bn128_types<254>::scalar_field_type;

constexpr static const typename alt_bn128_types<254>::integral_type a =
typename alt_bn128_types<254>::integral_type(
0x00); ///< coefficient of short Weierstrass curve $y^2=x^3+a*x+b$
constexpr static const typename alt_bn128_types<254>::integral_type b =
typename alt_bn128_types<254>::integral_type(
0x03); ///< coefficient of short Weierstrass curve $y^2=x^3+a*x+b$
///< coefficients of short Weierstrass curve $y^2=x^3+a*x+b$
constexpr static const typename alt_bn128_types<254>::base_field_type::value_type
a = 0x00;
constexpr static const typename alt_bn128_types<254>::base_field_type::value_type
b = 0x03;
};

template<>
Expand Down Expand Up @@ -104,9 +103,9 @@ namespace nil {
0x90689D0585FF075EC9E99AD690C3395BC4B313370B38EF355ACDADCD122975B_cppui_modular254)};
};

constexpr typename alt_bn128_types<254>::integral_type const
constexpr typename alt_bn128_types<254>::base_field_type::value_type const
alt_bn128_params<254, forms::short_weierstrass>::a;
constexpr typename alt_bn128_types<254>::integral_type const
constexpr typename alt_bn128_types<254>::base_field_type::value_type const
alt_bn128_params<254, forms::short_weierstrass>::b;

constexpr std::array<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,35 +42,35 @@ namespace nil {
using scalar_field_type = typename babyjubjub_types::scalar_field_type;

// Edwards representation constants a and d
constexpr static const typename babyjubjub_types::integral_type
constexpr static const typename babyjubjub_types::base_field_type::value_type
a = ///< twisted Edwards elliptic curve
0x292FC_cppui_modular18; ///< described by equation ax^2 + y^2 = 1 + dx^2y^2
constexpr static const typename babyjubjub_types::integral_type
constexpr static const typename babyjubjub_types::base_field_type::value_type
d = ///< twisted Edwards elliptic curve
0x292F8_cppui_modular18; ///< described by equation ax^2 + y^2 = 1 + dx^2y^2
};

constexpr
typename babyjubjub_types::integral_type const babyjubjub_params<forms::twisted_edwards>::a;
typename babyjubjub_types::base_field_type::value_type const babyjubjub_params<forms::twisted_edwards>::a;
constexpr
typename babyjubjub_types::integral_type const babyjubjub_params<forms::twisted_edwards>::d;
typename babyjubjub_types::base_field_type::value_type const babyjubjub_params<forms::twisted_edwards>::d;

template<>
struct babyjubjub_params<forms::montgomery> {
using base_field_type = typename babyjubjub_types::base_field_type;
using scalar_field_type = typename babyjubjub_types::scalar_field_type;

// Montgomery representation constants A and B
constexpr static const typename babyjubjub_types::integral_type
constexpr static const typename babyjubjub_types::base_field_type::value_type
A = ///< Montgomery elliptic curve
0x292FA_cppui_modular18; ///< described by equation b*y^2 = x^3 + a*x^2 + x
constexpr static const typename babyjubjub_types::integral_type
constexpr static const typename babyjubjub_types::base_field_type::value_type
B = ///< Montgomery elliptic curve
0x01; ///< described by equation b*y^2 = x^3 + a*x^2 + x
};

constexpr typename babyjubjub_types::integral_type const babyjubjub_params<forms::montgomery>::A;
constexpr typename babyjubjub_types::integral_type const babyjubjub_params<forms::montgomery>::B;
constexpr typename babyjubjub_types::base_field_type::value_type const babyjubjub_params<forms::montgomery>::A;
constexpr typename babyjubjub_types::base_field_type::value_type const babyjubjub_params<forms::montgomery>::B;

template<>
struct babyjubjub_g1_params<forms::twisted_edwards>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ namespace nil {
using base_field_type = typename bls12_types<377>::base_field_type;
using scalar_field_type = typename bls12_types<377>::scalar_field_type;

constexpr static const typename bls12_types<377>::integral_type a =
typename bls12_types<377>::integral_type(
0x00); ///< coefficient of short Weierstrass curve $y^2=x^3+a*x+b$
constexpr static const typename bls12_types<377>::integral_type b =
typename bls12_types<377>::integral_type(
0x01); ///< coefficient of short Weierstrass curve $y^2=x^3+a*x+b$
///< coefficients of short Weierstrass curve $y^2=x^3+a*x+b$
constexpr static const typename bls12_types<377>::base_field_type::value_type
a = 0x00;
constexpr static const typename bls12_types<377>::base_field_type::value_type
b = 0x01;
};

template<>
Expand Down Expand Up @@ -109,9 +108,9 @@ namespace nil {
};

constexpr
typename bls12_types<377>::integral_type const bls12_params<377, forms::short_weierstrass>::a;
typename bls12_types<377>::base_field_type::value_type const bls12_params<377, forms::short_weierstrass>::a;
constexpr
typename bls12_types<377>::integral_type const bls12_params<377, forms::short_weierstrass>::b;
typename bls12_types<377>::base_field_type::value_type const bls12_params<377, forms::short_weierstrass>::b;

constexpr std::array<
typename bls12_g1_params<377, forms::short_weierstrass>::field_type::value_type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ namespace nil {
using base_field_type = typename bls12_types<381>::base_field_type;
using scalar_field_type = typename bls12_types<381>::scalar_field_type;

constexpr static const typename bls12_types<381>::integral_type a =
typename bls12_types<381>::integral_type(
0x00); ///< coefficient of short Weierstrass curve $y^2=x^3+a*x+b$
constexpr static const typename bls12_types<381>::integral_type b =
typename bls12_types<381>::integral_type(
0x04); ///< coefficient of short Weierstrass curve $y^2=x^3+a*x+b$
///< coefficients of short Weierstrass curve $y^2=x^3+a*x+b$
constexpr static const typename bls12_types<381>::base_field_type::value_type
a = 0x00;
constexpr static const typename bls12_types<381>::base_field_type::value_type
b = 0x04;
};

template<>
Expand Down Expand Up @@ -109,9 +108,9 @@ namespace nil {
};

constexpr
typename bls12_types<381>::integral_type const bls12_params<381, forms::short_weierstrass>::a;
typename bls12_types<381>::base_field_type::value_type const bls12_params<381, forms::short_weierstrass>::a;
constexpr
typename bls12_types<381>::integral_type const bls12_params<381, forms::short_weierstrass>::b;
typename bls12_types<381>::base_field_type::value_type const bls12_params<381, forms::short_weierstrass>::b;

constexpr typename bls12_g2_params<381, forms::short_weierstrass>::field_type::value_type const
bls12_g2_params<381, forms::short_weierstrass>::b;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,14 @@ namespace nil {
using scalar_field_type = typename curve25519_types::scalar_field_type;
#ifdef __ZKLLVM__
#else
constexpr static typename curve25519_types::integral_type a = typename curve25519_types::integral_type(
0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec_cppui_modular255); ///< coefficient
///< of
///< Twisted
///< Edwards
///< curves
///< $a*x^2+y^2=1+d*x^2*y^2$
constexpr static typename curve25519_types::integral_type d = typename curve25519_types::integral_type(
0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3_cppui_modular255); ///< coefficient
///< of
///< Twisted
///< Edwards
///< curves
///< $a*x^2+y^2=1+d*x^2*y^2$
/* Coefficients of Twisted Edwards form:
* a*x^2 + y^2 = 1 + d * x^2 * y^2
* a = -1, d = -121665/121666
* */
constexpr static typename base_field_type::value_type a =
base_field_type::modulus - 1;
constexpr static typename base_field_type::value_type d =
- base_field_type::value_type(121665) / base_field_type::value_type(121666);
#endif
};

Expand Down Expand Up @@ -136,8 +130,8 @@ namespace nil {
constexpr std::array<typename curve25519_g1_params<forms::montgomery>::field_type::value_type, 2>
curve25519_g1_params<forms::montgomery>::one_fill;

constexpr typename curve25519_types::integral_type curve25519_params<forms::twisted_edwards>::a;
constexpr typename curve25519_types::integral_type curve25519_params<forms::twisted_edwards>::d;
constexpr typename curve25519_types::base_field_type::value_type curve25519_params<forms::twisted_edwards>::a;
constexpr typename curve25519_types::base_field_type::value_type curve25519_params<forms::twisted_edwards>::d;

constexpr std::array<typename curve25519_g1_params<forms::twisted_edwards>::field_type::value_type,
2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,20 @@ namespace nil {
* @return doubled element from group G1
*/
constexpr void double_inplace() {
if ( 2 * params_type::B * this->Y == field_value_type::zero() ) {
const field_value_type two(2u);
const field_value_type twoBY = two * params_type::B * this->Y;

if ( twoBY == field_value_type::zero() ) {
this->is_inf_point = true;
return;
}

if (!this->is_zero()) {
const field_value_type two(2u);
const field_value_type three(3u);
const field_value_type A(params_type::A);
const field_value_type B(params_type::B);

const field_value_type temp1i = (two * B * this->Y).inversed();
const field_value_type temp1i = twoBY.inversed();
const field_value_type temp2 =
three * this->X.squared() + two * A * this->X + field_value_type::one();
const field_value_type temp1i_sqr = temp1i.squared();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,6 @@ namespace nil {
return *this;
}

static curve_element from_affine(curve_element<params_type, form, curves::coordinates::affine> const &other) {
return curve_element(other.X, other.Y, other.X*other.Y, field_value_type::one());
}

template<typename Backend,
boost::multiprecision::expression_template_option ExpressionTemplates>
constexpr const curve_element& operator=(
Expand Down
Loading

0 comments on commit cdf6ac2

Please sign in to comment.