barretenberg
Loading...
Searching...
No Matches
ultra_composer.hpp
1#pragma once
2
3#include "barretenberg/flavor/plonk_flavors.hpp"
4#include "barretenberg/plonk/composer/composer_lib.hpp"
5#include "barretenberg/plonk/proof_system/prover/prover.hpp"
6#include "barretenberg/plonk/proof_system/proving_key/proving_key.hpp"
7#include "barretenberg/plonk/proof_system/verifier/verifier.hpp"
8#include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp"
9#include "barretenberg/proof_system/composer/composer_lib.hpp"
10#include "barretenberg/srs/factories/file_crs_factory.hpp"
11
12#include <cstddef>
13#include <utility>
14
15namespace proof_system::plonk {
17 public:
18 using Flavor = flavor::Ultra;
20 using Curve = Flavor::Curve;
21
22 static constexpr std::string_view NAME_STRING = "UltraPlonk";
23 static constexpr CircuitType type = CircuitType::ULTRA;
24 static constexpr size_t NUM_RESERVED_GATES = 4; // equal to the number of multilinear evaluations leaked
25 static constexpr size_t program_width = CircuitBuilder::NUM_WIRES;
26 std::shared_ptr<plonk::proving_key> circuit_proving_key;
27 std::shared_ptr<plonk::verification_key> circuit_verification_key;
28
29 bool computed_witness = false;
30
31 // This variable controls the amount with which the lookup table and witness values need to be shifted
32 // above to make room for adding randomness into the permutation and witness polynomials in the plookup widget.
33 // This must be (num_roots_cut_out_of_the_vanishing_polynomial - 1), since the variable num_roots_cut_out_of_
34 // vanishing_polynomial cannot be trivially fetched here, I am directly setting this to 4 - 1 = 3.
35 static constexpr size_t s_randomness = 3;
36
37 UltraComposer() = default;
38
39 UltraComposer(std::shared_ptr<proving_key> p_key, std::shared_ptr<verification_key> v_key)
40 : circuit_proving_key(std::move(p_key))
41 , circuit_verification_key(std::move(v_key))
42 {}
43
44 UltraComposer(UltraComposer&& other) noexcept = default;
45 UltraComposer(UltraComposer const& other) noexcept = default;
46 UltraComposer& operator=(UltraComposer&& other) noexcept = default;
47 UltraComposer& operator=(UltraComposer const& other) noexcept = default;
48 ~UltraComposer() = default;
49
50 std::vector<SelectorProperties> ultra_selector_properties()
51 {
52 // When reading and writing the proving key from a buffer we must precompute the Lagrange form of certain
53 // selector polynomials. In order to avoid a new selector type and definitions in the polynomial manifest, we
54 // can instead store the Lagrange forms of all the selector polynomials.
55 //
56 // This workaround increases the memory footprint of the prover, and is a possible place of improvement in the
57 // future. Below is the previous state showing where the Lagrange form is necessary for a selector:
58 // { "q_m", true }, { "q_c", true }, { "q_1", true }, { "q_2", true },
59 // { "q_3", true }, { "q_4", false }, { "q_arith", false }, { "q_sort", false },
60 // { "q_elliptic", false }, { "q_aux", false }, { "table_type", true },
61 std::vector<SelectorProperties> result{
62 { "q_m", true }, { "q_c", true }, { "q_1", true }, { "q_2", true },
63 { "q_3", true }, { "q_4", true }, { "q_arith", true }, { "q_sort", true },
64 { "q_elliptic", true }, { "q_aux", true }, { "table_type", true },
65 };
66 return result;
67 }
68
69 [[nodiscard]] size_t get_num_selectors() { return ultra_selector_properties().size(); }
70
71 std::shared_ptr<plonk::proving_key> compute_proving_key(CircuitBuilder& circuit_constructor);
72 std::shared_ptr<plonk::verification_key> compute_verification_key(CircuitBuilder& circuit_constructor);
73
74 void compute_witness(CircuitBuilder& circuit_constructor);
75
76 UltraProver create_prover(CircuitBuilder& circuit_constructor);
77 UltraVerifier create_verifier(CircuitBuilder& circuit_constructor);
78
81
84
85 void add_table_column_selector_poly_to_proving_key(polynomial& small, const std::string& tag);
86
94 static transcript::Manifest create_manifest(const size_t num_public_inputs)
95 {
96 return Flavor::create_manifest(num_public_inputs);
97 }
98};
99
100} // namespace proof_system::plonk
Definition: bn254.hpp:10
Definition: ultra_circuit_builder.hpp:31
Definition: prover.hpp:12
Definition: ultra_composer.hpp:16
UltraWithKeccakVerifier create_ultra_with_keccak_verifier(CircuitBuilder &circuit_constructor)
Create a verifier using keccak for the transcript.
Definition: ultra_composer.cpp:335
UltraToStandardProver create_ultra_to_standard_prover(CircuitBuilder &circuit_constructor)
Uses slightly different settings from the UltraProver.
Definition: ultra_composer.cpp:199
UltraToStandardVerifier create_ultra_to_standard_verifier(CircuitBuilder &circuit_constructor)
Create a verifier using pedersen hash for the transcript.
Definition: ultra_composer.cpp:314
UltraVerifier create_verifier(CircuitBuilder &circuit_constructor)
Definition: ultra_composer.cpp:294
std::shared_ptr< plonk::verification_key > compute_verification_key(CircuitBuilder &circuit_constructor)
Definition: ultra_composer.cpp:478
static transcript::Manifest create_manifest(const size_t num_public_inputs)
Create a manifest object.
Definition: ultra_composer.hpp:94
void compute_witness(CircuitBuilder &circuit_constructor)
Computes this.witness, which is basiclly a set of polynomials mapped-to by strings.
Definition: ultra_composer.cpp:24
UltraWithKeccakProver create_ultra_with_keccak_prover(CircuitBuilder &circuit_constructor)
Uses slightly different settings from the UltraProver.
Definition: ultra_composer.cpp:245
Definition: verifier.hpp:9
Definition: plonk_flavors.hpp:21
static transcript::Manifest create_manifest(const size_t num_public_inputs)
Create a manifest object.
Definition: plonk_flavors.hpp:39
Definition: manifest.hpp:11
Definition: widget.bench.cpp:13