Skip to content

Commit

Permalink
Tests fixed #335
Browse files Browse the repository at this point in the history
  • Loading branch information
ETatuzova committed Apr 10, 2024
1 parent 573fb8c commit 0e7b2e1
Show file tree
Hide file tree
Showing 17 changed files with 231 additions and 343 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ namespace nil {
const std::size_t j = start_row_index;
var component_x = var(component.W(0), static_cast<int>(j), false);
var component_y = var(component.W(1), static_cast<int>(j), false);
bp.add_copy_constraint({instance_input.x, component_x});
bp.add_copy_constraint({component_y, instance_input.y});
if( instance_input.x != component_x ) bp.add_copy_constraint({instance_input.x, component_x});
if( instance_input.y != component_y ) bp.add_copy_constraint({component_y, instance_input.y});
}

template<typename BlueprintFieldType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ namespace nil {
component_type(witness, constant, public_input, get_manifest(bits_amount_, mode_)),
bits_amount(bits_amount_),
mode(mode_),
range_check_subcomponent(witness, constant, public_input, bits_amount_) {

range_check_subcomponent(witness, constant, public_input, bits_amount_
) {
check_params(bits_amount, mode);
};

Expand Down Expand Up @@ -290,9 +290,10 @@ namespace nil {
&instance_input,
const std::uint32_t start_row_index) {


using var = typename plonk_comparison_unchecked<BlueprintFieldType>::var;
generate_circuit(component.range_check_subcomponent, bp, assignment,
{var(component.W(2), start_row_index + component.range_check_subcomponent.rows_amount)},
{var(component.W(2), start_row_index + component.range_check_subcomponent.rows_amount, false)},
start_row_index);

std::size_t selector_index = generate_gates(component, bp, assignment, instance_input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,10 @@ namespace nil {
using var = typename plonk_ed25519_range<BlueprintFieldType>::var;

std::size_t row = start_row_index;
bp.add_copy_constraint({var(component.W(0), static_cast<int>(row), false), instance_input.input[0]});
bp.add_copy_constraint({var(component.W(1), static_cast<int>(row), false), instance_input.input[1]});
bp.add_copy_constraint({var(component.W(2), static_cast<int>(row), false), instance_input.input[2]});
bp.add_copy_constraint({var(component.W(3), static_cast<int>(row), false), instance_input.input[3]});
if(var(component.W(0), static_cast<int>(row), false) != instance_input.input[0]) bp.add_copy_constraint({var(component.W(0), static_cast<int>(row), false), instance_input.input[0]});
if(var(component.W(1), static_cast<int>(row), false) != instance_input.input[1]) bp.add_copy_constraint({var(component.W(1), static_cast<int>(row), false), instance_input.input[1]});
if(var(component.W(2), static_cast<int>(row), false) != instance_input.input[2]) bp.add_copy_constraint({var(component.W(2), static_cast<int>(row), false), instance_input.input[2]});
if(var(component.W(3), static_cast<int>(row), false) != instance_input.input[3]) bp.add_copy_constraint({var(component.W(3), static_cast<int>(row), false), instance_input.input[3]});
}

template<typename BlueprintFieldType>
Expand Down
22 changes: 13 additions & 9 deletions include/nil/blueprint/components/algebra/fields/plonk/sqrt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,11 @@ namespace nil {
var output;

result_type(const sqrt &component, std::size_t component_start_row) {
output = var(component.W(0), component_start_row + 3 +
exp_component::get_rows_amount(15));
output = var(
component.W(0),
component_start_row + 3 + exp_component::get_rows_amount(15),
false
);
}

std::vector<std::reference_wrapper<var>> all_vars() {
Expand Down Expand Up @@ -205,14 +208,15 @@ namespace nil {
// check if y \in QR(q)
auto exp_instance =
// qr_check = 1 if y \in QR(q), -1 if y \in QNR(q), 0 if y = 0
exp_component({component.W(0), component.W(1), component.W(2), component.W(3),
component.W(4), component.W(5), component.W(6), component.W(7),
component.W(8), component.W(9), component.W(10), component.W(11),
component.W(12), component.W(13), component.W(14)}, {component.C(0)},
{});
exp_component({
component.W(0), component.W(1), component.W(2), component.W(3),
component.W(4), component.W(5), component.W(6), component.W(7),
component.W(8), component.W(9), component.W(10), component.W(11),
component.W(12), component.W(13), component.W(14)}, {component.C(0)},
{}
);
var qr_check = generate_circuit(exp_instance, bp, assignment, {instance_input.y, exp}, row).output;
row += exp_instance.rows_amount;

// x = sqrt(y) if y \in QR(q) or y = 0, -1 otherwise
auto mul_instance = mul_component({component.W(0), component.W(1), component.W(2)}, {}, {});
var x(component.W(0), row, false);
Expand Down Expand Up @@ -270,7 +274,7 @@ namespace nil {
template<typename BlueprintFieldType>
typename plonk_sqrt<BlueprintFieldType>::result_type
generate_assignments(
const plonk_sqrt<BlueprintFieldType> &component,\
const plonk_sqrt<BlueprintFieldType> &component,
assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType>>
&assignment,
const typename plonk_sqrt<BlueprintFieldType>::input_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ namespace nil {
// Proceed with care
using var = typename plonk_poseidon<BlueprintFieldType, FieldType>::var;
for (std::size_t i = 0; i < 3; i++) {
bp.add_copy_constraint({var(component.W(i), start_row_index), instance_input.input_state[i]});
bp.add_copy_constraint({var(component.W(i), start_row_index, false), instance_input.input_state[i]});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ namespace nil {
// Proceed with care
using var = typename plonk_flexible_poseidon<BlueprintFieldType>::var;
for (std::size_t i = 0; i < 3; i++) {
bp.add_copy_constraint({var(component.W(i), start_row_index), instance_input.input_state[i]});
bp.add_copy_constraint({var(component.W(i), start_row_index, false), instance_input.input_state[i]});
}
}

Expand Down
Loading

0 comments on commit 0e7b2e1

Please sign in to comment.