Skip to content

Commit

Permalink
Reflect changes from actor-zk project #216 (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
vo-nil authored Nov 3, 2023
1 parent 6405647 commit 623ec86
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 29 deletions.
21 changes: 14 additions & 7 deletions include/nil/crypto3/zk/commitments/batched_commitment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ namespace nil {
std::map<std::size_t, std::vector<std::vector<typename field_type::value_type>>> _points;

protected:
math::polynomial<typename field_type::value_type> get_V(const std::vector<typename field_type::value_type> &points) const{
math::polynomial<typename field_type::value_type> get_V(
const std::vector<typename field_type::value_type> &points) const {

math::polynomial<typename field_type::value_type> V = {1};
for( std::size_t xi_index = 0; xi_index < points.size(); xi_index++ ){
V *= math::polynomial<typename field_type::value_type>({-points[xi_index], 1});
Expand All @@ -87,8 +89,8 @@ namespace nil {
return V_multipliers;
}

math::polynomial<typename field_type::value_type> get_U(std::size_t b_ind, std::size_t poly_ind) const {

math::polynomial<typename field_type::value_type> get_U(std::size_t b_ind, std::size_t poly_ind) const{
const auto &points = _points.at(b_ind)[poly_ind];
BOOST_ASSERT(points.size() == this->_z.get_poly_points_number(b_ind, poly_ind));
std::vector<std::pair<typename field_type::value_type,typename field_type::value_type>> U_interpolation_points;
Expand Down Expand Up @@ -145,19 +147,24 @@ namespace nil {
_locked[index] = true;
_points[index].resize(_polys[index].size());
}
void eval_polys(){
for(auto const &[k, poly] : _polys){

void eval_polys() {
for(auto const &[k, poly] : _polys) {
_z.set_batch_size(k, poly.size());
auto const &point = _points.at(k);

BOOST_ASSERT(poly.size() == point.size() || point.size() == 1);
for( std::size_t i = 0; i < poly.size(); i++ ){

for (std::size_t i = 0; i < poly.size(); i++) {
_z.set_poly_points_number(k, i, point[i].size());
for(std::size_t j = 0; j < point[i].size(); j++){

for (std::size_t j = 0; j < point[i].size(); j++) {
_z.set(k, i, j, poly[i].evaluate(point[i][j]));
}
}
}
}

public:
boost::property_tree::ptree get_params() const{
boost::property_tree::ptree root;
Expand Down Expand Up @@ -228,7 +235,7 @@ namespace nil {
SchemeType &scheme,
typename SchemeType::transcript_type &transcript,
const typename SchemeType::preprocessed_data_type preprocessed_data
){
) {
return scheme.setup(transcript, preprocessed_data);
}

Expand Down
2 changes: 0 additions & 2 deletions include/nil/crypto3/zk/commitments/polynomial/kzg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@

#include <nil/crypto3/zk/transcript/fiat_shamir.hpp>
#include <nil/crypto3/math/polynomial/polynomial.hpp>
#include <nil/crypto3/math/polynomial/polynomial.hpp>

#include <nil/crypto3/zk/commitments/batched_commitment.hpp>

Expand Down Expand Up @@ -603,7 +602,6 @@ namespace nil {
auto right_side_pairing = algebra::pair_reduced<typename KZG::curve_type>(proof, right);

return left_side_pairing == right_side_pairing;
// return true;
}
} // namespace algorithms

Expand Down
8 changes: 4 additions & 4 deletions include/nil/crypto3/zk/commitments/polynomial/lpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace nil {
using poly_type = PolynomialType;
using lpc = LPCScheme;
using eval_storage_type = typename LPCScheme::eval_storage_type;
using preprocessed_data_type = std::map<std::size_t, std::vector<typename field_type::value_type>>;
using preprocessed_data_type = std::map<std::size_t, std::vector<value_type>>;

private:
std::map<std::size_t, precommitment_type> _trees;
Expand Down Expand Up @@ -149,7 +149,7 @@ namespace nil {
math::polynomial<value_type> U = this->get_U(b_ind, poly_ind);

math::polynomial<value_type> g_normal(this->_polys[b_ind][poly_ind].coefficients());
math::polynomial<value_type> Q = g_normal - this->get_U(b_ind, poly_ind);
math::polynomial<value_type> Q = g_normal - U;

for (const auto& V_mult: V_multipliers) {
Q /= V_mult;
Expand Down Expand Up @@ -264,10 +264,10 @@ namespace nil {

for( auto const &it: this->_points){
auto k = it.first;
for(std::size_t i = 0; i < proof.z.get_batch_size(k); i++) {
for (std::size_t i = 0; i < proof.z.get_batch_size(k); i++) {
combined_U[point_index] *= theta;
if (eval_map[k][i] == point_index) {
combined_U[point_index] += this->get_U(k,i);
combined_U[point_index] += this->get_U(k, i);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions include/nil/crypto3/zk/math/non_linear_combination.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ namespace nil {
}
this->terms.clear();
for (const auto& it: unique_terms) {
if (it.second != assignment_type::zero())
{
if (it.second != assignment_type::zero()) {
this->terms.emplace_back(it.first.get_vars(), it.second);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace nil {
namespace crypto3 {
namespace zk {
namespace snark {
namespace detail {
namespace detail {
// Interf-ace for lookup table definitions.
template<typename FieldType>
class lookup_subtable_definition{
Expand All @@ -53,7 +53,7 @@ namespace nil {

lookup_table_definition(const std::string table_name){
this->table_name = table_name;
}
}

virtual void generate() = 0;
virtual std::size_t get_columns_number() = 0;
Expand Down Expand Up @@ -89,7 +89,7 @@ namespace nil {
template<typename FieldType, typename ArithmetizationParams>
std::size_t pack_lookup_tables(
const std::map<std::string, std::size_t> &lookup_table_ids,
const std::map<std::string, std::shared_ptr<lookup_table_definition<FieldType>>> &lookup_tables,
const std::map<std::string, std::shared_ptr<lookup_table_definition<FieldType>>> &lookup_tables,
plonk_constraint_system<FieldType, ArithmetizationParams> &bp,
plonk_assignment_table<FieldType, ArithmetizationParams> &assignment,
const std::vector<std::size_t> &constant_columns_ids,
Expand Down Expand Up @@ -119,10 +119,11 @@ namespace nil {
for( const auto&[k, table]:lookup_tables ){
// Place table into constant_columns.
for( std::size_t i = 0; i < table->get_table().size(); i++ ){
if(constant_columns[i].size() < start_row + table->get_table()[i].size()){
constant_columns[i].resize(start_row + table->get_table()[i].size());
if( usable_rows_after < start_row + table->get_table()[i].size() ){
usable_rows_after = start_row + table->get_table()[i].size();
auto end = start_row + table->get_table()[i].size();
if(constant_columns[i].size() < end){
constant_columns[i].resize(end);
if( usable_rows_after < end ){
usable_rows_after = end;
}
}
for( std::size_t j = 0; j < table->get_table()[i].size(); j++ ){
Expand All @@ -142,7 +143,7 @@ namespace nil {
std::vector<plonk_variable<typename FieldType::value_type>> option;
for( const auto &column_index:subtable.column_indices ){
option.emplace_back( plonk_variable<typename FieldType::value_type>(
constant_columns_ids[column_index], 0,
constant_columns_ids[column_index], 0,
false, plonk_variable<typename FieldType::value_type>::column_type::constant
) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ namespace nil {
}

placeholder_proof<FieldType, ParamsType> process() {
PROFILE_PLACEHOLDER_SCOPE("Placeholder prover, total time");
PROFILE_PLACEHOLDER_SCOPE("Placeholder prover, total time:");

// 2. Commit witness columns and public_input columns
_commitment_scheme.append_to_batch(VARIABLE_VALUES_BATCH, _polynomial_table.witnesses());
Expand Down
2 changes: 2 additions & 0 deletions test/systems/plonk/placeholder/performance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ class placeholder_performance_test : public placeholder_performance_test_base {

compute_columns_rotations();

std::cout << "rows_amount = " << table_description.rows_amount << std::endl;

std::size_t table_rows_log = std::ceil(std::log2(table_description.rows_amount));
typename lpc_type::fri_type::params_type fri_params =
create_fri_params<typename lpc_type::fri_type, field_type>(table_rows_log);
Expand Down
8 changes: 3 additions & 5 deletions test/systems/plonk/placeholder/placeholder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,11 +619,9 @@ BOOST_AUTO_TEST_CASE(permutation_argument_test) {
for (int i = 0; i < argument_size; i++) {
BOOST_CHECK(prover_res.F_dfs[i].evaluate(y) == verifier_res[i]);
for (std::size_t j = 0; j < desc.rows_amount; j++) {
if(prover_res.F_dfs[i].evaluate(preprocessed_public_data.common_data.basic_domain->get_domain_element(j)) != 0){
BOOST_CHECK(
prover_res.F_dfs[i].evaluate(preprocessed_public_data.common_data.basic_domain->get_domain_element(j)) == field_type::value_type::zero()
);
}
BOOST_CHECK(
prover_res.F_dfs[i].evaluate(preprocessed_public_data.common_data.basic_domain->get_domain_element(j)) == field_type::value_type::zero()
);
}
}
}
Expand Down

0 comments on commit 623ec86

Please sign in to comment.