Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
interaction_def.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <string>
5#include <unordered_map>
6#include <vector>
7
16
17namespace bb::avm2::tracegen {
18
28
30 public:
32
33 // Old format with InteractionSettings first. TODO: Migrate.
34 template <typename InteractionSettings, InteractionType type> InteractionDefinition& add(auto&&... args)
35 {
36 std::string name = std::string(InteractionSettings::NAME);
37 interactions[name] = get_interaction_factory<type, InteractionSettings>(std::forward<decltype(args)>(args)...);
38 return *this;
39 }
40
41 template <InteractionType type, typename... InteractionSettings> InteractionDefinition& add(auto&&... args)
42 {
43 std::string name = (std::string(InteractionSettings::NAME) + ...);
44 interactions[name] =
45 get_interaction_factory<type, InteractionSettings...>(std::forward<decltype(args)>(args)...);
46 return *this;
47 }
48
49 // Jobs for production.
51 // Stricter/more assertive jobs for testing.
53
54 std::unique_ptr<InteractionBuilderInterface> get_job(const std::string& interaction_name) const;
55 std::unique_ptr<InteractionBuilderInterface> get_test_job(const std::string& interaction_name) const;
56 template <typename InteractionSettings> std::unique_ptr<InteractionBuilderInterface> get_test_job() const
57 {
58 return get_test_job(std::string(InteractionSettings::NAME));
59 }
60
61 private:
63 std::unordered_map<std::string, Factory> interactions;
64
65 template <InteractionType type, typename... InteractionSettings>
66 static Factory get_interaction_factory(auto&&... args)
67 {
68 if constexpr (type == InteractionType::LookupGeneric) {
69 return [args...](bool) {
70 // This class always checks.
71 return std::make_unique<LookupIntoDynamicTableGeneric<InteractionSettings...>>(args...);
72 };
73 } else if constexpr (type == InteractionType::LookupIntoBitwise) {
74 return [args...](bool strict) {
75 return strict ? std::make_unique<AddChecksToBuilder<LookupIntoBitwise<InteractionSettings...>>>(args...)
76 : std::make_unique<LookupIntoBitwise<InteractionSettings...>>(args...);
77 };
78 } else if constexpr (type == InteractionType::LookupIntoIndexedByClk) {
79 return [args...](bool strict) {
80 return strict ? std::make_unique<AddChecksToBuilder<LookupIntoIndexedByClk<InteractionSettings...>>>(
81 args...)
82 : std::make_unique<LookupIntoIndexedByClk<InteractionSettings...>>(args...);
83 };
84 } else if constexpr (type == InteractionType::LookupIntoPDecomposition) {
85 return [args...](bool strict) {
86 return strict ? std::make_unique<AddChecksToBuilder<LookupIntoPDecomposition<InteractionSettings...>>>(
87 args...)
88 : std::make_unique<LookupIntoPDecomposition<InteractionSettings...>>(args...);
89 };
90 } else if constexpr (type == InteractionType::LookupSequential) {
91 return [args...](bool) {
92 // This class always checks.
93 return std::make_unique<LookupIntoDynamicTableSequential<InteractionSettings...>>(args...);
94 };
95 } else if constexpr (type == InteractionType::Permutation) {
96 return [args...](bool strict) {
97 return strict ? std::make_unique<CheckingPermutationBuilder<InteractionSettings...>>(args...)
98 : std::make_unique<PermutationBuilder<InteractionSettings...>>(args...);
99 };
100 } else if constexpr (type == InteractionType::MultiPermutation) {
101 return
102 [args...](bool) { return std::make_unique<MultiPermutationBuilder<InteractionSettings...>>(args...); };
103 } else {
104 throw std::runtime_error("Interaction type not supported: " + std::to_string(static_cast<int>(type)));
105 }
106 }
107
108 const Factory& get_job_internal(const std::string& interaction_name) const;
109};
110
111} // namespace bb::avm2::tracegen
InteractionDefinition & add(auto &&... args)
std::vector< std::unique_ptr< InteractionBuilderInterface > > get_all_test_jobs() const
const Factory & get_job_internal(const std::string &interaction_name) const
std::unique_ptr< InteractionBuilderInterface > get_job(const std::string &interaction_name) const
std::vector< std::unique_ptr< InteractionBuilderInterface > > get_all_jobs() const
std::unique_ptr< InteractionBuilderInterface > get_test_job() const
std::function< std::unique_ptr< InteractionBuilderInterface >(bool strict)> Factory
std::unordered_map< std::string, Factory > interactions
static Factory get_interaction_factory(auto &&... args)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::string to_string(bb::avm2::ValueTag tag)