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

Fix non native field type conversion #229

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 0 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ 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)
endif()

cm_find_package(CM)
include(CMDeploy)
include(FindPkgConfig)
Expand Down Expand Up @@ -63,7 +59,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,14 @@ 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::backend_type(input.data.backend().base_data());
if (NonNativeFieldType::modulus_bits < BlueprintFieldType::modulus_bits) {
// set unused bits 0
typename BlueprintFieldType::integral_type base = 1;
typename BlueprintFieldType::integral_type mask = (base << NonNativeFieldType::modulus_bits) - 1;
chopped_val = chopped_val & mask;
}
res.push_back(typename BlueprintFieldType::value_type(chopped_val));
return res;
}
else {
Expand All @@ -177,7 +184,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 +206,7 @@ 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::backend_type(res.data.backend().base_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
${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