Skip to content

Commit

Permalink
parallel zk sync
Browse files Browse the repository at this point in the history
  • Loading branch information
vo-nil committed Dec 12, 2024
1 parent 84009c2 commit c86d3b2
Show file tree
Hide file tree
Showing 24 changed files with 76 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,8 @@ namespace nil {
const auto &table = lookup_tables[t_id];
auto key = std::tuple(table.tag_index, 0, plonk_variable<typename FieldType::value_type>::column_type::selector);
auto shifted_key = std::tuple(table.tag_index, 1, plonk_variable<typename FieldType::value_type>::column_type::selector);
typename FieldType::value_type selector_value = evaluations[key];;
typename FieldType::value_type shifted_selector_value = evaluations[shifted_key];;
typename FieldType::value_type selector_value = evaluations[key];
typename FieldType::value_type shifted_selector_value = evaluations[shifted_key];
for( std::size_t o_id = 0; o_id < table.lookup_options.size(); o_id++){
typename FieldType::value_type v = selector_value * (t_id + 1);
typename FieldType::value_type shifted_v = shifted_selector_value * (t_id + 1);
Expand All @@ -747,7 +747,7 @@ namespace nil {
for( std::size_t g_id = 0; g_id < lookup_gates.size(); g_id++ ){
const auto &gate = lookup_gates[g_id];
auto key = std::tuple(gate.tag_index, 0, plonk_variable<typename FieldType::value_type>::column_type::selector);
typename FieldType::value_type selector_value= evaluations[key];
typename FieldType::value_type selector_value = evaluations[key];
for( std::size_t c_id = 0; c_id < gate.constraints.size(); c_id++){
const auto &constraint = gate.constraints[c_id];
typename FieldType::value_type l = selector_value * constraint.table_id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ namespace nil {
_proof.commitments[VARIABLE_VALUES_BATCH] = _commitment_scheme.commit(VARIABLE_VALUES_BATCH);
}
transcript(_proof.commitments[VARIABLE_VALUES_BATCH]);

// 4. permutation_argument
if( constraint_system.copy_constraints().size() > 0 ){
auto permutation_argument = placeholder_permutation_argument<FieldType, ParamsType>::prove_eval(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ namespace nil {
std::copy(state.begin(), state.begin() + count, data.begin() + data.size() - count);

nil::crypto3::marshalling::status_type status;
big_uint_of_hash_size raw_result =
big_uint_of_hash_size raw_result =
nil::crypto3::marshalling::pack(state, status);
THROW_IF_ERROR_STATUS(status, "fiat_shamir_heuristic_sequential::challenge");
return raw_result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ namespace nil {
typedef typename containers::merkle_tree<MerkleTreeHashType, 2> merkle_tree_type;
typedef typename containers::merkle_proof<MerkleTreeHashType, 2> merkle_proof_type;

using Endianness = nil::marshalling::option::big_endian;
using Endianness = marshalling::option::big_endian;
using field_element_type =
nil::crypto3::marshalling::types::field_element<nil::marshalling::field_type<Endianness>,
nil::crypto3::marshalling::types::field_element<marshalling::field_type<Endianness>,
typename FieldType::value_type>;

using precommitment_type = merkle_tree_type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ namespace nil {
typedef typename containers::merkle_tree<MerkleTreeHashType, 2> merkle_tree_type;
typedef typename containers::merkle_proof<MerkleTreeHashType, 2> merkle_proof_type;

using Endianness = nil::marshalling::option::big_endian;
using Endianness = nil::crypto3::marshalling::option::big_endian;
using field_element_type =
nil::crypto3::marshalling::types::field_element<nil::marshalling::field_type<Endianness>,
nil::crypto3::marshalling::types::field_element<nil::crypto3::marshalling::field_type<Endianness>,
typename FieldType::value_type>;

using precommitment_type = merkle_tree_type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ namespace nil {
// For initial proof only, size of all values are similar
typedef std::vector<polynomial_values_type> polynomials_values_type;

using Endianness = nil::marshalling::option::big_endian;
using Endianness = nil::crypto3::marshalling::option::big_endian;
using field_element_type = nil::crypto3::marshalling::types::field_element<
nil::marshalling::field_type<Endianness>,
nil::crypto3::marshalling::field_type<Endianness>,
typename FieldType::value_type
>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

#include <nil/crypto3/algebra/type_traits.hpp>

#include <nil/crypto3/multiprecision/big_uint.hpp>

namespace nil {
namespace crypto3 {
namespace zk {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ namespace nil {
typename FieldType::value_type acc = alpha;

for (std::size_t i = 0; i <= f_folded.degree(); i++) {
f_folded[i] = two_inversed * ((1u + acc) * f[i] + (1u - acc) * f[domain->size() / 2 + i]);
f_folded[i] = two_inversed * (
(typename FieldType::value_type(1u) + acc) * f[i] +
(typename FieldType::value_type(1u) - acc) * f[domain->size() / 2 + i]);
acc *= omega_inversed;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ namespace nil {
return pow_seed + (std::size_t)pow_value_offset;
}

static inline bool verify(transcript_type &transcript, value_type proof_of_work, std::size_t GrindingBits=16) {
static inline bool verify(transcript_type &transcript, value_type proof_of_work, std::size_t GrindingBits = 16) {
transcript(proof_of_work);
integral_type mask =
(GrindingBits > 0 ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ namespace nil {
using transcript_hash_type = typename CommitmentSchemeType::transcript_hash_type;
using polynomial_type = typename CommitmentSchemeType::polynomial_type;
using proof_type = typename CommitmentSchemeType::proof_type;
using endianness = nil::marshalling::option::big_endian;
using endianness = nil::crypto3::marshalling::option::big_endian;
private:
params_type _params;
std::map<std::size_t, commitment_type> _commitments;
Expand Down Expand Up @@ -756,9 +756,9 @@ namespace nil {
_params,
this->_polys[index][i]);
this->_ind_commitments[index].push_back(single_commitment);
nil::marshalling::status_type status;
nil::crypto3::marshalling::status_type status;
std::vector<uint8_t> single_commitment_bytes =
nil::marshalling::pack<endianness>(single_commitment, status);
nil::crypto3::marshalling::pack<endianness>(single_commitment, status);
THROW_IF_ERROR_STATUS(status, "kzg::commit");
result.insert(result.end(), single_commitment_bytes.begin(), single_commitment_bytes.end());
}
Expand Down Expand Up @@ -843,9 +843,9 @@ namespace nil {
for (std::size_t j = 0; j < blob_size; j++) {
byteblob[j] = this->_commitments.at(k)[i * blob_size + j];
}
nil::marshalling::status_type status;
nil::crypto3::marshalling::status_type status;
typename curve_type::template g1_type<>::value_type
i_th_commitment = nil::marshalling::pack(byteblob, status);
i_th_commitment = nil::crypto3::marshalling::pack(byteblob, status);
THROW_IF_ERROR_STATUS(status, "kzg::verify_eval");
auto U_commit = nil::crypto3::zk::algorithms::commit_one<CommitmentSchemeType>
(_params, this->get_U(k, i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ namespace nil {
}
};

using endianness = nil::marshalling::option::big_endian;
using endianness = marshalling::option::big_endian;
using field_element_type = nil::crypto3::marshalling::types::field_element<
nil::marshalling::field_type<endianness>,
marshalling::field_type<endianness>,
commitment_type
>;
private:
Expand Down Expand Up @@ -208,9 +208,9 @@ namespace nil {
});
std::vector<std::uint8_t> result;
for (const auto& single_commitment : this->_ind_commitments[index]) {
nil::marshalling::status_type status;
nil::crypto3::marshalling::status_type status;
std::vector<uint8_t> single_commitment_bytes =
nil::marshalling::pack<endianness>(single_commitment, status);
marshalling::pack<endianness>(single_commitment, status);
THROW_IF_ERROR_STATUS(status, "kzg_v2::commit");
result.insert(result.end(), single_commitment_bytes.begin(), single_commitment_bytes.end());
}
Expand Down Expand Up @@ -332,7 +332,7 @@ namespace nil {
auto F = CommitmentSchemeType::single_commitment_type::zero();
auto rsum = CommitmentSchemeType::scalar_value_type::zero();

nil::marshalling::status_type status;
marshalling::status_type status;

for (const auto &it: this->_commitments) {
auto k = it.first;
Expand All @@ -344,7 +344,7 @@ namespace nil {
byteblob[j] = this->_commitments[k][i * blob_size + j];
}
typename curve_type::template g1_type<>::value_type
cm_i = nil::marshalling::pack(byteblob, status);
cm_i = marshalling::pack(byteblob, status);
THROW_IF_ERROR_STATUS(status, "kzg_v2::verify_eval");
auto Z_T_S_i = set_difference_polynom(_merged_points, this->_points.at(k)[i]).evaluate(
theta_2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ namespace nil {
, _fixed_polys_values(fixed_polys_values)
{
}


lpc_commitment_scheme(const typename fri_type::params_type &fri_params)
: _fri_params(fri_params), _etha(0u) {
}
Expand Down Expand Up @@ -172,6 +172,7 @@ namespace nil {

BOOST_ASSERT(this->_points.size() == this->_polys.size());
BOOST_ASSERT(this->_points.size() == this->_z.get_batches_num());

// For each batch we have a merkle tree.
for (auto const& it: this->_trees) {
transcript(it.second.root());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,6 @@ namespace nil {
return _public_inputs;
}

public_input_container_type move_public_inputs() {
return std::move(_public_inputs);
}

std::uint32_t constants_amount() const {
return _constants.size();
}
Expand All @@ -233,10 +229,6 @@ namespace nil {
return _constants;
}

constant_container_type move_constants() {
return std::move(_constants);
}

constexpr std::uint32_t selectors_amount() const {
return _selectors.size();
}
Expand Down Expand Up @@ -489,14 +481,14 @@ namespace nil {
return _private_table;
}

std::shared_ptr<private_table_type> move_private_table() {
return std::move(_private_table);
}

std::shared_ptr<public_table_type> public_table() const {
return _public_table;
}

std::shared_ptr<private_table_type> move_private_table() {
return std::move(_private_table);
}

std::shared_ptr<public_table_type> move_public_table() {
return std::move(_public_table);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ namespace nil {
namespace crypto3 {
namespace zk {
namespace snark {

/************************* PLONK constraint system ****************************/
constexpr static std::size_t const PLONK_SPECIAL_SELECTOR_ALL_USABLE_ROWS_SELECTED = std::numeric_limits<std::size_t>::max();
constexpr static std::size_t const PLONK_SPECIAL_SELECTOR_ALL_NON_FIRST_USABLE_ROWS_SELECTED = std::numeric_limits<std::size_t>::max() - 1; // Useful for lookup tables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ namespace nil {

template<typename FieldType>
math::polynomial_dfs<typename FieldType::value_type>
column_polynomial_dfs(plonk_column<FieldType> column_assignment,
column_polynomial_dfs(const plonk_column<FieldType>& column_assignment,
std::shared_ptr<math::evaluation_domain<FieldType>> domain) {

std::size_t d = std::distance(column_assignment.begin(), column_assignment.end()) - 1;
Expand All @@ -110,15 +110,15 @@ namespace nil {

template<typename FieldType>
std::vector<math::polynomial_dfs<typename FieldType::value_type>>
column_range_polynomial_dfs(std::vector<plonk_column<FieldType>> column_range_assignment,
column_range_polynomial_dfs(const std::vector<plonk_column<FieldType>>& column_range_assignment,
std::shared_ptr<math::evaluation_domain<FieldType>> domain) {

std::size_t columns_amount = column_range_assignment.size();
std::vector<math::polynomial_dfs<typename FieldType::value_type>> columns(columns_amount);

for (std::size_t column_index = 0; column_index < columns_amount; column_index++) {
columns[column_index] =
column_polynomial_dfs<FieldType>(std::move(column_range_assignment[column_index]), domain);
column_polynomial_dfs<FieldType>(column_range_assignment[column_index], domain);
}

return columns;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace nil {
plonk_lookup_table<FieldType> lookup_table;
std::string name;

dynamic_table_definition(std::string _name): name(_name), defined(false) {}
dynamic_table_definition(std::string _name): defined(false), name(_name) {}

void define(const plonk_lookup_table<FieldType> &table){
BOOST_ASSERT(!defined);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,30 @@ namespace nil {
padded_rows_amount = 8;

for (std::uint32_t w_index = 0; w_index <
table._private_table.witnesses_amount(); w_index++) {
table._private_table->witnesses_amount(); w_index++) {

table._private_table._witnesses[w_index].resize(padded_rows_amount,
table._private_table->_witnesses[w_index].resize(padded_rows_amount,
FieldType::value_type::zero());
}

for (std::uint32_t pi_index = 0; pi_index <
table._public_table.public_inputs_amount(); pi_index++) {
table._public_table->public_inputs_amount(); pi_index++) {

table._public_table._public_inputs[pi_index].resize(padded_rows_amount,
table._public_table->_public_inputs[pi_index].resize(padded_rows_amount,
FieldType::value_type::zero());
}

for (std::uint32_t c_index = 0; c_index <
table._public_table.constants_amount(); c_index++) {
table._public_table->constants_amount(); c_index++) {

table._public_table._constants[c_index].resize(padded_rows_amount,
table._public_table->_constants[c_index].resize(padded_rows_amount,
FieldType::value_type::zero());
}

for (std::uint32_t s_index = 0; s_index <
table._public_table.selectors_amount(); s_index++) {
table._public_table->selectors_amount(); s_index++) {

table._public_table._selectors[s_index].resize(padded_rows_amount,
table._public_table->_selectors[s_index].resize(padded_rows_amount,
FieldType::value_type::zero());
}

Expand Down Expand Up @@ -124,7 +124,6 @@ namespace nil {
table._private_table->_witnesses[w_index][i] = alg_rnd();
}
}

return padded_rows_amount;
}
} // namespace snark
Expand Down
Loading

0 comments on commit c86d3b2

Please sign in to comment.