Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

feature(crypto): vm-exec tool to run smart contracts locally #51

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
28 changes: 24 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)


#set(OPENSSL_ROOT_DIR "/opt/homebrew/opt/openssl/")
#set(GSL_ROOT_DIR "/opt/homebrew/opt/gsl/")
if(EMSCRIPTEN)
set(OPENSSL_FOUND "1")
set(OPENSSL_ROOT_DIR "/Users/altox/Desktop/openssl/openssl-1.1.1d/")
set(OPENSSL_INCLUDE_DIR "/Users/altox/Desktop/openssl/openssl-1.1.1d/include/")
set(OPENSSL_CRYPTO_LIBRARY "/Users/altox/Desktop/openssl/openssl-1.1.1d/libcrypto.a")
set(OPENSSL_SSL_LIBRARY "/Users/altox/Desktop/openssl/openssl-1.1.1d/libssl.a")
set(OPENSSL_LIBRARIES "${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY}")

set(ZLIB_LIBRARY /Users/altox/Desktop/zlib/)
set(ZLIB_INCLUDE_DIR /Users/altox/Desktop/zlib/)
else()
set(OPENSSL_ROOT_DIR "/opt/homebrew/opt/openssl/")
set(GSL_ROOT_DIR "/opt/homebrew/opt/gsl/")
endif()



project(TON VERSION 0.5 LANGUAGES C CXX)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
#set(OPENSSL_USE_STATIC_LIBS TRUE)
Expand Down Expand Up @@ -80,7 +100,7 @@ else()
endif()

#BEGIN internal
option(TON_ONLY_TONLIB "Use \"ON\" to build only tonlib." OFF)
option(TON_ONLY_TONLIB "Use \"ON\" to build only tonlib." ON)
if (TON_ONLY_TONLIB)
set(NOT_TON_ONLY_TONLIB false)
else()
Expand Down Expand Up @@ -204,7 +224,7 @@ find_package(Threads REQUIRED)
find_package(ZLIB REQUIRED)

if (TON_ARCH AND NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=${TON_ARCH}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()
if (THREADS_HAVE_PTHREAD_ARG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
Expand Down Expand Up @@ -245,10 +265,10 @@ elseif (CLANG OR GCC)
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -fvisibility=hidden -Wl,-dead_strip,-x,-S")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections -Wl,--exclude-libs,ALL")
# set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections -Wl,--exclude-libs,ALL")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
if (NOT TON_USE_ASAN AND NOT TON_USE_TSAN AND NOT MEMPROF)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--exclude-libs,ALL")
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--exclude-libs,ALL")
endif()
endif()
elseif (INTEL)
Expand Down
38 changes: 37 additions & 1 deletion crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,42 @@ if (WINGETOPT_FOUND)
target_link_libraries_system(tlbc wingetopt)
endif()

add_executable(vm-exec vm-exec/vm-exec.cpp vm-exec/StringLog.h vm-exec/common.cpp vm-exec/common.h)
target_include_directories(vm-exec PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_link_libraries(vm-exec PUBLIC ton_crypto terminal)
if(EMSCRIPTEN)
target_link_options(vm-exec PRIVATE -sEXPORTED_RUNTIME_METHODS=free,allocate,intArrayFromString,ALLOC_NORMAL,UTF8ToString)
target_link_options(vm-exec PRIVATE -sEXPORTED_FUNCTIONS=_vm_exec,_free)
target_link_options(vm-exec PRIVATE -sERROR_ON_UNDEFINED_SYMBOLS=0)
target_link_options(vm-exec PRIVATE -sFILESYSTEM=0)
target_link_options(vm-exec PRIVATE -Oz)
target_link_options(vm-exec PRIVATE -sIGNORE_MISSING_MAIN=1)
target_link_options(vm-exec PRIVATE -sAUTO_NATIVE_LIBRARIES=0)
target_link_options(vm-exec PRIVATE -sMODULARIZE=1)
target_compile_options(vm-exec PRIVATE -sNO_DISABLE_EXCEPTION_CATCHING)
endif()
if (WINGETOPT_FOUND)
target_link_libraries_system(func wingetop ton_crypto tdutils ton_crypto fift-lib)
endif()

add_library(vm-exec-lib SHARED vm-exec/vm-exec-lib.cpp vm-exec/StringLog.h vm-exec/common.cpp vm-exec/common.h)
target_link_libraries(vm-exec-lib PUBLIC ton_crypto terminal)
if(EMSCRIPTEN)
target_link_options(vm-exec-lib PRIVATE -sEXPORTED_RUNTIME_METHODS=ccall,cwrap,allocate,intArrayFromString,ALLOC_NORMAL,UTF8ToString)
target_link_options(vm-exec-lib PRIVATE -sMAIN_MODULE)
target_link_options(vm-exec-lib PRIVATE -sERROR_ON_UNDEFINED_SYMBOLS=0)
target_link_options(vm-exec-lib PRIVATE -sNO_DISABLE_EXCEPTION_CATCHING)
target_compile_options(vm-exec-lib PRIVATE -sNO_DISABLE_EXCEPTION_CATCHING)
endif()
set_target_properties(vm-exec-lib PROPERTIES LINK_FLAGS "-Wl,-exported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/vm-exec/vm-exec-lib_export_list")

add_executable(wallet_gen wallet_gen/wallet_gen.cpp)
target_include_directories(wallet_gen PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_link_libraries(wallet_gen PUBLIC ton_crypto tonlib terminal)
if (WINGETOPT_FOUND)
target_link_libraries_system(func wingetop ton_crypto tdutils ton_crypto fift-lib)
endif()

add_library(pow-miner-lib util/Miner.cpp util/Miner.h)
target_include_directories(pow-miner-lib PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_link_libraries(pow-miner-lib PUBLIC ton_crypto ton_block)
Expand Down Expand Up @@ -407,7 +443,7 @@ target_include_directories(create-state PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT
if (INTERNAL_COMPILE)
target_link_libraries(create-state PUBLIC ton_crypto fift-lib ton_block tonlib git)
else()
if (TONLIB_COMPILE)
if (TONLIB_COMPILE)
target_link_libraries(create-state PUBLIC ton_crypto fift-lib ton_block tonlib git)
else()
target_link_libraries(create-state PUBLIC ton_crypto fift-lib ton_block git)
Expand Down
39 changes: 39 additions & 0 deletions crypto/vm-exec/StringLog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// Created by Narek Abovyan on 22.02.2022.
//


#ifndef TON_STRINGLOG_H
#define TON_STRINGLOG_H

#include <thread>


class StringLog : public td::LogInterface {
public:
StringLog() {
}

void append(td::CSlice new_slice, int log_level) override {
lock.lock();
this->str.append(new_slice.str());
lock.unlock();
}

void rotate() override {
}

void clear() {
this->str.clear();
}

std::string get_string() const {
return this->str;
}

private:
std::string str;
std::mutex lock;
};

#endif //TON_STRINGLOG_H
Loading