Skip to content

Commit

Permalink
Merge pull request #11 from NilFoundation/update_parallel_crypto3
Browse files Browse the repository at this point in the history
Update parallel crypto3, that last 3 commits, up to commit 690302c6d5d9f7871a4ad54a6aa047ffa4ca4fca
  • Loading branch information
martun authored Sep 15, 2024
2 parents c09bc85 + 9bb58be commit 0d2e6a1
Show file tree
Hide file tree
Showing 53 changed files with 1,389 additions and 1,849 deletions.
8 changes: 0 additions & 8 deletions parallel-crypto3/libs/parallel-containers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@
# SOFTWARE.
#---------------------------------------------------------------------------//

cmake_minimum_required(VERSION 2.8.12)

cmake_policy(SET CMP0042 NEW)
cmake_policy(SET CMP0028 NEW)
cmake_policy(SET CMP0048 NEW)
cmake_policy(SET CMP0057 NEW)
cmake_policy(SET CMP0079 OLD)

include(CMConfig)
include(CMSetupVersion)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ namespace nil {
namespace zk {
namespace components {
template<typename, typename, std::size_t>
struct merkle_proof;
class merkle_proof;
} // namespace components
} // namespace zk
namespace marshalling {
namespace types {
template<typename, typename>
struct merkle_proof_marshalling;
class merkle_proof_marshalling;
}
} // namespace marshalling
namespace containers {
Expand Down Expand Up @@ -95,7 +95,7 @@ namespace nil {
typedef std::array<path_element_type, Arity - 1> layer_type;
typedef std::vector<layer_type> path_type;

merkle_proof_impl() : _li(0) {};
merkle_proof_impl() : _li(0), _root(value_type()) {};

merkle_proof_impl(std::size_t li, value_type root, path_type path) : _li(li), _root(root),
_path(path){};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ namespace nil {

typedef typename node_type::value_type value_type;
constexpr static const std::size_t value_bits = node_type::value_bits;
constexpr static const std::size_t arity = Arity;

typedef std::vector<value_type> container_type;

Expand Down Expand Up @@ -256,15 +257,15 @@ namespace nil {
}

bool operator==(const merkle_tree_impl &rhs) const {
return _hashes == rhs.val;
return _hashes == rhs._hashes;
}

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

allocator_type get_allocator() const BOOST_NOEXCEPT {
return this->val.__alloc();
return this->_hashes.__alloc();
}

iterator begin() BOOST_NOEXCEPT {
Expand Down
13 changes: 6 additions & 7 deletions parallel-crypto3/libs/parallel-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,12 @@
#include <boost/test/data/test_case.hpp>
#include <boost/test/data/monomorphic.hpp>

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

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

Expand Down
37 changes: 3 additions & 34 deletions parallel-crypto3/libs/parallel-math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,18 @@
# http://www.boost.org/LICENSE_1_0.txt
#---------------------------------------------------------------------------#

cmake_minimum_required(VERSION 2.8.12)

cmake_policy(SET CMP0028 NEW)
cmake_policy(SET CMP0042 NEW)
cmake_policy(SET CMP0048 NEW)
cmake_policy(SET CMP0057 NEW)
cmake_policy(SET CMP0076 NEW)

include(CMConfig)
include(CMSetupVersion)

if(NOT CMAKE_WORKSPACE_NAME OR NOT ("${CMAKE_WORKSPACE_NAME}" STREQUAL "actor"))
cm_workspace(actor)
endif()

macro(cm_find_package NAME)
foreach(ITERATOR ${CMAKE_WORKSPACE_LIST})
if(NOT "${NAME}" MATCHES "^${ITERATOR}_.*$" AND NOT "${NAME}" STREQUAL CM)
find_package(${ARGV})
else()
set(${ARGV0}_FOUND ON CACHE BOOL "")
endif()
endforeach()
endmacro()

cm_project(math WORKSPACE_NAME ${CMAKE_WORKSPACE_NAME} LANGUAGES ASM C CXX)

cm_find_package(CM)
include(CMDeploy)

option(BUILD_TESTS "Build unit tests" FALSE)

list(APPEND ${CURRENT_PROJECT_NAME}_PUBLIC_HEADERS)

list(APPEND ${CURRENT_PROJECT_NAME}_UNGROUPED_SOURCES)

list(APPEND ${CURRENT_PROJECT_NAME}_HEADERS ${${CURRENT_PROJECT_NAME}_PUBLIC_HEADERS})

list(APPEND ${CURRENT_PROJECT_NAME}_SOURCES ${${CURRENT_PROJECT_NAME}_UNGROUPED_SOURCES})

cm_setup_version(VERSION 0.1.0 PREFIX ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME})

add_library(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE)
Expand All @@ -67,14 +39,11 @@ target_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
crypto3::algebra
crypto3::multiprecision

${Boost_LIBRARIES})

find_package(Boost COMPONENTS random)
Boost::random
)

cm_deploy(TARGETS ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}
INCLUDE include
NAMESPACE ${CMAKE_WORKSPACE_NAME}::)

if(BUILD_TESTS)
add_subdirectory(test)
endif()
cm_add_test_subdirectory(test)
4 changes: 2 additions & 2 deletions parallel-crypto3/libs/parallel-math/crypto3.math.podspec.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"branch": "master"
},
"xcconfig": {
"CLANG_CXX_LANGUAGE_STANDARD": "c++14",
"CLANG_CXX_LANGUAGE_STANDARD": "c++17",
"CLANG_CXX_LIBRARY": "libc++",
"HEADER_SEARCH_PATHS": "\"${PODS_ROOT}/include/\""
},
Expand Down Expand Up @@ -84,4 +84,4 @@
]
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,67 @@
#include <nil/crypto3/math/domains/geometric_sequence_domain.hpp>
#include <nil/crypto3/math/domains/step_radix2_domain.hpp>

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

