Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit e1ac7ce

Browse files
committed
Added marshalling for preprocessed public data, LPC commitment state, polys_evaluator.
1 parent 4a10666 commit e1ac7ce

File tree

73 files changed

+3199
-1100
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+3199
-1100
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ else()
5353
target_architecture(CMAKE_TARGET_ARCHITECTURE)
5454
endif()
5555

56-
find_package(Boost REQUIRED COMPONENTS container random filesystem log log_setup program_options thread system unit_test_framework timer)
56+
find_package(Boost REQUIRED COMPONENTS container random filesystem log log_setup program_options thread system unit_test_framework timer log)
5757

5858
add_subdirectories("${CMAKE_CURRENT_LIST_DIR}/libs/")
5959
add_subdirectories("${CMAKE_CURRENT_LIST_DIR}/libs/marshalling")

libs/algebra/crypto3.algebra.podspec.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"branch": "master"
1919
},
2020
"xcconfig": {
21-
"CLANG_CXX_LANGUAGE_STANDARD": "c++14",
21+
"CLANG_CXX_LANGUAGE_STANDARD": "c++17",
2222
"CLANG_CXX_LIBRARY": "libc++",
2323
"HEADER_SEARCH_PATHS": "\"${PODS_ROOT}/include/\""
2424
},

libs/block/crypto3.block.podspec.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"branch": "master"
1818
},
1919
"xcconfig": {
20-
"CLANG_CXX_LANGUAGE_STANDARD": "c++14",
20+
"CLANG_CXX_LANGUAGE_STANDARD": "c++17",
2121
"CLANG_CXX_LIBRARY": "libc++",
2222
"HEADER_SEARCH_PATHS": "\"${PODS_ROOT}/include/\""
2323
},

libs/block/test/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ macro(define_block_cipher_test name)
2121
${Boost_INCLUDE_DIRS})
2222

2323
if(NOT CMAKE_CXX_STANDARD)
24-
set_target_properties(${test_name} PROPERTIES CXX_STANDARD 14)
24+
set_target_properties(${test_name} PROPERTIES CXX_STANDARD 17)
2525
endif()
2626

2727
string(CONCAT TEST_DATA ${CMAKE_CURRENT_SOURCE_DIR} "/data/" "${name}" ".json")

libs/blueprint/include/nil/blueprint/basic_non_native_policy.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include <nil/crypto3/algebra/curves/pallas.hpp>
3030
#include <nil/crypto3/algebra/curves/vesta.hpp>
3131
#include <nil/crypto3/algebra/curves/ed25519.hpp>
32+
#include <nil/crypto3/algebra/fields/bls12/base_field.hpp>
33+
#include <nil/crypto3/algebra/fields/bls12/scalar_field.hpp>
3234

3335
#include <boost/multiprecision/cpp_int.hpp>
3436
#include <nil/crypto3/zk/snark/arithmetization/plonk/constraint_system.hpp>
@@ -251,8 +253,6 @@ namespace nil {
251253
typedef std::array<var, ratio> non_native_var_type;
252254
};
253255

254-
255-
256256
/*
257257
* Native element type.
258258
*/

libs/codec/crypto3.codec.podspec.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"branch": "master"
1818
},
1919
"xcconfig": {
20-
"CLANG_CXX_LANGUAGE_STANDARD": "c++14",
20+
"CLANG_CXX_LANGUAGE_STANDARD": "c++17",
2121
"CLANG_CXX_LIBRARY": "libc++",
2222
"HEADER_SEARCH_PATHS": "\"${PODS_ROOT}/include/\""
2323
},

libs/codec/test/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ macro(define_codec_test name)
2424

2525
if(NOT CMAKE_CXX_STANDARD)
2626
set_target_properties(codec_${name}_test PROPERTIES
27-
CXX_STANDARD 14
27+
CXX_STANDARD 17
2828
CXX_STANDARD_REQUIRED TRUE)
2929
endif()
3030

