Skip to content

Commit

Permalink
Public input sizes, table description in common data structure #302
Browse files Browse the repository at this point in the history
  • Loading branch information
ETatuzova committed Mar 6, 2024
1 parent 8b5632c commit ee9da86
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,15 @@ namespace nil {
typedef math::term<variable_type> term_type;
typedef math::binary_arithmetic_operation<variable_type> binary_operation_type;
typedef math::pow_operation<variable_type> pow_operation_type;
typedef std::vector<std::size_t> public_input_sizes_type;

protected:
gates_container_type _gates;
copy_constraints_container_type _copy_constraints;
lookup_gates_container_type _lookup_gates;
lookup_tables_type _lookup_tables;
// If empty, then check full column
public_input_sizes_type _public_input_sizes;
public:
typedef FieldType field_type;

Expand All @@ -83,15 +86,30 @@ 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_sizes_type &public_input_sizes = {}
) :
_gates(gates),
_copy_constraints(copy_constraints),
_lookup_gates(lookup_gates),
_lookup_tables(lookup_tables)
_lookup_tables(lookup_tables),
_public_input_sizes(public_input_sizes)
{
}

std::size_t public_input_total_size() const {
return std::accumulate(_public_input_sizes.begin(), _public_input_sizes.end(), 0);
}

std::size_t public_input_size(std::size_t i) const {
assert(i < _public_input_sizes.size());
return _public_input_sizes[i];
}

std::size_t public_input_sizes_num() const {
return _public_input_sizes.size();
}

