Skip to content

Commit

Permalink
addition component #16
Browse files Browse the repository at this point in the history
  • Loading branch information
Luannet committed May 2, 2022
1 parent 443b23f commit a8228da
Show file tree
Hide file tree
Showing 7 changed files with 779 additions and 133 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,14 @@ namespace nil {
const params_type &params,
const std::size_t &component_start_row) {
std::size_t row = component_start_row;
bp.add_copy_constraint({{W0, static_cast<int>(row), false},
/*bp.add_copy_constraint({{W0, static_cast<int>(row), false},
params.input[0]});
bp.add_copy_constraint({{W1, static_cast<int>(row), false},
params.input[1]});
bp.add_copy_constraint({{W2, static_cast<int>(row), false},
params.input[2]});
bp.add_copy_constraint({{W3, static_cast<int>(row), false},
params.input[0]});
params.input[0]});*/
}


Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ endmacro()

set(NON_NATIVE_TESTS_FILES
"non_native/plonk/field_mul"
"non_native/plonk/field_add"
"non_native/plonk/non_native_range"
)

Expand Down
90 changes: 90 additions & 0 deletions test/non_native/plonk/field_add.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2021-2022 Mikhail Komarov <nemo@nil.foundation>
// Copyright (c) 2021-2022 Nikita Kaskov <nbering@nil.foundation>
// Copyright (c) 2022 Alisa Cherniaeva <a.cherniaeva@nil.foundation>
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//---------------------------------------------------------------------------//

#define BOOST_TEST_MODULE blueprint_plonk_non_native_field_test

#include <boost/test/unit_test.hpp>

#include <nil/crypto3/algebra/curves/pallas.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/pallas.hpp>

#include <nil/crypto3/algebra/curves/curve25519.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/ed25519.hpp>

#include <nil/crypto3/hash/algorithm/hash.hpp>
#include <nil/crypto3/hash/sha2.hpp>
#include <nil/crypto3/hash/keccak.hpp>

#include <nil/crypto3/zk/snark/arithmetization/plonk/params.hpp>

#include <nil/crypto3/zk/blueprint/plonk.hpp>
#include <nil/crypto3/zk/assignment/plonk.hpp>
#include <nil/crypto3/zk/components/non_native/algebra/fields/plonk/addition.hpp>

#include "../../test_plonk_component.hpp"

using namespace nil::crypto3;

BOOST_AUTO_TEST_SUITE(blueprint_plonk_test_suite)

BOOST_AUTO_TEST_CASE(blueprint_non_native_addition) {
auto start = std::chrono::high_resolution_clock::now();

using curve_type = algebra::curves::pallas;
using ed25519_type = algebra::curves::curve25519;
using BlueprintFieldType = typename curve_type::base_field_type;
constexpr std::size_t WitnessColumns = 9;
constexpr std::size_t PublicInputColumns = 1;
constexpr std::size_t ConstantColumns = 0;
constexpr std::size_t SelectorColumns = 2;
using ArithmetizationParams =
zk::snark::plonk_arithmetization_params<WitnessColumns, PublicInputColumns, ConstantColumns, SelectorColumns>;
using ArithmetizationType = zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>;
using hash_type = nil::crypto3::hashes::keccak_1600<256>;
constexpr std::size_t Lambda = 1;

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

using component_type = zk::components::non_native_field_element_addition<ArithmetizationType, curve_type, ed25519_type, 0, 1, 2, 3,
4, 5, 6, 7, 8>;

std::array<var, 4> input_var_a = {var(0, 0, false, var::column_type::public_input), var(0, 1, false, var::column_type::public_input),
var(0, 2, false, var::column_type::public_input), var(0, 3, false, var::column_type::public_input)};
std::array<var, 4> input_var_b = {var(0, 4, false, var::column_type::public_input), var(0, 5, false, var::column_type::public_input),
var(0, 6, false, var::column_type::public_input), var(0, 7, false, var::column_type::public_input)};

typename component_type::params_type params = {input_var_a, input_var_b};

std::vector<typename BlueprintFieldType::value_type> public_input = {45524, 52353, 68769, 5431, 3724, 342453, 5425, 54222};
//std::vector<typename BlueprintFieldType::value_type> public_input = {1, 0, 0, 0, 1, 0, 0, 0};

test_component<component_type, BlueprintFieldType, ArithmetizationParams, hash_type, Lambda>(params, public_input);

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

BOOST_AUTO_TEST_SUITE_END()
1 change: 1 addition & 0 deletions test/non_native/plonk/field_mul.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2021-2022 Mikhail Komarov <nemo@nil.foundation>
// Copyright (c) 2021-2022 Nikita Kaskov <nbering@nil.foundation>
// Copyright (c) 2022 Alisa Cherniaeva <a.cherniaeva@nil.foundation>
//
// MIT License
//
Expand Down

0 comments on commit a8228da

Please sign in to comment.