-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: bus updates #7522
feat: bus updates #7522
Changes from 5 commits
a75ef3c
0255cb0
fc42e8b
1a645f6
336e99f
05cd650
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,10 +47,12 @@ template <typename FF_> class DatabusLookupRelationImpl { | |
public: | ||
using FF = FF_; | ||
static constexpr size_t LENGTH = 5; // 1 + polynomial degree of this relation | ||
static constexpr size_t NUM_BUS_COLUMNS = 2; // calldata, return data | ||
static constexpr size_t NUM_BUS_COLUMNS = 3; // calldata, return data | ||
|
||
// Note: Inverse correctness subrelations are actually LENGTH-1; taking advantage would require additional work | ||
static constexpr std::array<size_t, NUM_BUS_COLUMNS * 2> SUBRELATION_PARTIAL_LENGTHS{ | ||
LENGTH, // inverse polynomial correctness subrelation | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you make it explicit why we have duplicates here and that they're not quite duplicates, they operate on different values? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
LENGTH, // log-derivative lookup argument subrelation | ||
LENGTH, // inverse polynomial correctness subrelation | ||
LENGTH, // log-derivative lookup argument subrelation | ||
LENGTH, // inverse polynomial correctness subrelation | ||
|
@@ -64,6 +66,8 @@ polynomials, | |
* exceed the subrelation partial degree, which is given by LENGTH - 1 in this case. | ||
*/ | ||
static constexpr std::array<size_t, NUM_BUS_COLUMNS * 2> SUBRELATION_WITNESS_DEGREES{ | ||
LENGTH - 1, // inverse polynomial correctness subrelation | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
LENGTH - 1, // log-derivative lookup argument subrelation | ||
LENGTH - 1, // inverse polynomial correctness subrelation | ||
LENGTH - 1, // log-derivative lookup argument subrelation | ||
LENGTH - 1, // inverse polynomial correctness subrelation | ||
|
@@ -72,14 +76,14 @@ polynomials, | |
|
||
// The lookup subrelations are "linearly dependent" in the sense that they establish the value of a sum across the | ||
// entire execution trace rather than a per-row identity. | ||
static constexpr std::array<bool, NUM_BUS_COLUMNS* 2> SUBRELATION_LINEARLY_INDEPENDENT = { | ||
true, false, true, false | ||
}; | ||
static constexpr std::array<bool, NUM_BUS_COLUMNS* 2> SUBRELATION_LINEARLY_INDEPENDENT = { true, false, true, | ||
false, true, false }; | ||
|
||
template <typename AllEntities> inline static bool skip([[maybe_unused]] const AllEntities& in) | ||
{ | ||
// Ensure the input does not contain a read gate or data that is being read | ||
return in.q_busread.is_zero() && in.calldata_read_counts.is_zero() && in.return_data_read_counts.is_zero(); | ||
return in.q_busread.is_zero() && in.calldata_read_counts.is_zero() && in.calldata_2_read_counts.is_zero() && | ||
in.return_data_read_counts.is_zero(); | ||
} | ||
|
||
// Interface for easy access of databus components by column (bus_idx) | ||
|
@@ -95,10 +99,20 @@ polynomials, | |
static auto& read_tags(const AllEntities& in) { return in.calldata_read_tags; } | ||
}; | ||
|
||
// Specialization for return data (bus_idx = 1) | ||
// Specialization for calldata_2 (bus_idx = 1) | ||
template <typename AllEntities> struct BusData</*bus_idx=*/1, AllEntities> { | ||
static auto& values(const AllEntities& in) { return in.return_data; } | ||
static auto& values(const AllEntities& in) { return in.calldata_2; } | ||
static auto& selector(const AllEntities& in) { return in.q_r; } | ||
static auto& inverses(AllEntities& in) { return in.calldata_2_inverses; } | ||
static auto& inverses(const AllEntities& in) { return in.calldata_2_inverses; } // const version | ||
static auto& read_counts(const AllEntities& in) { return in.calldata_2_read_counts; } | ||
static auto& read_tags(const AllEntities& in) { return in.calldata_2_read_tags; } | ||
}; | ||
|
||
// Specialization for return data (bus_idx = 2) | ||
template <typename AllEntities> struct BusData</*bus_idx=*/2, AllEntities> { | ||
static auto& values(const AllEntities& in) { return in.return_data; } | ||
static auto& selector(const AllEntities& in) { return in.q_o; } | ||
static auto& inverses(AllEntities& in) { return in.return_data_inverses; } | ||
static auto& inverses(const AllEntities& in) { return in.return_data_inverses; } // const version | ||
static auto& read_counts(const AllEntities& in) { return in.return_data_read_counts; } | ||
|
@@ -217,8 +231,12 @@ polynomials, | |
is_read = q_busread == 1 && polynomials.q_l[i] == 1; | ||
nonzero_read_count = polynomials.calldata_read_counts[i] > 0; | ||
} | ||
if constexpr (bus_idx == 1) { // return data | ||
if constexpr (bus_idx == 1) { // calldata_2 | ||
is_read = q_busread == 1 && polynomials.q_r[i] == 1; | ||
nonzero_read_count = polynomials.calldata_2_read_counts[i] > 0; | ||
} | ||
if constexpr (bus_idx == 2) { // return data | ||
is_read = q_busread == 1 && polynomials.q_o[i] == 1; | ||
nonzero_read_count = polynomials.return_data_read_counts[i] > 0; | ||
} | ||
// We only compute the inverse if this row contains a read gate or data that has been read | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,6 +171,12 @@ template <typename FF> class MegaCircuitBuilder_ : public UltraCircuitBuilder_<M | |
*/ | ||
void add_public_calldata(const uint32_t& in) { return append_to_bus_vector(BusId::CALLDATA, in); } | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a comment why we have two of this function. We could specialise the name for Aztec usecase (our proving system is not that general in the end) and call them calldata_function and calldata_kernel so 1 and 2 are not misused, but prolly there's even better naming options in terms of generality There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated the comment (this was just an oversight) and updated the naming to |
||
* @brief Add a witness variable to the public calldata. | ||
* | ||
*/ | ||
void add_public_calldata_2(const uint32_t& in) { return append_to_bus_vector(BusId::CALLDATA_2, in); } | ||
|
||
/** | ||
* @brief Add a witness variable to the public return_data. | ||
* | ||
|
@@ -190,6 +196,17 @@ template <typename FF> class MegaCircuitBuilder_ : public UltraCircuitBuilder_<M | |
return read_bus_vector(BusId::CALLDATA, read_idx_witness_idx); | ||
}; | ||
|
||
/** | ||
* @brief Read from calldata_2 and create a corresponding databus read gate | ||
* | ||
* @param read_idx_witness_idx Witness index for the calldata_2 read index | ||
* @return uint32_t Witness index for the result of the read | ||
*/ | ||
uint32_t read_calldata_2(const uint32_t& read_idx_witness_idx) | ||
{ | ||
return read_bus_vector(BusId::CALLDATA_2, read_idx_witness_idx); | ||
}; | ||
|
||
/** | ||
* @brief Read from return_data and create a corresponding databus read gate | ||
* | ||
|
@@ -207,6 +224,7 @@ template <typename FF> class MegaCircuitBuilder_ : public UltraCircuitBuilder_<M | |
} | ||
|
||
const BusVector& get_calldata() { return databus[static_cast<size_t>(BusId::CALLDATA)]; } | ||
const BusVector& get_calldata_2() { return databus[static_cast<size_t>(BusId::CALLDATA_2)]; } | ||
const BusVector& get_return_data() { return databus[static_cast<size_t>(BusId::RETURNDATA)]; } | ||
|
||
void create_poseidon2_external_gate(const poseidon2_external_gate_<FF>& in); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's somehow strange to me in hindsight that we were using q_r rather than q_o for a return value but supposingly it was for optimisations purposes so we dont have yet another column, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this has nothing to do with the original purpose of the selector, its just a means for not having a new individual selector for each bus column. This is similar to what is done in the aux relation