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: 158dd845c99f8f702979c20f1625730d126c4b20}
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 has_a = false;
27#if defined(__SIZEOF_INT128__) && !defined(__wasm__)
28 static constexpr bb::fr b{ 0xdd7056026000005a, 0x223fa97acb319311, 0xcc388229877910c0, 0x34394632b724eaa };
29#else
30 static constexpr bb::fr b{ 0x2646d52420000b3eUL, 0xf78d5ec872bf8119UL, 0x166fb9c3ec1f6749UL, 0x7a9ef7fabe69506UL };
31#endif
32 static constexpr bb::fr a{ 0UL, 0UL, 0UL, 0UL };
33
34 // generator point = (x, y) = (1, sqrt(-16)) = (1, -4i)
35 static constexpr bb::fr one_x = bb::fr::one();
36#if defined(__SIZEOF_INT128__) && !defined(__wasm__)
37 static constexpr bb::fr one_y{
38 0x11b2dff1448c41d8UL, 0x23d3446f21c77dc3UL, 0xaa7b8cf435dfafbbUL, 0x14b34cf69dc25d68UL
39 };
40#else
41 static constexpr bb::fr one_y{
42 0xc3e285a561883af3UL, 0x6fc5c2360a850101UL, 0xf35e144228647aa9UL, 0x2151a2fe48c68af6UL
43 };
44#endif
45};
47
48// specialize the name in msgpack schema generation
49// consumed by the typescript schema compiler, helps disambiguate templates
50inline std::string msgpack_schema_name(g1::affine_element const& /*unused*/)
51{
52 return "GrumpkinPoint";
53}
54
55}; // namespace bb::grumpkin
56
57namespace bb::curve {
58class Grumpkin {
59 public:
62 using Group = typename grumpkin::g1;
63 using Element = typename Group::element;
64 using AffineElement = typename Group::affine_element;
65
66 static constexpr const char* name = "Grumpkin";
67 static constexpr bool is_stdlib_type = false;
68
69 // Required by SmallSubgroupIPA argument. This constant needs to divide the size of the multiplicative subgroup of
70 // the ScalarField and satisfy SUBGROUP_SIZE > CONST_PROOF_SIZE_LOG_N * 3, since in every round of Sumcheck, the
71 // prover sends 3 elements to the verifier.
72 static constexpr size_t SUBGROUP_SIZE = 87;
73 // The generator below was derived by factoring r - 1 into primes, where r is the modulus of the Grumkin scalar
74 // field. A random field element was sampled and raised to the power (r - 1) / (3 * 29). We verified that the
75 // resulting element does not generate a smaller subgroup by further raising it to the powers of 3 and 29. To
76 // optimize the recursive verifier and avoid costly inversions, we also precompute and store its inverse.
78 ScalarField(uint256_t("0x147c647c09fb639514909e9f0513f31ec1a523bf8a0880bc7c24fbc962a9586b"));
80 ScalarField("0x0c68e27477b5e78cfab790bd3b59806fa871771f71ec7452cde5384f6e3a1988");
81 // The length of the polynomials used to mask the Sumcheck Round Univariates. In the ECCVM Sumcheck, the prover only
82 // sends 3 elements in every round - a commitment to the round univariate and its evaluations at 0 and 1. Therefore,
83 // length 3 is sufficient.
84 static constexpr uint32_t LIBRA_UNIVARIATES_LENGTH = 3;
85};
86} // namespace bb::curve
typename Group::element Element
Definition grumpkin.hpp:63
static constexpr size_t SUBGROUP_SIZE
Definition grumpkin.hpp:72
static constexpr uint32_t LIBRA_UNIVARIATES_LENGTH
Definition grumpkin.hpp:84
static constexpr bool is_stdlib_type
Definition grumpkin.hpp:67
typename grumpkin::g1 Group
Definition grumpkin.hpp:62
static constexpr ScalarField subgroup_generator_inverse
Definition grumpkin.hpp:79
static constexpr const char * name
Definition grumpkin.hpp:66
typename Group::affine_element AffineElement
Definition grumpkin.hpp:64
static constexpr ScalarField subgroup_generator
Definition grumpkin.hpp:77
group class. Represents an elliptic curve group element. Group is parametrised by Fq and Fr
Definition group.hpp:38
bb::group< bb::fr, bb::fq, G1Params > g1
Definition grumpkin.hpp:46
std::string msgpack_schema_name(g1::affine_element const &)
Definition grumpkin.hpp:50
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:41
static constexpr bb::fr b
Definition grumpkin.hpp:30
static constexpr bool has_a
Definition grumpkin.hpp:26
static constexpr bool USE_ENDOMORPHISM
Definition grumpkin.hpp:24
static constexpr bb::fr one_x
Definition grumpkin.hpp:35
static constexpr bb::fr a
Definition grumpkin.hpp:32