std::size_t num_gates() const {
return _gates.size();
}
Expand Down Expand Up @@ -217,7 +235,8 @@ namespace nil {

bool operator==(const plonk_constraint_system<FieldType> &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_sizes == other._public_input_sizes);
}
};
} // namespace snark
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,19 @@ namespace nil {
using commitment_scheme_type = typename ParamsType::commitment_scheme_type;
using commitments_type = public_commitments_type;
using verification_key_type = verification_key;
using transcript_hash_type = typename ParamsType::transcript_hash_type;
using table_description_type = plonk_table_description<FieldType>;

// marshalled
public_commitments_type commitments;
columns_rotations_type columns_rotations;

std::size_t rows_amount;
std::size_t usable_rows_amount;
std::size_t witness_columns;
std::size_t public_input_columns;
std::size_t constant_columns;
std::size_t selector_columns;

// not marshalled. They can be derived from other fields.
polynomial_dfs_type lagrange_0;
Expand All @@ -134,14 +140,20 @@ namespace nil {
std::vector<std::set<int>> col_rotations,
std::size_t rows,
std::size_t usable_rows,
std::size_t witness_columns,
std::size_t public_input_columns,
std::size_t constant_columns,
std::size_t selector_columns,
std::uint32_t max_gates_degree,
verification_key vk
): commitments(commts),
columns_rotations(col_rotations), rows_amount(rows), usable_rows_amount(usable_rows),
lagrange_0(D->size() - 1, D->size(), FieldType::value_type::zero()),
Z(std::vector<typename FieldType::value_type>(rows + 1, FieldType::value_type::zero())),
basic_domain(D),
max_gates_degree(max_gates_degree), vk(vk)
max_gates_degree(max_gates_degree), vk(vk),
witness_columns(witness_columns), public_input_columns(public_input_columns),
constant_columns(constant_columns), selector_columns(selector_columns)
{
// Z is polynomial -1, 0,..., 0, 1
Z[0] = -FieldType::value_type::one();
Expand All @@ -157,13 +169,19 @@ namespace nil {
std::vector<std::set<int>> col_rotations,
std::size_t rows,
std::size_t usable_rows,
std::size_t witness_columns,
std::size_t public_input_columns,
std::size_t constant_columns,
std::size_t selector_columns,
std::uint32_t max_gates_degree,
verification_key vk
): commitments(commts),
columns_rotations(col_rotations), rows_amount(rows), usable_rows_amount(usable_rows),
lagrange_0(rows - 1, rows, FieldType::value_type::zero()),
Z(std::vector<typename FieldType::value_type>(rows + 1, FieldType::value_type::zero())),
max_gates_degree(max_gates_degree), vk(vk)
max_gates_degree(max_gates_degree), vk(vk),
witness_columns(witness_columns), public_input_columns(public_input_columns),
constant_columns(constant_columns), selector_columns(selector_columns)
{
// Z is polynomial -1, 0,..., 0, 1
Z[0] = -FieldType::value_type::one();
Expand All @@ -181,6 +199,10 @@ namespace nil {
return rows_amount == rhs.rows_amount &&
usable_rows_amount == rhs.usable_rows_amount &&
columns_rotations == rhs.columns_rotations &&
witness_columns == rhs.witness_columns &&
public_input_columns == rhs.public_input_columns &&
constant_columns == rhs.constant_columns &&
selector_columns == rhs.selector_columns &&
commitments == rhs.commitments &&
basic_domain->size() == rhs.basic_domain->size() &&
lagrange_0 == rhs.lagrange_0 &&
Expand Down Expand Up @@ -508,7 +530,13 @@ namespace nil {
typename preprocessed_data_type::verification_key vk = {constraint_system_with_params_hash, public_commitments.fixed_values};
typename preprocessed_data_type::common_data_type common_data (
std::move(public_commitments), std::move(c_rotations),
N_rows, table_description.usable_rows_amount, max_gates_degree, vk
table_description.rows_amount,
table_description.usable_rows_amount,
table_description.witness_columns,
table_description.public_input_columns,
table_description.constant_columns,
table_description.selector_columns,
max_gates_degree, vk
);

transcript_type transcript(std::vector<std::uint8_t>({}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,18 @@ namespace nil {
auto numerator = challenge.pow(preprocessed_public_data.common_data.rows_amount) - FieldType::value_type::one();
numerator /= typename FieldType::value_type(preprocessed_public_data.common_data.rows_amount);

// If public input sizes are set, all of them should be set.
if(constraint_system.public_input_sizes_num() != 0 && constraint_system.public_input_sizes_num() != table_description.public_input_columns){
return false;
}

for( std::size_t i = 0; i < public_input.size(); ++i ){
typename FieldType::value_type value = FieldType::value_type::zero();
std::size_t max_size = public_input[i].size();
if (constraint_system.public_input_sizes_num() != 0)
max_size = std::min(max_size, constraint_system.public_input_size(i));
auto omega_pow = FieldType::value_type::one();
for( std::size_t j = 0; j < public_input[i].size(); ++j ){
for( std::size_t j = 0; j < max_size; ++j ){
value += (public_input[i][j] * omega_pow) / (challenge - omega_pow);
omega_pow = omega_pow * omega;
}
Expand Down
5 changes: 3 additions & 2 deletions test/systems/plonk/placeholder/circuits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ 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_lookup_table<FieldType>> lookup_tables;
std::vector<std::size_t> public_input_sizes;

circuit_description() : table_rows(0){
}
Expand Down Expand Up @@ -251,11 +251,12 @@ namespace nil {
typedef placeholder_circuit_params<FieldType> circuit_params;

circuit_description<FieldType, circuit_params, usable_rows, permutation> test_circuit;
test_circuit.public_input_sizes = {3};

std::vector<std::vector<typename FieldType::value_type>> table(table_columns);

std::vector<typename FieldType::value_type> q_add(test_circuit.usable_rows);
std::vector<typename FieldType::value_type> q_mul(test_circuit.usable_rows);
std::vector<typename FieldType::value_type> q_add(test_circuit.usable_rows);
for (std::size_t j = 0; j < table_columns; j++) {
table[j].resize(test_circuit.usable_rows);
}
Expand Down
6 changes: 5 additions & 1 deletion test/systems/plonk/placeholder/placeholder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,11 @@ BOOST_FIXTURE_TEST_CASE(prover_test, test_initializer){
desc.usable_rows_amount = circuit.usable_rows;
std::size_t table_rows_log = std::log2(desc.rows_amount);

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_sizes
);
typename policy_type::variable_assignment_type assignments = circuit.table;

std::vector<std::size_t> columns_with_copy_constraints = {0, 1, 2, 3};
Expand Down

0 comments on commit ee9da86

Please sign in to comment.