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: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
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
15constexpr size_t MAX_NO_WRAP_INTEGER_BIT_LENGTH = 252;
16
17using fq = bb::fr;
18using fr = bb::fq;
19
20struct G1Params {
21 static constexpr bool USE_ENDOMORPHISM = true;
22 static constexpr bool can_hash_to_curve = true;
23 static constexpr bool small_elements = true;
24 static constexpr bool has_a = false;
25// have checked in grumpkin.test_b that b is Montgomery form of -17
26#if defined(__SIZEOF_INT128__) && !defined(__wasm__)
27 static constexpr bb::fr b{ 0xdd7056026000005a, 0x223fa97acb319311, 0xcc388229877910c0, 0x34394632b724eaa };
28#else
29 static constexpr bb::fr b{ 0x2646d52420000b3eUL, 0xf78d5ec872bf8119UL, 0x166fb9c3ec1f6749UL, 0x7a9ef7fabe69506UL };
30#endif
31 static constexpr bb::fr a{ 0UL, 0UL, 0UL, 0UL };
32
33 // generator point = (x, y) = (1, sqrt(-16)), sqrt(-16) = 4i
34 static constexpr bb::fr one_x = bb::fr::one();
35#if defined(__SIZEOF_INT128__) && !defined(__wasm__)
36 static constexpr bb::fr one_y{
37 0x11b2dff1448c41d8UL, 0x23d3446f21c77dc3UL, 0xaa7b8cf435dfafbbUL, 0x14b34cf69dc25d68UL
38 };
39#else
40 static constexpr bb::fr one_y{
41 0xc3e285a561883af3UL, 0x6fc5c2360a850101UL, 0xf35e144228647aa9UL, 0x2151a2fe48c68af6UL
42 };
43#endif
44};
46
47}; // namespace bb::grumpkin
48
49namespace bb::curve {
50class Grumpkin {
51 public:
54 using Group = typename grumpkin::g1;
55 using Element = typename Group::element;
56 using AffineElement = typename Group::affine_element;
57
58 static constexpr const char* name = "Grumpkin";
59 // TODO(#673): This flag is temporary. It is needed in the verifier classes (GeminiVerifier, etc.) while these
60 // classes are instantiated with "native" curve types. Eventually, the verifier classes will be instantiated only
61 // with stdlib types, and "native" verification will be acheived via a simulated builder.
62 static constexpr bool is_stdlib_type = false;
63
64 // Required by SmallSubgroupIPA argument. This constant needs to divide the size of the multiplicative subgroup of
65 // the ScalarField and satisfy SUBGROUP_SIZE > CONST_PROOF_SIZE_LOG_N * 3, since in every round of Sumcheck, the
66 // prover sends 3 elements to the verifier.
67 static constexpr size_t SUBGROUP_SIZE = 87;
68 // The generator below was derived by factoring r - 1 into primes, where r is the modulus of the Grumkin scalar
69 // field. A random field element was sampled and raised to the power (r - 1) / (3 * 29). We verified that the
70 // resulting element does not generate a smaller subgroup by further raising it to the powers of 3 and 29. To
71 // optimize the recursive verifier and avoid costly inversions, we also precompute and store its inverse.
73 ScalarField(uint256_t("0x147c647c09fb639514909e9f0513f31ec1a523bf8a0880bc7c24fbc962a9586b"));
75 ScalarField("0x0c68e27477b5e78cfab790bd3b59806fa871771f71ec7452cde5384f6e3a1988");
76 // The length of the polynomials used to mask the Sumcheck Round Univariates. In the ECCVM Sumcheck, the prover only
77 // sends 3 elements in every round - a commitment to the round univariate and its evaluations at 0 and 1. Therefore,
78 // length 3 is sufficient.
79 static constexpr uint32_t LIBRA_UNIVARIATES_LENGTH = 3;
80};
81} // namespace bb::curve
typename Group::element Element
Definition grumpkin.hpp:55
static constexpr size_t SUBGROUP_SIZE
Definition grumpkin.hpp:67
static constexpr uint32_t LIBRA_UNIVARIATES_LENGTH
Definition grumpkin.hpp:79
static constexpr bool is_stdlib_type
Definition grumpkin.hpp:62
typename grumpkin::g1 Group
Definition grumpkin.hpp:54
static constexpr ScalarField subgroup_generator_inverse
Definition grumpkin.hpp:74
static constexpr const char * name
Definition grumpkin.hpp:58
typename Group::affine_element AffineElement
Definition grumpkin.hpp:56
static constexpr ScalarField subgroup_generator
Definition grumpkin.hpp:72
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:45
constexpr size_t MAX_NO_WRAP_INTEGER_BIT_LENGTH
Definition grumpkin.hpp:15
field< Bn254FqParams > fq
Definition fq.hpp:169
field< Bn254FrParams > fr
Definition fr.hpp:174
static constexpr field one()
static constexpr bool can_hash_to_curve
Definition grumpkin.hpp:22
static constexpr bb::fr one_y
Definition grumpkin.hpp:40
static constexpr bb::fr b
Definition grumpkin.hpp:29
static constexpr bool has_a
Definition grumpkin.hpp:24
static constexpr bool small_elements
Definition grumpkin.hpp:23
static constexpr bool USE_ENDOMORPHISM
Definition grumpkin.hpp:21
static constexpr bb::fr one_x
Definition grumpkin.hpp:34
static constexpr bb::fr a
Definition grumpkin.hpp:31