Skip to content

Commit

Permalink
Fixing the tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
martun committed Sep 15, 2024
1 parent bc2b5d5 commit a92f582
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 57 deletions.
3 changes: 2 additions & 1 deletion crypto3/libs/blueprint/test/zkevm/opcodes/iszero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#include <boost/test/unit_test.hpp>

#include <nil/blueprint/zkevm/zkevm_machine_interface.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/goldilocks64.hpp>

#include <nil/blueprint/blueprint/plonk/circuit.hpp>
Expand All @@ -35,6 +34,8 @@
#include <nil/blueprint/zkevm/zkevm_circuit.hpp>
#include "../opcode_tester.hpp"

#include <nil/blueprint/zkevm/operations/iszero.hpp>

using namespace nil::blueprint;
using namespace nil::crypto3::algebra;

Expand Down
5 changes: 2 additions & 3 deletions crypto3/libs/blueprint/test/zkevm/opcodes/mul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@
#include <nil/blueprint/blueprint/plonk/assignment.hpp>

#include <nil/blueprint/zkevm/zkevm_circuit.hpp>
#include <nil/blueprint/zkevm/zkevm_operation.hpp>
#include <nil/blueprint/zkevm/operations/mul.hpp>

#include "../opcode_tester.hpp"

#include <nil/blueprint/zkevm/operations/mul.hpp>

using namespace nil::blueprint;
using namespace nil::crypto3::algebra;

Expand Down
14 changes: 7 additions & 7 deletions crypto3/libs/containers/test/merkle/merkle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@

#define BOOST_TEST_MODULE containter_merkletree_test

#include <chrono>
#include <cstdio>
#include <limits>
#include <type_traits>
#include <cstdint>

#include <nil/crypto3/algebra/random_element.hpp>
#include <nil/crypto3/algebra/type_traits.hpp>
#include <nil/crypto3/hash/block_to_field_elements_wrapper.hpp>
Expand All @@ -41,7 +35,6 @@
#include <nil/crypto3/hash/keccak.hpp>
#include <nil/crypto3/hash/pedersen.hpp>
#include <nil/crypto3/hash/poseidon.hpp>
#include <nil/crypto3/hash/algorithm/hash.hpp>

#include <nil/crypto3/container/merkle/tree.hpp>
#include <nil/crypto3/container/merkle/proof.hpp>
Expand All @@ -50,6 +43,13 @@
#include <boost/test/data/test_case.hpp>
#include <boost/test/data/monomorphic.hpp>

#include <chrono>
#include <cstdio>
#include <cstdint>
#include <limits>
#include <type_traits>
#include <nil/crypto3/hash/algorithm/hash.hpp>

using namespace nil::crypto3;
using namespace nil::crypto3::containers;

Expand Down
13 changes: 7 additions & 6 deletions crypto3/libs/hash/test/crc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@

#define BOOST_TEST_MODULE crc_test

#include <iostream>
#include <string>
#include <cassert>
#include <cstdint>
#include <unordered_map>

#include <nil/crypto3/hash/algorithm/hash.hpp>

#include <nil/crypto3/hash/crc.hpp>
#include <nil/crypto3/hash/hash_state.hpp>

Expand All @@ -24,6 +19,12 @@
#include <boost/test/data/test_case.hpp>
#include <boost/test/data/monomorphic.hpp>

#include <iostream>
#include <string>
#include <cassert>
#include <cstdint>
#include <unordered_map>

using namespace nil::crypto3;
using namespace nil::crypto3::hashes;
using namespace nil::crypto3::accumulators;
Expand Down
12 changes: 6 additions & 6 deletions crypto3/libs/hash/test/tiger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@

#define BOOST_TEST_MODULE tiger_test

#include <iostream>
#include <string>
#include <unordered_map>
#include <cstdio>
#include <cstdint>

#include <nil/crypto3/hash/algorithm/hash.hpp>
#include <nil/crypto3/hash/adaptor/hashed.hpp>

Expand All @@ -45,6 +39,12 @@

#include <boost/static_assert.hpp>

#include <iostream>
#include <string>
#include <unordered_map>
#include <cstdio>
#include <cstdint>

