Skip to content

Commit

Permalink
populate ultra ops only through function
Browse files Browse the repository at this point in the history
  • Loading branch information
maramihali committed Mar 8, 2024
1 parent 835383c commit 0f792e3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,7 @@ ecc_op_tuple GoblinUltraCircuitBuilder_<FF>::decompose_ecc_operands(uint32_t op_
z_2 = z_2.to_montgomery_form();

// Populate ultra ops in OpQueue with the decomposed operands
op_queue->ultra_ops[0].emplace_back(this->variables[op_idx]);
op_queue->ultra_ops[1].emplace_back(x_lo);
op_queue->ultra_ops[2].emplace_back(x_hi);
op_queue->ultra_ops[3].emplace_back(y_lo);

op_queue->ultra_ops[0].emplace_back(this->zero_idx);
op_queue->ultra_ops[1].emplace_back(y_hi);
op_queue->ultra_ops[2].emplace_back(z_1);
op_queue->ultra_ops[3].emplace_back(z_2);
op_queue->populate_ultra_ops({ this->variables[op_idx], x_lo, x_hi, y_lo, y_hi, z_1, z_2 });

// Add variables for decomposition and get indices needed for op wires
auto x_lo_idx = this->add_variable(x_lo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ namespace bb {

enum EccOpCode { NULL_OP, ADD_ACCUM, MUL_ACCUM, EQUALITY };

struct UltraOpTuple {
using Fr = curve::BN254::ScalarField;
Fr op;
Fr x_lo;
Fr x_hi;
Fr y_lo;
Fr y_hi;
Fr z_1;
Fr z_2;
};

/**
* @brief Used to construct execution trace representations of elliptic curve operations.
*
Expand Down Expand Up @@ -34,7 +45,6 @@ class ECCOpQueue {
size_t previous_ultra_ops_size = 0; // M_{i-1}

std::array<Point, 4> ultra_ops_commitments;
std::array<Point, 4> previous_ultra_ops_commitments;

Point get_accumulator() { return accumulator; }

Expand Down Expand Up @@ -75,7 +85,6 @@ class ECCOpQueue {
previous_ultra_ops_size += previous.ultra_ops[0].size();
// Update commitments
ultra_ops_commitments = previous.ultra_ops_commitments;
previous_ultra_ops_commitments = previous.previous_ultra_ops_commitments;
}
/**
* @brief Prepend the information from the previous queue (used before accumulation/merge proof to be able to run
Expand Down Expand Up @@ -104,10 +113,7 @@ class ECCOpQueue {
lhs.previous_ultra_ops_size = rhs.previous_ultra_ops_size;
rhs.previous_ultra_ops_size = temp;
// Swap commitments
auto commit_temp = lhs.previous_ultra_ops_commitments;
lhs.previous_ultra_ops_commitments = rhs.previous_ultra_ops_commitments;
rhs.previous_ultra_ops_commitments = commit_temp;
commit_temp = lhs.ultra_ops_commitments;
auto commit_temp = lhs.ultra_ops_commitments;
lhs.ultra_ops_commitments = rhs.ultra_ops_commitments;
rhs.ultra_ops_commitments = commit_temp;
}
Expand All @@ -127,11 +133,7 @@ class ECCOpQueue {
[[nodiscard]] size_t get_previous_size() const { return previous_ultra_ops_size; }
[[nodiscard]] size_t get_current_size() const { return current_ultra_ops_size; }

void set_commitment_data(std::array<Point, 4>& commitments)
{
previous_ultra_ops_commitments = ultra_ops_commitments;
ultra_ops_commitments = commitments;
}
void set_commitment_data(std::array<Point, 4>& commitments) { ultra_ops_commitments = commitments; }

/**
* @brief Get a 'view' of the current ultra ops object
Expand Down Expand Up @@ -281,6 +283,19 @@ class ECCOpQueue {
.mul_scalar_full = 0,
});
}

void populate_ultra_ops(UltraOpTuple tuple)
{
ultra_ops[0].emplace_back(tuple.op);
ultra_ops[1].emplace_back(tuple.x_lo);
ultra_ops[2].emplace_back(tuple.x_hi);
ultra_ops[3].emplace_back(tuple.y_lo);

ultra_ops[0].emplace_back(0);
ultra_ops[1].emplace_back(tuple.y_hi);
ultra_ops[2].emplace_back(tuple.z_1);
ultra_ops[3].emplace_back(tuple.z_2);
}
};

} // namespace bb
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,11 @@ TEST_F(GoblinUltraHonkComposerTests, MultipleCircuitsHonkAndMerge)
// Compute the commitments to the aggregate op queue directly and check that they match those that were computed
// iteratively during transcript aggregation by the provers and stored in the op queue.
size_t aggregate_op_queue_size = op_queue->current_ultra_ops_size;
auto ultra_ops = op_queue->get_aggregate_transcript();
auto commitment_key = std::make_shared<CommitmentKey>(aggregate_op_queue_size);
size_t idx = 0;
for (auto& result : op_queue->ultra_ops_commitments) {
auto expected = commitment_key->commit(op_queue->ultra_ops[idx++]);
auto expected = commitment_key->commit(ultra_ops[idx++]);
EXPECT_EQ(result, expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ namespace bb {
template <class Flavor>
MergeProver_<Flavor>::MergeProver_(const std::shared_ptr<ECCOpQueue>& op_queue)
: op_queue(op_queue)
, pcs_commitment_key(std::make_shared<CommitmentKey>(op_queue->ultra_ops[0].size()))
{
// Update internal size data in the op queue that allows for extraction of e.g. previous aggregate transcript
op_queue->set_size_data();
pcs_commitment_key = std::make_shared<CommitmentKey>(op_queue->current_ultra_ops_size);
}

/**
Expand Down

0 comments on commit 0f792e3

Please sign in to comment.