Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
databus.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Complete, auditors: [Khashayar], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
8#include "../circuit_builders/circuit_builders_fwd.hpp"
9#include "../field/field.hpp"
13
14namespace bb::stdlib {
15
16template <typename Builder> class databus {
17 public:
18 databus() = default;
19
20 private:
21 class bus_vector {
22 private:
24
25 public:
26 bus_vector() = default;
27
30
41 void set_values(const std::vector<field_pt>& entries_in)
43
50 field_pt operator[](const field_pt& index) const
52
53 size_t size() const { return length; }
54 Builder* get_context() const { return context; }
55 void set_context(Builder* builder_context) { context = builder_context; }
56
57 private:
58 mutable std::vector<field_pt> entries; // bus vector entries
59 std::vector<OriginTag> _tags; // origin tags for each entry (restored on read)
60 size_t length = 0;
61 BusId bus_idx; // Idx of column in bus
62 mutable Builder* context = nullptr;
63 };
64
65 public:
66 // The columns of the DataBus.
70 for (uint8_t idx = 0; idx < MAX_APPS_PER_KERNEL; ++idx) {
71 result[idx] = bus_vector{ static_cast<BusId>(idx + 1) };
72 }
73 return result;
74 }();
76};
77
95template <class Builder> class DataBusDepot {
96 public:
98 using Commitment = typename Curve::Group;
101
102 // Storage for the return data commitments to be propagated via the public inputs
103 std::array<Commitment, MAX_APPS_PER_KERNEL> app_return_data_commitments;
105
106 // Existence flags indicating whether each return data commitment has been set
107 std::array<bool, MAX_APPS_PER_KERNEL> app_return_data_commitment_exists = []() {
108 std::array<bool, MAX_APPS_PER_KERNEL> result{};
109 result.fill(false);
110 return result;
111 }();
113
119
127 {
128 for (size_t idx = 0; idx < MAX_APPS_PER_KERNEL; ++idx) {
130 return false;
131 }
132 }
133 return true;
134 }
135
144 {
145 for (size_t idx = 0; idx < MAX_APPS_PER_KERNEL; ++idx) {
147 app_return_data_commitments[idx] = commitment;
149 return;
150 }
151 }
152 BB_ASSERT(false, "DataBusDepot has no free app return-data slot");
153 }
154
161 {
162 auto default_commitment = Commitment(CommitmentNative::infinity());
163 default_commitment.convert_constant_to_fixed_witness(&builder);
164 return default_commitment;
165 }
166
179
185 {
186 BB_ASSERT_LT(idx, MAX_APPS_PER_KERNEL, "DataBusDepot app return-data index out of bounds");
189 }
190 app_return_data_commitment_exists[idx] = false; // Reset the existence flag after retrieval
191 return app_return_data_commitments[idx];
192 }
193};
194
195} // namespace bb::stdlib
#define BB_ASSERT(expression,...)
Definition assert.hpp:70
#define BB_ASSERT_LT(left, right,...)
Definition assert.hpp:143
Class for managing propagation of databus return data commitments used in consistency checks.
Definition databus.hpp:95
std::array< bool, MAX_APPS_PER_KERNEL > app_return_data_commitment_exists
Definition databus.hpp:107
std::array< Commitment, MAX_APPS_PER_KERNEL > app_return_data_commitments
Definition databus.hpp:103
Commitment get_kernel_return_data_commitment(Builder &builder)
Get the previously set kernel return data commitment if it exists, else a default one.
Definition databus.hpp:171
typename Curve::ScalarFieldNative FrNative
Definition databus.hpp:100
bool kernel_return_data_commitment_exists
Definition databus.hpp:112
typename Curve::AffineElementNative CommitmentNative
Definition databus.hpp:99
static Commitment construct_default_commitment(Builder &builder)
Construct a default commitment for the databus return data.
Definition databus.hpp:160
Commitment kernel_return_data_commitment
Definition databus.hpp:104
bool app_return_data_slots_are_empty() const
Whether all app return-data slots are currently empty.
Definition databus.hpp:126
Commitment get_app_return_data_commitment(Builder &builder, const size_t idx)
Get the previously set app return data commitment if it exists, else a default one.
Definition databus.hpp:184
typename Curve::Group Commitment
Definition databus.hpp:98
void set_app_return_data_commitment(const Commitment &commitment)
Record an app return-data commitment in the next available slot.
Definition databus.hpp:143
void set_kernel_return_data_commitment(const Commitment &commitment)
Definition databus.hpp:114
field_pt operator[](const field_pt &index) const
Read from the bus vector with a witness index value. Creates a read gate.
Definition databus.cpp:55
std::vector< OriginTag > _tags
Definition databus.hpp:59
bus_vector(const BusId bus_idx)
Definition databus.hpp:28
void set_values(const std::vector< field_pt > &entries_in)
Set the entries of the bus vector from possibly unnormalized or constant inputs.
Definition databus.cpp:14
std::vector< field_pt > entries
Definition databus.hpp:58
Builder * get_context() const
Definition databus.hpp:54
void set_context(Builder *builder_context)
Definition databus.hpp:55
bus_vector return_data
Definition databus.hpp:75
std::array< bus_vector, MAX_APPS_PER_KERNEL > app_calldata
Definition databus.hpp:68
bus_vector kernel_calldata
Definition databus.hpp:67
AluTraceBuilder builder
Definition alu.test.cpp:124
BusId
Definition databus.hpp:75
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
GroupNative::affine_element AffineElementNative
Definition bn254.hpp:25
curve::BN254::ScalarField ScalarFieldNative
Definition bn254.hpp:21
element< CircuitBuilder, bigfield< CircuitBuilder, bb::Bn254FqParams >, ScalarField, GroupNative > Group
Definition bn254.hpp:31
VectorField result