Skip to content

Commit

Permalink
minor changes #98
Browse files Browse the repository at this point in the history
  • Loading branch information
CblPOK-git committed Jan 12, 2023
1 parent e8da88c commit 99c5987
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ namespace nil {

template<typename BlueprintFieldType, typename ArithmetizationParams, typename CurveType, std::size_t ScalarSize>
class endo_scalar<nil::crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>, CurveType, ScalarSize, 15>:
public component<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>, 15, 0, 0> {
public component<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>, 15, 0, 1> {
using component_type = component<
crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>,
15, 0, 0>;
15, 0, 1>;

using var = typename component_type::var;

using endo_params = endo_scalar_params<CurveType>;

public:
using var = typename component_type::var;
constexpr static const std::size_t rows_amount = 8;
constexpr static const std::size_t gates_amount = 2;

Expand Down Expand Up @@ -247,7 +247,7 @@ namespace nil {
const std::size_t first_selector_index) {

using F = typename BlueprintFieldType::value_type;
using var = nil::crypto3::zk::snark::plonk_variable<BlueprintFieldType>;
using var = typename plonk_endo_scalar<BlueprintFieldType, ArithmetizationParams, CurveType, ScalarSize>::var;

std::size_t selector_index_1 = first_selector_index;
std::size_t selector_index_2 = first_selector_index + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ namespace nil {
class unified_addition<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>,
CurveType, 11>:
public component<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>,
11,0,0> {
11,0,1> {

static_assert(std::is_same<typename CurveType::base_field_type, BlueprintFieldType>::value);

constexpr static const std::uint32_t WitnessAmount = 11;

using component_type = component<
crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>,
WitnessAmount,0,0>;
WitnessAmount,0,1>;

public:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ namespace nil {
15
>:
public component<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>,
15, 0, 0> {
15, 1, 1> {
using component_type = component<
crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>,
15, 0, 0>;
15, 1, 1>;

using var = typename component_type::var;

constexpr static const std::size_t witness_amount = 15;
constexpr static const std::size_t reserved_witnesses = 2; // base, accumulated_n
public:
using var = typename component_type::var;
constexpr static const std::size_t intermediate_start = 0 + reserved_witnesses;
constexpr static const std::size_t bits_per_intermediate_result =
2; // defines
Expand Down Expand Up @@ -246,8 +246,7 @@ namespace nil {
const typename plonk_exponentiation<BlueprintFieldType, ArithmetizationParams, ExponentSize, 15>::input_type instance_input,
const std::size_t first_selector_index) {

using var = nil::crypto3::zk::snark::plonk_variable<BlueprintFieldType>;

using var = typename plonk_exponentiation<BlueprintFieldType, ArithmetizationParams, ExponentSize, 15>::var;

typename BlueprintFieldType::value_type exponent_shift = 2;
exponent_shift = power(exponent_shift, component.bits_per_row);
Expand Down Expand Up @@ -297,7 +296,7 @@ namespace nil {
const typename plonk_exponentiation<BlueprintFieldType, ArithmetizationParams, ExponentSize, 15>::input_type instance_input,
const std::uint32_t start_row_index) {

using var = nil::crypto3::zk::snark::plonk_variable<BlueprintFieldType>;
using var = typename plonk_exponentiation<BlueprintFieldType, ArithmetizationParams, ExponentSize, 15>::var;

var zero(component.W(0), start_row_index, false, var::column_type::constant);
var one(component.W(0), start_row_index + 1, false, var::column_type::constant);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,13 @@ namespace nil {
// The last sum = x
template<typename BlueprintFieldType, typename ArithmetizationParams, std::size_t R>
class range_check<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>, R, 15>:
public component<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>,15,0,0> {
public component<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>,15,1,1> {

using component_type = component<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>, 15, 0, 0>;

using var = typename component_type::var;
using component_type = component<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>, 15, 1, 1>;

constexpr static const std::size_t witness_amount = 15;
public:
using var = typename component_type::var;
constexpr static const std::size_t chunk_size = 2;
constexpr static const std::size_t reserved_columns = 1;
constexpr static const std::size_t chunks_per_row = witness_amount - reserved_columns;
Expand Down Expand Up @@ -205,9 +204,9 @@ namespace nil {
const typename plonk_range_check<BlueprintFieldType, ArithmetizationParams, R>::input_type &instance_input,
const std::size_t first_selector_index) {

using var = nil::crypto3::zk::snark::plonk_variable<BlueprintFieldType>;
using var = typename plonk_range_check<BlueprintFieldType, ArithmetizationParams, R>::var;

typename BlueprintFieldType::value_type base_two = 2; //TODO
typename BlueprintFieldType::value_type base_two = 2;

std::vector<crypto3::zk::snark::plonk_constraint<BlueprintFieldType>> constraints;

Expand Down Expand Up @@ -248,7 +247,7 @@ namespace nil {
const typename plonk_range_check<BlueprintFieldType, ArithmetizationParams, R>::input_type &instance_input,
const std::uint32_t start_row_index) {

using var = nil::crypto3::zk::snark::plonk_variable<BlueprintFieldType>;
using var = typename plonk_range_check<BlueprintFieldType, ArithmetizationParams, R>::var;

var zero(0, start_row_index, false, var::column_type::constant);
bp.add_copy_constraint({zero, var(component.W(0), start_row_index, false)});
Expand All @@ -267,10 +266,10 @@ namespace nil {
const typename plonk_range_check<BlueprintFieldType, ArithmetizationParams, R>::input_type &instance_input,
const std::uint32_t start_row_index) {

using var = nil::crypto3::zk::snark::plonk_variable<BlueprintFieldType>;
using var = typename plonk_range_check<BlueprintFieldType, ArithmetizationParams, R>::var;

std::size_t row = start_row_index;
assignment.constant(component.W(0), row) = 0;
assignment.constant(component.C(0), row) = 0;
}

} // namespace components
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ namespace nil {
template<typename BlueprintFieldType, typename ArithmetizationParams>
class from_limbs<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>, 3>:
public component<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>,
3, 0, 0> {
3, 0, 1> {

using component_type = component<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>, 3, 0, 0>;
using component_type = component<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>, 3, 0, 1>;

public:

Expand Down Expand Up @@ -159,7 +159,7 @@ namespace nil {
const typename plonk_from_limbs<BlueprintFieldType, ArithmetizationParams>::input_type &instance_input,
const std::size_t first_selector_index) {

using var = nil::crypto3::zk::snark::plonk_variable<BlueprintFieldType>;
using var = typename plonk_from_limbs<BlueprintFieldType, ArithmetizationParams>::var;

typename BlueprintFieldType::value_type scalar = 2;
auto constraint_1 = bp.add_constraint(var(component.W(0), 0) + var(component.W(1), 0) * scalar.pow(64) - var(component.W(2), 0));
Expand Down
2 changes: 1 addition & 1 deletion test/algebra/curves/plonk/endo_scalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void test_endo_scalar(std::vector<typename CurveType::scalar_field_type::value_t
assert(expected_res == var_value(assignment, real_res.output));
};

component_type component_instance({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14},{},{});
component_type component_instance({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14},{},{0});

nil::crypto3::test_component<component_type, BlueprintFieldType, ArithmetizationParams, hash_type, Lambda> (component_instance, public_input, result_check, instance_input);
}
Expand Down
2 changes: 1 addition & 1 deletion test/algebra/curves/plonk/unified_addition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void test_unified_addition(std::vector<typename CurveType::base_field_type::valu
assert(expected_res.Y == var_value(assignment, real_res.Y));
};

component_type component_instance({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10},{},{});
component_type component_instance({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10},{},{0});

crypto3::test_component<component_type, BlueprintFieldType, ArithmetizationParams, hash_type, Lambda>(
component_instance, public_input, result_check, instance_input);
Expand Down
6 changes: 3 additions & 3 deletions test/algebra/fields/plonk/exponentiation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void test_exponentiation(std::vector<typename CurveType::base_field_type::value_
assert(expected_res == var_value(assignment, real_res.output));
};

component_type component_instance({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14},{},{});
component_type component_instance({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14},{0},{0});


nil::crypto3::test_component<component_type, BlueprintFieldType, ArithmetizationParams, hash_type, Lambda> (component_instance, public_input, result_check, instance_input);
Expand All @@ -99,7 +99,7 @@ BOOST_AUTO_TEST_CASE(blueprint_plonk_exponentiation) {
test_exponentiation<curve_type, 11>(public_input, expected_result);

auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - start);
std::cout << "base_scalar_mul: " << duration.count() << "ms" << std::endl;
std::cout << "exponentiation_test: " << duration.count() << "ms" << std::endl;
}

BOOST_AUTO_TEST_CASE(blueprint_plonk_exponentiation_2) {
Expand All @@ -118,7 +118,7 @@ BOOST_AUTO_TEST_CASE(blueprint_plonk_exponentiation_2) {
test_exponentiation<curve_type, 255>(public_input, expected_result);

auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - start);
std::cout << "base_scalar_mul: " << duration.count() << "ms" << std::endl;
std::cout << "exponentiation_test: " << duration.count() << "ms" << std::endl;
}

BOOST_AUTO_TEST_SUITE_END()
2 changes: 1 addition & 1 deletion test/algebra/fields/plonk/range_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void test_range_check(std::vector<typename BlueprintFieldType::value_type> publi
typename component_type::result_type &real_res) {
};

component_type component_instance({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14},{},{});
component_type component_instance({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14},{0},{0});

nil::crypto3::test_component<component_type, BlueprintFieldType, ArithmetizationParams, hash_type, Lambda> (component_instance, public_input, result_check, instance_input);

Expand Down
2 changes: 1 addition & 1 deletion test/verifiers/kimchi/sponge/oracles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void test_from_limbs(std::vector<typename BlueprintFieldType::value_type> public
assert(expected_res == var_value(assignment, real_res.result));
};

component_type component_instance({0, 1, 2}, {}, {});
component_type component_instance({0, 1, 2}, {}, {0});


nil::crypto3::test_component<component_type, BlueprintFieldType, ArithmetizationParams, hash_type, Lambda> (component_instance, public_input, result_check, instance_input);
Expand Down

0 comments on commit 99c5987

Please sign in to comment.