Skip to content

Commit

Permalink
Public input gate added ot constraint system #180
Browse files Browse the repository at this point in the history
  • Loading branch information
ETatuzova committed Oct 3, 2023
1 parent 5786b7b commit a8eaa51
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ namespace nil {
typedef std::vector<plonk_lookup_gate<FieldType, plonk_lookup_constraint<FieldType>>> lookup_gates_container_type;
typedef plonk_lookup_table<FieldType> lookup_table_type;
typedef std::vector<lookup_table_type> lookup_tables_type;
typedef std::vector<plonk_variable<typename FieldType::value_type>> 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;

Expand All @@ -74,11 +76,13 @@ namespace nil {
plonk_constraint_system(const gates_container_type &gates,
const copy_constraints_container_type &copy_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)
{
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -141,10 +149,11 @@ namespace nil {
}
return result;
}

bool operator==(const plonk_constraint_system<FieldType, ArithmetizationParams> &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
Expand Down
19 changes: 18 additions & 1 deletion test/systems/plonk/placeholder/circuits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ namespace nil {
std::vector<plonk_gate<FieldType, plonk_constraint<FieldType>>> gates;
std::vector<plonk_copy_constraint<FieldType>> copy_constraints;
std::vector<plonk_lookup_gate<FieldType, plonk_lookup_constraint<FieldType>>> lookup_gates;
std::vector<plonk_variable<typename FieldType::value_type>> public_input_gate;

std::vector<plonk_lookup_table<FieldType>> lookup_tables;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -465,6 +477,11 @@ namespace nil {
plonk_lookup_gate<FieldType, plonk_lookup_constraint<FieldType>> lookup_gate(0, lookup_constraints);
test_circuit.lookup_gates.push_back(lookup_gate);

plonk_variable<assignment_type> pi0(0, 0, false, plonk_variable<assignment_type>::column_type::witness);
plonk_variable<assignment_type> pi1(1, 0, false, plonk_variable<assignment_type>::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<FieldType> table1(3, 1); // 1 -- selector_id, 3 -- number of columns;
table1.append_option({c0, c1, c2});
Expand Down
38 changes: 26 additions & 12 deletions test/systems/plonk/placeholder/placeholder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::size_t> columns_with_copy_constraints = {0, 1, 2, 3};
Expand Down Expand Up @@ -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<std::size_t> columns_with_copy_constraints = {0, 1, 2, 3};
Expand Down Expand Up @@ -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<std::size_t> columns_with_copy_constraints = {0, 1, 2, 3};
Expand Down Expand Up @@ -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<std::size_t> columns_with_copy_constraints = {0, 1, 2, 3};
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit a8eaa51

Please sign in to comment.