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
13#include <cstdint>
14namespace bb {
15
20struct BusVector {
21
22 // A default value added to every databus column to ensure read gates exist. Set to 0 so that the commitment to a
23 // databus column containing only the default entry is the point at infinity, matching the default commitment used
24 // in DataBusDepot. This makes the default commitment independent of the databus polynomial offset.
25 static constexpr bb::fr DEFAULT_VALUE = 0;
26
32 void append(const uint32_t& idx)
33 {
34 data.emplace_back(idx);
35 read_counts.emplace_back(0);
36 }
37
38 size_t size() const { return data.size(); }
39
40 const uint32_t& operator[](size_t idx) const
41 {
42 BB_ASSERT_LT(idx, size());
43 return data[idx];
44 }
45
46 const uint32_t& get_read_count(size_t idx) const
47 {
48 BB_ASSERT_LT(idx, read_counts.size());
49 return read_counts[idx];
50 }
51
52 void increment_read_count(size_t idx)
53 {
54 BB_ASSERT_LT(idx, read_counts.size());
55 read_counts[idx]++;
56 }
57
58 private:
59 std::vector<uint32_t> read_counts; // count of reads at each index into data
60 std::vector<uint32_t> data; // variable indices corresponding to data in this bus vector
61};
62
72constexpr size_t NUM_BUS_COLUMNS = MAX_APPS_PER_KERNEL + /*kernel calldata*/ 1 + /*kernel returndata*/ 1;
73
74using DataBus = std::array<BusVector, NUM_BUS_COLUMNS>;
75enum class BusId : uint8_t {
77 APP_CALLDATA = 1,
78 RETURNDATA = MAX_APPS_PER_KERNEL + 1,
79};
80static_assert(static_cast<size_t>(BusId::RETURNDATA) == NUM_BUS_COLUMNS - 1, "BusId enum must match DataBus layout");
81
82} // namespace bb
#define BB_ASSERT_LT(left, right,...)
Definition assert.hpp:143
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
constexpr size_t NUM_BUS_COLUMNS
The DataBus; facilitates storage of public circuit input/output.
Definition databus.hpp:72
std::array< BusVector, NUM_BUS_COLUMNS > DataBus
Definition databus.hpp:74
BusId
Definition databus.hpp:75
A DataBus column.
Definition databus.hpp:20
std::vector< uint32_t > read_counts
Definition databus.hpp:59
void increment_read_count(size_t idx)
Definition databus.hpp:52
void append(const uint32_t &idx)
Add an element to the data defining this bus column.
Definition databus.hpp:32
std::vector< uint32_t > data
Definition databus.hpp:60
size_t size() const
Definition databus.hpp:38
const uint32_t & operator[](size_t idx) const
Definition databus.hpp:40
static constexpr bb::fr DEFAULT_VALUE
Definition databus.hpp:25
const uint32_t & get_read_count(size_t idx) const
Definition databus.hpp:46