Skip to content

Commit

Permalink
tests passing with databus additions to goblin
Browse files Browse the repository at this point in the history
  • Loading branch information
ledwards2225 committed Nov 1, 2023
1 parent 8a3851a commit b42af2d
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ class GoblinUltra {
Commitment ecc_op_wire_2_comm;
Commitment ecc_op_wire_3_comm;
Commitment ecc_op_wire_4_comm;
Commitment calldata_comm;
Commitment calldata_read_counts_comm;
Commitment sorted_accum_comm;
Commitment w_4_comm;
Commitment z_perm_comm;
Expand Down Expand Up @@ -540,6 +542,8 @@ class GoblinUltra {
ecc_op_wire_2_comm = deserialize_from_buffer<Commitment>(proof_data, num_bytes_read);
ecc_op_wire_3_comm = deserialize_from_buffer<Commitment>(proof_data, num_bytes_read);
ecc_op_wire_4_comm = deserialize_from_buffer<Commitment>(proof_data, num_bytes_read);
calldata_comm = deserialize_from_buffer<Commitment>(proof_data, num_bytes_read);
calldata_read_counts_comm = deserialize_from_buffer<Commitment>(proof_data, num_bytes_read);
sorted_accum_comm = deserialize_from_buffer<Commitment>(proof_data, num_bytes_read);
w_4_comm = deserialize_from_buffer<Commitment>(proof_data, num_bytes_read);
z_perm_comm = deserialize_from_buffer<Commitment>(proof_data, num_bytes_read);
Expand Down Expand Up @@ -576,6 +580,8 @@ class GoblinUltra {
serialize_to_buffer(ecc_op_wire_2_comm, proof_data);
serialize_to_buffer(ecc_op_wire_3_comm, proof_data);
serialize_to_buffer(ecc_op_wire_4_comm, proof_data);
serialize_to_buffer(calldata_comm, proof_data);
serialize_to_buffer(calldata_read_counts_comm, proof_data);
serialize_to_buffer(sorted_accum_comm, proof_data);
serialize_to_buffer(w_4_comm, proof_data);
serialize_to_buffer(z_perm_comm, proof_data);
Expand Down
211 changes: 117 additions & 94 deletions barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra_recursive.hpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ template <class Flavor> void ProverInstance_<Flavor>::compute_witness(Circuit& c
proving_key->w_o = wire_polynomials[2];
proving_key->w_4 = wire_polynomials[3];

// If Goblin, construct the ECC op queue wire polynomials
// If Goblin, construct the ECC op queue wire and databus polynomials
if constexpr (IsGoblinFlavor<Flavor>) {
construct_ecc_op_wire_polynomials(wire_polynomials);
construct_databus_polynomials(circuit);
}

// Construct the sorted concatenated list polynomials for the lookup argument
Expand Down Expand Up @@ -183,6 +184,30 @@ template <class Flavor> void ProverInstance_<Flavor>::construct_ecc_op_wire_poly
proving_key->ecc_op_wire_4 = op_wire_polynomials[3];
}

/**
* @brief
* @details
*
* @tparam Flavor
* @param circuit
*/
template <class Flavor> void ProverInstance_<Flavor>::construct_databus_polynomials(Circuit& circuit)
{
if constexpr (IsGoblinFlavor<Flavor>) {
polynomial public_calldata(dyadic_circuit_size);
polynomial calldata_read_counts(dyadic_circuit_size);

const size_t offset = Flavor::has_zero_row ? 1 : 0;
for (size_t idx = 0; idx < circuit.public_calldata.size(); ++idx) {
public_calldata[idx + offset] = circuit.get_variable(circuit.public_calldata[idx]);
calldata_read_counts[idx + offset] = circuit.get_variable(circuit.calldata_read_counts[idx]);
}

proving_key->calldata = public_calldata;
proving_key->calldata_read_counts = calldata_read_counts;
}
}

template <class Flavor>
std::shared_ptr<typename Flavor::ProvingKey> ProverInstance_<Flavor>::compute_proving_key(Circuit& circuit)
{
Expand Down Expand Up @@ -467,6 +492,7 @@ std::shared_ptr<typename Flavor::VerificationKey> ProverInstance_<Flavor>::compu
// due to its simple structure. Handling it in the same way as the lagrange polys for now for simplicity.
if constexpr (IsGoblinFlavor<Flavor>) {
verification_key->lagrange_ecc_op = commitment_key->commit(proving_key->lagrange_ecc_op);
verification_key->q_busread = commitment_key->commit(proving_key->q_busread);
}

// // See `add_recusrive_proof()` for how this recursive data is assigned.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ template <class Flavor> class ProverInstance_ {

void construct_ecc_op_wire_polynomials(auto&);

void construct_databus_polynomials(Circuit&);

void add_table_column_selector_poly_to_proving_key(barretenberg::polynomial& small, const std::string& tag);

void add_plookup_memory_records_to_wire_4(FF);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@ template <UltraFlavor Flavor> void UltraProver_<Flavor>::execute_wire_commitment
}

if constexpr (IsGoblinFlavor<Flavor>) {
// Commit to Goblin ECC op wires
auto op_wire_polys = instance->proving_key->get_ecc_op_wires();
auto labels = commitment_labels.get_ecc_op_wires();
for (size_t idx = 0; idx < Flavor::NUM_WIRES; ++idx) {
transcript.send_to_verifier(labels[idx], commitment_key->commit(op_wire_polys[idx]));
}
// Commit to DataBus columns
transcript.send_to_verifier(commitment_labels.calldata,
commitment_key->commit(instance->proving_key->calldata));
transcript.send_to_verifier(commitment_labels.calldata_read_counts,
commitment_key->commit(instance->proving_key->calldata_read_counts));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ template <typename Flavor> bool UltraVerifier_<Flavor>::verify_proof(const plonk
commitments.w_r = transcript.template receive_from_prover<Commitment>(commitment_labels.w_r);
commitments.w_o = transcript.template receive_from_prover<Commitment>(commitment_labels.w_o);

// If Goblin, get commitments to ECC op wire polynomials
// If Goblin, get commitments to ECC op wire polynomials and DataBus columns
if constexpr (IsGoblinFlavor<Flavor>) {
commitments.ecc_op_wire_1 =
transcript.template receive_from_prover<Commitment>(commitment_labels.ecc_op_wire_1);
Expand All @@ -80,6 +80,9 @@ template <typename Flavor> bool UltraVerifier_<Flavor>::verify_proof(const plonk
transcript.template receive_from_prover<Commitment>(commitment_labels.ecc_op_wire_3);
commitments.ecc_op_wire_4 =
transcript.template receive_from_prover<Commitment>(commitment_labels.ecc_op_wire_4);
commitments.calldata = transcript.template receive_from_prover<Commitment>(commitment_labels.calldata);
commitments.calldata_read_counts =
transcript.template receive_from_prover<Commitment>(commitment_labels.calldata_read_counts);
}

// Get challenge for sorted list batching and wire four memory records
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class GoblinUltraTranscriptTests : public ::testing::Test {
manifest_expected.add_entry(round, "ECC_OP_WIRE_2", size_G);
manifest_expected.add_entry(round, "ECC_OP_WIRE_3", size_G);
manifest_expected.add_entry(round, "ECC_OP_WIRE_4", size_G);
manifest_expected.add_entry(round, "CALLDATA", size_G);
manifest_expected.add_entry(round, "CALLDATA_READ_COUNTS", size_G);
manifest_expected.add_challenge(round, "eta");

round++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ template <typename FF_> class Ultra {

template <typename FF_> class UltraHonk : public Ultra<FF_> {
public:
static constexpr size_t NUM_SELECTORS = 11; // 12;
static constexpr size_t NUM_SELECTORS = 12;
using FF = FF_;
using SelectorType = std::vector<FF, barretenberg::ContainerSlabAllocator<FF>>;

// SelectorType& q_busread() { return this->selectors[11]; };
SelectorType& q_busread() { return this->selectors[11]; };

UltraHonk()
: Ultra<FF_>(NUM_SELECTORS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,30 @@ template <typename FF> void GoblinUltraCircuitBuilder_<FF>::add_gates_to_ensure_
{
UltraCircuitBuilder_<arithmetization::UltraHonk<FF>>::add_gates_to_ensure_all_polys_are_non_zero();

// WORKTODO: addtional logic to take care of q_busread selector
// this->w_l.emplace_back(this->zero_idx);
// this->w_r.emplace_back(this->zero_idx);
// this->w_o.emplace_back(this->zero_idx);
// this->w_4.emplace_back(this->zero_idx);
// this->q_m.emplace_back(1);
// this->q_1.emplace_back(1);
// this->q_2.emplace_back(1);
// this->q_3.emplace_back(1);
// this->q_c.emplace_back(0);
// this->q_sort.emplace_back(1);

// this->q_arith.emplace_back(1);
// this->q_4.emplace_back(1);
// this->q_lookup_type.emplace_back(0);
// this->q_elliptic.emplace_back(1);
// this->q_aux.emplace_back(1);
// pad_additional_selectors();
// ++this->num_gates;
// Additional gate to add a nonzero value to q_busread
this->w_l.emplace_back(this->zero_idx);
this->w_r.emplace_back(this->zero_idx);
this->w_o.emplace_back(this->zero_idx);
this->w_4.emplace_back(this->zero_idx);
this->q_m.emplace_back(0);
this->q_1.emplace_back(0);
this->q_2.emplace_back(0);
this->q_3.emplace_back(0);
this->q_c.emplace_back(0);
this->q_sort.emplace_back(0);

this->q_arith.emplace_back(0);
this->q_4.emplace_back(0);
this->q_lookup_type.emplace_back(0);
this->q_elliptic.emplace_back(0);
this->q_aux.emplace_back(0);
q_busread.emplace_back(1);
++this->num_gates;

// Add some nonzero values to the calldata and corresponding read counts
// WORKTODO: will need to do this more carefully once we actually have a databus lookup relation
public_calldata.emplace_back(this->one_idx);
calldata_read_counts.emplace_back(this->one_idx);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ template <typename FF> class GoblinUltraCircuitBuilder_ : public UltraCircuitBui
uint32_t equality_op_idx;

using WireVector = std::vector<uint32_t, ContainerSlabAllocator<uint32_t>>;
using SelectorVector = std::vector<FF, ContainerSlabAllocator<FF>>;

// Wires storing ecc op queue data; values are indices into the variables array
std::array<WireVector, arithmetization::UltraHonk<FF>::NUM_WIRES> ecc_op_wires;
Expand All @@ -44,8 +45,11 @@ template <typename FF> class GoblinUltraCircuitBuilder_ : public UltraCircuitBui
WireVector& ecc_op_wire_3 = std::get<2>(ecc_op_wires);
WireVector& ecc_op_wire_4 = std::get<3>(ecc_op_wires);

SelectorVector& q_busread = this->selectors.q_busread();

// DataBus call/return data arrays
std::vector<uint32_t> public_calldata;
std::vector<uint32_t> calldata_read_counts;
std::vector<uint32_t> public_return_data;

// Functions for adding ECC op queue "gates"
Expand Down Expand Up @@ -76,7 +80,7 @@ template <typename FF> class GoblinUltraCircuitBuilder_ : public UltraCircuitBui
void finalize_circuit();
void add_gates_to_ensure_all_polys_are_non_zero();

void pad_additional_selectors() override{};
void pad_additional_selectors() override { q_busread.emplace_back(0); };

size_t get_num_constant_gates() const override { return 0; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@ void construct_selector_polynomials(const typename Flavor::CircuitBuilder& circu
size_t gate_offset = zero_row_offset + circuit_constructor.public_inputs.size();

// If Goblin, (1) update the conventional gate offset to account for ecc op gates at the top of the execution trace,
// and (2) construct ecc op gate selector polynomial.
// and (2) construct ecc op gate selector polynomial. This selector is handled separately from the others since it
// is computable based simply on num_ecc_op_gates and thus is not constructed explicitly in the builder.
// Note 1: All other selectors will be automatically and correctly initialized to 0 on this domain.
// Note 2: If applicable, the ecc op gates are shifted down by 1 to account for a zero row.
if constexpr (IsGoblinFlavor<Flavor>) {
const size_t num_ecc_op_gates = circuit_constructor.num_ecc_op_gates;
gate_offset += num_ecc_op_gates;
const size_t op_gate_offset = zero_row_offset;
// The op gate selector is simply the indicator on the domain [offset, num_ecc_op_gates + offset - 1]
barretenberg::polynomial selector_poly_lagrange(proving_key->circuit_size);
barretenberg::polynomial ecc_op_selector(proving_key->circuit_size);
for (size_t i = 0; i < num_ecc_op_gates; ++i) {
selector_poly_lagrange[i + op_gate_offset] = 1;
ecc_op_selector[i + op_gate_offset] = 1;
}
proving_key->lagrange_ecc_op = selector_poly_lagrange;
proving_key->lagrange_ecc_op = ecc_op_selector;
}

// TODO(#398): Loose coupling here! Would rather build up pk from arithmetization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ std::array<typename Flavor::GroupElement, 2> UltraRecursiveVerifier_<Flavor>::ve
commitments.w_r = transcript.template receive_from_prover<Commitment>(commitment_labels.w_r);
commitments.w_o = transcript.template receive_from_prover<Commitment>(commitment_labels.w_o);

// If Goblin, get commitments to ECC op wire polynomials
// If Goblin, get commitments to ECC op wire polynomials and DataBus columns
if constexpr (IsGoblinFlavor<Flavor>) {
commitments.ecc_op_wire_1 =
transcript.template receive_from_prover<Commitment>(commitment_labels.ecc_op_wire_1);
Expand All @@ -67,6 +67,9 @@ std::array<typename Flavor::GroupElement, 2> UltraRecursiveVerifier_<Flavor>::ve
transcript.template receive_from_prover<Commitment>(commitment_labels.ecc_op_wire_3);
commitments.ecc_op_wire_4 =
transcript.template receive_from_prover<Commitment>(commitment_labels.ecc_op_wire_4);
commitments.calldata = transcript.template receive_from_prover<Commitment>(commitment_labels.calldata);
commitments.calldata_read_counts =
transcript.template receive_from_prover<Commitment>(commitment_labels.calldata_read_counts);
}

// Get challenge for sorted list batching and wire four memory records
Expand Down

0 comments on commit b42af2d

Please sign in to comment.