Skip to content

Commit

Permalink
Merge pull request #106 from NilFoundation/105-runtime-selectors-amount
Browse files Browse the repository at this point in the history
Runtime selectors amount processing
  • Loading branch information
nkaskov authored Dec 4, 2022
2 parents d55a528 + de22d44 commit f9b421a
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 218 deletions.
50 changes: 18 additions & 32 deletions include/nil/crypto3/zk/snark/arithmetization/plonk/assignment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace nil {
namespace blueprint {
template<typename ArithmetizationType, std::size_t... BlueprintParams>
class assignment;
} // namespace blueprint
} // namespace blueprint
namespace crypto3 {
namespace zk {
namespace snark {
Expand All @@ -55,13 +55,10 @@ namespace nil {
using witnesses_container_type = std::array<ColumnType, ArithmetizationParams::witness_columns>;

protected:

witnesses_container_type _witnesses;

public:
plonk_private_table(
witnesses_container_type witness_columns = {}) :
_witnesses(witness_columns) {
plonk_private_table(witnesses_container_type witness_columns = {}) : _witnesses(witness_columns) {
}

std::uint32_t witnesses_amount() const {
Expand All @@ -86,7 +83,6 @@ namespace nil {
return _witnesses[index];
index -= ArithmetizationParams::witness_columns;
return {};

}

constexpr std::uint32_t size() const {
Expand All @@ -96,31 +92,28 @@ namespace nil {
friend std::uint32_t basic_padding<FieldType, ArithmetizationParams, ColumnType>(
plonk_table<FieldType, ArithmetizationParams, ColumnType> &table);

friend struct nil::blueprint::assignment<plonk_constraint_system<FieldType,
ArithmetizationParams>>;
friend struct nil::blueprint::assignment<plonk_constraint_system<FieldType, ArithmetizationParams>>;
};

template<typename FieldType, typename ArithmetizationParams, typename ColumnType>
struct plonk_public_table {

using public_input_container_type = std::array<ColumnType, ArithmetizationParams::public_input_columns>;
using public_input_container_type =
std::array<ColumnType, ArithmetizationParams::public_input_columns>;
using constant_container_type = std::array<ColumnType, ArithmetizationParams::constant_columns>;
using selector_container_type = std::array<ColumnType, ArithmetizationParams::selector_columns>;
using selector_container_type = std::vector<ColumnType>;

protected:

public_input_container_type _public_inputs;
constant_container_type _constants;
selector_container_type _selectors;

public:
plonk_public_table(
public_input_container_type public_input_columns = {},
constant_container_type constant_columns = {},
selector_container_type selector_columns = {}) :
plonk_public_table(public_input_container_type public_input_columns = {},
constant_container_type constant_columns = {},
selector_container_type selector_columns = {}) :
_public_inputs(public_input_columns),
_constants(constant_columns),
_selectors(selector_columns) {
_constants(constant_columns), _selectors(selector_columns) {
}

std::uint32_t public_inputs_amount() const {
Expand Down Expand Up @@ -189,16 +182,13 @@ namespace nil {
}

constexpr std::uint32_t size() const {
return public_inputs_amount() +
constants_amount() +
selectors_amount();
return public_inputs_amount() + constants_amount() + selectors_amount();
}

friend std::uint32_t basic_padding<FieldType, ArithmetizationParams, ColumnType>(
plonk_table<FieldType, ArithmetizationParams, ColumnType> &table);

friend struct nil::blueprint::assignment<plonk_constraint_system<FieldType,
ArithmetizationParams>>;
friend struct nil::blueprint::assignment<plonk_constraint_system<FieldType, ArithmetizationParams>>;
};

template<typename FieldType, typename ArithmetizationParams, typename ColumnType>
Expand Down Expand Up @@ -290,31 +280,27 @@ namespace nil {
std::uint32_t rows_amount() const {
std::uint32_t rows_amount = 0;

for (std::uint32_t w_index = 0; w_index <
witnesses_amount(); w_index++) {
for (std::uint32_t w_index = 0; w_index < witnesses_amount(); w_index++) {
rows_amount = std::max(rows_amount, witness_column_size(w_index));
}

for (std::uint32_t pi_index = 0; pi_index <
public_inputs_amount(); pi_index++) {
for (std::uint32_t pi_index = 0; pi_index < public_inputs_amount(); pi_index++) {
rows_amount = std::max(rows_amount, public_input_column_size(pi_index));
}

for (std::uint32_t c_index = 0; c_index <
constants_amount(); c_index++) {
for (std::uint32_t c_index = 0; c_index < constants_amount(); c_index++) {
rows_amount = std::max(rows_amount, constant_column_size(c_index));
}

for (std::uint32_t s_index = 0; s_index <
selectors_amount(); s_index++) {
for (std::uint32_t s_index = 0; s_index < selectors_amount(); s_index++) {
rows_amount = std::max(rows_amount, selector_column_size(s_index));
}

return rows_amount;
}

friend std::uint32_t basic_padding<FieldType, ArithmetizationParams, ColumnType>(
plonk_table &table);
friend std::uint32_t
basic_padding<FieldType, ArithmetizationParams, ColumnType>(plonk_table &table);
};

template<typename FieldType, typename ArithmetizationParams>
Expand Down
19 changes: 9 additions & 10 deletions include/nil/crypto3/zk/snark/arithmetization/plonk/params.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,18 @@ namespace nil {
namespace zk {
namespace snark {

template<std::size_t WitnessColumns, std::size_t PublicInputColumns, std::size_t ConstantColumns,
std::size_t SelectorColumns>
template<std::uint32_t WitnessColumns, std::uint32_t PublicInputColumns, std::uint32_t ConstantColumns>
struct plonk_arithmetization_params {
constexpr static const std::size_t witness_columns = WitnessColumns;
constexpr static const std::size_t public_input_columns = PublicInputColumns;
constexpr static const std::size_t constant_columns = ConstantColumns;
constexpr static const std::size_t selector_columns = SelectorColumns;
constexpr static const std::uint32_t witness_columns = WitnessColumns;
constexpr static const std::uint32_t public_input_columns = PublicInputColumns;
constexpr static const std::uint32_t constant_columns = ConstantColumns;

constexpr static const std::size_t private_columns = witness_columns;
constexpr static const std::size_t public_columns =
public_input_columns + constant_columns + selector_columns;
constexpr static const std::uint32_t private_variables_columns = witness_columns;
constexpr static const std::uint32_t public_variables_columns =
public_input_columns + constant_columns;

constexpr static const std::size_t total_columns = private_columns + public_columns;
constexpr static const std::uint32_t total_variables_columns =
private_variables_columns + public_variables_columns;
};

#ifdef ZK_RUNTIME_CIRCUIT_DEFINITION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,9 @@ namespace nil {
template<typename FieldType, typename ArithmetizationParams>
struct plonk_table_description {
constexpr static const std::size_t witness_columns = ArithmetizationParams::witness_columns;
constexpr static const std::size_t public_input_columns = ArithmetizationParams::public_input_columns;
constexpr static const std::size_t public_input_columns =
ArithmetizationParams::public_input_columns;
constexpr static const std::size_t constant_columns = ArithmetizationParams::constant_columns;
constexpr static const std::size_t selector_columns = ArithmetizationParams::selector_columns;

std::size_t rows_amount = 0;
std::size_t usable_rows_amount = 0;

std::size_t global_index(const plonk_variable<FieldType> &a) const {
switch (a.type) {
case plonk_variable<FieldType>::column_type::witness:
return a.index;
case plonk_variable<FieldType>::column_type::public_input:
return witness_columns + a.index;
case plonk_variable<FieldType>::column_type::constant:
return witness_columns + public_input_columns + a.index;
case plonk_variable<FieldType>::column_type::selector:
return witness_columns + public_input_columns + constant_columns + a.index;
}
}

std::size_t table_width() const {
return witness_columns + public_input_columns + constant_columns + selector_columns;
}
};

#ifdef ZK_RUNTIME_CIRCUIT_DEFINITION
template<typename FieldType>
struct plonk_table_description {
std::size_t witness_columns;
std::size_t public_input_columns;
std::size_t constant_columns;
std::size_t selector_columns;

std::size_t rows_amount = 0;
Expand All @@ -90,7 +62,6 @@ namespace nil {
return witness_columns + public_input_columns + constant_columns + selector_columns;
}
};
#endif
} // namespace snark
} // namespace zk
} // namespace crypto3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ namespace nil {
typedef TranscriptHashType transcript_hash_type;

constexpr static const std::size_t witness_columns = ArithmetizationParams::witness_columns;
constexpr static const std::size_t public_input_columns = ArithmetizationParams::public_input_columns;
constexpr static const std::size_t public_input_columns =
ArithmetizationParams::public_input_columns;
constexpr static const std::size_t constant_columns = ArithmetizationParams::constant_columns;
constexpr static const std::size_t selector_columns = ArithmetizationParams::selector_columns;

using arithmetization_params = ArithmetizationParams;

Expand All @@ -63,20 +63,19 @@ namespace nil {
batched_commitment_params_type;

using fixed_values_commitment_scheme_type =
commitments::batched_lpc<FieldType, batched_commitment_params_type, constant_columns + selector_columns + 2, false>;
commitments::batched_lpc<FieldType, batched_commitment_params_type, 0, false>;

using runtime_size_commitment_scheme_type =
commitments::batched_lpc<FieldType, batched_commitment_params_type, 0, false>;
using variable_values_commitment_scheme_type =
commitments::batched_lpc<FieldType, batched_commitment_params_type, witness_columns + public_input_columns, false>;
commitments::batched_lpc<FieldType, batched_commitment_params_type,
witness_columns + public_input_columns, false>;
using witness_commitment_scheme_type =
commitments::batched_lpc<FieldType, batched_commitment_params_type, witness_columns, true>;
using public_input_commitment_scheme_type =
commitments::batched_lpc<FieldType, batched_commitment_params_type, public_input_columns, true>;
using constant_commitment_scheme_type =
commitments::batched_lpc<FieldType, batched_commitment_params_type, constant_columns, true>;
using selector_commitment_scheme_type =
commitments::batched_lpc<FieldType, batched_commitment_params_type, selector_columns, true>;
using special_commitment_scheme_type =
commitments::batched_lpc<FieldType, batched_commitment_params_type, 2, true>;
using permutation_commitment_scheme_type =
Expand Down
Loading

0 comments on commit f9b421a

Please sign in to comment.