Skip to content

Commit

Permalink
Updated placeholder and hashes. (#321)
Browse files Browse the repository at this point in the history
* Moved large function from lookup_argument to constraint_system, fixed bug in evaluation points#320

* Adjust basic batched fri to refactored consumer

---------

Co-authored-by: x-mass <[email protected]>
  • Loading branch information
ETatuzova and x-mass authored May 7, 2024
1 parent d6ea7e2 commit f8f66ae
Show file tree
Hide file tree
Showing 10 changed files with 292 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,13 @@ namespace nil {
const std::shared_ptr <math::evaluation_domain<FieldType>> &D) {

using namespace algorithms;
std::vector <std::array<detail::leaf_data_type<FRI>, detail::leaf_data_size_multiplier<FRI> * list_size>> y_data;
std::vector<
::nil::crypto3::zk::detail::field_element_consumer<
FieldType,
MerkleTreeHashType,
field_element_type
>
> y_data;
y_data.resize(D->m);
std::array <std::vector<typename FieldType::value_type>, list_size> poly_dfs;
for (std::size_t i = 0; i < list_size; i++) {
Expand All @@ -139,9 +145,9 @@ namespace nil {
}

for (std::size_t i = 0; i < D->m; i++) {
auto& consumer = y_data[i];
for (std::size_t j = 0; j < list_size; j++) {
auto write_iter = y_data[i].begin() + detail::leaf_data_size_multiplier<FRI> * j;
detail::write_field_element_to_iter<FRI>(write_iter, poly_dfs[j][i]);
consumer.consume(poly_dfs[j][i]);
}
}

Expand Down Expand Up @@ -271,6 +277,12 @@ namespace nil {
V,
transcript_type &transcript = transcript_type()) {

using fri_field_element_consumer = ::nil::crypto3::zk::detail::field_element_consumer<
FieldType,
MerkleTreeHashType,
field_element_type
>;

std::uint64_t idx = transcript.template int_challenge<std::uint64_t>();
typename FieldType::value_type x = fri_params.D[0]->get_domain_element(1).pow(idx);

Expand All @@ -294,21 +306,18 @@ namespace nil {

for (std::size_t j = 0; j < m; j++) {

std::array < detail::leaf_data_type<FRI>, detail::leaf_data_size_multiplier<FRI> * leaf_size > leaf_data;
fri_field_element_consumer leaf_data(leaf_size);

for (std::size_t polynom_index = 0; polynom_index < leaf_size; polynom_index++) {
auto write_iter =
leaf_data.begin() + detail::leaf_data_size_multiplier<FRI> * polynom_index;
detail::write_field_element_to_iter<FRI>(write_iter, proof.round_proofs[i].y[polynom_index][j]);
leaf_data.consume(proof.round_proofs[i].y[polynom_index][j]);
}

if (!proof.round_proofs[i].p[j].validate(leaf_data)) {
return false;
}
}

std::array < detail::leaf_data_type<FRI>, detail::leaf_data_size_multiplier<FRI> * leaf_size > leaf_data;

fri_field_element_consumer leaf_data(leaf_size);
for (std::size_t polynom_index = 0; polynom_index < leaf_size; polynom_index++) {

std::array<typename FieldType::value_type, m> y;
Expand All @@ -333,12 +342,10 @@ namespace nil {
math::polynomial<typename FieldType::value_type> interpolant =
math::lagrange_interpolation(interpolation_points);

typename FieldType::value_type leaf =
typename FieldType::value_type& leaf =
proof.round_proofs[i].colinear_value[polynom_index];

field_element_type leaf_val(leaf);
auto write_iter = leaf_data.begin() + field_element_type::length() * polynom_index;
detail::write_field_element_to_iter<FRI>(write_iter, leaf);
leaf_data.consume(leaf);

if (interpolant.evaluate(alpha) !=
proof.round_proofs[i].colinear_value[polynom_index]) {
Expand Down Expand Up @@ -378,6 +385,11 @@ namespace nil {
U,
const math::polynomial<typename FieldType::value_type> V,
transcript_type &transcript = transcript_type()) {
using fri_field_element_consumer = ::nil::crypto3::zk::detail::field_element_consumer<
FieldType,
MerkleTreeHashType,
field_element_type
>;

std::uint64_t idx = transcript.template int_challenge<std::uint64_t>();
typename FieldType::value_type x = fri_params.D[0]->get_domain_element(1).pow(idx);
Expand All @@ -401,23 +413,21 @@ namespace nil {
}

for (std::size_t j = 0; j < m; j++) {
std::array < detail::leaf_data_type<FRI>, detail::leaf_data_size_multiplier<FRI> * leaf_size > leaf_data;
fri_field_element_consumer leaf_data(leaf_size);

for (std::size_t polynom_index = 0; polynom_index < leaf_size; polynom_index++) {

typename FieldType::value_type leaf = proof.round_proofs[i].y[polynom_index][j];
typename FieldType::value_type& leaf = proof.round_proofs[i].y[polynom_index][j];

auto write_iter =
leaf_data.begin() + detail::leaf_data_size_multiplier<FRI> * polynom_index;
detail::write_field_element_to_iter<FRI>(write_iter, leaf);
leaf_data.consume(leaf);
}

if (!proof.round_proofs[i].p[j].validate(leaf_data)) {
return false;
}
}

std::array < detail::leaf_data_type<FRI>, detail::leaf_data_size_multiplier<FRI> * leaf_size > leaf_data;
fri_field_element_consumer leaf_data(leaf_size);

for (std::size_t polynom_index = 0; polynom_index < leaf_size; polynom_index++) {

Expand All @@ -443,11 +453,10 @@ namespace nil {
math::polynomial<typename FieldType::value_type> interpolant =
math::lagrange_interpolation(interpolation_points);

typename FieldType::value_type leaf =
typename FieldType::value_type& leaf =
proof.round_proofs[i].colinear_value[polynom_index];

auto write_iter = leaf_data.begin() + detail::leaf_data_size_multiplier<FRI> * polynom_index;
detail::write_field_element_to_iter<FRI>(write_iter, leaf);
leaf_data.consume(leaf);

if (interpolant.evaluate(alpha) !=
proof.round_proofs[i].colinear_value[polynom_index]) {
Expand Down Expand Up @@ -485,6 +494,11 @@ namespace nil {
const math::polynomial<typename FieldType::value_type> U,
const math::polynomial<typename FieldType::value_type> V,
transcript_type &transcript = transcript_type()) {
using fri_field_element_consumer = ::nil::crypto3::zk::detail::field_element_consumer<
FieldType,
MerkleTreeHashType,
field_element_type
>;

std::size_t idx = transcript.template int_challenge<std::size_t>();
typename FieldType::value_type x = fri_params.D[0]->get_domain_element(1).pow(idx);
Expand All @@ -508,24 +522,22 @@ namespace nil {
}

for (std::size_t j = 0; j < m; j++) {
std::array < detail::leaf_data_type<FRI>, detail::leaf_data_size_multiplier<FRI> * leaf_size > leaf_data;
fri_field_element_consumer leaf_data(leaf_size);

for (std::size_t polynom_index = 0; polynom_index < leaf_size;
polynom_index++) {

typename FieldType::value_type leaf = proof.round_proofs[i].y[polynom_index][j];
typename FieldType::value_type& leaf = proof.round_proofs[i].y[polynom_index][j];

auto write_iter = leaf_data.begin() +
detail::leaf_data_size_multiplier<FRI> * polynom_index;
detail::write_field_element_to_iter<FRI>(write_iter, leaf);
leaf_data.consume(leaf);
}

if (!proof.round_proofs[i].p[j].validate(leaf_data)) {
return false;
}
}

std::array < detail::leaf_data_type<FRI>, detail::leaf_data_size_multiplier<FRI> * leaf_size > leaf_data;
fri_field_element_consumer leaf_data(leaf_size);

for (std::size_t polynom_index = 0; polynom_index < leaf_size;
polynom_index++) {
Expand All @@ -552,10 +564,9 @@ namespace nil {
math::polynomial<typename FieldType::value_type> interpolant =
math::lagrange_interpolation(interpolation_points);

typename FieldType::value_type leaf = proof.round_proofs[i].colinear_value[polynom_index];
typename FieldType::value_type& leaf = proof.round_proofs[i].colinear_value[polynom_index];

auto write_iter = leaf_data.begin() + detail::leaf_data_size_multiplier<FRI> * polynom_index;
detail::write_field_element_to_iter<FRI>(write_iter, leaf);
leaf_data.consume(leaf);

if (interpolant.evaluate(alpha) !=
proof.round_proofs[i].colinear_value[polynom_index]) {
Expand Down
Loading

0 comments on commit f8f66ae

Please sign in to comment.