diff --git a/CMakeLists.txt b/CMakeLists.txt index babad017c9d074eefb6908dd46c4f3d997a513d2..52c3dfc80c8c7862d02006a56eafe1895db9c49a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ project(cellframe-sdk C) cmake_minimum_required(VERSION 3.0) set(CMAKE_C_STANDARD 11) -set(CELLFRAME_SDK_NATIVE_VERSION "2.9-9") +set(CELLFRAME_SDK_NATIVE_VERSION "3.0-0") add_definitions ("-DCELLFRAME_SDK_VERSION=\"${CELLFRAME_SDK_NATIVE_VERSION}\"") set(DAPSDK_MODULES "") message("Cellframe modules: ${CELLFRAME_MODULES}") diff --git a/cmake/OS_Detection.cmake b/cmake/OS_Detection.cmake index 161a5b8fa690764c43d26f5e2f027b1c8119834c..df005742c04124f02e6a8ecb47b3b9218d828b79 100644 --- a/cmake/OS_Detection.cmake +++ b/cmake/OS_Detection.cmake @@ -79,19 +79,19 @@ if(UNIX) if (LINUX) if(DAP_DEBUG) - set(_CCOPT "-DDAP_DEBUG -Wall -Wno-deprecated-declarations -Wno-unused-local-typedefs -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -pg -g3 -ggdb -fno-eliminate-unused-debug-symbols -fno-strict-aliasing") + set(_CCOPT "-DDAP_DEBUG -Wall -Wno-unused-command-line-argument -Wno-deprecated-declarations -Wno-unused-local-typedefs -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -pg -g3 -ggdb -fno-eliminate-unused-debug-symbols -fno-strict-aliasing") set(_LOPT "-pg") SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg") else() - set(_CCOPT "-Wno-deprecated-declarations -Wno-unused-local-typedefs -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -O3 -fPIC -fno-strict-aliasing -fno-ident -ffast-math -ftree-vectorize -fno-asynchronous-unwind-tables -ffunction-sections -Wl,--gc-sections -Wl,--strip-all -std=gnu11") + set(_CCOPT "-Wno-deprecated-declarations -Wno-unused-command-line-argument -Wno-unused-local-typedefs -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -O3 -fPIC -fno-strict-aliasing -fno-ident -ffast-math -ftree-vectorize -fno-asynchronous-unwind-tables -ffunction-sections -Wl,--gc-sections -Wl,--strip-all -std=gnu11") endif() elseif (DARWIN) if(DAP_DEBUG) - set(_CCOPT "-L/usr/local/lib -I/usr/local/include -DDAP_DEBUG -Wall -Wno-unused-command-line-argument -Wno-deprecated-declarations -Wno-unused-local-typedefs -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -g3 -ggdb -fno-eliminate-unused-debug-symbols -fno-strict-aliasing -std=c11") + set(_CCOPT "-L/usr/local/lib -I/usr/local/include -DDAP_DEBUG -Wall -Wno-address-of-packed-member -Wno-unused-command-line-argument -Wno-deprecated-declarations -Wno-unused-local-typedefs -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -g3 -ggdb -fno-eliminate-unused-debug-symbols -fno-strict-aliasing -std=c11") set(_LOPT "-L/usr/local/lib ") SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") else() - set(_CCOPT "-L /usr/local/lib -I/usr/local/include -Wno-deprecated-declarations -Wno-unused-command-line-argument -Wno-unused-local-typedefs -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -O3 -fPIC -fno-strict-aliasing -fno-ident -ffast-math -ftree-vectorize -fno-asynchronous-unwind-tables -ffunction-sections -std=c11") + set(_CCOPT "-L /usr/local/lib -I/usr/local/include -Wno-address-of-packed-member -Wno-deprecated-declarations -Wno-unused-command-line-argument -Wno-unused-local-typedefs -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -O3 -fPIC -fno-strict-aliasing -fno-ident -ffast-math -ftree-vectorize -fno-asynchronous-unwind-tables -ffunction-sections -std=c11") set(_LOPT "-L /usr/local/lib") SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L/usr/local/lib") endif() diff --git a/dap-sdk/core/include/dap_math_ops.h b/dap-sdk/core/include/dap_math_ops.h index b7bd03b4b92c4d74ddcb833184e97b19137e8a12..1423f6f39dd291f4424761724c8859ab8b6f3e3a 100755 --- a/dap-sdk/core/include/dap_math_ops.h +++ b/dap-sdk/core/include/dap_math_ops.h @@ -1,43 +1,202 @@ #pragma once #include <stdint.h> - #include "dap_common.h" +#include <stdio.h> -#if defined(__GNUC__) || defined (__clang__) - -#if __SIZEOF_INT128__ == 16 - -#define DAP_GLOBAL_IS_INT128 -typedef __int128 _dap_int128_t; -#if !defined (int128_t) +#ifdef DAP_GLOBAL_IS_INT128 typedef __int128 int128_t; +typedef __uint128 uint128_t; +#else +typedef union uint128 { + struct { + uint64_t hi; + uint64_t lo; + } DAP_ALIGN_PACKED; + uint64_t u64[2]; + uint32_t u32[4]; +} DAP_ALIGN_PACKED uint128_t; #endif -#if !defined (uint128_t) -typedef unsigned __int128 uint128_t; -#endif +typedef struct unsign256 { + uint128_t hi; + uint128_t lo; +} DAP_ALIGN_PACKED uint256_t; +static const uint128_t two_power_64={ .hi = 1, .lo = 0}; -#else // __SIZEOF_INT128__ == 16 -typedef union uint128 { - uint64_t u64[2]; - uint32_t u32[4]; -} uint128_t; +static const uint64_t lo_32=0xffffffff; +static const uint64_t hi_32=0xffffffff00000000; +static const uint64_t ones_64=0xffffffffffffffff; + +/** + * @brief SUM_64_64 + * @param a_arg1 + * @param a_arg2 + * @param a_result + * @return + */ +static inline int SUM_64_64(uint64_t a_arg1,uint64_t a_arg2,uint64_t* a_result ) +{ + int overflow_flag; + *a_result=a_arg1+a_arg2; + overflow_flag=(*a_result<a_arg1); + return overflow_flag; +} + +/** + * @brief SUM_64_128 + * @details !!! This function returns void because THERE CANNOT BE OVERFLOW IN A (64,64)->128 SUM!!!! + * @param a_arg1 + * @param a_arg2 + * @param a_result + */ +static inline void SUM_64_128(uint64_t a_arg1,uint64_t a_arg2,uint128_t* a_result ) +{ + int overflow_flag; + a_result->lo=a_arg1+a_arg2; + a_result->hi=(a_result->lo<a_arg1); +} + +/** + * @brief ADD_64_INTO_128 + * @details Mixed precision: add a uint64_t into a unsign128_t + * @param a_arg + * @param a_proc_value + * @return + */ +static inline int ADD_64_INTO_128(uint64_t a_arg,uint128_t* a_proc_value ) +{ + int overflow_flag; + uint64_t overflow_64; + uint64_t temp; + temp=a_proc_value->lo; + overflow_flag=SUM_64_64(a_arg,temp,&a_proc_value->lo); + overflow_64=overflow_flag; + temp=a_proc_value->hi; + overflow_flag=SUM_64_64(overflow_64,temp,&a_proc_value->hi); + return overflow_flag; +} -typedef union int128 { - int64_t i64[2]; - int32_t i32[4]; -} int128_t; +/** + * @brief SUM_128_128 + * @param a_arg1 + * @param a_arg2 + * @param a_result + * @return + */ +static inline int SUM_128_128(uint128_t a_arg1,uint128_t a_arg2,uint128_t* a_result) +{ + int overflow_flag; + overflow_flag=SUM_64_64(a_arg1.lo,a_arg2.lo,&a_result->lo); + uint64_t carry_in_64=overflow_flag; + uint64_t intermediate_value=0; + overflow_flag=0; + overflow_flag=SUM_64_64(a_arg1.hi,a_arg2.hi,&intermediate_value); + carry_in_64=overflow_flag; + overflow_flag=0; + overflow_flag=SUM_64_64(carry_in_64,intermediate_value,&a_result->hi); + return overflow_flag; +} -typedef int128_t _dap_int128_t; +/** + * @brief SUM_256_256 + * @param a_arg1 + * @param a_arg2 + * @param a_result + * @return + */ +static inline int SUM_256_256(uint256_t a_arg1,uint256_t a_arg2,uint256_t* a_result) +{ + int overflow_flag; + overflow_flag=SUM_128_128(a_arg1.lo,a_arg2.lo,&a_result->lo); + uint128_t carry_in_128; + carry_in_128.hi=0; + carry_in_128.lo=overflow_flag; + uint128_t intermediate_value; + intermediate_value.hi=0; + intermediate_value.lo=0; + overflow_flag=0; + overflow_flag=SUM_128_128(carry_in_128,a_arg1.hi,&intermediate_value); + + //we store overflow_flag in case there is already overflow + int overflow_flag_bis=0; + + overflow_flag_bis=SUM_128_128(intermediate_value,a_arg2.hi,&a_result->hi); + overflow_flag=overflow_flag||overflow_flag_bis; + return overflow_flag; +} -#endif // __SIZEOF_INT128__ == 16 +/** + * @brief dap_uint128_add + * @param a_arg1 + * @param a_arg2 + * @return + */ +static inline uint128_t dap_uint128_add (uint128_t a_arg1, uint128_t a_arg2) +{ + uint128_t l_ret; + memset(&l_ret,0,sizeof(l_ret)); -#endif //defined(__GNUC__) || defined (__clang__) + SUM_128_128(a_arg1, a_arg2, & l_ret); + return l_ret; +} -uint128_t dap_uint128_substract(uint128_t a, uint128_t b); -uint128_t dap_uint128_add(uint128_t a, uint128_t b); -bool dap_uint128_check_equal(uint128_t a, uint128_t b); +/** + * @brief dap_uint128_substract + * @param a + * @param b + * @return + */ +static inline uint128_t dap_uint128_substract(uint128_t a, uint128_t b) +{ +#ifdef DAP_GLOBAL_IS_INT128 + if (a < b) { + _log_it("dap_math_ops",L_WARNING, "Substract result overflow"); + return 0; + } + return a - b; +#else + uint128_t l_ret = {}; + if (a.u64[0] < b.u64[0] || (a.u64[0] == b.u64[0] && a.u64[1] < b.u64[1])) { + _log_it("dap_math_ops",L_WARNING, "Substract result overflow"); + return l_ret; + } + l_ret.u64[0] = a.u64[0] - b.u64[0]; + l_ret.u64[1] = a.u64[1] - b.u64[1]; + if (a.u64[1] < b.u64[1]) + l_ret.u64[0]--; + return l_ret; +#endif + +} +/** + * @brief dap_uint128_check_equal + * @param a_arg1 + * @param a_arg2 + * @return + */ +static inline bool dap_uint128_check_equal(uint128_t a_arg1, uint128_t a_arg2) +{ +#ifdef DAP_GLOBAL_IS_INT128 + return a_128_bit == b_128_bit; +#else + return a_arg1.lo==a_arg2.lo && a_arg1.hi==a_arg2.hi; +#endif +} + +/** + * @brief dap_unsign256_t_check_equal + * @param a_arg1 + * @param a_arg2 + * @return + */ +static inline bool dap_unsign256_t_check_equal(uint256_t a_arg1, uint256_t a_arg2) +{ + return a_arg1.lo.lo==a_arg2.lo.lo && + a_arg1.lo.hi==a_arg2.lo.hi && + a_arg1.hi.lo==a_arg2.hi.lo && + a_arg1.hi.hi==a_arg2.hi.hi; +} diff --git a/dap-sdk/core/libdap.pri b/dap-sdk/core/libdap.pri index e4288f257471cf0f51dfa068995da51644116c1d..e9efbd1cf209589e3547a1fbd27000e979fb1d9d 100755 --- a/dap-sdk/core/libdap.pri +++ b/dap-sdk/core/libdap.pri @@ -20,7 +20,6 @@ unix: !android : ! darwin { LIBS += -lrt -ljson-c -lmagic } - contains(DAP_FEATURES, ssl){ include($$PWD/../../3rdparty/wolfssl/wolfssl.pri) }else{ @@ -53,6 +52,13 @@ win32 { HEADERS += $$PWD/../../3rdparty/uthash/src/utlist.h \ $$PWD/../../3rdparty/uthash/src/uthash.h +<<<<<<< HEAD +======= +#if(DAPSDK_MODULES MATCHES "ssl-support") +# include($$PWD/../../3rdparty/wolfssl/wolfssl.pri) +#endif() + +>>>>>>> bd29a4e40515ee89520114dd5287c289e5f83b02 # Sources itself HEADERS += $$PWD/include/dap_common.h \ $$PWD/include/dap_binary_tree.h \ diff --git a/dap-sdk/core/src/dap_math_ops.c b/dap-sdk/core/src/dap_math_ops.c deleted file mode 100644 index 502d7ecb60a71c242b8d3be79fd396d683baa5b8..0000000000000000000000000000000000000000 --- a/dap-sdk/core/src/dap_math_ops.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Authors: - * Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net> - * DeM Labs Ltd. https://demlabs.net - * Copyright (c) 2021 - * All rights reserved. - - This file is part of DAP SDK the open source project - - DAP SDK is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - DAP SDK is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with any DAP SDK based project. If not, see <http://www.gnu.org/licenses/>. -*/ -#include "dap_math_ops.h" -#define LOG_TAG "dap_math_ops" - -/** - * @brief dap_chain_balance_substract - * @param a - * @param b - * @return - */ -uint128_t dap_uint128_substract(uint128_t a, uint128_t b) -{ -#ifdef DAP_GLOBAL_IS_INT128 - if (a < b) { - log_it(L_WARNING, "Substract result overflow"); - return 0; - } - return a - b; -#else - uint128_t l_ret = {}; - if (a.u64[0] < b.u64[0] || (a.u64[0] == b.u64[0] && a.u64[1] < b.u64[1])) { - log_it(L_WARNING, "Substract result overflow"); - return l_ret; - } - l_ret.u64[0] = a.u64[0] - b.u64[0]; - l_ret.u64[1] = a.u64[1] - b.u64[1]; - if (a.u64[1] < b.u64[1]) - l_ret.u64[0]--; - return l_ret; -#endif -} - -/** - * @brief dap_chain_balance_add - * @param a - * @param b - * @return - */ -uint128_t dap_uint128_add(uint128_t a, uint128_t b) -{ -#ifdef DAP_GLOBAL_IS_INT128 - uint128_t l_ret = a + b; - if (l_ret < a || l_ret < b) { - log_it(L_WARNING, "Sum result overflow"); - return 0; - } -#else - uint128_t l_ret = {}; - l_ret.u64[0] = a.u64[0] + b.u64[0]; - l_ret.u64[1] = a.u64[1] + b.u64[1]; - if (l_ret.u64[1] < a.u64[1] || l_ret.u64[1] < b.u64[1]) - l_ret.u64[0]++; - if (l_ret.u64[0] < a.u64[0] || l_ret.u64[0] < b.u64[0]) { - log_it(L_WARNING, "Sum result overflow"); - uint128_t l_nul = {}; - return l_nul; - } -#endif - return l_ret; -} - -/** - * @brief dap_uint128_check_equal - * @param a - * @param b - * @return - */ -bool dap_uint128_check_equal(uint128_t a, uint128_t b) -{ -#ifdef DAP_GLOBAL_IS_INT128 - return a == b; -#else - return a.u64[0]==b.u64[0] && a.u64[1]==b.u64[1]; -#endif - -} diff --git a/dap-sdk/core/test/math/unit_test.cpp b/dap-sdk/core/test/math/unit_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c37afbddb5e94e6f4367b2eb4c7a18ff1998f3e6 --- /dev/null +++ b/dap-sdk/core/test/math/unit_test.cpp @@ -0,0 +1,252 @@ +#include <boost/multiprecision/cpp_int.hpp> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include "dap_math_ops.h" +#include <cmath> +#include <iostream> +#include <fstream> + +int main() +{ + using namespace boost::multiprecision; + + //density constant value=2147483646 + std::uint64_t i; + std::uint64_t j; + std::uint64_t k; + std::uint64_t l; + std::uint64_t msb_one=0x7fffffffffffffff; + std::uint64_t lsb_one=1; + boost::uint64_t max_64=(std::numeric_limits<boost::uint64_t>::max)(); + int density_constant=40000; + //2147483646 + int density_index; + int error_counter_sum_64_128=0; + + + unsign256_t dap_test_256_one; + unsign256_t dap_test_256_two; + unsign256_t dap_test_256_sum; + int overflow_flag; + + //otherwise the sum structure is filled with garbage + dap_test_256_sum.lo.lo=0; + dap_test_256_sum.lo.hi=0; + dap_test_256_sum.hi.lo=0; + dap_test_256_sum.hi.hi=0; + + std::ofstream sum_256_256_file; + sum_256_256_file.open ("SUM_256_256.txt"); + + std::ofstream prod_64_128_file; + prod_64_128_file.open ("PROD_64_128.txt"); + + + uint128_t hi_64{"0xffffffffffffffff0000000000000000"}; + uint128_t lo_64{"0x0000000000000000ffffffffffffffff"}; + uint128_t max_128{"0xffffffffffffffffffffffffffffffff"}; + + uint128_t two_64{"0x000000000000000010000000000000000"}; + + + + uint256_t boost_two_64{"0x00000000000000000000000000000000010000000000000000"}; + uint256_t boost_two_128{"0x0000000000000000100000000000000000000000000000000"}; + uint256_t boost_two_192{"0x1000000000000000000000000000000000000000000000000"}; + + + + uint256_t boost_test_256_one; + uint256_t boost_test_256_two; + uint256_t boost_test_256_sum; + + uint256_t boost_dap_256_comparison; + + + + uint128_t boost_dap_64_128_comparison; + + int error_counter_sum=0; + int error_counter_prod=0; + int verbose_output=0; + + + for (density_index = 0; density_index<density_constant; density_index+=1000){ + + i=density_index; + j=2*density_index; + k=3*density_index; + l=4*density_index; + + dap_test_256_one.lo.lo=i; + dap_test_256_one.lo.hi=j; + dap_test_256_one.hi.lo=k; + dap_test_256_one.hi.hi=l; + + + uint256_t boost_test_256_one_coeff_2_0=i; + uint256_t boost_test_256_one_coeff_2_64=j; + uint256_t boost_test_256_one_coeff_2_128=k; + uint256_t boost_test_256_one_coeff_2_192=l; + + + + boost_test_256_one=boost_test_256_one_coeff_2_0 + boost_test_256_one_coeff_2_64*boost_two_64 + +boost_test_256_one_coeff_2_128*boost_two_128+boost_test_256_one_coeff_2_192*boost_two_192; + + + i=max_64-(density_index+1); + j=max_64-2*(density_index+1); + k=max_64-3*(density_index+1); + l=max_64-4*(density_index+1); + dap_test_256_two.lo.lo=i; + dap_test_256_two.lo.hi=j; + dap_test_256_two.hi.lo=k; + dap_test_256_two.hi.hi=l; + + uint256_t boost_test_256_two_coeff_2_0=i; + uint256_t boost_test_256_two_coeff_2_64=j; + uint256_t boost_test_256_two_coeff_2_128=k; + uint256_t boost_test_256_two_coeff_2_192=l; + + + boost_test_256_two=boost_test_256_two_coeff_2_0 + boost_test_256_two_coeff_2_64*boost_two_64 + +boost_test_256_two_coeff_2_128*boost_two_128+boost_test_256_two_coeff_2_192*boost_two_192; + + + +// add(boost_add_256, i, j); + overflow_flag=SUM_256_256(dap_test_256_one,dap_test_256_two,&dap_test_256_sum); + boost_test_256_sum=add(boost_test_256_sum,boost_test_256_one,boost_test_256_two); + + boost_dap_256_comparison=dap_test_256_sum.lo.lo+dap_test_256_sum.lo.hi*boost_two_64+ + dap_test_256_sum.hi.lo*boost_two_128+dap_test_256_sum.hi.hi*boost_two_192; + + if(boost_dap_256_comparison!=boost_test_256_sum){ + error_counter_sum+=1; + sum_256_256_file << "incorrect output for density index=" << std::endl; + sum_256_256_file << density_index << std::endl;} + + + +// unsign128_t dap_test_64_128_prod; +// uint128_t boost_test_64_128_prod; +// uint128_t boost_dap_128_prod_comparison; +// +// multiply(boost_test_64_128_prod, i, j); +// MULT_64_128(i,j,dap_test_64_128_prod); +// boost_dap_128_prod_comparison=dap_test_64_128_prod.lo+dap_test_64_128_prod.hi*hi_64; +// +// if(boost_dap_128_prod_comparison!=boost_test_64_128_prod){ +// error_counter_prod+=1;} + + + + if(verbose_output==1){ + + if(boost_dap_256_comparison!=boost_test_256_sum){ + + sum_256_256_file << "dap_test_256_one"<< std::endl; + + sum_256_256_file << (dap_test_256_one.lo.lo)<< std::endl; + sum_256_256_file << (dap_test_256_one.lo.hi)<< std::endl; + sum_256_256_file << (dap_test_256_one.hi.lo)<< std::endl; + sum_256_256_file << (dap_test_256_one.hi.hi)<< std::endl; + + + sum_256_256_file << "dap_test_256_two"<< std::endl; + + sum_256_256_file << (dap_test_256_two.lo.lo)<< std::endl; + sum_256_256_file << (dap_test_256_two.lo.hi)<< std::endl; + sum_256_256_file << (dap_test_256_two.hi.lo)<< std::endl; + sum_256_256_file << (dap_test_256_two.hi.hi)<< std::endl; + + sum_256_256_file << "dap_test_256_sum"<< std::endl; + + sum_256_256_file << (dap_test_256_sum.lo.lo)<< std::endl; + sum_256_256_file << (dap_test_256_sum.lo.hi)<< std::endl; + sum_256_256_file << (dap_test_256_sum.hi.lo)<< std::endl; + sum_256_256_file << (dap_test_256_sum.hi.hi)<< std::endl; + + sum_256_256_file << "boost_test_256_one"<< std::endl; + + sum_256_256_file << (boost_test_256_one)<< std::endl; + + sum_256_256_file << "boost_test_256_one factor 0"<< std::endl; + + sum_256_256_file << (boost_test_256_one_coeff_2_0)<< std::endl; + + sum_256_256_file << "boost_test_256_one factor 1"<< std::endl; + + sum_256_256_file << (boost_test_256_one_coeff_2_64*boost_two_64)<< std::endl; + + sum_256_256_file << "boost_test_256_one factor 2"<< std::endl; + + sum_256_256_file << (boost_test_256_one_coeff_2_128*boost_two_128)<< std::endl; + + + sum_256_256_file << "boost_test_256_one factor 3"<< std::endl; + + sum_256_256_file << (boost_test_256_one_coeff_2_192*boost_two_192)<< std::endl; + + + + sum_256_256_file << "boost_test_256_two"<< std::endl; + + sum_256_256_file << (boost_test_256_two)<< std::endl; + + + sum_256_256_file << "boost sum is"<< std::endl; + + + sum_256_256_file << (boost_test_256_sum)<< std::endl; + + sum_256_256_file << "boost comparison is"<< std::endl; + + + sum_256_256_file << (boost_dap_256_comparison)<< std::endl;} + + +// if(boost_dap_256_comparison!=boost_test_256_sum){ +// +// prod_64_128_file << "boost_dap_128_prod_comparison"<< std::endl; +// +// prod_64_128_file << (boost_dap_128_prod_comparison)<< std::endl; +// +// prod_64_128_file << "boost_test_64_128_prod"<< std::endl; +// +// prod_64_128_file << (boost_test_64_128_prod)<< std::endl; +// +//} +// + + + + + + +} + + + overflow_flag=0; + + } + + + sum_256_256_file.close(); + + if(error_counter_sum==0){ + + std::cout<< "SUM_256_256 returns identical results to boost:: 256 bit addition"<< std::endl;} + +// +// if(error_counter_prod==0){ +// +// std::cout<< "SUM_256_256 returns identical results to boost:: 256 bit addition"<< std::endl;} + + + return 0; +} + + diff --git a/modules/chain/dap_chain_ledger.c b/modules/chain/dap_chain_ledger.c index f5f6cad96fe314737b8a18574e8b5150665fadfa..4d501aeb19aa7f1266048d60ba2c9a05700e3449 100644 --- a/modules/chain/dap_chain_ledger.c +++ b/modules/chain/dap_chain_ledger.c @@ -2569,8 +2569,11 @@ uint128_t dap_chain_ledger_calc_balance_full(dap_ledger_t *a_ledger, const dap_c if(l_out_item_count >= MAX_OUT_ITEMS) { if(s_debug_more) log_it(L_ERROR, "Too many 'out' items=%d in transaction (max=%d)", l_out_item_count, MAX_OUT_ITEMS); - if (l_out_item_count >= MAX_OUT_ITEMS) - return 0; + if (l_out_item_count >= MAX_OUT_ITEMS){ + uint128_t l_ret; + memset(&l_ret,0,sizeof(l_ret)); + return l_ret; + } } int l_out_idx_tmp = 0; for (dap_list_t *l_list_tmp = l_list_out_items; l_list_tmp; l_list_tmp = dap_list_next(l_list_tmp), l_out_idx_tmp++) { diff --git a/modules/common/include/dap_chain_common.h b/modules/common/include/dap_chain_common.h index 6a94a2241f477e84a4bcb5b397b08017827c38f7..807079680d020d03bfe04f03c0a750c25e7ef697 100644 --- a/modules/common/include/dap_chain_common.h +++ b/modules/common/include/dap_chain_common.h @@ -246,7 +246,7 @@ DAP_STATIC_INLINE uint128_t dap_chain_uint128_from(uint64_t a_from) #ifdef DAP_GLOBAL_IS_INT128 return (uint128_t)a_from; #else - uint128_t l_ret = { .u64 = {0, a_from} }; + uint128_t l_ret = {{ .0, a_from}}; return l_ret; #endif } diff --git a/modules/net/dap_chain_node_cli_cmd_tx.c b/modules/net/dap_chain_node_cli_cmd_tx.c index 3885d764a163a0adedc5d79cbe6e1608c427e218..c528c8dd5b18b326294653931ade2469b3a08af7 100644 --- a/modules/net/dap_chain_node_cli_cmd_tx.c +++ b/modules/net/dap_chain_node_cli_cmd_tx.c @@ -1023,14 +1023,16 @@ static char* dap_db_history_token_list(dap_chain_t * a_chain, const char *a_toke break; case DAP_CHAIN_DATUM_TOKEN_TYPE_PUBLIC: { char *l_addr = dap_chain_addr_to_str(&l_token->header_public.premine_address); + char * l_balance = dap_chain_balance_to_coins(l_token->header_public.total_supply); dap_string_append_printf(l_str_out, - " total_supply: %.0llf(%llu), flags: 0x%x\n, premine_supply: %llu, premine_address '%s'\n", - l_token->header_public.total_supply / DATOSHI_LD, + " total_supply: %s (%llu), flags: 0x%x\n, premine_supply: %llu, premine_address '%s'\n", + l_balance, l_token->header_public.total_supply, l_token->header_public.flags, l_token->header_public.premine_supply, l_addr ? l_addr : "-"); DAP_DELETE(l_addr); + DAP_DELETE(l_balance); } break; default: @@ -1147,14 +1149,16 @@ static char* dap_db_history_filter(dap_chain_t * a_chain, dap_ledger_t *a_ledger break; case DAP_CHAIN_DATUM_TOKEN_TYPE_PUBLIC: { char *l_addr = dap_chain_addr_to_str(&l_token->header_public.premine_address); + char * l_balance = dap_chain_balance_to_coins(l_token->header_public.total_supply); dap_string_append_printf(l_str_out, - " total_supply: %.0llf(%llu), flags: 0x%x\n, premine_supply: %llu, premine_address '%s'\n", - l_token->header_public.total_supply / DATOSHI_LD, + " total_supply: %s (%llu), flags: 0x%x\n, premine_supply: %llu, premine_address '%s'\n", + l_balance, l_token->header_public.total_supply, l_token->header_public.flags, l_token->header_public.premine_supply, l_addr ? l_addr : "-"); DAP_DELETE(l_addr); + DAP_DELETE(l_balance); } break; default: diff --git a/modules/net/dap_chain_node_client.c b/modules/net/dap_chain_node_client.c index 093c84bc349c7ed500676c9015fa2a7f0b0a7de0..910b0c4ec6ea20459909ff31231eabae114fe578 100644 --- a/modules/net/dap_chain_node_client.c +++ b/modules/net/dap_chain_node_client.c @@ -84,7 +84,6 @@ typedef struct dap_chain_node_client_handle { static dap_chain_node_client_handle_t * s_clients = NULL; - //static int listen_port_tcp = 8079; static void s_stage_connected_callback(dap_client_t *a_client, void *a_arg); @@ -234,6 +233,7 @@ static bool s_timer_update_states_callback(void * a_arg ) } } } + // if we not returned yet l_me->state = NODE_CLIENT_STATE_DISCONNECTED; if (l_me->keep_connection) { @@ -593,11 +593,13 @@ dap_chain_node_client_t* dap_chain_node_client_create_n_connect(dap_chain_net_t return NULL; } dap_chain_node_client_t *l_node_client = DAP_NEW_Z(dap_chain_node_client_t); + l_node_client->state = NODE_CLIENT_STATE_DISCONNECTED; l_node_client->callbacks_arg = a_callback_arg; if(a_callbacks) memcpy(&l_node_client->callbacks,a_callbacks,sizeof (*a_callbacks)); l_node_client->info = a_node_info; + l_node_client->uuid = dap_uuid_generate_uint128(); l_node_client->net = a_net; l_node_client->uuid = dap_uuid_generate_uint128(); dap_chain_node_client_handle_t * l_client_handle = DAP_NEW_Z(dap_chain_node_client_handle_t); diff --git a/modules/net/include/dap_chain_node_client.h b/modules/net/include/dap_chain_node_client.h index 776f93ea224dc45a2ba9b7aa095526aef03efe84..d54907d2552c4d4f58ffff90921caa27cdff5b7e 100644 --- a/modules/net/include/dap_chain_node_client.h +++ b/modules/net/include/dap_chain_node_client.h @@ -67,7 +67,6 @@ typedef struct dap_chain_node_client_callbacks{ typedef struct dap_chain_node_client { dap_chain_node_client_state_t state; uint128_t uuid; - bool sync_gdb; bool sync_chains; @@ -119,6 +118,7 @@ typedef struct dap_chain_node_client { dap_chain_node_client_callbacks_t callbacks; void * callbacks_arg; } dap_chain_node_client_t; + #define DAP_CHAIN_NODE_CLIENT(a) (a ? (dap_chain_node_client_t *) (a)->_inheritor : NULL) int dap_chain_node_client_init(void);