libs/containers/include/nil/crypto3/container/merkle/tree.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ namespace nil {
175175

176176
typedef typename node_type::value_type value_type;
177177
constexpr static const std::size_t value_bits = node_type::value_bits;
178+
constexpr static const std::size_t arity = Arity;
178179

179180
typedef std::vector<value_type> container_type;
180181

@@ -253,15 +254,15 @@ namespace nil {
253254
}
254255

255256
bool operator==(const merkle_tree_impl &rhs) const {
256-
return _hashes == rhs.val;
257+
return _hashes == rhs._hashes;
257258
}
258259

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

263264
allocator_type get_allocator() const BOOST_NOEXCEPT {
264-
return this->val.__alloc();
265+
return this->_hashes.__alloc();
265266
}
266267

267268
iterator begin() BOOST_NOEXCEPT {

libs/hash/crypto3.hash.podspec.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"branch": "master"
1818
},
1919
"xcconfig": {
20-
"CLANG_CXX_LANGUAGE_STANDARD": "c++14",
20+
"CLANG_CXX_LANGUAGE_STANDARD": "c++17",
2121
"CLANG_CXX_LIBRARY": "libc++",
2222
"HEADER_SEARCH_PATHS": "\"${PODS_ROOT}/include/\""
2323
},

libs/kdf/crypto3.kdf.podspec.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"branch": "master"
1818
},
1919
"xcconfig": {
20-
"CLANG_CXX_LANGUAGE_STANDARD": "c++14",
20+
"CLANG_CXX_LANGUAGE_STANDARD": "c++17",
2121
"CLANG_CXX_LIBRARY": "libc++",
2222
"HEADER_SEARCH_PATHS": "\"${PODS_ROOT}/include/\""
2323
},

libs/mac/crypto3.mac.podspec.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"branch": "master"
1818
},
1919
"xcconfig": {
20-
"CLANG_CXX_LANGUAGE_STANDARD": "c++14",
20+
"CLANG_CXX_LANGUAGE_STANDARD": "c++17",
2121
"CLANG_CXX_LIBRARY": "libc++",
2222
"HEADER_SEARCH_PATHS": "\"${PODS_ROOT}/include/\""
2323
},

libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/types/field_element.hpp

