Skip to content

Commit

Permalink
Changing plonk_variable template argument type (#38)
Browse files Browse the repository at this point in the history
* Changing plonk_variable template argument type.

* Few small fixes.

* Few small changes.

* Fixed everything.
  • Loading branch information
martun authored Jul 26, 2023
1 parent 6479d8a commit 763c20f
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 94 deletions.
2 changes: 1 addition & 1 deletion include/nil/crypto3/marshalling/math/types/expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ namespace nil {
struct expression<TTypeBase, nil::crypto3::math::expression<VariableType>,
typename std::enable_if<std::is_same<
VariableType, nil::crypto3::zk::snark::plonk_variable<
typename VariableType::field_type>>::value>::type> {
typename VariableType::assignment_type>>::value>::type> {
using type =
nil::marshalling::types::bundle<
TTypeBase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace nil {
nil::marshalling::option::sequence_size_field_prefix<nil::marshalling::types::integral<TTypeBase, std::size_t>>
>,
// std::vector<VariableType> lookup_value;
nil::crypto3::marshalling::types::variables<TTypeBase, typename PlonkLookupConstraint::field_type>
nil::crypto3::marshalling::types::variables<TTypeBase, typename PlonkLookupConstraint::field_type::value_type>
>
>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace nil {

template<typename PlonkConstraintSystem, typename Endianness>
plonk_constraint_system<nil::marshalling::field_type<Endianness>, PlonkConstraintSystem>
fill_plonk_constraint_system(const PlonkConstraintSystem &system){
fill_plonk_constraint_system(const PlonkConstraintSystem &system) {
using TTypeBase = nil::marshalling::field_type<Endianness>;
using result_type = plonk_constraint_system<TTypeBase, PlonkConstraintSystem>;

Expand Down Expand Up @@ -86,4 +86,4 @@ namespace nil {
} // namespace crypto3
} // namespace nil

#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ namespace nil {

/*********************** Plonk copy constraint ****************************/
template<typename TTypeBase, typename FieldType>
using plonk_copy_constraint = nil::marshalling::types::bundle<TTypeBase, std::tuple<
typename variable<TTypeBase, nil::crypto3::zk::snark::plonk_variable<FieldType>>::type,
typename variable<TTypeBase, nil::crypto3::zk::snark::plonk_variable<FieldType>>::type
using plonk_copy_constraint = nil::marshalling::types::bundle<TTypeBase, std::tuple<
typename variable<TTypeBase, nil::crypto3::zk::snark::plonk_variable<typename FieldType::value_type>>::type,
typename variable<TTypeBase, nil::crypto3::zk::snark::plonk_variable<typename FieldType::value_type>>::type
>>;

template<typename FieldType, typename Endianness>
nil::crypto3::marshalling::types::plonk_copy_constraint<typename nil::marshalling::field_type<Endianness>, FieldType>
fill_plonk_copy_constraint(const nil::crypto3::zk::snark::plonk_copy_constraint<FieldType> &copy_constraint){
using TTypeBase = nil::marshalling::field_type<Endianness>;
using VariableType = nil::crypto3::zk::snark::plonk_variable<FieldType>;
using result_type = nil::crypto3::marshalling::types::plonk_copy_constraint<TTypeBase, VariableType>;
using VariableType = nil::crypto3::zk::snark::plonk_variable<typename FieldType::value_type>;
using result_type = nil::crypto3::marshalling::types::plonk_copy_constraint<TTypeBase, FieldType>;

return result_type(
std::make_tuple(
Expand All @@ -50,8 +50,8 @@ namespace nil {
FieldType> &filled_copy_constraint){

using TTypeBase = nil::marshalling::field_type<Endianness>;
using VariableType = nil::crypto3::zk::snark::plonk_variable<FieldType>;
using result_type = nil::crypto3::zk::snark::plonk_copy_constraint<typename VariableType::field_type>;
using VariableType = nil::crypto3::zk::snark::plonk_variable<typename FieldType::value_type>;
using result_type = nil::crypto3::zk::snark::plonk_copy_constraint<FieldType>;
return std::make_pair(
make_variable<VariableType, Endianness>(std::get<0>(filled_copy_constraint.value())),
make_variable<VariableType, Endianness>(std::get<1>(filled_copy_constraint.value()))
Expand All @@ -63,7 +63,7 @@ namespace nil {
template<typename TTypeBase, typename FieldType>
using plonk_copy_constraints = nil::marshalling::types::array_list<
TTypeBase,
plonk_copy_constraint<TTypeBase, nil::crypto3::zk::snark::plonk_copy_constraint<FieldType>>,
plonk_copy_constraint<TTypeBase, FieldType>,
nil::marshalling::option::sequence_size_field_prefix<nil::marshalling::types::integral<TTypeBase, std::size_t>>
>;

Expand Down
22 changes: 10 additions & 12 deletions include/nil/crypto3/marshalling/zk/types/plonk/variable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ namespace nil {
struct variable;

/********************************* plonk_variable ***************************/
template<typename TTypeBase, typename Field>
struct variable<TTypeBase, nil::crypto3::zk::snark::plonk_variable<Field>> {
template<typename TTypeBase, typename AssignmentType>
struct variable<TTypeBase, nil::crypto3::zk::snark::plonk_variable<AssignmentType>> {
using type = nil::marshalling::types::bundle<
TTypeBase,
std::tuple<
Expand All @@ -65,7 +65,7 @@ namespace nil {
template<typename Variable, typename Endianness>
typename std::enable_if<
std::is_same<Variable,
nil::crypto3::zk::snark::plonk_variable<typename Variable::field_type>>::value,
nil::crypto3::zk::snark::plonk_variable<typename Variable::assignment_type>>::value,
typename variable<nil::marshalling::field_type<Endianness>, Variable>::type>::type
fill_variable(const Variable &var) {
using TTypeBase = nil::marshalling::field_type<Endianness>;
Expand All @@ -82,7 +82,7 @@ namespace nil {

template<typename Variable, typename Endianness>
typename std::enable_if<std::is_same<Variable, nil::crypto3::zk::snark::plonk_variable<
typename Variable::field_type>>::value,
typename Variable::assignment_type>>::value,
Variable>::type
make_variable(
const typename variable<nil::marshalling::field_type<Endianness>, Variable>::type &filled_var) {
Expand All @@ -94,20 +94,20 @@ namespace nil {
}

/****************** vector of plonk_variable *************************/
template<typename TTypeBase, typename Field>
template<typename TTypeBase, typename AssignmentType>
using variables = nil::marshalling::types::array_list<
TTypeBase,
typename variable<TTypeBase, nil::crypto3::zk::snark::plonk_variable<Field>>::type,
typename variable<TTypeBase, nil::crypto3::zk::snark::plonk_variable<AssignmentType>>::type,
nil::marshalling::option::sequence_size_field_prefix<nil::marshalling::types::integral<TTypeBase, std::size_t>>
>;

template<typename Variable, typename Endianness>
variables<nil::marshalling::field_type<Endianness>, typename Variable::field_type>
variables<nil::marshalling::field_type<Endianness>, typename Variable::assignment_type>
fill_variables(const std::vector<Variable> &vars) {
using TTypeBase = nil::marshalling::field_type<Endianness>;
using Field = typename Variable::field_type;
using AssignmentType = typename Variable::assignment_type;

variables<TTypeBase, Field> filled_vars;
variables<TTypeBase, AssignmentType> filled_vars;
for (const auto &var : vars) {
filled_vars.value().push_back(fill_variable<Variable, Endianness>(var));
}
Expand All @@ -117,9 +117,7 @@ namespace nil {

template<typename Variable, typename Endianness>
std::vector<Variable>
make_variables(const variables<nil::marshalling::field_type<Endianness>, typename Variable::field_type> &filled_vars){
using Field = typename Variable::field_type;

make_variables(const variables<nil::marshalling::field_type<Endianness>, typename Variable::assignment_type> &filled_vars){
std::vector<Variable> vars;
for (std::size_t i = 0; i < filled_vars.value().size(); i++) {
vars.emplace_back(make_variable<Variable, Endianness>(filled_vars.value().at(i)));
Expand Down
74 changes: 37 additions & 37 deletions test/detail/circuits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ namespace nil {

test_circuit.init();

plonk_variable<FieldType> w0(0, 0,
plonk_variable<FieldType>::column_type::witness);
plonk_variable<FieldType> w1(0, 0,
plonk_variable<FieldType>::column_type::witness);
plonk_variable<FieldType> w2(0, 0,
plonk_variable<FieldType>::column_type::witness);
plonk_variable<typename FieldType::value_type> w0(0, 0,
plonk_variable<typename FieldType::value_type>::column_type::witness);
plonk_variable<typename FieldType::value_type> w1(0, 0,
plonk_variable<typename FieldType::value_type>::column_type::witness);
plonk_variable<typename FieldType::value_type> w2(0, 0,
plonk_variable<typename FieldType::value_type>::column_type::witness);

plonk_constraint<FieldType> add_constraint;
add_constraint += w0;
Expand Down Expand Up @@ -272,10 +272,10 @@ namespace nil {
q_add[i] = one;
q_mul[i] = FieldType::value_type::zero();

plonk_variable<FieldType> x(1, i, false,
plonk_variable<FieldType>::column_type::witness);
plonk_variable<FieldType> y(2, i - 1, false,
plonk_variable<FieldType>::column_type::witness);
plonk_variable<typename FieldType::value_type> x(1, i, false,
plonk_variable<typename FieldType::value_type>::column_type::witness);
plonk_variable<typename FieldType::value_type> y(2, i - 1, false,
plonk_variable<typename FieldType::value_type>::column_type::witness);
test_circuit.copy_constraints.push_back(plonk_copy_constraint<FieldType>(x, y));
}

Expand All @@ -288,10 +288,10 @@ namespace nil {
q_add[i] = FieldType::value_type::zero();
q_mul[i] = one;

plonk_variable<FieldType> x(1, i, false,
plonk_variable<FieldType>::column_type::witness);
plonk_variable<FieldType> y(0, 0, false,
plonk_variable<FieldType>::column_type::public_input);
plonk_variable<typename FieldType::value_type> x(1, i, false,
plonk_variable<typename FieldType::value_type>::column_type::witness);
plonk_variable<typename FieldType::value_type> y(0, 0, false,
plonk_variable<typename FieldType::value_type>::column_type::public_input);
test_circuit.copy_constraints.push_back(plonk_copy_constraint<FieldType>(x, y));
}

Expand All @@ -317,14 +317,14 @@ namespace nil {

test_circuit.init();

plonk_variable<FieldType> w0(0, 0, true,
plonk_variable<FieldType>::column_type::witness);
plonk_variable<FieldType> w1(1, 0, true,
plonk_variable<FieldType>::column_type::witness);
plonk_variable<FieldType> w2(2, 0, true,
plonk_variable<FieldType>::column_type::witness);
plonk_variable<FieldType> w0_prev(0, -1, true,
plonk_variable<FieldType>::column_type::witness);
plonk_variable<typename FieldType::value_type> w0(0, 0, true,
plonk_variable<typename FieldType::value_type>::column_type::witness);
plonk_variable<typename FieldType::value_type> w1(1, 0, true,
plonk_variable<typename FieldType::value_type>::column_type::witness);
plonk_variable<typename FieldType::value_type> w2(2, 0, true,
plonk_variable<typename FieldType::value_type>::column_type::witness);
plonk_variable<typename FieldType::value_type> w0_prev(0, -1, true,
plonk_variable<typename FieldType::value_type>::column_type::witness);

plonk_constraint<FieldType> add_constraint;
add_constraint += w0;
Expand Down Expand Up @@ -425,25 +425,25 @@ namespace nil {
public_input_assignment, constant_assignment, selectors_assignment));

test_circuit.init();
plonk_variable<FieldType> w0(0, 0, true,
plonk_variable<FieldType>::column_type::witness);
plonk_variable<FieldType> w1(1, 0, true,
plonk_variable<FieldType>::column_type::witness);
plonk_variable<FieldType> w2(2, 0, true,
plonk_variable<FieldType>::column_type::witness);
plonk_variable<typename FieldType::value_type> w0(0, 0, true,
plonk_variable<typename FieldType::value_type>::column_type::witness);
plonk_variable<typename FieldType::value_type> w1(1, 0, true,
plonk_variable<typename FieldType::value_type>::column_type::witness);
plonk_variable<typename FieldType::value_type> w2(2, 0, true,
plonk_variable<typename FieldType::value_type>::column_type::witness);

plonk_variable<FieldType> c0(0, 0, true,
plonk_variable<FieldType>::column_type::constant);
plonk_variable<FieldType> c1(1, 0, true,
plonk_variable<FieldType>::column_type::constant);
plonk_variable<FieldType> c2(2, 0, true,
plonk_variable<FieldType>::column_type::constant);
plonk_variable<typename FieldType::value_type> c0(0, 0, true,
plonk_variable<typename FieldType::value_type>::column_type::constant);
plonk_variable<typename FieldType::value_type> c1(1, 0, true,
plonk_variable<typename FieldType::value_type>::column_type::constant);
plonk_variable<typename FieldType::value_type> c2(2, 0, true,
plonk_variable<typename FieldType::value_type>::column_type::constant);


plonk_lookup_constraint<FieldType> lookup_constraint;
math::term<plonk_variable<FieldType>> w0_term(w0);
math::term<plonk_variable<FieldType>> w1_term(w1);
math::term<plonk_variable<FieldType>> w2_term(w2);
math::term<plonk_variable<typename FieldType::value_type>> w0_term(w0);
math::term<plonk_variable<typename FieldType::value_type>> w1_term(w1);
math::term<plonk_variable<typename FieldType::value_type>> w2_term(w2);
lookup_constraint.lookup_input.push_back(w0_term);
lookup_constraint.lookup_input.push_back(w1_term);
lookup_constraint.lookup_input.push_back(w2_term);
Expand Down
Loading

0 comments on commit 763c20f

Please sign in to comment.