-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fcc9aa7
commit 3d95476
Showing
3 changed files
with
100 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...cpp/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_goblin.test.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#include "barretenberg/common/test.hpp" | ||
#include <type_traits> | ||
|
||
#include "../biggroup/biggroup.hpp" | ||
#include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders.hpp" | ||
|
||
#include "barretenberg/stdlib/primitives/curves/bn254.hpp" | ||
|
||
#include "barretenberg/numeric/random/engine.hpp" | ||
#include <memory> | ||
|
||
namespace test_stdlib_biggroup_goblin { | ||
namespace { | ||
auto& engine = numeric::random::get_debug_engine(); | ||
} | ||
|
||
using namespace proof_system::plonk; | ||
|
||
template <typename Curve> class stdlib_biggroup_goblin : public testing::Test { | ||
using element_ct = typename Curve::Element; | ||
using scalar_ct = typename Curve::ScalarField; | ||
|
||
using fq = typename Curve::BaseFieldNative; | ||
using fr = typename Curve::ScalarFieldNative; | ||
using g1 = typename Curve::GroupNative; | ||
using affine_element = typename g1::affine_element; | ||
using element = typename g1::element; | ||
|
||
using Builder = typename Curve::Builder; | ||
|
||
static constexpr auto EXPECT_CIRCUIT_CORRECTNESS = [](Builder& builder, bool expected_result = true) { | ||
info("builder gates = ", builder.get_num_gates()); | ||
EXPECT_EQ(builder.check_circuit(), expected_result); | ||
}; | ||
|
||
public: | ||
/** | ||
* @brief Test goblin-style batch mul | ||
* @details Check that 1) Goblin-style batch mul returns correct value, and 2) resulting circuit is correct | ||
* | ||
*/ | ||
static void test_goblin_style_batch_mul() | ||
{ | ||
const bool goblin_flag = true; // used to indicate goblin-style in batch_mul | ||
const size_t num_points = 5; | ||
Builder builder; | ||
|
||
std::vector<affine_element> points; | ||
std::vector<fr> scalars; | ||
for (size_t i = 0; i < num_points; ++i) { | ||
points.push_back(affine_element(element::random_element())); | ||
scalars.push_back(fr::random_element()); | ||
} | ||
|
||
std::vector<element_ct> circuit_points; | ||
std::vector<scalar_ct> circuit_scalars; | ||
for (size_t i = 0; i < num_points; ++i) { | ||
circuit_points.push_back(element_ct::from_witness(&builder, points[i])); | ||
circuit_scalars.push_back(scalar_ct::from_witness(&builder, scalars[i])); | ||
} | ||
|
||
element_ct result_point = element_ct::template batch_mul<goblin_flag>(circuit_points, circuit_scalars); | ||
|
||
element expected_point = g1::one; | ||
expected_point.self_set_infinity(); | ||
for (size_t i = 0; i < num_points; ++i) { | ||
expected_point += (element(points[i]) * scalars[i]); | ||
} | ||
|
||
expected_point = expected_point.normalize(); | ||
fq result_x(result_point.x.get_value().lo); | ||
fq result_y(result_point.y.get_value().lo); | ||
|
||
EXPECT_EQ(result_x, expected_point.x); | ||
EXPECT_EQ(result_y, expected_point.y); | ||
|
||
EXPECT_CIRCUIT_CORRECTNESS(builder); | ||
} | ||
}; | ||
|
||
using TestTypes = testing::Types<stdlib::bn254<proof_system::UltraCircuitBuilder>>; | ||
|
||
TYPED_TEST_SUITE(stdlib_biggroup_goblin, TestTypes); | ||
|
||
HEAVY_TYPED_TEST(stdlib_biggroup_goblin, batch_mul) | ||
{ | ||
TestFixture::test_goblin_style_batch_mul(); | ||
} | ||
} // namespace test_stdlib_biggroup_goblin |