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
39 void set_values(const std::vector<field_pt>& entries_in)
41
48 field_pt operator[](const field_pt& index) const
50
51 size_t size() const { return length; }
52 Builder* get_context() const { return context; }
53 void set_context(Builder* builder_context) { context = builder_context; }
54
55 private:
56 mutable std::vector<field_pt> entries; // bus vector entries
57 std::vector<OriginTag> _tags; // origin tags for each entry (restored on read)
58 size_t length = 0;
59 BusId bus_idx; // Idx of column in bus
60 mutable Builder* context = nullptr;
61 };
62
63 public:
64 // The columns of the DataBus.
68 for (uint8_t idx = 0; idx < MAX_APPS_PER_KERNEL; ++idx) {
69 result[idx] = bus_vector{ static_cast<BusId>(idx + 1) };
70 }
71 return result;
72 }();
74};
75
93template <class Builder> class DataBusDepot {
94 public:
96 using Commitment = typename Curve::Group;
99
100 // Storage for the return data commitments to be propagated via the public inputs
101 std::array<Commitment, MAX_APPS_PER_KERNEL> app_return_data_commitments;
103
104 // Existence flags indicating whether each return data commitment has been set
105 std::array<bool, MAX_APPS_PER_KERNEL> app_return_data_commitment_exists = []() {
106 std::array<bool, MAX_APPS_PER_KERNEL> result{};
107 result.fill(false);
108 return result;
109 }();
111
117
125 {
126 for (size_t idx = 0; idx < MAX_APPS_PER_KERNEL; ++idx) {
128 return false;
129 }
130 }
131 return true;
132 }
133
142 {
143 for (size_t idx = 0; idx < MAX_APPS_PER_KERNEL; ++idx) {
145 app_return_data_commitments[idx] = commitment;
147 return;
148 }
149 }
150 BB_ASSERT(false, "DataBusDepot has no free app return-data slot");
151 }
152
159 {
160 auto default_commitment = Commitment(CommitmentNative::infinity());
161 default_commitment.convert_constant_to_fixed_witness(&builder);
162 return default_commitment;
163 }
164
177
183 {
184 BB_ASSERT_LT(idx, MAX_APPS_PER_KERNEL, "DataBusDepot app return-data index out of bounds");
187 }
188 app_return_data_commitment_exists[idx] = false; // Reset the existence flag after retrieval
189 return app_return_data_commitments[idx];
190 }
191};
192
193} // 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:93
std::array< bool, MAX_APPS_PER_KERNEL > app_return_data_commitment_exists
Definition databus.hpp:105
std::array< Commitment, MAX_APPS_PER_KERNEL > app_return_data_commitments
Definition databus.hpp:101
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:169
typename Curve::ScalarFieldNative FrNative
Definition databus.hpp:98
bool kernel_return_data_commitment_exists
Definition databus.hpp:110
typename Curve::AffineElementNative CommitmentNative
Definition databus.hpp:97
static Commitment construct_default_commitment(Builder &builder)
Construct a default commitment for the databus return data.
Definition databus.hpp:158
Commitment kernel_return_data_commitment
Definition databus.hpp:102
bool app_return_data_slots_are_empty() const
Whether all app return-data slots are currently empty.
Definition databus.hpp:124
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:182
typename Curve::Group Commitment
Definition databus.hpp:96
void set_app_return_data_commitment(const Commitment &commitment)
Record an app return-data commitment in the next available slot.
Definition databus.hpp:141
void set_kernel_return_data_commitment(const Commitment &commitment)
Definition databus.hpp:112
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:48
std::vector< OriginTag > _tags
Definition databus.hpp:57
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:56
Builder * get_context() const
Definition databus.hpp:52
void set_context(Builder *builder_context)
Definition databus.hpp:53
bus_vector return_data
Definition databus.hpp:73
std::array< bus_vector, MAX_APPS_PER_KERNEL > app_calldata
Definition databus.hpp:66
bus_vector kernel_calldata
Definition databus.hpp:65
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