Skip to content

Commit

Permalink
gate caclulation changes #20
Browse files Browse the repository at this point in the history
  • Loading branch information
SK0M0R0H committed Mar 12, 2022
1 parent 6c309ba commit eb322ab
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 deletions include/nil/crypto3/zk/snark/relations/plonk/constraint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ namespace nil {

term_value = term_value * assignment;
}
acc = acc + term_value * nlt.coeff;
acc = acc + term_value;
}
return acc;
}
Expand All @@ -148,7 +148,7 @@ namespace nil {
key = std::make_tuple(var.index, var.rotation, var.type);
term_value = term_value * assignments[key];
}
acc = acc + term_value * nlt.coeff;
acc = acc + term_value;
}
return acc;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace nil {
const plonk_polynomial_table<FieldType, ParamsType::witness_columns,
ParamsType::public_input_columns, ParamsType::constant_columns,
ParamsType::selector_columns> &column_polynomials,
transcript_type &transcript = transcript_type()) {
transcript_type &transcript = transcript_type()) { //TODO: remove fri_params

typename FieldType::value_type theta = transcript.template challenge<FieldType>();

Expand Down
25 changes: 14 additions & 11 deletions test/systems/plonk/circuits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,11 @@ namespace nil {
}

// init values
typename FieldType::value_type one = FieldType::value_type::one();
table[0][0] = algebra::random_element<FieldType>();
table[0][1] = algebra::random_element<FieldType>();
table[0][2] = algebra::random_element<FieldType>();
table[0][3] = algebra::random_element<FieldType>();
table[1][0] = algebra::random_element<FieldType>();
table[2][0] = algebra::random_element<FieldType>();
table[3][0] = algebra::random_element<FieldType>();
q_add[0] = FieldType::value_type::zero();
q_mul[0] = FieldType::value_type::zero();

Expand All @@ -266,7 +267,7 @@ namespace nil {
table[1][i] = table[2][i - 1];
table[2][i] = table[0][i] + table[1][i];
table[3][i] = FieldType::value_type::zero();
q_add[i] = FieldType::value_type::one();
q_add[i] = one;
q_mul[i] = FieldType::value_type::zero();

plonk_variable<FieldType> x(1, i, false,
Expand All @@ -283,7 +284,7 @@ namespace nil {
table[2][i] = table[0][i] * table[1][i];
table[3][i] = FieldType::value_type::zero();
q_add[i] = FieldType::value_type::zero();
q_mul[i] = FieldType::value_type::one();
q_mul[i] = one;

plonk_variable<FieldType> x(1, i, false,
plonk_variable<FieldType>::column_type::witness);
Expand Down Expand Up @@ -316,25 +317,27 @@ namespace nil {

test_circuit.init();

plonk_variable<FieldType> w0(0, plonk_variable<FieldType>::rotation_type::current,
plonk_variable<FieldType> w0(0, plonk_variable<FieldType>::rotation_type::current, true,
plonk_variable<FieldType>::column_type::witness);
plonk_variable<FieldType> w1(0, plonk_variable<FieldType>::rotation_type::current,
plonk_variable<FieldType> w1(1, plonk_variable<FieldType>::rotation_type::current, true,
plonk_variable<FieldType>::column_type::witness);
plonk_variable<FieldType> w2(0, plonk_variable<FieldType>::rotation_type::current,
plonk_variable<FieldType> w2(2, plonk_variable<FieldType>::rotation_type::current, true,
plonk_variable<FieldType>::column_type::witness);

plonk_constraint<FieldType> add_constraint;
add_constraint.add_term(w0);
add_constraint.add_term(w1);
add_constraint.add_term(-w2);
add_constraint.add_term(w2, -one);

std::vector<plonk_constraint<FieldType>> add_gate_costraints {add_constraint};
plonk_gate<FieldType> add_gate(0, add_gate_costraints);
test_circuit.gates.push_back(add_gate);

plonk_constraint<FieldType> mul_constraint;
add_constraint.add_term(w0 * w1);
add_constraint.add_term(-w2);
typename plonk_constraint<FieldType>::term_type w0_term(w0);
typename plonk_constraint<FieldType>::term_type w1_term(w1);
mul_constraint.add_term(w0_term * w1_term);
mul_constraint.add_term(w2, -one);

std::vector<plonk_constraint<FieldType>> mul_gate_costraints {mul_constraint};
plonk_gate<FieldType> mul_gate(1, mul_gate_costraints);
Expand Down

0 comments on commit eb322ab

Please sign in to comment.