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
8
#include "
barretenberg/vm2/tracegen/lib/interaction_builder.hpp
"
9
#include "
barretenberg/vm2/tracegen/lib/lookup_builder.hpp
"
10
#include "
barretenberg/vm2/tracegen/lib/lookup_into_bitwise.hpp
"
11
#include "
barretenberg/vm2/tracegen/lib/lookup_into_indexed_by_clk.hpp
"
12
#include "
barretenberg/vm2/tracegen/lib/lookup_into_p_decomposition.hpp
"
13
#include "
barretenberg/vm2/tracegen/lib/multi_permutation_builder.hpp
"
14
#include "
barretenberg/vm2/tracegen/lib/permutation_builder.hpp
"
15
#include "
barretenberg/vm2/tracegen/lib/shared_index_cache.hpp
"
16
#include "
barretenberg/vm2/tracegen/lib/test_interaction_builder.hpp
"
17
18
namespace
bb::avm2::tracegen
{
19
20
enum class
InteractionType
{
21
LookupGeneric
,
22
LookupSequential
,
23
LookupIntoBitwise
,
24
LookupIntoIndexedByClk
,
25
LookupIntoPDecomposition
,
26
Permutation
,
27
MultiPermutation
,
28
};
29
30
class
InteractionDefinition
{
31
public
:
32
InteractionDefinition
() =
default
;
33
34
// Old format with InteractionSettings first. TODO: Migrate.
35
template
<
typename
InteractionSettings, InteractionType type>
InteractionDefinition
&
add
(
auto
&&... args)
36
{
37
std::string name = std::string(InteractionSettings::NAME);
38
interactions
[name] = get_interaction_factory<type, InteractionSettings>(
std::forward
<
decltype
(args)>(args)...);
39
return
*
this
;
40
}
41
42
template
<
InteractionType
type
,
typename
... InteractionSettings>
InteractionDefinition
&
add
(
auto
&&... args)
43
{
44
std::string name = (std::string(InteractionSettings::NAME) + ...);
45
interactions
[name] =
46
get_interaction_factory
<
type
, InteractionSettings...>(
std::forward<decltype(args)>
(args)...);
47
return
*
this
;
48
}
49
50
// Jobs for production (with shared index cache for efficient lookup index sharing).
51
std::vector<std::unique_ptr<InteractionBuilderInterface>
>
get_all_jobs
(
SharedIndexCache
& cache)
const
;
52
// Stricter/more assertive jobs for testing.
53
std::vector<std::unique_ptr<InteractionBuilderInterface>
>
get_all_test_jobs
(
SharedIndexCache
& cache)
const
;
54
55
std::unique_ptr<InteractionBuilderInterface>
get_job
(
const
std::string& interaction_name,
56
SharedIndexCache
& cache)
const
;
57
std::unique_ptr<InteractionBuilderInterface>
get_test_job
(
const
std::string& interaction_name,
58
SharedIndexCache
& cache)
const
;
59
template
<
typename
InteractionSettings>
60
std::unique_ptr<InteractionBuilderInterface>
get_test_job
(
SharedIndexCache
& cache)
const
61
{
62
return
get_test_job
(std::string(InteractionSettings::NAME), cache);
63
}
64
65
private
:
66
// Factory takes (strict, cache) and returns the interaction builder.
67
using
Factory
=
std::function<std::unique_ptr<InteractionBuilderInterface>
(
bool
strict,
SharedIndexCache
& cache)>;
68
std::unordered_map<std::string, Factory>
interactions
;
69
70
template
<
InteractionType
type
,
typename
... InteractionSettings>
71
static
Factory
get_interaction_factory
(
auto
&&... args)
72
{
73
if
constexpr
(
type
==
InteractionType::LookupGeneric
) {
74
return
[args...](bool,
SharedIndexCache
& cache) {
75
// This class always checks.
76
return
std::make_unique<
LookupIntoDynamicTableGeneric
<InteractionSettings...>>(cache, args...);
77
};
78
}
else
if
constexpr
(
type
==
InteractionType::LookupIntoBitwise
) {
79
return
[args...](
bool
strict,
SharedIndexCache
&) {
80
return
strict ? std::make_unique<
AddChecksToBuilder
<
LookupIntoBitwise
<InteractionSettings...>>>(args...)
81
: std::make_unique<
LookupIntoBitwise
<InteractionSettings...>>(args...);
82
};
83
}
else
if
constexpr
(
type
==
InteractionType::LookupIntoIndexedByClk
) {
84
return
[args...](
bool
strict,
SharedIndexCache
&) {
85
return
strict ? std::make_unique<
AddChecksToBuilder
<
LookupIntoIndexedByClk
<InteractionSettings...>>>(
86
args...)
87
: std::make_unique<
LookupIntoIndexedByClk
<InteractionSettings...>>(args...);
88
};
89
}
else
if
constexpr
(
type
==
InteractionType::LookupIntoPDecomposition
) {
90
return
[args...](
bool
strict,
SharedIndexCache
&) {
91
return
strict ? std::make_unique<
AddChecksToBuilder
<
LookupIntoPDecomposition
<InteractionSettings...>>>(
92
args...)
93
: std::make_unique<
LookupIntoPDecomposition
<InteractionSettings...>>(args...);
94
};
95
}
else
if
constexpr
(
type
==
InteractionType::LookupSequential
) {
96
return
[args...](bool,
SharedIndexCache
&) {
97
// This class always checks.
98
return
std::make_unique<
LookupIntoDynamicTableSequential
<InteractionSettings...>>(args...);
99
};
100
}
else
if
constexpr
(
type
==
InteractionType::Permutation
) {
101
return
[args...](
bool
strict,
SharedIndexCache
&) {
102
return
strict ? std::make_unique<
CheckingPermutationBuilder
<InteractionSettings...>>(args...)
103
: std::make_unique<
PermutationBuilder
<InteractionSettings...>>(args...);
104
};
105
}
else
if
constexpr
(
type
==
InteractionType::MultiPermutation
) {
106
return
[args...](bool,
SharedIndexCache
&) {
107
return
std::make_unique<
MultiPermutationBuilder
<InteractionSettings...>>(args...);
108
};
109
}
else
{
110
throw
std::runtime_error(
"Interaction type not supported: "
+
std::to_string
(
static_cast<
int
>
(
type
)));
111
}
112
}
113
114
const
Factory
&
get_job_internal
(
const
std::string& interaction_name)
const
;
115
};
116
117
}
// namespace bb::avm2::tracegen
bb::avm2::tracegen::AddChecksToBuilder
Definition
test_interaction_builder.hpp:19
bb::avm2::tracegen::CheckingPermutationBuilder
Definition
test_interaction_builder.hpp:54
bb::avm2::tracegen::InteractionDefinition
Definition
interaction_def.hpp:30
bb::avm2::tracegen::InteractionDefinition::add
InteractionDefinition & add(auto &&... args)
Definition
interaction_def.hpp:35
bb::avm2::tracegen::InteractionDefinition::get_all_test_jobs
std::vector< std::unique_ptr< InteractionBuilderInterface > > get_all_test_jobs(SharedIndexCache &cache) const
Definition
interaction_def.cpp:16
bb::avm2::tracegen::InteractionDefinition::get_test_job
std::unique_ptr< InteractionBuilderInterface > get_test_job(SharedIndexCache &cache) const
Definition
interaction_def.hpp:60
bb::avm2::tracegen::InteractionDefinition::get_all_jobs
std::vector< std::unique_ptr< InteractionBuilderInterface > > get_all_jobs(SharedIndexCache &cache) const
Definition
interaction_def.cpp:5
bb::avm2::tracegen::InteractionDefinition::get_test_job
std::unique_ptr< InteractionBuilderInterface > get_test_job(const std::string &interaction_name, SharedIndexCache &cache) const
Definition
interaction_def.cpp:33
bb::avm2::tracegen::InteractionDefinition::get_job_internal
const Factory & get_job_internal(const std::string &interaction_name) const
Definition
interaction_def.cpp:39
bb::avm2::tracegen::InteractionDefinition::get_job
std::unique_ptr< InteractionBuilderInterface > get_job(const std::string &interaction_name, SharedIndexCache &cache) const
Definition
interaction_def.cpp:27
bb::avm2::tracegen::InteractionDefinition::Factory
std::function< std::unique_ptr< InteractionBuilderInterface >(bool strict, SharedIndexCache &cache)> Factory
Definition
interaction_def.hpp:67
bb::avm2::tracegen::InteractionDefinition::interactions
std::unordered_map< std::string, Factory > interactions
Definition
interaction_def.hpp:68
bb::avm2::tracegen::InteractionDefinition::InteractionDefinition
InteractionDefinition()=default
bb::avm2::tracegen::InteractionDefinition::get_interaction_factory
static Factory get_interaction_factory(auto &&... args)
Definition
interaction_def.hpp:71
bb::avm2::tracegen::LookupIntoBitwise
Definition
lookup_into_bitwise.hpp:9
bb::avm2::tracegen::LookupIntoDynamicTableGeneric
Definition
lookup_builder.hpp:77
bb::avm2::tracegen::LookupIntoDynamicTableSequential
Definition
lookup_builder.hpp:166
bb::avm2::tracegen::LookupIntoIndexedByClk
Definition
lookup_into_indexed_by_clk.hpp:18
bb::avm2::tracegen::LookupIntoPDecomposition
Definition
lookup_into_p_decomposition.hpp:11
bb::avm2::tracegen::MultiPermutationBuilder
Definition
multi_permutation_builder.hpp:35
bb::avm2::tracegen::PermutationBuilder
Definition
permutation_builder.hpp:8
bb::avm2::tracegen::SharedIndexCache
Definition
shared_index_cache.hpp:35
GetEnvVarMutationOptions::type
@ type
interaction_builder.hpp
lookup_builder.hpp
lookup_into_bitwise.hpp
lookup_into_indexed_by_clk.hpp
lookup_into_p_decomposition.hpp
multi_permutation_builder.hpp
bb::avm2::tracegen
Definition
full_row.hpp:9
bb::avm2::tracegen::InteractionType
InteractionType
Definition
interaction_def.hpp:20
bb::avm2::tracegen::InteractionType::LookupGeneric
@ LookupGeneric
bb::avm2::tracegen::InteractionType::MultiPermutation
@ MultiPermutation
bb::avm2::tracegen::InteractionType::LookupSequential
@ LookupSequential
bb::avm2::tracegen::InteractionType::LookupIntoPDecomposition
@ LookupIntoPDecomposition
bb::avm2::tracegen::InteractionType::LookupIntoBitwise
@ LookupIntoBitwise
bb::avm2::tracegen::InteractionType::LookupIntoIndexedByClk
@ LookupIntoIndexedByClk
bb::avm2::tracegen::InteractionType::Permutation
@ Permutation
std::get
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition
tuple.hpp:13
std::to_string
std::string to_string(bb::avm2::ValueTag tag)
Definition
tagged_value.cpp:402
permutation_builder.hpp
shared_index_cache.hpp
test_interaction_builder.hpp
src
barretenberg
vm2
tracegen
lib
interaction_def.hpp
Generated by
1.9.8