Skip to content

Commit

Permalink
define pad directly in arith to avoid virtual
Browse files Browse the repository at this point in the history
  • Loading branch information
ledwards2225 committed Nov 2, 2023
1 parent 3cd2dc6 commit 351eab6
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ template <typename FF_> class Ultra {
using FF = FF_;
using SelectorType = std::vector<FF, barretenberg::ContainerSlabAllocator<FF>>;

std::vector<SelectorType> selectors;
private:
std::array<SelectorType, NUM_SELECTORS> selectors;

public:
SelectorType& q_m() { return selectors[0]; };
SelectorType& q_c() { return selectors[1]; };
SelectorType& q_1() { return selectors[2]; };
Expand All @@ -85,19 +87,22 @@ template <typename FF_> class Ultra {
SelectorType& q_aux() { return selectors[9]; };
SelectorType& q_lookup_type() { return selectors[10]; };

Ultra(size_t num_selectors = NUM_SELECTORS)
: selectors(num_selectors)
{}

const auto& get() const { return selectors; };

void reserve(size_t size_hint)
{
for (auto& p : selectors) {
p.reserve(size_hint);
for (auto& vec : selectors) {
vec.reserve(size_hint);
}
}

/**
* @brief Add zeros to all selectors which are not part of the conventional Ultra arithmetization
* @details Does nothing for this class since this IS the conventional Ultra arithmetization
*
*/
void pad_additional(){};

// Note: These are needed for Plonk only (for poly storage in a std::map). Must be in same order as above struct.
inline static const std::vector<std::string> selector_names = { "q_m", "q_c", "q_1", "q_2",
"q_3", "q_4", "q_arith", "q_sort",
Expand All @@ -110,17 +115,49 @@ template <typename FF_> class Ultra {
*
* @tparam FF_
*/
template <typename FF_> class UltraHonk : public Ultra<FF_> {
template <typename FF_> class UltraHonk {
public:
static constexpr size_t NUM_WIRES = 4;
static constexpr size_t NUM_SELECTORS = 12;
using FF = FF_;
using SelectorType = std::vector<FF, barretenberg::ContainerSlabAllocator<FF>>;

private:
std::array<SelectorType, NUM_SELECTORS> selectors;

public:
SelectorType& q_m() { return selectors[0]; };
SelectorType& q_c() { return selectors[1]; };
SelectorType& q_1() { return selectors[2]; };
SelectorType& q_2() { return selectors[3]; };
SelectorType& q_3() { return selectors[4]; };
SelectorType& q_4() { return selectors[5]; };
SelectorType& q_arith() { return selectors[6]; };
SelectorType& q_sort() { return selectors[7]; };
SelectorType& q_elliptic() { return selectors[8]; };
SelectorType& q_aux() { return selectors[9]; };
SelectorType& q_lookup_type() { return selectors[10]; };
SelectorType& q_busread() { return this->selectors[11]; };

UltraHonk()
: Ultra<FF_>(NUM_SELECTORS)
{}
const auto& get() const { return selectors; };

void reserve(size_t size_hint)
{
for (auto& vec : selectors) {
vec.reserve(size_hint);
}
}

/**
* @brief Add zeros to all selectors which are not part of the conventional Ultra arithmetization
* @details Facilitates reuse of Ultra gate construction functions in arithmetizations which extend the conventional
* Ultra arithmetization
*
*/
void pad_additional() { q_busread().emplace_back(0); };

// Note: Unused. Needed only for consistency with Ultra arith (which is used by Plonk)
inline static const std::vector<std::string> selector_names = {};
};

class GoblinTranslator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,6 @@ template <typename FF> class GoblinUltraCircuitBuilder_ : public UltraCircuitBui
void finalize_circuit();
void add_gates_to_ensure_all_polys_are_non_zero();

/**
* @brief Utility for adding zeros to selectors which are not part of the conventional Ultra arithmetization
*
*/
void pad_additional_selectors() override { q_busread.emplace_back(0); };

size_t get_num_constant_gates() const override { return 0; }

/**
Expand Down
Loading

0 comments on commit 351eab6

Please sign in to comment.