namespace nil {
namespace crypto3 {
namespace math {

namespace detail {
/*!
@brief
A convenience method for choosing an evaluation domain
Returns an evaluation domain object in which the domain S has size
|S| >= MinSize.
The function get_evaluation_domain is chosen from different supported domains,
depending on MinSize.
*/
using namespace nil::crypto3::algebra;

template<typename FieldType>
bool is_basic_radix2_domain(std::size_t m) {
const std::size_t log_m = static_cast<std::size_t>(std::ceil(std::log2(m)));

return (m > 1) && (log_m <= fields::arithmetic_params<FieldType>::s) && (m == (1ul << log_m));
}

template<typename FieldType>
bool is_extended_radix2_domain(std::size_t m) {
const std::size_t log_m = static_cast<std::size_t>(std::ceil(std::log2(m)));
const std::size_t small_m = m / 2;
const std::size_t log_small_m = static_cast<std::size_t>(std::ceil(std::log2(small_m)));

return (m > 1) && (log_m == fields::arithmetic_params<FieldType>::s + 1) &&
(small_m == (1ul << log_small_m)) &&
(log_small_m <= fields::arithmetic_params<FieldType>::s);
}

template<typename FieldType>
bool is_step_radix2_domain(std::size_t m) {
const std::size_t log_m = static_cast<std::size_t>(std::ceil(std::log2(m)));
const std::size_t shift_log_m = (1ul << log_m);
const std::size_t log_shift_log_m = static_cast<std::size_t>(std::ceil(std::log2(shift_log_m)));
const std::size_t small_m = m - (1ul << (static_cast<std::size_t>(std::ceil(std::log2(m))) - 1));
const std::size_t log_small_m = static_cast<std::size_t>(std::ceil(std::log2(small_m)));

return (m > 1) && (small_m == (1ul << log_small_m)) && (shift_log_m == (1ul << log_shift_log_m)) &&
(log_shift_log_m <= fields::arithmetic_params<FieldType>::s);
}

template<typename FieldType>
bool is_geometric_sequence_domain(std::size_t m) {
return (m > 1) &&
(typename FieldType::value_type(fields::arithmetic_params<FieldType>::geometric_generator) !=
FieldType::value_type::zero());
}

template<typename FieldType>
bool is_arithmetic_sequence_domain(std::size_t m) {
return (m > 1) && (typename FieldType::value_type(
fields::arithmetic_params<FieldType>::arithmetic_generator) !=
FieldType::value_type::zero());
}

} // namespace detail

/*!
@brief
A convenience method for choosing an evaluation domain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ namespace nil {

polynomial(size_type n, const value_type& x, const allocator_type& a) : val(n, x, a) {
}

template<typename InputIterator>
polynomial(InputIterator first, InputIterator last) : val(first, last) {
if (val.empty()) {
Expand Down Expand Up @@ -114,22 +115,23 @@ namespace nil {
polynomial(polynomial&& x, const allocator_type& a) : val(std::move(x.val), a) {
}

polynomial(const FieldValueType& value, std::size_t power = 0) : val(power + 1, FieldValueType::zero()) {
this->operator[](power) = value;
}

explicit polynomial(const container_type &c) : val(c) {
if (val.empty()) {
val.push_back(FieldValueType::zero());
}
}

explicit polynomial(container_type &&c) : val(std::move(c)) {
explicit polynomial(container_type &&c) : val(std::forward<container_type>(c)) {
if (val.empty()) {
val.push_back(FieldValueType::zero());
}
}

polynomial(const FieldValueType& value, std::size_t power = 0)
: val(power + 1, FieldValueType::zero()) {
this->operator[](power) = value;
}

polynomial& operator=(const polynomial& x) {
val = x.val;
return *this;
Expand Down Expand Up @@ -158,6 +160,7 @@ namespace nil {
bool operator==(const polynomial& rhs) const {
return val == rhs.val;
}

bool operator!=(const polynomial& rhs) const {
return !(rhs == *this);
}
Expand Down Expand Up @@ -191,9 +194,11 @@ namespace nil {
const_iterator begin() const BOOST_NOEXCEPT {
return val.begin();
}

iterator end() BOOST_NOEXCEPT {
return val.end();
}

const_iterator end() const BOOST_NOEXCEPT {
return val.end();
}
Expand Down Expand Up @@ -241,41 +246,51 @@ namespace nil {
size_type capacity() const BOOST_NOEXCEPT {
return val.capacity();
}

bool empty() const BOOST_NOEXCEPT {
return val.empty();
}

size_type max_size() const BOOST_NOEXCEPT {
return val.max_size();
}

void reserve(size_type _n) {
return val.reserve(_n);
}

void shrink_to_fit() BOOST_NOEXCEPT {
return val.shrink_to_fit();
}

reference operator[](size_type _n) BOOST_NOEXCEPT {
return val[_n];
}

const_reference operator[](size_type _n) const BOOST_NOEXCEPT {
return val[_n];
}

reference at(size_type _n) {
return val.at(_n);
}

const_reference at(size_type _n) const {
return val.at(_n);
}

reference front() BOOST_NOEXCEPT {
return val.front();
}

const_reference front() const BOOST_NOEXCEPT {
return val.front();
}

reference back() BOOST_NOEXCEPT {
return val.back();
}

const_reference back() const BOOST_NOEXCEPT {
return val.back();
}
Expand Down Expand Up @@ -312,6 +327,7 @@ namespace nil {
iterator insert(const_iterator _position, value_type&& _x) {
return val.insert(_position, _x);
}

template<class... Args>
iterator emplace(const_iterator _position, Args&&... _args) {
return val.template emplace(_position, _args...);
Expand Down Expand Up @@ -409,7 +425,7 @@ namespace nil {
void condense() {
while (std::distance(this->cbegin(), this->cend()) > 1 &&
this->back() == typename std::iterator_traits<decltype(std::begin(
std::declval<container_type>()))>::value_type()) {
std::declval<container_type>()))>::value_type()) {
this->pop_back();
}
}
Expand Down Expand Up @@ -474,6 +490,7 @@ namespace nil {
multiplication(*this, *this, other);
return *this;
}

/**
* Perform the standard Euclidean Division algorithm.
* Input: Polynomial A, Polynomial B, where A / B
Expand Down Expand Up @@ -598,7 +615,7 @@ namespace nil {
os << *poly.begin();
} else {
os << "[Polynomial, size " << poly.size() << " values ";
for( auto it = poly.begin(); it != poly.end(); it++ ){
for (auto it = poly.begin(); it != poly.end(); ++it) {
os << "0x" << std::hex << it->data << ", ";
}
os << "]";
Expand Down
Loading

0 comments on commit 0d2e6a1

Please sign in to comment.