barretenberg
Loading...
Searching...
No Matches
instances.hpp
1#pragma once
2#include "barretenberg/sumcheck/instance/prover_instance.hpp"
3#include "barretenberg/sumcheck/instance/verifier_instance.hpp"
4
5namespace proof_system::honk {
6
7template <typename Flavor_, size_t NUM_> struct ProverInstances_ {
8 public:
9 static_assert(NUM_ > 0, "Must have at least one prover instance");
10 using Flavor = Flavor_;
11 using FoldingParameters = typename Flavor::FoldingParameters;
12 using FF = typename Flavor::FF;
13 static constexpr size_t NUM = NUM_;
15
16 using ArrayType = std::array<std::shared_ptr<Instance>, NUM_>;
17 // The extended length here is the length of a composition of polynomials.
18 static constexpr size_t EXTENDED_LENGTH = (Flavor::MAX_TOTAL_RELATION_LENGTH - 1) * (NUM - 1) + 1;
19 static constexpr size_t BATCHED_EXTENDED_LENGTH = (Flavor::MAX_TOTAL_RELATION_LENGTH - 1 + NUM - 1) * (NUM - 1) + 1;
22 ArrayType _data;
23 RelationParameters relation_parameters;
24 AlphaType alpha;
25 std::vector<FF> next_gate_challenges;
26
27 std::shared_ptr<Instance> const& operator[](size_t idx) const { return _data[idx]; }
28 typename ArrayType::iterator begin() { return _data.begin(); };
29 typename ArrayType::iterator end() { return _data.end(); };
30 ProverInstances_() = default;
31 ProverInstances_(std::vector<std::shared_ptr<Instance>> data)
32 {
33 ASSERT(data.size() == NUM);
34 for (size_t idx = 0; idx < data.size(); idx++) {
35 _data[idx] = std::move(data[idx]);
36 }
37 };
38
57 std::vector<Univariate<FF, NUM>> row_to_univariates(size_t row_idx) const
58 {
59 auto insts_prover_polynomials_views = get_polynomials_views();
60 std::vector<Univariate<FF, NUM>> results;
61 // Set the size corresponding to the number of rows in the execution trace
62 results.resize(insts_prover_polynomials_views[0].size());
63 size_t instance_idx = 0;
64 // Iterate over the prover polynomials' views corresponding to each instance
65 for (auto& get_all : insts_prover_polynomials_views) {
66 // Iterate over all columns in the trace execution of an instance and extract their value at row_idx.
67 for (auto [result, poly_ptr] : zip_view(results, get_all)) {
68 result.evaluations[instance_idx] = (poly_ptr)[row_idx];
69 }
70 instance_idx++;
71 }
72 return results;
73 }
74
75 private:
76 // Returns a vector containing pointer views to the prover polynomials corresponding to each instance.
77 auto get_polynomials_views() const
78 {
79 // As a practical measure, get the first instance's view to deduce the vector type
80 std::vector get_alls{ _data[0]->prover_polynomials.get_all() };
81 // complete the views, starting from the second item
82 for (size_t i = 1; i < NUM; i++) {
83 get_alls.push_back(_data[i]->prover_polynomials.get_all());
84 }
85 return get_alls;
86 }
87};
88
89template <typename Flavor_, size_t NUM_> struct VerifierInstances_ {
90 using Flavor = Flavor_;
91 using VerificationKey = typename Flavor::VerificationKey;
93 using ArrayType = std::array<std::shared_ptr<Instance>, NUM_>;
94
95 public:
96 static constexpr size_t NUM = NUM_;
97 static constexpr size_t BATCHED_EXTENDED_LENGTH = (Flavor::MAX_TOTAL_RELATION_LENGTH - 1 + NUM - 1) * (NUM - 1) + 1;
98 ArrayType _data;
99 std::shared_ptr<Instance> const& operator[](size_t idx) const { return _data[idx]; }
100 typename ArrayType::iterator begin() { return _data.begin(); };
101 typename ArrayType::iterator end() { return _data.end(); };
102
104 {
105 std::generate(_data.begin(), _data.end(), []() { return std::make_unique<Instance>(); });
106 };
107};
108} // namespace proof_system::honk
An Instance is normally constructed from a finalized circuit and it's role is to compute all the poly...
Definition: prover_instance.hpp:20
Definition: verifier_instance.hpp:6
VerificationKey_< PrecomputedEntities< Commitment > > VerificationKey
The verification key is responsible for storing the the commitments to the precomputed (non-witnessk)...
Definition: goblin_translator.hpp:941
Definition: zip_view.hpp:159
Defines particular circuit builder types expected to be used for circuit construction in stdlib and c...
Definition: claim.hpp:6
Definition: instances.hpp:7
Definition: instances.hpp:89