Skip to content

Commit

Permalink
Merge pull request #176 from gogoex/python-dlopen-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
aguycalled authored Jan 6, 2025
2 parents a7ff776 + 2e0470b commit d83fbfa
Show file tree
Hide file tree
Showing 12 changed files with 257 additions and 186 deletions.
5 changes: 4 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ BLSCT_H = \
blsct/building_block/lazy_points.h \
blsct/building_block/pedersen_commitment.h \
blsct/building_block/weighted_inner_prod_arg.h \
blsct/chain.h \
blsct/common.h \
blsct/double_public_key.h \
blsct/eip_2333/bls12_381_keygen.h \
Expand Down Expand Up @@ -226,6 +227,7 @@ BLSCT_CPP = \
blsct/building_block/lazy_point.cpp \
blsct/building_block/lazy_points.cpp \
blsct/building_block/weighted_inner_prod_arg.cpp \
blsct/chain.cpp \
blsct/common.cpp \
blsct/double_public_key.cpp \
blsct/eip_2333/bls12_381_keygen.cpp \
Expand Down Expand Up @@ -1478,6 +1480,7 @@ libblsct_a_SOURCES = \
support/cleanse.cpp \
support/lockedpool.cpp \
uint256.cpp \
util/moneystr.cpp \
util/rbf.cpp \
util/strencodings.cpp \
util/time.cpp \
Expand Down Expand Up @@ -1517,7 +1520,7 @@ libunivalue_blsct_a_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/$(UNIVALUE_INCLUDE_DIR
libunivalue_blsct_a_CXXFLAGS = $(AM_CXXFLAGS) -fPIC

libblsct_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -fPIC
libblsct_a_CPPFLAGS = $(AM_CPPFLAGS) $(BLS_INCLUDES) $(BOOST_CPPFLAGS) -I$(srcdir)/$(UNIVALUE_INCLUDE_DIR_INT)
libblsct_a_CPPFLAGS = $(AM_CPPFLAGS) $(BLS_INCLUDES) $(BOOST_CPPFLAGS) -DLIBBLSCT -I$(srcdir)/$(UNIVALUE_INCLUDE_DIR_INT)

if ENABLE_SSE41
libblsct_a_CXXFLAGS += $(SSE41_CXXFLAGS)
Expand Down
185 changes: 93 additions & 92 deletions src/bls/src/proj/bls384_256.vcxproj
Original file line number Diff line number Diff line change
@@ -1,92 +1,93 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.3" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{1DBB979A-C212-45CD-9563-446A96F87F72}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>ec_test</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(SolutionDir)common.props" />
<Import Project="$(SolutionDir)debug.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(SolutionDir)common.props" />
<Import Project="$(SolutionDir)release.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<TargetExt>.lib</TargetExt>
<OutDir>$(SolutionDir)lib\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<TargetExt>.lib</TargetExt>
<OutDir>$(SolutionDir)lib\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="$(SolutionDir)..\src\bls\src\bls_c384_256.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.3" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{1DBB979A-C212-45CD-9563-446A96F87F72}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>ec_test</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(SolutionDir)common.props" />
<Import Project="$(SolutionDir)debug.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(SolutionDir)common.props" />
<Import Project="$(SolutionDir)release.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<TargetExt>.lib</TargetExt>
<OutDir>$(SolutionDir)lib\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<TargetExt>.lib</TargetExt>
<OutDir>$(SolutionDir)lib\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>$(SolutionDir)mcl\lib\mcl.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="$(SolutionDir)..\src\bls\src\bls_c384_256.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
42 changes: 42 additions & 0 deletions src/blsct/chain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2025 The Navio developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <blsct/chain.h>
#include <blsct/key_io.h>
#include <mutex>

static std::string g_chain;
static std::mutex g_set_chain_mutex;

const std::string& get_chain() {
return g_chain;
}

bool set_chain(enum Chain chain)
{
std::lock_guard<std::mutex> lock(g_set_chain_mutex);
if (!g_chain.empty()) {
return false;
}

switch (chain) {
case MainNet:
g_chain = blsct::bech32_hrp::Main;
break;

case TestNet:
g_chain = blsct::bech32_hrp::TestNet;
break;

case SigNet:
g_chain = blsct::bech32_hrp::SigNet;
break;

case RegTest:
g_chain = blsct::bech32_hrp::RegTest;
break;
}
return true;
}

30 changes: 30 additions & 0 deletions src/blsct/chain.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2025 The Navio developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef NAVIO_BLSCT_CHAIN_H
#define NAVIO_BLSCT_CHAIN_H

#include <string>

const std::string& get_chain();

#ifdef __cplusplus
extern "C" {
#endif

enum Chain {
MainNet,
TestNet,
SigNet,
RegTest
};

bool set_chain(enum Chain chain);

#ifdef __cplusplus
} // extern "C"
#endif

#endif // NAVIO_BLSCT_CHAIN_H

46 changes: 8 additions & 38 deletions src/blsct/external_api/blsct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <blsct/wallet/address.h>
#include <blsct/wallet/helpers.h>
#include <blsct/wallet/txfactory_base.h>
#include <common/args.h>
#include <common/url.h>
#include <crypto/common.h>
#include <memory.h>
Expand All @@ -28,16 +27,12 @@
#include <optional>
#include <string>

static std::string g_chain;
static std::mutex g_init_mutex;
static std::mutex g_set_chain_mutex;
static bulletproofs::RangeProofLogic<Mcl>* g_rpl;
static bool g_is_little_endian;

const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
UrlDecodeFn* const URL_DECODE = urlDecode;

extern "C" {
UrlDecodeFn* const URL_DECODE = nullptr;

static bool is_little_endian() {
uint16_t n = 1;
Expand All @@ -51,38 +46,13 @@ void init()

Mcl::Init for_side_effect_only;

g_chain = blsct::bech32_hrp::Main;
if (!set_chain(Chain::MainNet)) {
throw std::runtime_error("Chain has already been set");
}
g_is_little_endian = is_little_endian();
g_rpl = new(std::nothrow) bulletproofs::RangeProofLogic<Mcl>();
}

bool set_chain(enum Chain chain)
{
std::lock_guard<std::mutex> lock(g_set_chain_mutex);
if (!g_chain.empty()) {
return false;
}

switch (chain) {
case MainNet:
g_chain = blsct::bech32_hrp::Main;
break;

case TestNet:
g_chain = blsct::bech32_hrp::TestNet;
break;

case SigNet:
g_chain = blsct::bech32_hrp::SigNet;
break;

case RegTest:
g_chain = blsct::bech32_hrp::RegTest;
break;
}
return true;
}

BlsctRetVal* succ(
void* value,
size_t value_size
Expand Down Expand Up @@ -226,7 +196,8 @@ BlsctRetVal* decode_address(
return err(BLSCT_BAD_DPK_SIZE);
}
std::string enc_addr(blsct_enc_addr);
auto maybe_dpk = blsct::DecodeDoublePublicKey(g_chain, enc_addr);
auto chain = get_chain();
auto maybe_dpk = blsct::DecodeDoublePublicKey(chain, enc_addr);
if (maybe_dpk) {
auto dpk = maybe_dpk.value();
if (dpk.IsValid()) {
Expand Down Expand Up @@ -259,7 +230,8 @@ BlsctRetVal* encode_address(

auto bech32_encoding = encoding == Bech32 ?
bech32_mod::Encoding::BECH32 : bech32_mod::Encoding::BECH32M;
auto enc_dpk_str = EncodeDoublePublicKey(g_chain, bech32_encoding, dpk);
auto chain = get_chain();
auto enc_dpk_str = EncodeDoublePublicKey(chain, bech32_encoding, dpk);
size_t BUF_SIZE = enc_dpk_str.size() + 1;
MALLOC_BYTES(char, enc_addr, BUF_SIZE);
RETURN_ERR_IF_MEM_ALLOC_FAILED(enc_addr);
Expand Down Expand Up @@ -1283,5 +1255,3 @@ BlsctDoublePubKey* gen_dpk_with_keys_and_sub_addr_id(
return blsct_dpk;
}

} // extern "C"

Loading

0 comments on commit d83fbfa

Please sign in to comment.