diff --git a/include/nil/crypto3/zk/snark/arithmetization/plonk/constraint_system.hpp b/include/nil/crypto3/zk/snark/arithmetization/plonk/constraint_system.hpp index 05fdf5323..18a2b0308 100644 --- a/include/nil/crypto3/zk/snark/arithmetization/plonk/constraint_system.hpp +++ b/include/nil/crypto3/zk/snark/arithmetization/plonk/constraint_system.hpp @@ -59,12 +59,14 @@ namespace nil { typedef std::vector>> lookup_gates_container_type; typedef plonk_lookup_table lookup_table_type; typedef std::vector lookup_tables_type; + typedef std::vector> public_input_gate_type; protected: gates_container_type _gates; copy_constraints_container_type _copy_constraints; lookup_gates_container_type _lookup_gates; lookup_tables_type _lookup_tables; + public_input_gate_type _public_input_gate; public: typedef FieldType field_type; @@ -74,11 +76,13 @@ namespace nil { plonk_constraint_system(const gates_container_type &gates, const copy_constraints_container_type ©_constraints, const lookup_gates_container_type &lookup_gates = {}, - const lookup_tables_type &lookup_tables = {}) : + const lookup_tables_type &lookup_tables = {}, + const public_input_gate_type &public_input_gate = {}) : _gates(gates), _copy_constraints(copy_constraints), _lookup_gates(lookup_gates), - _lookup_tables(lookup_tables) + _lookup_tables(lookup_tables), + _public_input_gate(public_input_gate) { } @@ -99,6 +103,10 @@ namespace nil { // return true; // } + const public_input_gate_type &public_input_gate() const { + return _public_input_gate; + } + const gates_container_type &gates() const { return _gates; } @@ -141,10 +149,11 @@ namespace nil { } return result; } - + bool operator==(const plonk_constraint_system &other) const { return (this->_gates == other._gates) && (this->_copy_constraints == other._copy_constraints) && - (this->_lookup_gates == other._lookup_gates) && (this->_lookup_tables == other._lookup_tables); + (this->_lookup_gates == other._lookup_gates) && (this->_lookup_tables == other._lookup_tables) && + (this->_public_input_gate == other._public_input_gate); } }; } // namespace snark diff --git a/test/systems/plonk/placeholder/circuits.hpp b/test/systems/plonk/placeholder/circuits.hpp index 197954658..093b2c880 100644 --- a/test/systems/plonk/placeholder/circuits.hpp +++ b/test/systems/plonk/placeholder/circuits.hpp @@ -73,6 +73,7 @@ namespace nil { std::vector>> gates; std::vector> copy_constraints; std::vector>> lookup_gates; + std::vector> public_input_gate; std::vector> lookup_tables; @@ -365,9 +366,20 @@ namespace nil { test_circuit.gates.push_back(mul_gate); return test_circuit; - } + } + //---------------------------------------------------------------------------// + // Test circuit 3 (simplest lookup) + // i | w_0 | w_1 | w_2 | c_0 | c_1 | c_2 | s | lt | + // 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | + // 1 | | | | 1 | 0 | 1 | 0 | 1 | + // 2 | | | | 0 | 1 | 0 | 0 | 1 | + // 3 | | | | 1 | 0 | 0 | 0 | 1 | + // + // {w_0, w_1, w_2} \in {c_0, c_1, c_2} + // public_input_gate: w_0[0], w_1[0], w_2[0] + //---------------------------------------------------------------------------// constexpr static const std::size_t witness_columns_3 = 3; constexpr static const std::size_t public_columns_3 = 0; constexpr static const std::size_t constant_columns_3 = 3; @@ -465,6 +477,11 @@ namespace nil { plonk_lookup_gate> lookup_gate(0, lookup_constraints); test_circuit.lookup_gates.push_back(lookup_gate); + plonk_variable pi0(0, 0, false, plonk_variable::column_type::witness); + plonk_variable pi1(1, 0, false, plonk_variable::column_type::witness); + test_circuit.public_input_gate.push_back(pi0); + test_circuit.public_input_gate.push_back(pi1); + // Add constructor for lookup table plonk_lookup_table table1(3, 1); // 1 -- selector_id, 3 -- number of columns; table1.append_option({c0, c1, c2}); diff --git a/test/systems/plonk/placeholder/placeholder.cpp b/test/systems/plonk/placeholder/placeholder.cpp index 0bae51047..1e717932b 100644 --- a/test/systems/plonk/placeholder/placeholder.cpp +++ b/test/systems/plonk/placeholder/placeholder.cpp @@ -270,7 +270,9 @@ BOOST_FIXTURE_TEST_CASE(prover_test, test_initializer) { desc.rows_amount = placeholder_test_params::table_rows; desc.usable_rows_amount = placeholder_test_params::usable_rows; - typename policy_type::constraint_system_type constraint_system(circuit.gates, circuit.copy_constraints, circuit.lookup_gates); + typename policy_type::constraint_system_type constraint_system( + circuit.gates, circuit.copy_constraints, circuit.lookup_gates, circuit.lookup_tables, circuit.public_input_gate + ); typename policy_type::variable_assignment_type assignments = circuit.table; std::vector columns_with_copy_constraints = {0, 1, 2, 3}; @@ -358,7 +360,9 @@ BOOST_FIXTURE_TEST_CASE(prover_test, test_initializer){ desc.rows_amount = table_rows; desc.usable_rows_amount = usable_rows; - typename policy_type::constraint_system_type constraint_system(circuit.gates, circuit.copy_constraints, circuit.lookup_gates); + typename policy_type::constraint_system_type constraint_system( + circuit.gates, circuit.copy_constraints, circuit.lookup_gates, circuit.lookup_tables, circuit.public_input_gate + ); typename policy_type::variable_assignment_type assignments = circuit.table; std::vector columns_with_copy_constraints = {0, 1, 2, 3}; @@ -468,8 +472,11 @@ BOOST_AUTO_TEST_CASE(permutation_polynomials_test) { desc.rows_amount = table_rows; desc.usable_rows_amount = usable_rows; - typename policy_type::constraint_system_type constraint_system(circuit.gates, circuit.copy_constraints, - circuit.lookup_gates); + typename policy_type::constraint_system_type constraint_system( + circuit.gates, circuit.copy_constraints, + circuit.lookup_gates, circuit.lookup_tables, + circuit.public_input_gate + ); typename policy_type::variable_assignment_type assignments = circuit.table; std::vector columns_with_copy_constraints = {0, 1, 2, 3}; @@ -565,8 +572,9 @@ BOOST_AUTO_TEST_CASE(permutation_argument_test) { desc.rows_amount = table_rows; desc.usable_rows_amount = usable_rows; - typename policy_type::constraint_system_type constraint_system(circuit.gates, circuit.copy_constraints, - circuit.lookup_gates); + typename policy_type::constraint_system_type constraint_system( + circuit.gates, circuit.copy_constraints, circuit.lookup_gates, circuit.lookup_tables, circuit.public_input_gate + ); typename policy_type::variable_assignment_type assignments = circuit.table; std::vector columns_with_copy_constraints = {0, 1, 2, 3}; @@ -677,7 +685,8 @@ BOOST_FIXTURE_TEST_CASE(prover_test, test_initializer) { circuit.gates, circuit.copy_constraints, circuit.lookup_gates, - circuit.lookup_tables + circuit.lookup_tables, + circuit.public_input_gate ); typename policy_type::variable_assignment_type assignments = circuit.table; @@ -715,7 +724,8 @@ BOOST_AUTO_TEST_CASE(lookup_test) { circuit.gates, circuit.copy_constraints, circuit.lookup_gates, - circuit.lookup_tables + circuit.lookup_tables, + circuit.public_input_gate ); typename policy_type::variable_assignment_type assignments = circuit.table; @@ -881,7 +891,8 @@ BOOST_FIXTURE_TEST_CASE(prover_test, test_initializer) { circuit.gates, circuit.copy_constraints, circuit.lookup_gates, - circuit.lookup_tables + circuit.lookup_tables, + circuit.public_input_gate ); typename policy_type::variable_assignment_type assignments = circuit.table; @@ -919,7 +930,8 @@ BOOST_AUTO_TEST_CASE(lookup_test) { circuit.gates, circuit.copy_constraints, circuit.lookup_gates, - circuit.lookup_tables + circuit.lookup_tables, + circuit.public_input_gate ); typename policy_type::variable_assignment_type assignments = circuit.table; @@ -1083,7 +1095,8 @@ BOOST_FIXTURE_TEST_CASE(prover_test, test_initializer) { circuit.gates, circuit.copy_constraints, circuit.lookup_gates, - circuit.lookup_tables + circuit.lookup_tables, + circuit.public_input_gate ); typename policy_type::variable_assignment_type assignments = circuit.table; @@ -1161,7 +1174,8 @@ BOOST_FIXTURE_TEST_CASE(prover_test, test_initializer) { circuit.gates, circuit.copy_constraints, circuit.lookup_gates, - circuit.lookup_tables + circuit.lookup_tables, + circuit.public_input_gate ); typename policy_type::variable_assignment_type assignments = circuit.table;