Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
grumpkin.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Completed, auditors: [Federico], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
8
9#include "../../groups/group.hpp"
10#include "../bn254/fq.hpp"
11#include "../bn254/fr.hpp"
12
13namespace bb::grumpkin {
14
15// Max num bits such that all numbers represented by that many bits are smaller than fr::modulus
16constexpr size_t MAX_NO_WRAP_INTEGER_BIT_LENGTH = 252;
17static_assert((uint256_t(1) << (MAX_NO_WRAP_INTEGER_BIT_LENGTH + 1)) - 1 < fr::modulus,
18 "MAX_NO_WRAP_INTEGER_BIT_LENGTH is too large");
19
20using fq = bb::fr;
21using fr = bb::fq;
22
23struct G1Params {
24 static constexpr bool USE_ENDOMORPHISM = true;
25 static constexpr bool can_hash_to_curve = true;
26 static constexpr bool small_elements = true;
27 static constexpr bool has_a = false;
28#if defined(__SIZEOF_INT128__) && !defined(__wasm__)
29 static constexpr bb::fr b{ 0xdd7056026000005a, 0x223fa97acb319311, 0xcc388229877910c0, 0x34394632b724eaa };
30#else
31 static constexpr bb::fr b{ 0x2646d52420000b3eUL, 0xf78d5ec872bf8119UL, 0x166fb9c3ec1f6749UL, 0x7a9ef7fabe69506UL };
32#endif
33 static constexpr bb::fr a{ 0UL, 0UL, 0UL, 0UL };
34
35 // generator point = (x, y) = (1, sqrt(-16)) = (1, -4i)
36 static constexpr bb::fr one_x = bb::fr::one();
37#if defined(__SIZEOF_INT128__) && !defined(__wasm__)
38 static constexpr bb::fr one_y{
39 0x11b2dff1448c41d8UL, 0x23d3446f21c77dc3UL, 0xaa7b8cf435dfafbbUL, 0x14b34cf69dc25d68UL
40 };
41#else
42 static constexpr bb::fr one_y{
43 0xc3e285a561883af3UL, 0x6fc5c2360a850101UL, 0xf35e144228647aa9UL, 0x2151a2fe48c68af6UL
44 };
45#endif
46};
48
49// specialize the name in msgpack schema generation
50// consumed by the typescript schema compiler, helps disambiguate templates
51inline std::string msgpack_schema_name(g1::affine_element const& /*unused*/)
52{
53 return "GrumpkinPoint";
54}
55
56}; // namespace bb::grumpkin
57
58namespace bb::curve {
59class Grumpkin {
60 public:
63 using Group = typename grumpkin::g1;
64 using Element = typename Group::element;
65 using AffineElement = typename Group::affine_element;
66
67 static constexpr const char* name = "Grumpkin";
68 static constexpr bool is_stdlib_type = false;
69
70 // Required by SmallSubgroupIPA argument. This constant needs to divide the size of the multiplicative subgroup of
71 // the ScalarField and satisfy SUBGROUP_SIZE > CONST_PROOF_SIZE_LOG_N * 3, since in every round of Sumcheck, the
72 // prover sends 3 elements to the verifier.
73 static constexpr size_t SUBGROUP_SIZE = 87;
74 // The generator below was derived by factoring r - 1 into primes, where r is the modulus of the Grumkin scalar
75 // field. A random field element was sampled and raised to the power (r - 1) / (3 * 29). We verified that the
76 // resulting element does not generate a smaller subgroup by further raising it to the powers of 3 and 29. To
77 // optimize the recursive verifier and avoid costly inversions, we also precompute and store its inverse.
79 ScalarField(uint256_t("0x147c647c09fb639514909e9f0513f31ec1a523bf8a0880bc7c24fbc962a9586b"));
81 ScalarField("0x0c68e27477b5e78cfab790bd3b59806fa871771f71ec7452cde5384f6e3a1988");
82 // The length of the polynomials used to mask the Sumcheck Round Univariates. In the ECCVM Sumcheck, the prover only
83 // sends 3 elements in every round - a commitment to the round univariate and its evaluations at 0 and 1. Therefore,
84 // length 3 is sufficient.
85 static constexpr uint32_t LIBRA_UNIVARIATES_LENGTH = 3;
86};
87} // namespace bb::curve
typename Group::element Element
Definition grumpkin.hpp:64
static constexpr size_t SUBGROUP_SIZE
Definition grumpkin.hpp:73
static constexpr uint32_t LIBRA_UNIVARIATES_LENGTH
Definition grumpkin.hpp:85
static constexpr bool is_stdlib_type
Definition grumpkin.hpp:68
typename grumpkin::g1 Group
Definition grumpkin.hpp:63
static constexpr ScalarField subgroup_generator_inverse
Definition grumpkin.hpp:80
static constexpr const char * name
Definition grumpkin.hpp:67
typename Group::affine_element AffineElement
Definition grumpkin.hpp:65
static constexpr ScalarField subgroup_generator
Definition grumpkin.hpp:78
group class. Represents an elliptic curve group element. Group is parametrised by Fq and Fr
Definition group.hpp:36
bb::group< bb::fr, bb::fq, G1Params > g1
Definition grumpkin.hpp:47
std::string msgpack_schema_name(g1::affine_element const &)
Definition grumpkin.hpp:51
constexpr size_t MAX_NO_WRAP_INTEGER_BIT_LENGTH
Definition grumpkin.hpp:16
field< Bn254FqParams > fq
Definition fq.hpp:153
field< Bn254FrParams > fr
Definition fr.hpp:155
static constexpr field one()
static constexpr uint256_t modulus
static constexpr bool can_hash_to_curve
Definition grumpkin.hpp:25
static constexpr bb::fr one_y
Definition grumpkin.hpp:42
static constexpr bb::fr b
Definition grumpkin.hpp:31
static constexpr bool has_a
Definition grumpkin.hpp:27
static constexpr bool small_elements
Definition grumpkin.hpp:26
static constexpr bool USE_ENDOMORPHISM
Definition grumpkin.hpp:24
static constexpr bb::fr one_x
Definition grumpkin.hpp:36
static constexpr bb::fr a
Definition grumpkin.hpp:33