Skip to content

Commit

Permalink
modify the mocking function to update both the ultra_ops and raw_ops
Browse files Browse the repository at this point in the history
  • Loading branch information
maramihali committed Mar 8, 2024
1 parent 3779893 commit 28c38ea
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,11 @@ TEST(GoblinUltraCircuitBuilder, GoblinEccOpQueueUltraOps)
for (size_t i = 1; i < 4; ++i) {
for (size_t j = 0; j < builder.num_ecc_op_gates; ++j) {
auto op_wire_val = builder.variables[builder.blocks.ecc_op.wires[i][j]];
// NOTE: each ultra_ops vector at index 0 has mock operations mimicking interactions with a first circuit so
// NOTE: each ultra_ops vector has mock operations mimicking interactions with a first circuit so
// the merge protocol works as expected because zero-commitment issues, these will be removed after
// https://github.com/AztecProtocol/barretenberg/issues/871 is resolved.
auto ultra_op_val = ultra_ops[i][j + 1];
// https://github.com/AztecProtocol/barretenberg/issues/871 is resolved and hence we won't have an
// ops_offset in the op_queue any longer.
auto ultra_op_val = ultra_ops[i][j + builder.op_queue->ops_offset];
ASSERT_EQ(op_wire_val, ultra_op_val);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "barretenberg/commitment_schemes/commitment_key.hpp"
#include "barretenberg/ecc/curves/bn254/bn254.hpp"
#include "barretenberg/proof_system/circuit_builder/eccvm/eccvm_builder_types.hpp"

Expand Down Expand Up @@ -46,6 +47,8 @@ class ECCOpQueue {

std::array<Point, 4> ultra_ops_commitments;

size_t ops_offset;

/**
* @brief Construct a new ECCOpQueue object, populating it with some mock data that mimics interactions with a
* previous circuit in order to avoid zero commitments in the merge protocol.
Expand Down Expand Up @@ -305,15 +308,58 @@ class ECCOpQueue {
*/
void populate_with_mock_initital_data()
{
// Add a single row of data to the op queue and commit to each column as [1] * FF(data)
std::array<Point, 4> mock_op_queue_commitments;
for (size_t idx = 0; idx < 4; idx++) {
auto mock_data = Fr::random_element();
this->ultra_ops[idx].emplace_back(mock_data);
mock_op_queue_commitments[idx] = Point::one() * mock_data;
using CommitmentKey = bb::CommitmentKey<Curve>;

auto point = Point::one() * Fr::random_element();
auto scalar = Fr::random_element();

const auto decompose_point = [&](const Point point) {
// Decompose point coordinates (Fq) into hi-lo relaxed chunks (Fr) of 68 bits
const size_t CHUNK_SIZE = 2 * 68;
auto x_256 = uint256_t(point.x);
auto y_256 = uint256_t(point.y);
auto x_lo = Fr(x_256.slice(0, CHUNK_SIZE));
auto x_hi = Fr(x_256.slice(CHUNK_SIZE, CHUNK_SIZE * 2));
auto y_lo = Fr(y_256.slice(0, CHUNK_SIZE));
auto y_hi = Fr(y_256.slice(CHUNK_SIZE, CHUNK_SIZE * 2));

return std::tuple(x_lo, x_hi, y_lo, y_hi);
};

// Mock the mul_accum as if it was encountered in a circuit and update ultra_ops and raw_ops
{
mul_accumulate(point, scalar);
auto [x_lo, x_hi, y_lo, y_hi] = decompose_point(point);
// Split scalar into 128 bit endomorphism scalars
Fr z_1 = 0;
Fr z_2 = 0;
auto converted = scalar.from_montgomery_form();
Fr::split_into_endomorphism_scalars(converted, z_1, z_2);
z_1 = z_1.to_montgomery_form();
z_2 = z_2.to_montgomery_form();
populate_ultra_ops({ Fr(MUL_ACCUM), x_lo, x_hi, y_lo, y_hi, z_1, z_2 });
}

// Mock the eq
{
auto result = eq();
auto [x_lo, x_hi, y_lo, y_hi] = decompose_point(result);

populate_ultra_ops({ Fr(EQUALITY), x_lo, x_hi, y_lo, y_hi, 0, 0 });
}
// Set some internal data based on the size of the op queue data
this->set_size_data();
ops_offset = current_ultra_ops_size;

std::array<Point, 4> mock_op_queue_commitments;
srs::init_crs_factory("../srs_db/ignition");
// Manually compute the op queue transcript commitments (which would normally be done by the merge prover)
auto commitment_key = CommitmentKey(get_current_size());
size_t idx = 0;
for (auto& entry : get_aggregate_transcript()) {
mock_op_queue_commitments[idx++] = commitment_key.commit(entry);
}

// Add the commitments to the op queue data for use by the next circuit
this->set_commitment_data(mock_op_queue_commitments);
}
Expand Down

0 comments on commit 28c38ea

Please sign in to comment.