using namespace nil::crypto3;
using namespace nil::crypto3::accumulators;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifndef CRYPTO3_CPP_INT_MODULAR_HPP
#define CRYPTO3_CPP_INT_MODULAR_HPP

#include <cstdint>

// Suddenly, BOOST_MP_ASSERT is NOT BOOST_MP_CXX14_CONSTEXPR, and it is used in BOOST_MP_CXX14_CONSTEXPR functions throughout the boost, resulting to compilation errors on all compilers in debug mode. We need to switch assertions off inside cpp_int to make this code compile in debug mode. So we use this workaround to turn off file 'boost/multiprecision/detail/assert.hpp' which contains definition of BOOST_MP_ASSERT and BOOST_MP_ASSERT_MSG.

#include <boost/multiprecision/detail/number_base.hpp> // for BOOST_MP_IS_CONST_EVALUATED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace nil {
template<typename FieldType, typename ColumnType>
class plonk_private_table {
public:
using column_type = ColumnType;
using witnesses_container_type = std::vector<ColumnType>;
using VariableType = plonk_variable<ColumnType>;

Expand Down Expand Up @@ -151,6 +152,7 @@ namespace nil {
template<typename FieldType, typename ColumnType>
class plonk_public_table {
public:
using column_type = ColumnType;
using public_input_container_type = std::vector<ColumnType>;
using constant_container_type = std::vector<ColumnType>;
using selector_container_type = std::vector<ColumnType>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ namespace nil {
return evaluator.evaluate();
}

typename VariableType::assignment_type evaluate(detail::plonk_evaluation_map<VariableType> &assignments) const {
typename VariableType::assignment_type
evaluate(detail::plonk_evaluation_map<VariableType> &assignments) const {

math::expression_evaluator<VariableType> evaluator(
*this,
[&assignments](const VariableType &var) -> const typename VariableType::assignment_type& {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ namespace nil {
const std::vector<std::size_t> &constant_columns_ids,
std::size_t usable_rows
){
// std::cout << "Packing lookup tables" << std::endl;
// std::cout << "Usable rows before: " << usable_rows << std::endl;
std::size_t usable_rows_after = usable_rows;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ namespace nil {
std::vector<math::polynomial_dfs<typename FieldType::value_type>> h_v = S_sigma;
BOOST_ASSERT(global_indices.size() == S_id.size());
BOOST_ASSERT(global_indices.size() == S_sigma.size());

for (std::size_t i = 0; i < S_id.size(); i++) {
BOOST_ASSERT(column_polynomials[global_indices[i]].size() == basic_domain->size());
BOOST_ASSERT(S_id[i].size() == basic_domain->size());
Expand All @@ -122,6 +123,7 @@ namespace nil {
}

V_P[0] = FieldType::value_type::one();

for (std::size_t j = 1; j < basic_domain->size(); j++) {
typename FieldType::value_type nom = FieldType::value_type::one();
typename FieldType::value_type denom = FieldType::value_type::one();
Expand Down Expand Up @@ -191,16 +193,19 @@ namespace nil {
F_dfs[1] -= preprocessed_data.q_blind;
F_dfs[1] *= V_P_shifted;
} else {
PROFILE_SCOPE("PERMUTATION ARGUMENT else block");
math::polynomial_dfs<typename FieldType::value_type> previous_poly = V_P;
math::polynomial_dfs<typename FieldType::value_type> current_poly = V_P;
for( std::size_t i = 0; i < preprocessed_data.common_data.permutation_parts-1; i++ ){
auto g = gs[i];
auto h = hs[i];
const auto& g = gs[i];
const auto& h = hs[i];
auto reduced_g = reduce_dfs_polynomial_domain(g, basic_domain->m);
auto reduced_h = reduce_dfs_polynomial_domain(h, basic_domain->m);

for(std::size_t j = 0; j < preprocessed_data.common_data.desc.usable_rows_amount; j++){
current_poly[j] = (previous_poly[j] * reduced_g[j]) * reduced_h[j].inversed();
}

commitment_scheme.append_to_batch(PERMUTATION_BATCH, current_poly);
auto part = permutation_alphas[i] * (previous_poly * g - current_poly * h);
F_dfs[1] += part;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ namespace nil {

template<typename FieldType, typename ParamsType>
class placeholder_public_preprocessor {
typedef detail::placeholder_policy<FieldType, ParamsType> policy_type;
typedef typename plonk_constraint<FieldType>::variable_type variable_type;
typedef typename math::polynomial<typename FieldType::value_type> polynomial_type;
typedef typename math::polynomial_dfs<typename FieldType::value_type> polynomial_dfs_type;
using policy_type = detail::placeholder_policy<FieldType, ParamsType>;
using variable_type = typename plonk_constraint<FieldType>::variable_type;
using value_type = typename FieldType::value_type;
using polynomial_type = typename math::polynomial<value_type>;
using polynomial_dfs_type = typename math::polynomial_dfs<value_type>;
using params_type = ParamsType;
using commitment_scheme_type = typename params_type::commitment_scheme_type;
using commitment_type = typename commitment_scheme_type::commitment_type;
Expand All @@ -79,15 +80,21 @@ namespace nil {
static std::size_t permutation_partitions_num(
std::size_t permutation_size,
std::size_t max_quotient_chunks
){
if( permutation_size == 0 ) return 0;
if( max_quotient_chunks == 0 ){
) {
if (permutation_size == 0) return 0;
if (max_quotient_chunks == 0) {
return 1;
}
return (permutation_size % (max_quotient_chunks - 1) == 0)? permutation_size / (max_quotient_chunks - 1) : permutation_size / (max_quotient_chunks - 1) + 1;
return (permutation_size % (max_quotient_chunks - 1) == 0) ?
permutation_size / (max_quotient_chunks - 1) :
permutation_size / (max_quotient_chunks - 1) + 1;
}

struct preprocessed_data_type {
// Used in marshalling.
using plonk_public_polynomial_dfs_table_type = plonk_public_polynomial_dfs_table<FieldType>;
using polynomial_dfs_type = typename math::polynomial_dfs<typename FieldType::value_type>;

struct public_commitments_type {
commitment_type fixed_values;

Expand Down Expand Up @@ -155,6 +162,8 @@ namespace nil {
std::uint32_t permutation_parts;
std::uint32_t lookup_parts;

common_data_type(const common_data_type& other) = default;

// Constructor with pregenerated domain
common_data_type(
std::shared_ptr<math::evaluation_domain<FieldType>> D,
Expand Down Expand Up @@ -253,17 +262,30 @@ namespace nil {
}
};

plonk_public_polynomial_dfs_table<FieldType> public_polynomial_table;
bool operator==(const preprocessed_data_type &rhs) const {
return public_polynomial_table == rhs.public_polynomial_table &&
permutation_polynomials == rhs.permutation_polynomials &&
identity_polynomials == rhs.identity_polynomials &&
q_last == rhs.q_last &&
q_blind == rhs.q_blind &&
common_data == rhs.common_data;
}

bool operator!=(const preprocessed_data_type &rhs) const {
return !(rhs == *this);
}

plonk_public_polynomial_dfs_table_type public_polynomial_table;

// S_sigma
std::vector<polynomial_dfs_type> permutation_polynomials;
// S_id
std::vector<polynomial_dfs_type> identity_polynomials;

polynomial_dfs_type q_last;
polynomial_dfs_type q_blind;
polynomial_dfs_type q_last;
polynomial_dfs_type q_blind;

common_data_type common_data;
common_data_type common_data;
};

private:
Expand Down Expand Up @@ -499,7 +521,8 @@ namespace nil {
commitment_scheme.append_to_batch(FIXED_VALUES_BATCH, public_table.constants());
commitment_scheme.append_to_batch(FIXED_VALUES_BATCH, public_table.selectors());

auto result = typename preprocessed_data_type::public_commitments_type({commitment_scheme.commit(FIXED_VALUES_BATCH)});
typename preprocessed_data_type::public_commitments_type result(
{commitment_scheme.commit(FIXED_VALUES_BATCH)});
commitment_scheme.mark_batch_as_fixed(FIXED_VALUES_BATCH);
return result;
}
Expand Down
Loading

0 comments on commit a92f582

Please sign in to comment.