Skip to content

Commit

Permalink
Added correctness tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rumata888 committed Oct 16, 2024
1 parent f157b5b commit a9fb44d
Showing 1 changed file with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "barretenberg/common/thread.hpp"
#include "barretenberg/honk/proof_system/permutation_library.hpp"
#include "barretenberg/plonk_honk_shared/library/grand_product_library.hpp"
#include "barretenberg/translator_vm/translator_flavor.hpp"

#include <gtest/gtest.h>
#include <unordered_set>
using namespace bb;

/**
Expand All @@ -24,6 +26,9 @@ template <typename Flavor, typename Relation> void check_relation(auto circuit_s
// Evaluate each constraint in the relation and check that each is satisfied
Relation::accumulate(result, polynomials.get_row(i), params, 1);
for (auto& element : result) {
if (element != 0) {
info(i);
}
ASSERT_EQ(element, 0);
}
}
Expand Down Expand Up @@ -311,8 +316,9 @@ TEST_F(TranslatorRelationCorrectnessTests, TranslatorExtraRelationsCorrectness)
}

// Fill in lagrange even polynomial
for (size_t i = 2; i < mini_circuit_size; i += 2) {
prover_polynomials.lagrange_even_in_minicircuit.at(i) = 1;
for (size_t i = 1; i < mini_circuit_size - 1; i += 2) {
prover_polynomials.lagrange_odd_in_minicircuit.at(i) = 1;
prover_polynomials.lagrange_even_in_minicircuit.at(i + 1) = 1;
}
constexpr size_t NUMBER_OF_POSSIBLE_OPCODES = 6;
constexpr std::array<uint64_t, NUMBER_OF_POSSIBLE_OPCODES> possible_opcode_values = { 0, 1, 2, 3, 4, 8 };
Expand All @@ -323,6 +329,23 @@ TEST_F(TranslatorRelationCorrectnessTests, TranslatorExtraRelationsCorrectness)
possible_opcode_values[static_cast<size_t>(engine.get_random_uint8() % NUMBER_OF_POSSIBLE_OPCODES)];
}

std::unordered_set<size_t> range_constraint_polynomial_ids;
for (auto& concatenation_group : prover_polynomial_ids.get_groups_to_be_concatenated()) {
for (auto& id : concatenation_group) {
range_constraint_polynomial_ids.insert(id);
}
}

// Assign random values to the mini-circuit part of the range constraint polynomials

for (const auto& range_constraint_polynomial_id : range_constraint_polynomial_ids) {
parallel_for_range(mini_circuit_size - 2, [&](size_t start, size_t end) {
// We want to iterate from 1 to mini_circuit_size - 2 (inclusive)
for (size_t i = start + 1; i < end + 1; i++) {
polynomial_container[range_constraint_polynomial_id].at(i) = fr::random_element();
}
});
}
// Initialize used lagrange polynomials
prover_polynomials.lagrange_second.at(1) = 1;
prover_polynomials.lagrange_second_to_last_in_minicircuit.at(mini_circuit_size - 2) = 1;
Expand Down Expand Up @@ -352,6 +375,9 @@ TEST_F(TranslatorRelationCorrectnessTests, TranslatorExtraRelationsCorrectness)

// Check that Accumulator Transfer relation is satisfied across each row of the prover polynomials
check_relation<Flavor, std::tuple_element_t<3, Relations>>(circuit_size, prover_polynomials, params);

// Check that Zero Constraint relation is satisfied across each row of the prover polynomials
check_relation<Flavor, std::tuple_element_t<6, Relations>>(circuit_size, prover_polynomials, params);
}
/**
* @brief Test the correctness of TranslatorFlavor's Decomposition Relation
Expand Down

0 comments on commit a9fb44d

Please sign in to comment.