-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: DataBus notion with calldata/return data (#5504)
The DataBus will eventually contain 3 columns: calldata, return data, and a 3rd for storing "function" calldata/returndata. Prior to this PR, we only had calldata (implemented as a proof of concept). This PR introduced a more proper notion of the `DataBus` and adds return data to its functionality. (No 3rd column yet). Each column (`BusVector`) of the `DataBus` essentially behaves the same way so the bulk of the work in this PR is simply making that logic generic/shareable in the `GoblinUltraCircuitBuilder` and the `DataBusLookupRelation`. Note: In prior work I collected some of the generic log-derivative lookup logic (originally introduced by Zac for the ECCVM) in `logderivative_library.hpp`. I'm no longer using that shared logic for the Databus for a few reasons: 1) the library is now also used by the AVM so any changes would have touched many avm files, 2) the DataBus relation needs functionality for multiple "tables" (bus columns) whereas others only have one, and 3) the library methods were over generalized in a way not needed for the DataBus (multiple read/write terms) that obscured the simple structure of the Databus lookup relation.
- Loading branch information
1 parent
1912802
commit 95a1d8a
Showing
14 changed files
with
590 additions
and
223 deletions.
There are no files selected for viewing
241 changes: 163 additions & 78 deletions
241
barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/databus.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
namespace bb { | ||
|
||
using namespace bb; | ||
|
||
/** | ||
* @brief A DataBus column | ||
* | ||
*/ | ||
struct BusVector { | ||
|
||
/** | ||
* @brief Add an element to the data defining this bus column | ||
* | ||
* @param idx Index of the element in the variables vector of a builder | ||
*/ | ||
void append(const uint32_t& idx) | ||
{ | ||
data.emplace_back(idx); | ||
read_counts.emplace_back(0); | ||
} | ||
|
||
size_t size() const { return data.size(); } | ||
|
||
const uint32_t& operator[](size_t idx) const | ||
{ | ||
ASSERT(idx < size()); | ||
return data[idx]; | ||
} | ||
|
||
const uint32_t& get_read_count(size_t idx) const | ||
{ | ||
ASSERT(idx < read_counts.size()); | ||
return read_counts[idx]; | ||
} | ||
|
||
void increment_read_count(size_t idx) | ||
{ | ||
ASSERT(idx < read_counts.size()); | ||
read_counts[idx]++; | ||
} | ||
|
||
private: | ||
std::vector<uint32_t> read_counts; // count of reads at each index into data | ||
std::vector<uint32_t> data; // variable indices corresponding to data in this bus vector | ||
}; | ||
|
||
/** | ||
* @brief The DataBus; facilitates storage of public circuit input/output | ||
* @details The DataBus is designed to facilitate efficient transfer of large amounts of public data between circuits. | ||
* It is expected that only a small subset of the data being passed needs to be used in any single circuit, thus we | ||
* provide a read mechanism (implemented through a Builder) that results in prover work proportional to only the data | ||
* that is used. (The prover must still commit to all data in each bus vector but we do not need to hash all data | ||
* in-circuit as we would with public inputs). | ||
* | ||
*/ | ||
struct DataBus { | ||
BusVector calldata; // the public input to the circuit | ||
BusVector return_data; // the public output of the circuit | ||
}; | ||
|
||
} // namespace bb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.