Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
ultra_circuit_checker.hpp
Go to the documentation of this file.
1#pragma once
13
14#include <optional>
15
16namespace bb {
17
19 public:
20 using FF = bb::fr;
29
42 template <typename Builder> static bool check(const Builder& builder_in);
43
44 private:
45 struct TagCheckData; // Container for data pertaining to generalized permutation tag check
46 struct MemoryCheckData; // Container for data pertaining to RAM/RAM record check
47 using Key = std::array<FF, 4>; // Key type for lookup table hash table
48 struct HashFunction; // Custom hash function for lookup table hash table
50
54 template <typename Builder> static Builder prepare_circuit(const Builder& builder_in);
55
66 template <typename Builder>
67 static bool check_block(Builder& builder,
68 auto& block,
69 TagCheckData& tag_data,
70 MemoryCheckData& memory_data,
71 LookupHashTable& lookup_hash_table);
72
73#ifdef ULTRA_FUZZ
74 template <typename Builder> static bool relaxed_check_memory_relation(Builder& builder);
75 template <typename Builder> static bool relaxed_check_delta_range_relation(Builder& builder);
76#endif
77
87 template <typename Relation> static bool check_relation(auto& values, auto& params);
88
95 static bool check_lookup(auto& values, auto& lookup_hash_table);
96
103 template <typename Builder> static bool check_databus_read(auto& values, Builder& builder);
104
111 static bool check_tag_data(const TagCheckData& tag_data);
112
121 template <typename Builder> static auto init_empty_values();
122
134 template <typename Builder>
135 static void populate_values(
136 Builder& builder, auto& block, auto& values, TagCheckData& tag_data, MemoryCheckData& memory_data, size_t idx);
137
142 FF left_product = FF::one(); // product of (value + γ ⋅ tag)
143 FF right_product = FF::one(); // product of (value + γ ⋅ tau[tag])
144 const FF gamma = FF::random_element(); // randomness for the tag check
145
146 // We need to include each variable only once
147 std::unordered_set<size_t> encountered_variables;
148 };
149
154 // randomness for constructing wire 4 mem records
158
159 std::unordered_set<size_t> read_record_gates; // row indices for gates containing RAM/ROM read mem record
160 std::unordered_set<size_t> write_record_gates; // row indices for gates containing RAM/ROM write mem record
161 // Construct hash tables for memory read/write indices to efficiently determine if row is a memory record
163 {
164 for (const auto& gate_idx : builder.memory_read_records) {
165 read_record_gates.insert(gate_idx);
166 }
167 for (const auto& gate_idx : builder.memory_write_records) {
168 write_record_gates.insert(gate_idx);
169 }
170 }
171 };
172
173 // Hash for lookups hash table for efficiently checking if lookups are present in set of tables used by circuit
175 const FF mult_const = FF(uint256_t(0x1337, 0x1336, 0x1335, 0x1334));
178
179 size_t operator()(const Key& entry) const
180 {
181 FF result = entry[0] + mult_const * entry[1] + mc_sqr * entry[2] + mc_cube * entry[3];
182 return static_cast<size_t>(result.reduce_once().data[0]);
183 }
184 };
185};
186
187} // namespace bb
A wrapper for Relations to expose methods used by the Sumcheck prover or verifier to add the contribu...
std::unordered_set< Key, HashFunction > LookupHashTable
static bool check_databus_read(auto &values, Builder &builder)
Check that the {index, value} pair contained in a databus read gate reflects the actual value present...
static bool check_relation(auto &values, auto &params)
Check that a given relation is satisfied for the provided inputs corresponding to a single row.
static bool check_tag_data(const TagCheckData &tag_data)
Check whether the left and right running tag products are equal.
static bool check_lookup(auto &values, auto &lookup_hash_table)
Check whether the values in a lookup gate are contained within a corresponding hash table.
static auto init_empty_values()
Helper for initializing an empty AllValues container of the right Flavor based on Builder.
static void populate_values(Builder &builder, auto &block, auto &values, TagCheckData &tag_data, MemoryCheckData &memory_data, size_t idx)
Populate the values required to check the correctness of a single "row" of the circuit.
static bool check(const Builder &builder_in)
Check the correctness of a circuit witness.
static Builder prepare_circuit(const Builder &builder_in)
Copy the builder and finalize it before checking its validity.
static bool check_block(Builder &builder, auto &block, TagCheckData &tag_data, MemoryCheckData &memory_data, LookupHashTable &lookup_hash_table)
Checks that the provided witness satisfies all gates contained in a single execution trace block.
AluTraceBuilder builder
Definition alu.test.cpp:123
Entry point for Barretenberg command-line interface.
field< Bn254FrParams > fr
Definition fr.hpp:174
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
size_t operator()(const Key &entry) const
Struct for managing memory record data for ensuring RAM/ROM correctness.
Struct for managing the running tag product data for ensuring tag correctness.
std::unordered_set< size_t > encountered_variables
static constexpr field one()
static field random_element(numeric::RNG *engine=nullptr) noexcept
BB_INLINE constexpr field sqr() const noexcept
BB_INLINE constexpr field reduce_once() const noexcept