Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crypto3 compatibility #230

Merged
merged 7 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 3 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
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)
cmake_minimum_required(VERSION 3.17.0)

list(APPEND CMAKE_MODULE_PATH
"${CMAKE_CURRENT_LIST_DIR}/cmake"
Expand All @@ -14,32 +8,18 @@ list(APPEND CMAKE_MODULE_PATH
include(CMConfig)
include(CMSetupVersion)

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

cm_project(assigner WORKSPACE_NAME ${CMAKE_WORKSPACE_NAME} LANGUAGES C CXX)

if(NOT Boost_FOUND AND NOT CMAKE_CROSSCOMPILING)
find_package(Boost COMPONENTS REQUIRED filesystem log log_setup program_options thread system)
if(NOT CMAKE_WORKSPACE_NAME OR NOT ("${CMAKE_WORKSPACE_NAME}" STREQUAL "crypto3"))
cm_workspace(crypto3)
endif()

cm_find_package(CM)
include(CMDeploy)
include(FindPkgConfig)

option(BUILD_WITH_CCACHE "Build with ccache usage" TRUE)
option(BUILD_TESTS "Build unit tests" FALSE)
option(BUILD_EXAMPLES "Build examples" FALSE)

if(UNIX AND BUILD_WITH_CCACHE)
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)
endif()

if(UNIX AND BUILD_WITH_PROCPS)
find_package(Procps)
endif()
Expand All @@ -63,7 +43,6 @@ set_target_properties(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} PROPERTIES
target_include_directories(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>"

${Boost_INCLUDE_DIRS})

target_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} INTERFACE
Expand Down
23 changes: 15 additions & 8 deletions include/nil/blueprint/non_native_marshalling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,13 @@ namespace nil {
else {
if constexpr (non_native_policy::ratio == 1) {
column_type<BlueprintFieldType> res;
res.push_back(typename BlueprintFieldType::value_type(typename BlueprintFieldType::integral_type(input.data)));

typename BlueprintFieldType::integral_type chopped_val =
typename BlueprintFieldType::integral_type(
typename NonNativeFieldType::integral_type(input.data)
);

res.push_back(typename BlueprintFieldType::value_type(chopped_val));
akokoshn marked this conversation as resolved.
Show resolved Hide resolved
return res;
}
else {
Expand All @@ -177,7 +183,7 @@ namespace nil {
}

template<typename BlueprintFieldType, typename NonNativeFieldType>
typename NonNativeFieldType::value_type vector_into_value (column_type<BlueprintFieldType> input) {
typename BlueprintFieldType::integral_type vector_into_value (column_type<BlueprintFieldType> input) {
using non_native_policy = typename nil::blueprint::detail::basic_non_native_policy_field_type<BlueprintFieldType, NonNativeFieldType>;

if (input.size() != non_native_policy::ratio) {
Expand All @@ -199,7 +205,8 @@ namespace nil {
chopped_field[i] = input[i];
}
typename NonNativeFieldType::value_type res = non_native_policy::glue_non_native(chopped_field);
return res;
return typename BlueprintFieldType::integral_type(
typename NonNativeFieldType::integral_type(res.data));
}
}
}
Expand Down Expand Up @@ -315,23 +322,23 @@ namespace nil {
switch (field_type) {
case llvm::GALOIS_FIELD_CURVE25519_BASE: {
using operating_field_type = typename nil::crypto3::algebra::curves::ed25519::base_field_type;
return typename BlueprintFieldType::integral_type(vector_into_value<BlueprintFieldType, operating_field_type>(input).data);
return vector_into_value<BlueprintFieldType, operating_field_type>(input);
}
case llvm::GALOIS_FIELD_CURVE25519_SCALAR: {
using operating_field_type = typename nil::crypto3::algebra::curves::ed25519::scalar_field_type;
return typename BlueprintFieldType::integral_type(vector_into_value<BlueprintFieldType, operating_field_type>(input).data);
return vector_into_value<BlueprintFieldType, operating_field_type>(input);
}
case llvm::GALOIS_FIELD_PALLAS_BASE: {
using operating_field_type = typename nil::crypto3::algebra::curves::pallas::base_field_type;
return typename BlueprintFieldType::integral_type(vector_into_value<BlueprintFieldType, operating_field_type>(input).data);
return vector_into_value<BlueprintFieldType, operating_field_type>(input);
}
case llvm::GALOIS_FIELD_PALLAS_SCALAR: {
using operating_field_type = typename nil::crypto3::algebra::curves::pallas::scalar_field_type;
return typename BlueprintFieldType::integral_type(vector_into_value<BlueprintFieldType, operating_field_type>(input).data);
return vector_into_value<BlueprintFieldType, operating_field_type>(input);
}
case llvm::GALOIS_FIELD_BLS12381_BASE: {
using operating_field_type = typename nil::crypto3::algebra::curves::bls12<381>::base_field_type;
return typename BlueprintFieldType::integral_type(vector_into_value<BlueprintFieldType, operating_field_type>(input).data);
return vector_into_value<BlueprintFieldType, operating_field_type>(input);
}
default:
UNREACHABLE("unsupported field operand type");
Expand Down
9 changes: 4 additions & 5 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

include(CMTest)

cm_find_package(Boost REQUIRED COMPONENTS log log_setup random unit_test_framework)

cm_test_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}

crypto3::all
Expand All @@ -26,9 +24,10 @@ macro(define_assigner_test test)
cm_test(NAME ${full_test_name} SOURCES ${test}.cpp)

target_include_directories(${full_test_name} PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>"
${CMAKE_CURRENT_SOURCE_DIR}/../../circifier/llvm/include
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_BINARY_DIR}/include
${CMAKE_SOURCE_DIR}/libs/blueprint/include
${CMAKE_SOURCE_DIR}/libs/circifier/llvm/include
akokoshn marked this conversation as resolved.
Show resolved Hide resolved
${CMAKE_BINARY_DIR}/libs/circifier/llvm/include

${Boost_INCLUDE_DIRS})
Expand Down
2 changes: 1 addition & 1 deletion test/input_reader_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ BOOST_AUTO_TEST_CASE(input_reader_legacy_format) {

BOOST_AUTO_TEST_CASE(input_reader_mixed_format) {

column_type<BlueprintFieldType> expected = {0x12345678901234567890_cppui255, 2, 3, 4, 5, 6, 7, 8};
column_type<BlueprintFieldType> expected = {0x12345678901234567890_cppui_modular255, 2, 3, 4, 5, 6, 7, 8};
const char *input_string =
R"([ {"array": [{"field":"0x12345678901234567890"}, {"field": 2}, {"field<pallas_base>" :3} ]},
{"array<field<pallas_base>>": [ 4, 5, 6, 7, 8]}])";
Expand Down