Skip to content

Commit

Permalink
Some 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 7cddd34
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 65 deletions.
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace nil {
placeholder_info = nil::crypto3::zk::snark::prepare_placeholder_info<typename PlaceholderParams::placeholder_params>(
constraint_system,
common_data, fri_params,
PlaceholderParams::WitnessColumns + PlaceholderParams::PublicInputColumns + PlaceholderParams::ComponentConstantColumns
constraint_system.permuted_columns().size()
);

fill_vector();
Expand Down Expand Up @@ -105,6 +105,8 @@ namespace nil {
std::vector<std::vector<var>> _round_proof_hashes;

void fill_vector() {
auto &desc = common_data.desc;

std::size_t cur = 0;
_commitments.push_back(var(0, cur++, false, var::column_type::public_input));
var_vector.push_back(_commitments[0]);
Expand All @@ -126,43 +128,52 @@ namespace nil {
// Z-s
// Fixed values batch.
// Permutation polynomials
for(std::size_t i = 0; i < placeholder_info.permutation_size * 4; i++){
std::cout << "placeholder_info.permutation_size = " << constraint_system.permuted_columns().size() << std::endl;
for(auto &column: constraint_system.permuted_columns()){
std::cout << "Permuted column " << column << std::endl;
}
std::size_t permutation_size = constraint_system.permuted_columns().size();
std::size_t points_num = 0;
for(std::size_t i = 0; i < permutation_size * 2; i++){
var_vector.push_back(var(0, cur++, false, var::column_type::public_input));
points_num++;
}
// Special selectors
var_vector.push_back(var(0, cur++, false, var::column_type::public_input));
var_vector.push_back(var(0, cur++, false, var::column_type::public_input));
var_vector.push_back(var(0, cur++, false, var::column_type::public_input));
var_vector.push_back(var(0, cur++, false, var::column_type::public_input));
var_vector.push_back(var(0, cur++, false, var::column_type::public_input));
var_vector.push_back(var(0, cur++, false, var::column_type::public_input));
points_num += 4;
//Constant columns
for( std::size_t i = 0; i < PlaceholderParams::ConstantColumns; i++){
for( std::size_t j = 0; j < common_data.columns_rotations[PlaceholderParams::WitnessColumns + PlaceholderParams::PublicInputColumns + i].size(); j++){
for( std::size_t i = 0; i < desc.constant_columns; i++){
for( std::size_t j = 0; j < common_data.columns_rotations[desc.witness_columns + desc.public_input_columns + i].size(); j++){
var_vector.push_back(var(0, cur++, false, var::column_type::public_input));
points_num++;
}
var_vector.push_back(var(0, cur++, false, var::column_type::public_input));
}
//Selector columns
for( std::size_t i = 0; i < PlaceholderParams::SelectorColumns; i++){
for( std::size_t j = 0; j < common_data.columns_rotations[PlaceholderParams::WitnessColumns + PlaceholderParams::PublicInputColumns + PlaceholderParams::ConstantColumns + i].size(); j++){
for( std::size_t i = 0; i < desc.selector_columns; i++){
for( std::size_t j = 0; j < common_data.columns_rotations[desc.witness_columns + desc.public_input_columns + desc.public_input_columns + i].size(); j++){
var_vector.push_back(var(0, cur++, false, var::column_type::public_input));
points_num++;
}
var_vector.push_back(var(0, cur++, false, var::column_type::public_input));
}
//Variable values
//Witness columns
for( std::size_t i = 0; i < PlaceholderParams::WitnessColumns; i++){
for( std::size_t i = 0; i < desc.witness_columns; i++){
for( std::size_t j = 0; j < common_data.columns_rotations[i].size(); j++){
var_vector.push_back(var(0, cur++, false, var::column_type::public_input));
points_num++;
}
}
//Public input columns
for( std::size_t i = 0; i < PlaceholderParams::PublicInputColumns; i++){
for( std::size_t j = 0; j < common_data.columns_rotations[i + PlaceholderParams::WitnessColumns].size(); j++){
for( std::size_t i = 0; i < desc.public_input_columns; i++){
for( std::size_t j = 0; j < common_data.columns_rotations[i + desc.witness_columns].size(); j++){
var_vector.push_back(var(0, cur++, false, var::column_type::public_input));
points_num++;
}
}
std::cout << "Proof input points num = " << points_num << std::endl;
//Permutation Polynomials
var_vector.push_back(var(0, cur++, false, var::column_type::public_input));
var_vector.push_back(var(0, cur++, false, var::column_type::public_input));
Expand Down Expand Up @@ -190,13 +201,13 @@ namespace nil {
}

// Query proofs
_merkle_tree_positions.resize(PlaceholderParams::Lambda);
_initial_proof_values.resize(PlaceholderParams::Lambda);
_initial_proof_hashes.resize(PlaceholderParams::Lambda);
_round_proof_values.resize(PlaceholderParams::Lambda);
_round_proof_hashes.resize(PlaceholderParams::Lambda);
_merkle_tree_positions.resize(fri_params.lambda);
_initial_proof_values.resize(fri_params.lambda);
_initial_proof_hashes.resize(fri_params.lambda);
_round_proof_values.resize(fri_params.lambda);
_round_proof_hashes.resize(fri_params.lambda);
std::cout << "Poly input num = " << placeholder_info.poly_num << std::endl;
for( std::size_t i = 0; i < PlaceholderParams::Lambda; i++){
for( std::size_t i = 0; i < fri_params.lambda; i++){
// Initial proof values
_initial_proof_values[i] = {};
for( std::size_t j = 0; j < placeholder_info.poly_num; j++ ){
Expand Down Expand Up @@ -243,10 +254,10 @@ namespace nil {
}
}
private:
common_data_type common_data;
constraint_system_type constraint_system;
const common_data_type &common_data;
const constraint_system_type &constraint_system;
std::vector<var> var_vector;
typename PlaceholderParams::fri_params_type fri_params;
const typename PlaceholderParams::fri_params_type &fri_params;
placeholder_info_type placeholder_info;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include <nil/crypto3/zk/snark/arithmetization/plonk/constraint_system.hpp>
#include <nil/crypto3/zk/snark/systems/plonk/placeholder/preprocessor.hpp>
#include <nil/crypto3/zk/snark/systems/plonk/placeholder/proof.hpp>
#include <nil/crypto3/zk/snark/systems/plonk/placeholder/profiling.hpp>
#include <nil/crypto3/zk/snark/systems/plonk/placeholder/detail/profiling.hpp>

#include <nil/blueprint/blueprint/plonk/assignment.hpp>
#include <nil/blueprint/blueprint/plonk/circuit.hpp>
Expand Down Expand Up @@ -211,16 +211,17 @@ namespace nil {
const typename SrcParams::fri_params_type &fri_params
): component_type(witnesses, constants, public_inputs, get_manifest())
{
auto &desc = common_data.desc;
placeholder_info = nil::crypto3::zk::snark::prepare_placeholder_info<typename SrcParams::placeholder_params>(
constraint_system,
common_data, fri_params,
SrcParams::WitnessColumns + SrcParams::PublicInputColumns + SrcParams::ComponentConstantColumns
constraint_system.permuted_columns().size()
);
rows_amount = 100000; // TODO: count rows carefully
vk0 = common_data.vk.constraint_system_with_params_hash;
vk1 = common_data.vk.fixed_values_commitment;
fri_params_r = fri_params.r;
fri_params_lambda = SrcParams::Lambda;
fri_params_lambda = fri_params.lambda;
fri_omega = fri_params.D[0]->get_domain_element(1);
fri_domain_size = fri_params.D[0]->size();
fri_initial_merkle_proof_size = log2(fri_params.D[0]->m) - 1;
Expand Down Expand Up @@ -380,7 +381,7 @@ namespace nil {
for( std::size_t j = 0; j < component.fri_initial_merkle_proof_size; j++){
x_index_input.b.push_back(instance_input.merkle_tree_positions[i][j]);
}
generate_assignments(
typename x_index_component_type::result_type x_index_output = generate_assignments(
x_index_instance, assignment, x_index_input, row
);
row += x_index_instance.rows_amount;
Expand All @@ -403,7 +404,7 @@ namespace nil {
colinear_checks_input.alphas.push_back(challenges.fri_alphas[j]);
colinear_checks_input.bs.push_back(instance_input.merkle_tree_positions[i][instance_input.merkle_tree_positions[i].size() - j - 1]);
}
generate_assignments(
typename colinear_checks_component_type::result_type colinear_checks_output = generate_assignments(
colinear_checks_instance, assignment, colinear_checks_input, row
);
row += colinear_checks_instance.rows_amount;
Expand Down Expand Up @@ -431,14 +432,13 @@ namespace nil {
poseidon_rows += poseidon_instance.rows_amount;
merkle_leaf_rows += poseidon_instance.rows_amount;
}
// std::cout << "Merkle leaf " << var_value(assignment, poseidon_output.output_state[2]) << std::endl;
var hash_var = poseidon_output.output_state[2];
// std::cout << "First hash i = " << i << "; cur_hash = " << cur_hash << " = " << instance_input.initial_proof_hashes[i][cur_hash] << " = " << var_value(assignment, instance_input.initial_proof_hashes[i][cur_hash]) << std::endl;
for( std::size_t k = 0; k < component.fri_initial_merkle_proof_size; k++){
swap_input_type swap_input;
swap_input.arr.push_back({instance_input.merkle_tree_positions[i][k],
instance_input.initial_proof_hashes[i][cur_hash], hash_var});
auto swap_result = assignment.template add_input_to_batch_assignment<swap_component_type, std::size_t>(
auto swap_result = assignment.template add_input_to_batch<swap_component_type, std::size_t>(
swap_input, 1);
poseidon_input = {zero_var, swap_result.output[0].first, swap_result.output[0].second};
poseidon_output = generate_assignments(poseidon_instance, assignment, poseidon_input, row);
Expand Down Expand Up @@ -471,7 +471,7 @@ namespace nil {
swap_input_type swap_input;
swap_input.arr.push_back({instance_input.merkle_tree_positions[i][k],
instance_input.round_proof_hashes[i][cur_hash], hash_var});
auto swap_result = assignment.template add_input_to_batch_assignment<swap_component_type, std::size_t>(
auto swap_result = assignment.template add_input_to_batch<swap_component_type, std::size_t>(
swap_input, 1);
poseidon_input = {zero_var, swap_result.output[0].first, swap_result.output[0].second};
poseidon_output = generate_assignments(poseidon_instance, assignment, poseidon_input, row);
Expand Down Expand Up @@ -621,7 +621,7 @@ namespace nil {
for( std::size_t j = 0; j < component.fri_initial_merkle_proof_size; j++ ){
x_index_input.b.push_back(instance_input.merkle_tree_positions[i][j]);
}
generate_circuit(
typename x_index_component_type::result_type x_index_output = generate_circuit(
x_index_instance, bp, assignment, x_index_input, row
);
row += x_index_instance.rows_amount;
Expand All @@ -643,7 +643,7 @@ namespace nil {
colinear_checks_input.alphas.push_back(challenges.fri_alphas[j]);
colinear_checks_input.bs.push_back(instance_input.merkle_tree_positions[i][instance_input.merkle_tree_positions[i].size() - j - 1]);
}
generate_circuit(
typename colinear_checks_component_type::result_type colinear_checks_output = generate_circuit(
colinear_checks_instance, bp, assignment, colinear_checks_input, row
);
row += colinear_checks_instance.rows_amount;
Expand All @@ -669,7 +669,7 @@ namespace nil {
swap_input_type swap_input;
swap_input.arr.push_back({instance_input.merkle_tree_positions[i][k],
instance_input.initial_proof_hashes[i][cur_hash], hash_var});
auto swap_result = assignment.template add_input_to_batch_circuit<swap_component_type, std::size_t>(
auto swap_result = assignment.template add_input_to_batch<swap_component_type, std::size_t>(
swap_input, 1);
poseidon_input = {zero_var, swap_result.output[0].first, swap_result.output[0].second};
poseidon_output = generate_circuit(poseidon_instance, bp, assignment, poseidon_input, row);
Expand All @@ -683,6 +683,7 @@ namespace nil {
bp.add_copy_constraint({poseidon_output.output_state[2], instance_input.commitments[j-1]});
}
// Compute y-s for first round
std::size_t round_merkle_proof_size = component.fri_initial_merkle_proof_size;
// Round proofs
cur = 0;
cur_hash = 0;
Expand All @@ -700,7 +701,7 @@ namespace nil {
swap_input_type swap_input;
swap_input.arr.push_back({instance_input.merkle_tree_positions[i][k],
instance_input.round_proof_hashes[i][cur_hash], hash_var});
auto swap_result = assignment.template add_input_to_batch_circuit<swap_component_type, std::size_t>(
auto swap_result = assignment.template add_input_to_batch<swap_component_type, std::size_t>(
swap_input, 1);
poseidon_input = {zero_var, swap_result.output[0].first, swap_result.output[0].second};
poseidon_output = generate_circuit(poseidon_instance, bp, assignment, poseidon_input, row);
Expand Down
Loading

0 comments on commit 7cddd34

Please sign in to comment.