Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
claim.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
12
13namespace bb {
19template <typename Curve> class OpeningPair {
20 using Fr = typename Curve::ScalarField;
21
22 public:
24 Fr evaluation; // v = p(r)
25
26 bool operator==(const OpeningPair& other) const = default;
27};
28
34template <typename Curve> class ProverOpeningClaim {
35 using Fr = typename Curve::ScalarField;
37
38 public:
40 OpeningPair<Curve> opening_pair; // (challenge r, evaluation v = p(r))
41 // Gemini Folds have to be opened at `challenge` and -`challenge`. Instead of copying a polynomial into 2 claims, we
42 // raise the flag that turns on relevant claim processing logic in Shplonk.
43 bool gemini_fold = false;
44};
45
53template <typename Curve> class OpeningClaim {
56 using Fr = typename Curve::ScalarField;
57
58 public:
59 using Builder =
61 // (challenge r, evaluation v = p(r))
63 // commitment to univariate polynomial p(X)
65
66 static constexpr bool IS_GRUMPKIN =
68 // Size of public inputs representation of an opening claim over Grumpkin: 2 * 4 + 2 = 10
69 static constexpr size_t PUBLIC_INPUTS_SIZE = IS_GRUMPKIN ? GRUMPKIN_OPENING_CLAIM_SIZE : INVALID_PUBLIC_INPUTS_SIZE;
70
76 uint32_t set_public()
78 {
79 uint32_t start_idx = opening_pair.challenge.set_public();
80 opening_pair.evaluation.set_public();
81 commitment.set_public();
82
83 return start_idx;
84 }
85
92 const std::span<const stdlib::field_t<Builder>, PUBLIC_INPUTS_SIZE>& limbs)
94 {
95 const size_t FIELD_SIZE = Fr::PUBLIC_INPUTS_SIZE;
96 const size_t COMMITMENT_SIZE = Commitment::PUBLIC_INPUTS_SIZE;
97 std::span<const stdlib::field_t<Builder>, FIELD_SIZE> challenge_limbs{ limbs.data(), FIELD_SIZE };
98 std::span<const stdlib::field_t<Builder>, FIELD_SIZE> evaluation_limbs{ limbs.data() + FIELD_SIZE, FIELD_SIZE };
99 std::span<const stdlib::field_t<Builder>, COMMITMENT_SIZE> commitment_limbs{ limbs.data() + 2 * FIELD_SIZE,
100 COMMITMENT_SIZE };
101 auto challenge = Fr::reconstruct_from_public(challenge_limbs);
102 auto evaluation = Fr::reconstruct_from_public(evaluation_limbs);
103 auto commitment = Commitment::reconstruct_from_public(commitment_limbs);
104
105 return OpeningClaim<Curve>{ { challenge, evaluation }, commitment };
106 }
107
115 {
116 const size_t FIELD_SIZE = Fr::PUBLIC_INPUTS_SIZE;
117 const size_t COMMITMENT_SIZE = Commitment::PUBLIC_INPUTS_SIZE;
118 std::span<const bb::fr, FIELD_SIZE> challenge_limbs{ limbs.data(), FIELD_SIZE };
119 std::span<const bb::fr, FIELD_SIZE> evaluation_limbs{ limbs.data() + FIELD_SIZE, FIELD_SIZE };
120 std::span<const bb::fr, COMMITMENT_SIZE> commitment_limbs{ limbs.data() + 2 * FIELD_SIZE, COMMITMENT_SIZE };
121
122 Fr challenge = Fr::reconstruct_from_public(challenge_limbs);
123 Fr evaluation = Fr::reconstruct_from_public(evaluation_limbs);
124 Commitment commitment = Commitment::reconstruct_from_public(commitment_limbs);
125
126 return OpeningClaim<Curve>{ { challenge, evaluation }, commitment };
127 }
128
130 requires(Curve::is_stdlib_type)
131 {
133 { static_cast<typename Curve::NativeCurve::ScalarField>(opening_pair.challenge.get_value()),
134 static_cast<typename Curve::NativeCurve::ScalarField>(opening_pair.evaluation.get_value()) },
135 commitment.get_value()
136 };
137 }
146 bool verify(std::shared_ptr<CK> ck, const bb::Polynomial<Fr>& polynomial) const
147 {
148 Fr real_eval = polynomial.evaluate(opening_pair.challenge);
149 if (real_eval != opening_pair.evaluation) {
150 return false;
151 }
152 // Note: real_commitment is a raw type, while commitment may be a linear combination.
153 auto real_commitment = ck->commit(polynomial);
154 return (real_commitment == commitment);
155 };
156
157 bool operator==(const OpeningClaim& other) const = default;
158};
159
169template <typename Curve> struct BatchOpeningClaim {
170 std::vector<typename Curve::AffineElement> commitments;
173};
174} // namespace bb
CommitmentKey object over a pairing group 𝔾₁.
Unverified claim (C,r,v) for some witness polynomial p(X) such that.
Definition claim.hpp:53
static OpeningClaim< Curve > reconstruct_from_public(const std::span< const stdlib::field_t< Builder >, PUBLIC_INPUTS_SIZE > &limbs)
Reconstruct an opening claim from limbs stored on the public inputs.
Definition claim.hpp:91
bool verify(std::shared_ptr< CK > ck, const bb::Polynomial< Fr > &polynomial) const
inefficiently check that the claim is correct by recomputing the commitment and evaluating the polyno...
Definition claim.hpp:146
static OpeningClaim< Curve > reconstruct_from_public(const std::span< const bb::fr, PUBLIC_INPUTS_SIZE > &limbs)
Reconstruct a native opening claim from native field elements.
Definition claim.hpp:113
OpeningPair< Curve > opening_pair
Definition claim.hpp:62
std::conditional_t< std::is_same_v< Curve, stdlib::grumpkin< UltraCircuitBuilder > >, UltraCircuitBuilder, void > Builder
Definition claim.hpp:60
auto get_native_opening_claim() const
Definition claim.hpp:129
static constexpr bool IS_GRUMPKIN
Definition claim.hpp:66
static constexpr size_t PUBLIC_INPUTS_SIZE
Definition claim.hpp:69
Commitment commitment
Definition claim.hpp:64
bool operator==(const OpeningClaim &other) const =default
uint32_t set_public()
Set the witness indices for the opening claim to public.
Definition claim.hpp:76
typename Curve::AffineElement Commitment
Definition claim.hpp:55
typename Curve::ScalarField Fr
Definition claim.hpp:56
Opening pair (r,v) for some witness polynomial p(X) such that p(r) = v.
Definition claim.hpp:19
typename Curve::ScalarField Fr
Definition claim.hpp:20
bool operator==(const OpeningPair &other) const =default
Structured polynomial class that represents the coefficients 'a' of a_0 + a_1 x .....
Fr evaluate(const Fr &z, size_t target_size) const
Polynomial p and an opening pair (r,v) such that p(r) = v.
Definition claim.hpp:34
Polynomial polynomial
Definition claim.hpp:39
OpeningPair< Curve > opening_pair
Definition claim.hpp:40
typename Curve::ScalarField Fr
Definition claim.hpp:35
typename Group::affine_element AffineElement
Definition grumpkin.hpp:56
Entry point for Barretenberg command-line interface.
UltraCircuitBuilder_< UltraExecutionTraceBlocks > UltraCircuitBuilder
CommitmentKey< Curve > ck
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
An accumulator consisting of the Shplonk evaluation challenge and vectors of commitments and scalars.
Definition claim.hpp:169
Curve::ScalarField evaluation_point
Definition claim.hpp:172
std::vector< typename Curve::AffineElement > commitments
Definition claim.hpp:170
std::vector< typename Curve::ScalarField > scalars
Definition claim.hpp:171
static constexpr size_t PUBLIC_INPUTS_SIZE
static field reconstruct_from_public(const std::span< const field< V >, PUBLIC_INPUTS_SIZE > &limbs)