Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed ArithmetizationParams from template arguments. [SyncWith: crypto3-zk#292] #333

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/plonk/addition_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE(blueprint_plonk_addition_example) {
constexpr std::size_t SelectorColumns = 1;
using ArithmetizationParams =
zk::snark::plonk_arithmetization_params<WitnessColumns, PublicInputColumns, ConstantColumns, SelectorColumns>;
using ArithmetizationType = zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>;
using ArithmetizationType = zk::snark::plonk_constraint_system<BlueprintFieldType>;
using hash_type = nil::crypto3::hashes::keccak_1600<256>;
constexpr std::size_t Lambda = 40;

Expand All @@ -76,7 +76,7 @@ BOOST_AUTO_TEST_CASE(blueprint_plonk_addition_example) {

std::vector<typename BlueprintFieldType::value_type> public_input = {x, y, sum};

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

BOOST_AUTO_TEST_SUITE_END()
7 changes: 3 additions & 4 deletions example/plonk/addition_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ namespace nil {
/// Constraints:
/// x + y = sum <=> W0 + W1 = W2
template<typename BlueprintFieldType,
typename ArithmetizationParams,
std::size_t W0,
std::size_t W1,
std::size_t W2>
Expand Down Expand Up @@ -151,7 +150,7 @@ namespace nil {
private:
static void generate_gates(
blueprint<ArithmetizationType> &bp,
blueprint_assignment_table<ArithmetizationType> &assignment,
blueprint_assignment_table<ArithmetizationType> &assignment,
const params_type &params,
allocated_data_type &allocated_data,
const std::size_t start_row_index) {
Expand All @@ -163,7 +162,7 @@ namespace nil {
allocated_data.add_selector = selector_index;
} else {
selector_index = allocated_data.add_selector;
assignment.enable_selector(selector_index, start_row_index);
assignment.enable_selector(selector_index, start_row_index);
}

// var(i, 0) defines cell at the column i with rotation 0 (we'll elaborate rotation in the next examples)
Expand All @@ -172,7 +171,7 @@ namespace nil {

if (!allocated_data.previously_allocated) {
// gate composes multiple constraints together
bp.add_gate(selector_index,
bp.add_gate(selector_index,
{ constraint_1
});
allocated_data.previously_allocated = true;
Expand Down
6 changes: 3 additions & 3 deletions example/plonk/component_template.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace nil {
class component_template;

template<typename BlueprintFieldType,
typename ArithmetizationParams,

typename CurveType,
std::size_t W0,
std::size_t W1,
Expand Down Expand Up @@ -129,13 +129,13 @@ namespace nil {
private:
static void generate_gates(
blueprint<ArithmetizationType> &bp,
blueprint_assignment_table<ArithmetizationType> &assignment,
blueprint_assignment_table<ArithmetizationType> &assignment,
const params_type &params,
allocated_data_type &allocated_data,
const std::size_t start_row_index) {

if (!allocated_data.previously_allocated) {
} else {
} else {
}

}
Expand Down
46 changes: 22 additions & 24 deletions include/nil/blueprint/blueprint/plonk/assignment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,19 @@
namespace nil {
namespace blueprint {

template<typename ArithmetizationType, std::size_t... BlueprintParams>
template<typename ArithmetizationType>
class assignment;

template<typename ArithmetizationType, std::size_t... BlueprintParams>
template<typename ArithmetizationType>
class circuit;

template<typename BlueprintFieldType,
typename ArithmetizationParams>
class assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType,
ArithmetizationParams>>
: public crypto3::zk::snark::plonk_assignment_table<BlueprintFieldType,
ArithmetizationParams> {
template<typename BlueprintFieldType>
class assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType>>
: public crypto3::zk::snark::plonk_assignment_table<BlueprintFieldType> {

using zk_type = crypto3::zk::snark::plonk_assignment_table<BlueprintFieldType,
ArithmetizationParams>;
using zk_type = crypto3::zk::snark::plonk_assignment_table<BlueprintFieldType>;

typedef crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType,
ArithmetizationParams> ArithmetizationType;
typedef crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType> ArithmetizationType;

using var = crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>;
using value_type = typename BlueprintFieldType::value_type;
Expand All @@ -75,9 +70,14 @@ namespace nil {
public:
static constexpr const std::size_t private_storage_index = std::numeric_limits<std::size_t>::max();

assignment() :
crypto3::zk::snark::plonk_assignment_table<BlueprintFieldType,
ArithmetizationParams>() {
assignment(std::size_t witness_amount, std::size_t public_input_amount,
std::size_t constant_amount, std::size_t selector_amount)
: zk_type(witness_amount, public_input_amount, constant_amount, selector_amount) {
}

assignment(const crypto3::zk::snark::plonk_table_description<BlueprintFieldType> &desc)
: zk_type(desc.witness_columns, desc.public_input_columns,
desc.constant_columns, desc.selector_columns) {
}

virtual value_type &selector(std::size_t selector_index, std::uint32_t row_index) {
Expand Down Expand Up @@ -172,7 +172,7 @@ namespace nil {
}

virtual value_type &witness(std::uint32_t witness_index, std::uint32_t row_index) {
BLUEPRINT_ASSERT(witness_index < ArithmetizationParams::WitnessColumns);
BLUEPRINT_ASSERT(witness_index < this->_private_table._witnesses.size());

if (this->_private_table._witnesses[witness_index].size() <= row_index)
this->_private_table._witnesses[witness_index].resize(row_index + 1);
Expand All @@ -182,7 +182,7 @@ namespace nil {
}

virtual value_type witness(std::uint32_t witness_index, std::uint32_t row_index) const {
BLUEPRINT_ASSERT(witness_index < ArithmetizationParams::WitnessColumns);
BLUEPRINT_ASSERT(witness_index < this->_private_table._witnesses.size());
BLUEPRINT_ASSERT(row_index < this->_private_table._witnesses[witness_index].size());

return this->_private_table._witnesses[witness_index][row_index];
Expand Down Expand Up @@ -235,7 +235,7 @@ namespace nil {
virtual value_type &constant(
std::uint32_t constant_index, std::uint32_t row_index) {

assert(constant_index < zk_type::constants_amount());
BLUEPRINT_ASSERT(constant_index < zk_type::constants_amount());

if (zk_type::constant_column_size(constant_index) <= row_index)
this->_public_table._constants[constant_index].resize(row_index + 1);
Expand Down Expand Up @@ -374,17 +374,15 @@ namespace nil {
}
};

template<typename BlueprintFieldType,
typename ArithmetizationParams>
template<typename BlueprintFieldType>
typename BlueprintFieldType::value_type var_value(
const assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType,
ArithmetizationParams>> &input_assignment,
const assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType>> &input_assignment,
const crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type> &input_var) {
using var_column_type =
typename crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>::column_type;
using assignment_type =
assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>;
using assignment_type = assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType>>;
// This SHOULD be handled by a separate variable type
// (Or even better: properly extracted from the component)
// But adding a new variable type breaks assigner
// So we add a type without actually adding a type
if (input_var.index == assignment_type::private_storage_index) {
Expand Down
66 changes: 41 additions & 25 deletions include/nil/blueprint/blueprint/plonk/assignment_proxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@

namespace nil {
namespace blueprint {
template<typename ArithmetizationType, std::size_t... BlueprintParams>

template<typename ArithmetizationType>
class assignment_proxy;

template<typename BlueprintFieldType,
typename ArithmetizationParams>
class assignment_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType,
ArithmetizationParams>>
: public assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType,
ArithmetizationParams>> {
template<typename ArithmetizationType>
class circuit;

template<typename BlueprintFieldType>
class assignment_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType>>
: public assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType>> {

typedef crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType,
ArithmetizationParams> ArithmetizationType;
typedef crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType> ArithmetizationType;

using value_type = typename BlueprintFieldType::value_type;
using column_type = typename crypto3::zk::snark::plonk_column<BlueprintFieldType>;
Expand All @@ -53,9 +53,14 @@ namespace nil {
std::set<std::uint32_t> used_rows;
std::set<std::uint32_t> used_selector_rows;
public:
assignment_proxy(std::shared_ptr<assignment<ArithmetizationType>> assignment,
assignment_proxy(std::shared_ptr<assignment<ArithmetizationType>> assignment_,
std::uint32_t _id) :
assignment_ptr(assignment),
assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType>>(
assignment_->witnesses_amount(),
assignment_->public_inputs_amount(),
assignment_->constants_amount(),
assignment_->selectors_amount()),
assignment_ptr(assignment_),
id(_id),
check(false) {
assert(assignment_ptr);
Expand Down Expand Up @@ -265,6 +270,22 @@ namespace nil {
return assignment_ptr->get_lookup_constant_amount();
}

void resize_witnesses(std::uint32_t new_size) override {
assignment_ptr->resize_witnesses(new_size);
}

void resize_public_inputs(std::uint32_t new_size) override {
assignment_ptr->resize_public_inputs(new_size);
}

void resize_constants(std::uint32_t new_size) override {
assignment_ptr->resize_constants(new_size);
}

void resize_selectors(std::uint32_t new_size) override {
assignment_ptr->resize_selectors(new_size);
}

value_type private_storage(std::uint32_t storage_index) const override {
return assignment_ptr->private_storage(storage_index);
}
Expand Down Expand Up @@ -398,11 +419,9 @@ namespace nil {
}
};

template<typename BlueprintFieldType,
typename ArithmetizationParams>
template<typename BlueprintFieldType>
crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type> save_shared_var(
assignment_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType,
ArithmetizationParams>> &input_assignment,
assignment_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType>> &input_assignment,
const crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type> &input_var) {
using var = crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>;
std::uint32_t row_index = input_assignment.shared_column_size(0);
Expand All @@ -411,11 +430,9 @@ namespace nil {
return res;
}

template<typename BlueprintFieldType,
typename ArithmetizationParams>
template<typename BlueprintFieldType>
std::vector<crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>> save_shared_var(
assignment_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType,
ArithmetizationParams>> &input_assignment,
assignment_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType>> &input_assignment,
const std::vector<crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>> &input_vars) {
std::vector<crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>> res;
for (const auto &it : input_vars) {
Expand All @@ -424,12 +441,11 @@ namespace nil {
return res;
}

template<typename BlueprintFieldType,
typename ArithmetizationParams>
bool is_satisfied(const circuit_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType,
ArithmetizationParams>> &bp,
const assignment_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType,
ArithmetizationParams>> &assignments){
template<typename BlueprintFieldType>
bool is_satisfied(const circuit_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType>>
&bp,
const assignment_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType>>
&assignments) {

const auto& used_gates = bp.get_used_gates();

Expand Down
29 changes: 12 additions & 17 deletions include/nil/blueprint/blueprint/plonk/circuit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,38 +36,35 @@
#include <nil/crypto3/zk/snark/arithmetization/plonk/copy_constraint.hpp>
#include <nil/crypto3/zk/snark/arithmetization/plonk/lookup_constraint.hpp>
#include <nil/crypto3/zk/snark/arithmetization/plonk/variable.hpp>
#include <nil/blueprint/blueprint/plonk/assignment.hpp>

#include <nil/blueprint/blueprint/plonk/assignment.hpp>
#include <nil/blueprint/gate_id.hpp>
#include <nil/blueprint/lookup_library.hpp>

namespace nil {
namespace blueprint {

template<typename ArithmetizationType, std::size_t... BlueprintParams>
template<typename ArithmetizationType>
class circuit;

template<typename ArithmetizationType, std::size_t... BlueprintParams>
template<typename ArithmetizationType>
class assignment;

template<typename BlueprintFieldType,
typename ArithmetizationParams>
class circuit<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType,
ArithmetizationParams>>
: public crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType,
ArithmetizationParams> {
template<typename BlueprintFieldType>
class circuit<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType>>
: public crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType> {

typedef crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType,
ArithmetizationParams> ArithmetizationType;
typedef crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType> ArithmetizationType;

private:
using gate_id_type = gate_id<BlueprintFieldType, ArithmetizationParams>;
using gate_id_type = gate_id<BlueprintFieldType>;
using constraint_type = crypto3::zk::snark::plonk_constraint<BlueprintFieldType>;
using gate_selector_map = std::map<gate_id_type, std::size_t>;
using gate_type = crypto3::zk::snark::plonk_gate<BlueprintFieldType, constraint_type>;

using lookup_constraint_type = crypto3::zk::snark::plonk_lookup_constraint<BlueprintFieldType>;
using lookup_gate_type = crypto3::zk::snark::plonk_lookup_gate<BlueprintFieldType, lookup_constraint_type>;
using lookup_gate_id_type = lookup_gate_id<BlueprintFieldType, ArithmetizationParams>;
using lookup_gate_id_type = lookup_gate_id<BlueprintFieldType>;
using lookup_gate_selector_map = std::map<lookup_gate_id_type, std::size_t>;

using lookup_table_definition = typename nil::crypto3::zk::snark::lookup_table_definition<BlueprintFieldType>;
Expand All @@ -80,8 +77,7 @@ namespace nil {
public:
typedef BlueprintFieldType blueprint_field_type;

circuit(crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType,
ArithmetizationParams> constraint_system) :
circuit(ArithmetizationType constraint_system) :
ArithmetizationType(constraint_system) { }

circuit() : ArithmetizationType() {}
Expand Down Expand Up @@ -191,8 +187,7 @@ namespace nil {

virtual void add_copy_constraint(const crypto3::zk::snark::plonk_copy_constraint<BlueprintFieldType> &copy_constraint) {
static const std::size_t private_storage_index =
assignment<crypto3::zk::snark::plonk_constraint_system<
BlueprintFieldType, ArithmetizationParams>>::private_storage_index;
assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType>>::private_storage_index;
if (copy_constraint.first == copy_constraint.second) {
return;
}
Expand Down
Loading
Loading