+10-11
Original file line numberDiff line numberDiff line change
@@ -686,12 +686,16 @@ namespace nil {
686686
// return field;
687687
// }
688688

689-
template<typename FieldValueType, typename Endianness>
690-
nil::marshalling::types::array_list<
691-
nil::marshalling::field_type<Endianness>,
692-
field_element<nil::marshalling::field_type<Endianness>, FieldValueType>,
689+
690+
template<typename FieldValueType, typename TTypeBase>
691+
using field_element_vector = nil::marshalling::types::array_list<
692+
TTypeBase,
693+
field_element<TTypeBase, FieldValueType>,
693694
nil::marshalling::option::sequence_size_field_prefix<
694-
nil::marshalling::types::integral<nil::marshalling::field_type<Endianness>, std::size_t>>>
695+
nil::marshalling::types::integral<TTypeBase, std::size_t>>>;
696+
697+
template<typename FieldValueType, typename Endianness>
698+
field_element_vector<FieldValueType, nil::marshalling::field_type<Endianness>>
695699
fill_field_element_vector(const std::vector<FieldValueType> &field_elem_vector) {
696700

697701
using TTypeBase = nil::marshalling::field_type<Endianness>;
@@ -711,12 +715,7 @@ namespace nil {
711715

712716
template<typename FieldValueType, typename Endianness>
713717
std::vector<FieldValueType> make_field_element_vector(
714-
const nil::marshalling::types::array_list<
715-
nil::marshalling::field_type<Endianness>,
716-
field_element<nil::marshalling::field_type<Endianness>, FieldValueType>,
717-
nil::marshalling::option::sequence_size_field_prefix<
718-
nil::marshalling::types::integral<nil::marshalling::field_type<Endianness>, std::size_t>>>
719-
&field_elem_vector) {
718+
const field_element_vector<FieldValueType, nil::marshalling::field_type<Endianness>>& field_elem_vector) {
720719

721720
std::vector<FieldValueType> result;
722721
result.reserve(field_elem_vector.value().size());

libs/marshalling/core/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ if(CRYPTO3_MARSHALLING_THROWS)
1919
add_definitions(-DCRYPTO3_MARSHALLING_THROWS)
2020
endif()
2121

22+
if(NOT CMAKE_CXX_STANDARD)
23+
set_target_properties(${test_name} PROPERTIES CXX_STANDARD 17)
24+
endif()
25+
2226
cm_setup_version(VERSION 0.1.0 PREFIX ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME})
2327

2428
add_library(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE)

libs/marshalling/core/include/nil/marshalling/options.hpp

+10
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343

4444
namespace nil {
4545
namespace marshalling {
46+
namespace types {
47+
// We cannot include integral.hpp, it includes this file. So just declare the class.
48+
template<typename TFieldBase, typename T, typename... TOptions>
49+
class integral;
50+
}
51+
4652
namespace option {
4753
namespace detail {
4854

@@ -286,6 +292,10 @@ namespace nil {
286292
template<typename TField>
287293
struct sequence_size_field_prefix { };
288294

295+
template <typename TTypeBase>
296+
using size_t_sequence_size_field_prefix = sequence_size_field_prefix<
297+
nil::marshalling::types::integral<TTypeBase, std::size_t>>;
298+
289299
/// @brief Option that modifies the default behaviour of collection fields to
290300
/// prepend the serialized data with number of @b bytes information.
291301
/// @details Similar to @ref sequence_size_field_prefix, but instead of

libs/marshalling/core/include/nil/marshalling/types/adapter/sequence_size_field_prefix.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
namespace nil {
3333
namespace marshalling {
3434
namespace types {
35+
3536
namespace adapter {
3637

3738
template<typename TSizeField, typename TBase>
@@ -129,7 +130,6 @@ namespace nil {
129130
base_impl_type::write_no_status(iter);
130131
}
131132
};
132-
133133
} // namespace adapter
134134
} // namespace types
135135
} // namespace marshalling

libs/marshalling/core/include/nil/marshalling/types/array_list.hpp

+76
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@
2626
#ifndef MARSHALLING_ARRAY_LIST_HPP
2727
#define MARSHALLING_ARRAY_LIST_HPP
2828

29+
#include <functional>
2930
#include <vector>
31+
#include <map>
3032

3133
#include <nil/marshalling/status_type.hpp>
3234
#include <nil/marshalling/types/array_list/behaviour.hpp>
3335
#include <nil/marshalling/types/detail/options_parser.hpp>
3436

3537
#include <nil/marshalling/types/tag.hpp>
38+
#include <nil/detail/type_traits.hpp>
3639

3740
namespace nil {
3841
namespace marshalling {
@@ -404,6 +407,79 @@ namespace nil {
404407
return field;
405408
}
406409

410+
// We use this type of array_list waay too often, so this is a shortcut, not to copy-paste it all the time.
411+
template<typename TFieldBase, typename TElement>
412+
using standard_array_list = array_list<
413+
TFieldBase,
414+
TElement,
415+
nil::marshalling::option::size_t_sequence_size_field_prefix<TFieldBase>>;
416+
417+
// Very often we just need an array list of std::size_t, so here's another shortcut.
418+
template<typename TFieldBase>
419+
using standard_size_t_array_list = array_list<
420+
TFieldBase,
421+
nil::marshalling::types::integral<TFieldBase, std::size_t>,
422+
nil::marshalling::option::size_t_sequence_size_field_prefix<TFieldBase>>;
423+
424+
// Helper functions to convert to/from an arraylist.
425+
template<typename TFieldBase, typename TMarshalledElement, typename Range>
426+
typename std::enable_if<
427+
nil::detail::is_range<Range>::value,
428+
standard_array_list<TFieldBase, TMarshalledElement>>::type
429+
fill_standard_array_list(
430+
const Range& input_range,
431+
std::function<TMarshalledElement(const typename Range::value_type&)> element_marshalling) {
432+
standard_array_list<TFieldBase, TMarshalledElement> result;
433+
for (const auto& v: input_range) {
434+
result.value().push_back(element_marshalling(v));
435+
}
436+
return result;
437+
}
438+
439+
template<typename TFieldBase, typename TElement, typename TMarshalledElement>
440+
std::vector<TElement> make_standard_array_list(
441+
const standard_array_list<TFieldBase, TMarshalledElement>& filled_array,
442+
std::function<TElement(const TMarshalledElement&)> element_de_marshalling) {
443+
std::vector<TElement> result;
444+
for (const auto& v: filled_array.value()) {
445+
result.push_back(element_de_marshalling(v));
446+
}
447+
return result;
448+
}
449+
450+
// Helper functions to marshall an std::map.
451+
// We keep TKey, TValue at the end, because they can be decuded from the map type, but the other 3
452+
// arguments must be provided explicitly.
453+
template<typename TFieldBase, typename TMarshalledKey, typename TMarshalledValue, typename TKey, typename TValue>
454+
std::pair<standard_array_list<TFieldBase, TMarshalledKey>, standard_array_list<TFieldBase, TMarshalledValue>>
455+
fill_std_map(
456+
const std::map<TKey, TValue>& input_map,
457+
std::function<TMarshalledKey(const TKey&)> key_marshalling,
458+
std::function<TMarshalledValue(const TValue&)> value_marshalling) {
459+
standard_array_list<TFieldBase, TMarshalledKey> result_keys;
460+
standard_array_list<TFieldBase, TMarshalledValue> result_values;
461+
for (const auto& [k, v]: input_map) {
462+
result_keys.value().push_back(key_marshalling(k));
463+
result_values.value().push_back(value_marshalling(v));
464+
}
465+
return {result_keys, result_values};
466+
}
467+
468+
template<typename TFieldBase, typename TKey, typename TValue, typename TMarshalledKey, typename TMarshalledValue>
469+
std::map<TKey, TValue> make_std_map(
470+
const standard_array_list<TFieldBase, TMarshalledKey>& filled_keys,
471+
const standard_array_list<TFieldBase, TMarshalledValue>& filled_values,
472+
std::function<TKey(const TMarshalledKey&)> key_de_marshalling,
473+
std::function<TValue(const TMarshalledValue&)> value_de_marshalling) {
474+
assert(filled_keys.value().size() == filled_values.value().size());
475+
476+
std::map<TKey, TValue> result;
477+
for (std::size_t i = 0; i < filled_keys.value().size(); ++i) {
478+
result[key_de_marshalling(filled_keys.value()[i])] = value_de_marshalling(filled_values.value()[i]);
479+
}
480+
return result;
481+
}
482+
407483
} // namespace types
408484
} // namespace marshalling
409485
} // namespace nil

libs/marshalling/core/include/nil/marshalling/types/integral.hpp

+13
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,19 @@ namespace nil {
439439
return field;
440440
}
441441

442+
// This is a helper, frequently used to convert size_t. It just shortens our code.
443+
template<typename TFieldBase>
444+
integral<TFieldBase, std::size_t> fill_size_t(const std::size_t& v) {
445+
integral<TFieldBase, std::size_t> result;
446+
result.value() = v;
447+
return result;
448+
}
449+
450+
template<typename TFieldBase>
451+
std::size_t make_size_t(const integral<TFieldBase, std::size_t>& v) {
452+
return v.value();
453+
}
454+
442455
} // namespace types
443456
} // namespace marshalling
444457
} // namespace nil

0 commit comments

Comments
 (0)